Method: Booker::Client#initialize

Defined in:
lib/booker/client.rb

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/booker/client.rb', line 29

def initialize(options = {})
  options.each { |key, value| send(:"#{key}=", value) }
  self.request_timeout ||= DEFAULT_REQUEST_TIMEOUT
  self.base_url ||= get_base_url
  self.auth_base_url ||= ENV['BOOKER_API_BASE_URL'] || DEFAULT_AUTH_BASE_URL
  self.client_id ||= ENV['BOOKER_CLIENT_ID']
  self.client_secret ||= ENV['BOOKER_CLIENT_SECRET']
  self.api_subscription_key ||= ENV['BOOKER_API_SUBSCRIPTION_KEY']
  if self.auth_with_client_credentials.nil?
    self.auth_with_client_credentials = ENV['BOOKER_API_AUTH_WITH_CLIENT_CREDENTIALS'] == 'true'
  end
  if self.temp_access_token.present?
    begin
      self.temp_access_token_expires_at = token_expires_at(self.temp_access_token)
      self.access_token_scope = token_scope(self.temp_access_token)
    rescue JWT::ExpiredSignature => ex
      raise ex unless self.auth_with_client_credentials || self.refresh_token.present?
    end
  end
  if self.access_token_scope.blank?
    self.access_token_scope = VALID_ACCESS_TOKEN_SCOPES.first
  elsif !self.access_token_scope.in?(VALID_ACCESS_TOKEN_SCOPES)
    raise ArgumentError, "access_token_scope must be one of: #{VALID_ACCESS_TOKEN_SCOPES.join(', ')}"
  end
end