Class: VAProfile::V3::AddressValidation::Service
- Inherits:
-
Service
- Object
- Common::Client::Base
- Service
- VAProfile::V3::AddressValidation::Service
- Includes:
- Common::Client::Concerns::Monitoring
- Defined in:
- lib/va_profile/v3/address_validation/service.rb
Overview
Wrapper for the VA profile address validation/suggestions API
Constant Summary collapse
- STATSD_KEY_PREFIX =
"#{VAProfile::Service::STATSD_KEY_PREFIX}.address_validation".freeze
Instance Method Summary collapse
-
#address_suggestions(address) ⇒ VAProfile::AddressValidation::AddressSuggestionsResponse
Get address suggestions and override key from the VA profile API.
-
#candidate(address) ⇒ Hash
Raw data from VA profile address validation API including address suggestions, validation key, and address errors.
- #handle_error(error) ⇒ Object private
-
#initialize ⇒ Service
constructor
A new instance of Service.
Methods included from Common::Client::Concerns::Monitoring
#increment, #increment_failure, #increment_total, #with_monitoring
Methods inherited from Service
breakers_service, #final_failure?, #log_dates, #parse_messages, #perform, #person_transaction?, #person_transaction_failure?, #raise_backend_exception, #raise_invalid_body, #report_stats_on, #save_error_details
Methods inherited from Common::Client::Base
#config, configuration, #connection, #delete, #get, #perform, #post, #put, #raise_backend_exception, #raise_not_authenticated, #request, #sanitize_headers!, #service_name
Methods included from SentryLogging
#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger, #set_sentry_metadata
Constructor Details
#initialize ⇒ Service
Returns a new instance of Service.
20 |
# File 'lib/va_profile/v3/address_validation/service.rb', line 20 def initialize; end |
Instance Method Details
#address_suggestions(address) ⇒ VAProfile::AddressValidation::AddressSuggestionsResponse
Get address suggestions and override key from the VA profile API
25 26 27 28 29 30 31 |
# File 'lib/va_profile/v3/address_validation/service.rb', line 25 def address_suggestions(address) with_monitoring do candidate_res = candidate(address) AddressSuggestionsResponse.new(candidate_res) end end |
#candidate(address) ⇒ Hash
Returns raw data from VA profile address validation API including address suggestions, validation key, and address errors.
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/va_profile/v3/address_validation/service.rb', line 35 def candidate(address) begin res = perform( :post, 'candidate', address.address_validation_req.to_json ) rescue => e handle_error(e) end res.body end |
#handle_error(error) ⇒ Object (private)
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/va_profile/v3/address_validation/service.rb', line 51 def handle_error(error) raise error unless error.is_a?(Common::Client::Errors::ClientError) save_error_details(error) raise_invalid_body(error, self.class) unless error.body.is_a?(Hash) raise Common::Exceptions::BackendServiceException.new( 'VET360_AV_ERROR', detail: error.body ) end |