Class: DirectDeposit::Configuration
- Inherits:
-
Common::Client::Configuration::REST
- Object
- Common::Client::Configuration::Base
- Common::Client::Configuration::REST
- DirectDeposit::Configuration
- Defined in:
- lib/lighthouse/direct_deposit/configuration.rb
Overview
HTTP client configuration for the Service, sets the base path, the base request headers, and a service name for breakers and metrics.
Constant Summary collapse
- API_SCOPES =
%w[direct.deposit.read direct.deposit.write].freeze
- DIRECT_DEPOSIT_PATH =
'services/direct-deposit-management/v1/direct-deposit'
- TOKEN_PATH =
'oauth2/direct-deposit-management/system/v1/token'
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
- #access_token ⇒ Object
-
#base_path ⇒ String
Base path for direct_deposit URLs.
-
#connection ⇒ Faraday::Connection
Creates a Faraday connection with parsing json and breakers functionality.
-
#get(path, params = {}) ⇒ Faraday::Response
Response from GET request.
- #get_access_token? ⇒ Boolean private
-
#put(path, body = {}) ⇒ Faraday::Response
Response from POST request.
-
#service_name ⇒ String
Service name to use in breakers and metrics.
-
#settings ⇒ Config::Options
Settings for direct_deposit API.
-
#token_service ⇒ Auth::ClientCredentials::Service
private
Service used to generate access tokens.
-
#use_mocks? ⇒ Boolean
private
Should the service use mock data in lower environments.
Methods inherited from Common::Client::Configuration::Base
#breakers_error_threshold, #breakers_exception_handler, #breakers_matcher, #breakers_service, #create_new_breakers_service, #current_module, #request_options, #service_exception
Instance Method Details
#access_token ⇒ Object
73 74 75 |
# File 'lib/lighthouse/direct_deposit/configuration.rb', line 73 def access_token token_service.get_token if get_access_token? end |
#base_path ⇒ String
Returns Base path for direct_deposit URLs.
29 30 31 |
# File 'lib/lighthouse/direct_deposit/configuration.rb', line 29 def base_path "#{settings.host}/#{DIRECT_DEPOSIT_PATH}" end |
#connection ⇒ Faraday::Connection
Creates a Faraday connection with parsing json and breakers functionality.
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/lighthouse/direct_deposit/configuration.rb', line 59 def connection @conn ||= Faraday.new(base_path, headers: base_request_headers, request: ) do |faraday| faraday.use :breakers faraday.use Faraday::Response::RaiseError faraday.request :json faraday.response :betamocks if use_mocks? faraday.response :snakecase, symbolize: false faraday.response :json, content_type: /\bjson/ faraday.adapter Faraday.default_adapter end end |
#get(path, params = {}) ⇒ Faraday::Response
Returns response from GET request.
43 44 45 |
# File 'lib/lighthouse/direct_deposit/configuration.rb', line 43 def get(path, params = {}) connection.get(path, params, { Authorization: "Bearer #{access_token}" }) end |
#get_access_token? ⇒ Boolean (private)
86 87 88 |
# File 'lib/lighthouse/direct_deposit/configuration.rb', line 86 def get_access_token? !use_mocks? || Settings.betamocks.recording end |
#put(path, body = {}) ⇒ Faraday::Response
Returns response from POST request.
50 51 52 |
# File 'lib/lighthouse/direct_deposit/configuration.rb', line 50 def put(path, body = {}) connection.put(path, body, { Authorization: "Bearer #{access_token}" }) end |
#service_name ⇒ String
Returns Service name to use in breakers and metrics.
36 37 38 |
# File 'lib/lighthouse/direct_deposit/configuration.rb', line 36 def service_name 'LIGHTHOUSE_DIRECT_DEPOSIT' end |
#settings ⇒ Config::Options
Returns Settings for direct_deposit API.
22 23 24 |
# File 'lib/lighthouse/direct_deposit/configuration.rb', line 22 def settings Settings.lighthouse.direct_deposit end |
#token_service ⇒ Auth::ClientCredentials::Service (private)
Returns Service used to generate access tokens.
93 94 95 96 97 98 99 100 |
# File 'lib/lighthouse/direct_deposit/configuration.rb', line 93 def token_service url = "#{settings.host}/#{TOKEN_PATH}" token = settings.access_token @token_service ||= Auth::ClientCredentials::Service.new( url, API_SCOPES, token.client_id, token.aud_claim_url, token.rsa_key, 'direct-deposit' ) end |
#use_mocks? ⇒ Boolean (private)
Returns Should the service use mock data in lower environments.
82 83 84 |
# File 'lib/lighthouse/direct_deposit/configuration.rb', line 82 def use_mocks? settings.use_mocks || false end |