Class: VAProfile::AddressValidation::Service

Inherits:
Service show all
Includes:
Common::Client::Concerns::Monitoring
Defined in:
lib/va_profile/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

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

#initializeService

Returns a new instance of Service.



19
# File 'lib/va_profile/address_validation/service.rb', line 19

def initialize; end

Instance Method Details

#address_suggestions(address) ⇒ VAProfile::AddressValidation::AddressSuggestionsResponse

Get address suggestions and override key from the VA profile API

Returns:



24
25
26
27
28
29
30
# File 'lib/va_profile/address_validation/service.rb', line 24

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.

Returns:

  • (Hash)

    raw data from VA profile address validation API including address suggestions, validation key, and address errors



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/va_profile/address_validation/service.rb', line 34

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)



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/va_profile/address_validation/service.rb', line 50

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