Class: FriendlyShipping::Services::Ups::ParseCityStateLookupResponse

Inherits:
Object
  • Object
show all
Extended by:
Dry::Monads::Result::Mixin
Defined in:
lib/friendly_shipping/services/ups/parse_city_state_lookup_response.rb

Class Method Summary collapse

Class Method Details

.call(request:, response:, location:) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/friendly_shipping/services/ups/parse_city_state_lookup_response.rb', line 9

def self.call(request:, response:, location:)
  parsing_result = ParseXMLResponse.call(
    request: request,
    response: response,
    expected_root_tag: 'AddressValidationResponse'
  )
  parsing_result.fmap do |xml|
    FriendlyShipping::ApiResult.new(
      [
        Physical::Location.new(
          city: xml.at('AddressValidationResult/Address/City')&.text,
          region: xml.at('AddressValidationResult/Address/StateProvinceCode')&.text,
          country: location.country,
          zip: xml.at('AddressValidationResult/Address/PostcodePrimaryLow')&.text,
        )
      ],
      original_request: request,
      original_response: response
    )
  end
end