Class: BenefitsIntake::Configuration

Inherits:
Common::Client::Configuration::REST show all
Defined in:
lib/lighthouse/benefits_intake/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.

Instance Attribute Summary

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

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

Class Method Summary collapse

Instance Method Summary collapse

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

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

Class Method Details

.base_request_headersHash

Returns The basic headers required for any Lighthouse API call.

Returns:

  • (Hash)

    The basic headers required for any Lighthouse API call



39
40
41
42
43
44
# File 'lib/lighthouse/benefits_intake/configuration.rb', line 39

def self.base_request_headers
  key = Settings.lighthouse.benefits_intake.api_key
  raise "No api_key set for benefits_intake. Please set 'lighthouse.benefits_intake.api_key'" if key.nil?

  super.merge('apikey' => key)
end

Instance Method Details

#breakers_error_thresholdObject



72
73
74
# File 'lib/lighthouse/benefits_intake/configuration.rb', line 72

def breakers_error_threshold
  80 # breakers will be tripped if error rate reaches 80% over a two minute period.
end

#connectionFaraday::Connection

Creates a connection with json parsing and breaker functionality.

Returns:

  • (Faraday::Connection)

    a Faraday connection instance.



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/lighthouse/benefits_intake/configuration.rb', line 51

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

    faraday.request :multipart
    faraday.request :json

    faraday.response :betamocks if use_mocks?
    faraday.response :json
    faraday.adapter Faraday.default_adapter
  end
end

#intake_settingsConfig::Options

Returns Settings for benefits_claims API.

Returns:

  • (Config::Options)

    Settings for benefits_claims API.



17
18
19
# File 'lib/lighthouse/benefits_intake/configuration.rb', line 17

def intake_settings
  Settings.lighthouse.benefits_intake
end

#service_nameString

Returns Service name to use in breakers and metrics.

Returns:

  • (String)

    Service name to use in breakers and metrics.



32
33
34
# File 'lib/lighthouse/benefits_intake/configuration.rb', line 32

def service_name
  'BenefitsIntake'
end

#service_pathString

Returns Base path.

Returns:

  • (String)

    Base path.



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

def service_path
  url = [intake_settings.host, intake_settings.path, intake_settings.version]
  url.map { |segment| segment.sub(%r{^/}, '').chomp('/') }.join('/')
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.



68
69
70
# File 'lib/lighthouse/benefits_intake/configuration.rb', line 68

def use_mocks?
  intake_settings.use_mocks || false
end