Class: Lighthouse::LettersGenerator::Configuration
Constant Summary
collapse
- SETTINGS =
Settings.lighthouse.letters_generator
- SCOPES =
%w[letters.read].freeze
Instance Attribute Summary
#base_request_headers, #open_timeout, #read_timeout, #request_types, #user_agent
Instance Method Summary
collapse
#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
#connection ⇒ Object
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: , 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_url ⇒ Object
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_token ⇒ Object
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_name ⇒ Object
25
26
27
|
# File 'lib/lighthouse/letters_generator/configuration.rb', line 25
def service_name
'Lighthouse_LettersGenerator'
end
|
#token_service ⇒ Object
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.
45
46
47
|
# File 'lib/lighthouse/letters_generator/configuration.rb', line 45
def use_mocks?
SETTINGS.use_mocks || false
end
|