Class: VAProfile::Models::ValidationAddress
- Inherits:
-
BaseAddress
- Object
- Base
- BaseAddress
- VAProfile::Models::ValidationAddress
- Defined in:
- lib/va_profile/models/validation_address.rb
Overview
Model for addresses sent and received from the VA profile address validation API
Constant Summary
Constants inherited from BaseAddress
BaseAddress::ADDRESS_FIELD_LIMIT, BaseAddress::ADDRESS_POUS, BaseAddress::ADDRESS_TYPES, BaseAddress::CORRESPONDENCE, BaseAddress::DOMESTIC, BaseAddress::INTERNATIONAL, BaseAddress::MILITARY, BaseAddress::RESIDENCE, BaseAddress::VALID_ALPHA_REGEX, BaseAddress::VALID_NUMERIC_REGEX
Constants inherited from Base
Class Method Summary collapse
-
.build_from_address_suggestion(address_suggestion_hash) ⇒ VAProfile::Models::ValidationAddress
Validation address model created from address validation API response.
- .regional_attributes(address_type, address_hash) ⇒ Object
Instance Method Summary collapse
-
#address_validation_req ⇒ Hash
Convert a ValidationAddress into a hash that can be sent to the address validation API.
Methods inherited from BaseAddress
Methods included from Concerns::Expirable
#effective_end_date_has_passed
Methods included from Concerns::Defaultable
Class Method Details
.build_from_address_suggestion(address_suggestion_hash) ⇒ VAProfile::Models::ValidationAddress
Returns validation address model created from address validation API response.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/va_profile/models/validation_address.rb', line 38 def self.build_from_address_suggestion(address_suggestion_hash) address_hash = address_suggestion_hash['address'] address_type = address_suggestion_hash['address_meta_data']['address_type'].upcase attributes = { address_line1: address_hash['address_line1'], address_line2: address_hash['address_line2'], address_line3: address_hash['address_line3'], address_type:, city: address_hash['city'], country_name: address_hash['country']['name'], country_code_iso3: address_hash['country']['iso3_code'] }.merge(regional_attributes(address_type, address_hash)) new(attributes) end |
.regional_attributes(address_type, address_hash) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/va_profile/models/validation_address.rb', line 54 def self.regional_attributes(address_type, address_hash) if address_type == INTERNATIONAL { province: address_hash['state_province']['name'], international_postal_code: address_hash['international_postal_code'] } else { state_code: address_hash['state_province']['code'], county_code: address_hash.dig('county', 'county_fips_code'), county_name: address_hash.dig('county', 'name'), zip_code: address_hash['zip_code5'], zip_code_suffix: address_hash['zip_code4'] } end end |
Instance Method Details
#address_validation_req ⇒ Hash
Convert a ValidationAddress into a hash that can be sent to the address validation API
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/va_profile/models/validation_address.rb', line 13 def address_validation_req Common::HashHelpers.deep_remove_blanks( requestAddress: attributes.slice( :address_line1, :address_line2, :address_line3, :city, :international_postal_code ).deep_transform_keys { |k| k.to_s.camelize(:lower) }.merge( requestCountry: { countryCode: @country_code_iso3 }, addressPOU: @address_pou, stateProvince: { code: @state_code, name: @province }, zipCode5: @zip_code, zipCode4: @zip_code_suffix ) ) end |