Class: BenefitsEducation::Configuration

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

SYSTEM_NAME =
'VA.gov'
TOKEN_PATH =
'oauth2/benefits-education/system/v1/token'
API_PATH =
'services/benefits-education/v1/education/chapter33'
API_SCOPES =
%w[education.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

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

Instance Method Details

#access_tokenString (private)

Returns a Bearer token to be included in requests to the Lighthouse API.

Returns:

  • (String)

    a Bearer token to be included in requests to the Lighthouse API



84
85
86
# File 'lib/lighthouse/benefits_education/configuration.rb', line 84

def access_token
  token_service.get_token if get_access_token?
end

#base_pathString

Returns API endpoint for benefits_education.

Returns:

  • (String)

    API endpoint for benefits_education



30
31
32
# File 'lib/lighthouse/benefits_education/configuration.rb', line 30

def base_path
  "#{benefits_education_settings.host}/#{API_PATH}"
end

#benefits_education_settingsConfig::Options

Returns Settings for Lighthouse benefits_education API.

Returns:

  • (Config::Options)

    Settings for Lighthouse benefits_education API.



23
24
25
# File 'lib/lighthouse/benefits_education/configuration.rb', line 23

def benefits_education_settings
  Settings.lighthouse.benefits_education
end

#connectionFaraday::Connection

Creates a Faraday connection with parsing json and breakers functionality.

Returns:

  • (Faraday::Connection)

    a Faraday connection instance.



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/lighthouse/benefits_education/configuration.rb', line 53

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 use_mocks?
    faraday.response :json, content_type: /\bjson/
    faraday.adapter Faraday.default_adapter
  end
end

#get(icn) ⇒ Faraday::Response

Returns response from GET request: A veteran’s education benefits.

Parameters:

  • icn: (String)

    Veteran’s icn

Returns:

  • (Faraday::Response)

    response from GET request: A veteran’s education benefits



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

def get(icn)
  connection.get('', { icn: }, { Authorization: "Bearer #{access_token}" })
end

#get_access_token?Boolean (private)

Returns Should the service make a call out to retrieve an access token.

Returns:

  • (Boolean)

    Should the service make a call out to retrieve an access token



78
79
80
# File 'lib/lighthouse/benefits_education/configuration.rb', line 78

def get_access_token?
  !use_mocks? || Settings.betamocks.recording
end

#service_nameString

Returns Service name to use in breakers and metrics.

Returns:

  • (String)

    Service name to use in breakers and metrics.



37
38
39
# File 'lib/lighthouse/benefits_education/configuration.rb', line 37

def service_name
  'BENEFITS_EDUCATION'
end

#token_serviceAuth::ClientCredentials::Service (private)

Returns Service used to generate access token, used when making a request to the Lighthouse API.

Returns:



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/lighthouse/benefits_education/configuration.rb', line 92

def token_service
  lighthouse_client_id = benefits_education_settings.access_token.client_id
  lighthouse_rsa_key_path = benefits_education_settings.access_token.rsa_key
  token_url = "#{benefits_education_settings.host}/#{TOKEN_PATH}"

  # aud_claim_url found here:
  # https://developer.va.gov/explore/api/education-benefits/client-credentials#:~:text=Description-,aud,-True
  aud_claim_url ||= benefits_education_settings.access_token.aud_claim_url

  @token_service ||= Auth::ClientCredentials::Service.new(
    token_url,
    API_SCOPES,
    lighthouse_client_id,
    aud_claim_url,
    lighthouse_rsa_key_path,
    'benefits-education'
  )
end

#use_mocks?Boolean (private)

Returns Should the service use mock data in lower environments.

Returns:

  • (Boolean)

    Should the service use mock data in lower environments.



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

def use_mocks?
  benefits_education_settings.use_mocks || false
end