Class: SabyVok::Auth

Inherits:
Object
  • Object
show all
Includes:
Mutex_m
Defined in:
lib/saby_vok/auth.rb

Constant Summary collapse

JSON_HEADERS =
{ "Content-Type" => "application/json; charset=utf-8" }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(credentials:, oauth_url:, timeout:, logger: nil) ⇒ Auth

Returns a new instance of Auth.

Parameters:

  • credentials (Hash, #to_h)

    keys :client_id, :client_secret, :secret_key

  • oauth_url (String)

    OAuth endpoint URL

  • timeout (Integer)

    request timeout in seconds

  • logger (Logger, nil) (defaults to: nil)


18
19
20
21
22
23
24
25
26
27
28
# File 'lib/saby_vok/auth.rb', line 18

def initialize(credentials:, oauth_url:, timeout:, logger: nil)
  super() # Mutex_m init
  creds = normalize_credentials(credentials)
  @client_id = creds.fetch(:client_id)
  @client_secret = creds.fetch(:client_secret)
  @secret_key = creds.fetch(:secret_key)
  @oauth_uri = URI(oauth_url)
  @timeout = timeout
  @logger = logger
  @tokens = nil
end

Instance Method Details

#invalidate!void

This method returns an undefined value.



45
46
47
48
49
# File 'lib/saby_vok/auth.rb', line 45

def invalidate!
  synchronize do
    @tokens = nil
  end
end

#refresh!Hash{Symbol=>String}

Returns refreshed tokens.

Returns:

  • (Hash{Symbol=>String})

    refreshed tokens



38
39
40
41
42
# File 'lib/saby_vok/auth.rb', line 38

def refresh!
  synchronize do
    @tokens = obtain_tokens
  end
end

#tokensHash{Symbol=>String}

Returns :access_token and :session_id.

Returns:

  • (Hash{Symbol=>String})

    :access_token and :session_id



31
32
33
34
35
# File 'lib/saby_vok/auth.rb', line 31

def tokens
  synchronize do
    @tokens ||= obtain_tokens
  end
end