lib/friendly_shipping/services/usps/parse_rate_response.rb
# Iterate over all packages and parse the rates for each package
#
# @param [Nokogiri::XML::Node] xml The XML document containing packages and rates
# @param [Physical::Shipment] shipment The shipment we're trying to get rates for
#
# @return [Hash<Physical::Package => Array<FriendlyShipping::Rate>>]
Iterate over all packages and parse the rates for each package
Iterate over all packages and parse the rates for each package
def rates_from_response_node(xml, shipment, options)
            xml.xpath(PACKAGE_NODE_XPATH).each_with_object({}) do |package_node, result|
              package_id = package_node['ID']
              corresponding_package = shipment.packages[package_id.to_i]
              package_options = options.options_for_package(corresponding_package)
              raise BoxNotFoundError if corresponding_package.nil?
              result[corresponding_package] = package_node.xpath(SERVICE_NODE_NAME).map do |service_node|
                ParsePackageRate.call(service_node, corresponding_package, package_options)
              end
            end
          end
def rates_from_response_node ( xml , shipment , options ) xml . xpath ( PACKAGE_NODE_XPATH ) . each_with_object ( { } ) do | package_node , result | package_id = package_node [ 'ID' ] corresponding_package = shipment . packages [ package_id . to_i ] package_options = options . options_for_package ( corresponding_package ) raise BoxNotFoundError if corresponding_package . nil? result [ corresponding_package ] = package_node . xpath ( SERVICE_NODE_NAME ) . map do | service_node | ParsePackageRate . call ( service_node , corresponding_package , package_options ) end end end
Iterate over all packages and parse the rates for each package
Iterate over all packages and parse the rates for each package
# There should always be a package in the original shipment that corresponds to the package ID # in the USPS response.
None
Hash<Physical::Package => Array<FriendlyShipping::Rate>>
xml
<not_specific>
shipment
<not_specific>
options
<not_specific>
<not_specific>
shipment The shipment we're trying to get rates for
shipment The shipment we ' re trying to get rates for