Sha256: 24dfc98cfb2db20ed5c33fa78b3527a764af4de90593743ec4e410459dfdefc1

Contents?: true

Size: 1.02 KB

Versions: 14

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

module FriendlyShipping
  module Services
    class Ups
      class ParseCityStateLookupResponse
        extend Dry::Monads::Result::Mixin

        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
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
friendly_shipping-0.9.0 lib/friendly_shipping/services/ups/parse_city_state_lookup_response.rb
friendly_shipping-0.8.1 lib/friendly_shipping/services/ups/parse_city_state_lookup_response.rb
friendly_shipping-0.8.0 lib/friendly_shipping/services/ups/parse_city_state_lookup_response.rb
friendly_shipping-0.7.3 lib/friendly_shipping/services/ups/parse_city_state_lookup_response.rb
friendly_shipping-0.7.2 lib/friendly_shipping/services/ups/parse_city_state_lookup_response.rb
friendly_shipping-0.7.1 lib/friendly_shipping/services/ups/parse_city_state_lookup_response.rb
friendly_shipping-0.7.0 lib/friendly_shipping/services/ups/parse_city_state_lookup_response.rb
friendly_shipping-0.6.5 lib/friendly_shipping/services/ups/parse_city_state_lookup_response.rb
friendly_shipping-0.6.4 lib/friendly_shipping/services/ups/parse_city_state_lookup_response.rb
friendly_shipping-0.6.3 lib/friendly_shipping/services/ups/parse_city_state_lookup_response.rb
friendly_shipping-0.6.2 lib/friendly_shipping/services/ups/parse_city_state_lookup_response.rb
friendly_shipping-0.6.1 lib/friendly_shipping/services/ups/parse_city_state_lookup_response.rb
friendly_shipping-0.6.0 lib/friendly_shipping/services/ups/parse_city_state_lookup_response.rb
friendly_shipping-0.5.3 lib/friendly_shipping/services/ups/parse_city_state_lookup_response.rb