class BambooId::ApiKeyFetcher

Attributes

code[RW]
error[RW]
subdomain[RW]

Public Class Methods

new(code:, subdomain:) click to toggle source
# File lib/bamboo_id/api_key_fetcher.rb, line 5
def initialize(code:, subdomain:)
  self.code      = code
  self.subdomain = subdomain
  self.error     = nil
end

Public Instance Methods

fetch() click to toggle source
# File lib/bamboo_id/api_key_fetcher.rb, line 11
def fetch
  unless access_token_request.successful?
    self.error = "Could not get access token: #{access_token_request.error}"
    return false
  end

  unless api_key_request.successful?
    self.error = "Could not get API key."
    return false
  end

  api_key_request.key
end

Private Instance Methods

access_token_request() click to toggle source
# File lib/bamboo_id/api_key_fetcher.rb, line 31
def access_token_request
  @access_token_request ||= Requests::AccessTokenRequest.new(
    temporary_code: code,
    subdomain: subdomain
  )
end
api_key_request() click to toggle source
# File lib/bamboo_id/api_key_fetcher.rb, line 38
def api_key_request
  @api_key_request ||= Requests::ApiKeyRequest.new(
    id_token: access_token_request.id_token,
    subdomain: subdomain
  )
end