Class: EMIS::Service
- Inherits:
-
Common::Client::Base
- Object
- Common::Client::Base
- EMIS::Service
- Defined in:
- lib/emis/service.rb
Overview
HTTP Client for EMIS requests. Requests and responses are SOAP format
Direct Known Subclasses
MilitaryInformationService, MilitaryInformationServiceV2, PaymentService, PaymentServiceV2, VeteranStatusService
Constant Summary collapse
- STATSD_KEY_PREFIX =
Prefix string for StatsD monitoring
'api.emis'
Class Method Summary collapse
-
.create_endpoints(endpoints) ⇒ Object
Create methods for each endpoint in EMIS API.
-
.get_endpoint_attributes(endpoint) ⇒ Array<String, Symbol>
Helper for extracting endpoint attributes from the endpoint configuration.
Instance Method Summary collapse
-
#create_edipi_or_icn_message(edipi:, icn:, request_name:) ⇒ EMIS::Messages::EdipiOrIcnMessage
protected
Creates a SOAP request body that includes user identifiers to send to the EMIS API.
-
#make_request(response_type:, operation:, request_name:, edipi: nil, icn: nil, version: 'V1') ⇒ EMIS::Responses
protected
Helper for sending requests to the EMIS API.
Methods included from Common::Client::Concerns::LogAsWarningHelpers
Methods inherited from Common::Client::Base
configuration, #raise_backend_exception
Methods included from SentryLogging
#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger
Class Method Details
.create_endpoints(endpoints) ⇒ Object
Create methods for each endpoint in EMIS API.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/emis/service.rb', line 25 def self.create_endpoints(endpoints) endpoints.each do |endpoint| operation, request_name, version = get_endpoint_attributes(endpoint) define_method(operation) do || edipi, icn = .values_at(:edipi, :icn) parameters = { edipi:, icn:, request_name:, operation:, response_type: "EMIS::Responses::#{operation.camelize}Response#{version.upcase}".constantize } parameters[:version] = version unless version.empty? make_request(**parameters) end end end |
.get_endpoint_attributes(endpoint) ⇒ Array<String, Symbol>
Helper for extracting endpoint attributes from the endpoint configuration
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/emis/service.rb', line 53 def self.get_endpoint_attributes(endpoint) operation = nil request_name = nil if endpoint.is_a?(Array) operation = endpoint[0].to_s request_name = endpoint[1] version = endpoint[2] || '' else operation = endpoint.to_s request_name = "#{endpoint.to_s.camelize(:lower).sub(/^get/, '').camelize(:lower)}Request" version = '' end [operation, request_name, version] end |
Instance Method Details
#create_edipi_or_icn_message(edipi:, icn:, request_name:) ⇒ EMIS::Messages::EdipiOrIcnMessage (protected)
Creates a SOAP request body that includes user identifiers to send to the EMIS API
115 116 117 118 119 120 121 122 |
# File 'lib/emis/service.rb', line 115 def (edipi:, icn:, request_name:) EMIS::Messages::EdipiOrIcnMessage.new( edipi:, icn:, request_name:, custom_namespaces: ).to_xml end |
#make_request(response_type:, operation:, request_name:, edipi: nil, icn: nil, version: 'V1') ⇒ EMIS::Responses (protected)
Helper for sending requests to the EMIS API
rubocop:disable Metrics/ParameterLists
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/emis/service.rb', line 82 def make_request(response_type:, operation:, request_name:, edipi: nil, icn: nil, version: 'V1') = ( edipi:, icn:, request_name: ) raw_response = warn_for_service_unavailable do perform( :post, '', , soapaction: "http://viers.va.gov/cdi/eMIS/#{operation.camelize(:lower)}/#{version.downcase}" ) end response_type.new(raw_response) # :nocov: rescue Faraday::ConnectionFailed => e Rails.logger.error "eMIS connection failed: #{e.}" EMIS::Responses::ErrorResponse.new(e) rescue Common::Client::Errors::ClientError => e Rails.logger.error "eMIS error: #{e.}" EMIS::Responses::ErrorResponse.new(e) # :nocov: end |