diff --git a/config/initializers/breakers.rb b/config/initializers/breakers.rb index c9d4f1188f3..57da61650bd 100644 --- a/config/initializers/breakers.rb +++ b/config/initializers/breakers.rb @@ -21,6 +21,7 @@ require 'mhv_ac/configuration' require 'mpi/configuration' require 'pagerduty/configuration' +require 'post911_sob/dgib/configuration' require 'preneeds/configuration' require 'rx/configuration' require 'sm/configuration' @@ -62,6 +63,7 @@ HCA::Configuration.instance.breakers_service, MHVAC::Configuration.instance.breakers_service, MPI::Configuration.instance.breakers_service, + Post911SOB::DGIB::Configuration.instance.breakers_service, Preneeds::Configuration.instance.breakers_service, SM::Configuration.instance.breakers_service, VAProfile::AddressValidation::Configuration.instance.breakers_service, diff --git a/config/settings.yml b/config/settings.yml index 84b48ea9f97..ae6ac19c385 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -1454,6 +1454,9 @@ dgi: jwt: public_key_path: spec/fixtures/post911_sob/dgib/public_test.pem private_key_path: spec/fixtures/post911_sob/dgib/private_test.pem + claimants: + url: ~ + mock: false # Settings for the VEText integration (mobile push notifications) vetext_push: diff --git a/lib/post911_sob/dgib/client.rb b/lib/post911_sob/dgib/client.rb new file mode 100644 index 00000000000..a9ed572f32a --- /dev/null +++ b/lib/post911_sob/dgib/client.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +require 'common/client/base' +require 'post911_sob/dgib/configuration' +require 'post911_sob/dgib/authentication_token_service' + +module Post911SOB + module DGIB + class Client < Common::Client::Base + include Common::Client::Concerns::Monitoring + + configuration Post911SOB::DGIB::Configuration + + BENEFIT_TYPE = 'Chapter33' + + def initialize(claimant_id) + @claimant_id = claimant_id + + super() + end + + def get_entitlement_transferred_out + # TO-DO add monitoring and serialized response + # TO-DO Filter response by chapter33 benefit type + options = { timeout: 60 } + perform(:get, end_point, {}, request_headers, options) + end + + private + + def end_point + "transferees/#{@claimant_id}/toe" + end + + def request_headers + { + Authorization: "Bearer #{Post911SOB::DGIB::AuthenticationTokenService.call}" + } + end + end + end +end diff --git a/lib/post911_sob/dgib/configuration.rb b/lib/post911_sob/dgib/configuration.rb new file mode 100644 index 00000000000..640bcb8e263 --- /dev/null +++ b/lib/post911_sob/dgib/configuration.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +require 'common/client/configuration/rest' + +module Post911SOB + module DGIB + class Configuration < Common::Client::Configuration::REST + SETTINGS = Settings.dgi.post911_sob.claimants + + # TO-DO: Datadog + + def base_path + SETTINGS.url.to_s + end + + def service_name + 'Post911SOB/DGIB' + end + + 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 :json + + faraday.response :betamocks if mock_enabled? + faraday.response :snakecase, symbolize: false + faraday.response :json, content_type: /\bjson/ # ensures only json content types parsed + faraday.adapter Faraday.default_adapter + end + end + + private + + def mock_enabled? + SETTINGS.mock || false + end + end + end +end diff --git a/rakelib/post911_sob.rake b/rakelib/post911_sob.rake new file mode 100644 index 00000000000..853260892aa --- /dev/null +++ b/rakelib/post911_sob.rake @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'post911_sob/dgib/client' + +namespace :post911_sob do + namespace :dgib do + desc 'Test connection between vets-api and DGIB claimant-service' + task :connect, %i[claimant_id base_url] => :environment do |_cmd, args| + args.with_defaults(base_url: Settings.dgi.post911_sob.claimants.url) + + # Allow for base url to be overridden for testing purposes + Settings.dgi.post911_sob.claimants.url = args[:base_url] + + client = Post911SOB::DGIB::Client.new(args[:claimant_id]) + client.get_entitlement_transferred_out + end + end +end