Class: BenefitsReferenceData::Configuration

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

#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 benefits_reference_data API call.

Returns:

  • (Hash)

    The basic headers required for any benefits_reference_data API call.



35
36
37
38
39
40
# File 'lib/lighthouse/benefits_reference_data/configuration.rb', line 35

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

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

Instance Method Details

#base_pathString

Returns Base path for benefits_reference_data URLs.

Returns:

  • (String)

    Base path for benefits_reference_data URLs.



17
18
19
20
21
22
23
# File 'lib/lighthouse/benefits_reference_data/configuration.rb', line 17

def base_path
  settings = Settings.lighthouse.benefits_reference_data
  url = settings.url
  path = settings.path
  version = settings.version
  safe_slash_merge(url, path, version)
end

#breakers_error_thresholdObject



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

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

#connectionFaraday::Connection

Creates the a connection with parsing json and adding breakers functionality.

Returns:

  • (Faraday::Connection)

    a Faraday connection instance.



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/lighthouse/benefits_reference_data/configuration.rb', line 47

def connection
  @conn ||= Faraday.new(base_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 mock_enabled?
    faraday.response :json
    faraday.adapter Faraday.default_adapter
  end
end

#mock_enabled?Boolean

Returns Should the service use mock data in lower environments.

Returns:

  • (Boolean)

    Should the service use mock data in lower environments.



64
65
66
# File 'lib/lighthouse/benefits_reference_data/configuration.rb', line 64

def mock_enabled?
  Settings.lighthouse.benefits_reference_data.mock || false
end

#safe_slash_merge(*url_segments) ⇒ Object (private)



74
75
76
# File 'lib/lighthouse/benefits_reference_data/configuration.rb', line 74

def safe_slash_merge(*url_segments)
  url_segments.map { |segment| segment.sub(%r{^/}, '').chomp('/') }.join('/')
end

#service_nameString

Returns Service name to use in breakers and metrics.

Returns:

  • (String)

    Service name to use in breakers and metrics.



28
29
30
# File 'lib/lighthouse/benefits_reference_data/configuration.rb', line 28

def service_name
  'BenefitsReferenceData'
end