-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into API-42322-Extract-OrgWebServiceBean-from-l…
…ocalBGS
- Loading branch information
Showing
14 changed files
with
247 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
lib/disability_compensation/providers/brd/lighthouse_staging_brd_provider.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'disability_compensation/providers/brd/lighthouse_brd_provider' | ||
require 'lighthouse/benefits_reference_data_staging/service' | ||
|
||
class LighthouseStagingBRDProvider < LighthouseBRDProvider | ||
def initialize(_current_user) | ||
super | ||
@service = BenefitsReferenceData::Staging::Service.new | ||
end | ||
end |
68 changes: 68 additions & 0 deletions
68
lib/lighthouse/benefits_reference_data_staging/configuration.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'common/client/configuration/rest' | ||
require 'faraday/multipart' | ||
|
||
module BenefitsReferenceData | ||
## | ||
# HTTP client configuration for the {BenefitsReferenceData::Service}, | ||
# sets the base path, the base request headers, and a service name for breakers and metrics. | ||
|
||
module Staging | ||
class Configuration < Common::Client::Configuration::REST | ||
self.read_timeout = Settings.lighthouse.benefits_reference_data.timeout || 20 | ||
|
||
## | ||
# @return [String] Base path for benefits_reference_data URLs. | ||
# | ||
def base_path | ||
settings = Settings.lighthouse.benefits_reference_data | ||
url = settings.staging_url | ||
path = settings.path | ||
version = settings.version | ||
safe_slash_merge(url, path, version) | ||
end | ||
|
||
## | ||
# @return [String] Service name to use in breakers and metrics. | ||
# | ||
def service_name | ||
'BenefitsReferenceDataStaging' | ||
end | ||
|
||
## | ||
# @return [Hash] The basic headers required for any benefits_reference_data API call. | ||
# | ||
def self.base_request_headers | ||
key = Settings.lighthouse.staging_api_key | ||
message = "No api_key set for LH benefits_reference_data_staging. Please set 'lighthouse.staging_api_key'" | ||
raise message if key.nil? | ||
|
||
super.merge('apiKey' => key) | ||
end | ||
|
||
## | ||
# Creates the a connection with parsing json and adding breakers functionality. | ||
# | ||
# @return [Faraday::Connection] a Faraday connection instance. | ||
# | ||
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 :json | ||
faraday.adapter Faraday.default_adapter | ||
end | ||
end | ||
|
||
private | ||
|
||
def safe_slash_merge(*url_segments) | ||
url_segments.map { |segment| segment.sub(%r{^/}, '').chomp('/') }.join('/') | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'common/client/base' | ||
require 'common/client/concerns/monitoring' | ||
require 'common/client/errors' | ||
require 'common/exceptions/forbidden' | ||
require 'common/exceptions/schema_validation_errors' | ||
require 'lighthouse/benefits_reference_data_staging/configuration' | ||
require 'lighthouse/benefits_reference_data/service_exception' | ||
|
||
module BenefitsReferenceData | ||
## | ||
# Proxy Service for the Lighthouse Benefits Reference Data API. | ||
|
||
module Staging | ||
class Service < Common::Client::Base | ||
include SentryLogging | ||
include Common::Client::Concerns::Monitoring | ||
|
||
configuration BenefitsReferenceData::Staging::Configuration | ||
|
||
# ap @configuration.base_request_headers; exit | ||
|
||
STATSD_KEY_PREFIX = 'api.benefits_reference_data_staging' | ||
|
||
## | ||
# Hit a Benefits Reference Data End-point | ||
# | ||
# @path end-point [string|symbol] a string or symbol of the end-point you wish to hit. | ||
# @params params hash [Hash] a hash of key-value pairs of parameters | ||
# | ||
# @return [Faraday::Response] | ||
# | ||
def get_data(path:, params: {}) | ||
headers = config.base_request_headers | ||
begin | ||
response = perform :get, path, params, headers | ||
rescue => e | ||
raise BenefitsReferenceData::ServiceException.new(e), 'Lighthouse Error' | ||
end | ||
response | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
spec/lib/disability_compensation/providers/brd/lighthouse_staging_brd_provider_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
require 'disability_compensation/factories/api_provider_factory' | ||
require 'disability_compensation/providers/brd/lighthouse_staging_brd_provider' | ||
require 'support/disability_compensation_form/shared_examples/brd_provider' | ||
require 'lighthouse/service_exception' | ||
|
||
RSpec.describe LighthouseStagingBRDProvider do | ||
let(:current_user) { build(:user, :loa3) } | ||
|
||
before do | ||
@provider = LighthouseStagingBRDProvider.new(current_user) | ||
Flipper.enable(ApiProviderFactory::FEATURE_TOGGLE_BRD) | ||
Flipper.enable(:disability_compensation_staging_lighthouse_brd) | ||
end | ||
|
||
after do | ||
Flipper.disable(ApiProviderFactory::FEATURE_TOGGLE_BRD) | ||
Flipper.disable(:disability_compensation_staging_lighthouse_brd) | ||
end | ||
|
||
it_behaves_like 'brd provider' | ||
|
||
it 'retrieves separation locations from the Lighthouse API' do | ||
VCR.use_cassette('brd/separation_locations_staging') do | ||
response = @provider.get_separation_locations | ||
expect(response.separation_locations.length).to eq(327) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.