Class: Lighthouse::LettersGenerator::Configuration

Inherits:
Common::Client::Configuration::REST show all
Defined in:
lib/lighthouse/letters_generator/configuration.rb

Constant Summary collapse

SETTINGS =
Settings.lighthouse.letters_generator
SCOPES =
%w[letters.read].freeze

Instance Attribute Summary

Attributes inherited from Common::Client::Configuration::Base

#base_request_headers, #open_timeout, #read_timeout, #request_types, #user_agent

Instance Method Summary collapse

Methods inherited from Common::Client::Configuration::Base

#base_path, #breakers_error_threshold, #breakers_exception_handler, #breakers_matcher, #breakers_service, #create_new_breakers_service, #current_module, #request_options, #service_exception

Instance Method Details

#connectionObject



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/lighthouse/letters_generator/configuration.rb', line 29

def connection
  @conn ||= Faraday.new(generator_url, headers: base_request_headers, request: request_options) do |faraday|
    faraday.use      :breakers
    faraday.use      Faraday::Response::RaiseError

    faraday.request :json

    faraday.response :betamocks if use_mocks?
    faraday.response :json, content_type: /\bjson/
    faraday.adapter Faraday.default_adapter
  end
end

#generator_urlObject



21
22
23
# File 'lib/lighthouse/letters_generator/configuration.rb', line 21

def generator_url
  URI path_join(SETTINGS.url, SETTINGS.path)
end

#get_access_tokenObject



49
50
51
# File 'lib/lighthouse/letters_generator/configuration.rb', line 49

def get_access_token
  use_mocks? ? '' : token_service.get_token
end

#path_join(*paths) ⇒ Object



14
15
16
17
18
19
# File 'lib/lighthouse/letters_generator/configuration.rb', line 14

def path_join(*paths)
  paths.reduce('') do |acc, p|
    trimmed_slash = p.gsub(%r{(^/+|/+$)}, '')
    acc + "#{trimmed_slash}/"
  end.chop!
end

#service_nameObject



25
26
27
# File 'lib/lighthouse/letters_generator/configuration.rb', line 25

def service_name
  'Lighthouse_LettersGenerator'
end

#token_serviceObject



53
54
55
56
57
58
59
60
# File 'lib/lighthouse/letters_generator/configuration.rb', line 53

def token_service
  token = SETTINGS.access_token
  url = URI path_join(SETTINGS.url, token.path)

  @token_service ||= Auth::ClientCredentials::Service.new(
    url, SCOPES, token.client_id, token.aud_claim_url, token.rsa_key, 'letters_generator'
  )
end

#use_mocks?Boolean

Returns Should the service use mock data in lower environments.

Returns:

  • (Boolean)

    Should the service use mock data in lower environments.



45
46
47
# File 'lib/lighthouse/letters_generator/configuration.rb', line 45

def use_mocks?
  SETTINGS.use_mocks || false
end