Class: FriendlyShipping::Services::Usps::SerializeRateRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/friendly_shipping/services/usps/serialize_rate_request.rb

Constant Summary collapse

MAX_REGULAR_PACKAGE_SIDE =
Measured::Length(12, :inches)

Class Method Summary collapse

Class Method Details

.call(shipment:, login:, options:) ⇒ Object

Parameters:



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/friendly_shipping/services/usps/serialize_rate_request.rb', line 19

def call(shipment:, login:, options:)
  xml_builder = Nokogiri::XML::Builder.new do |xml|
    xml.RateV4Request('USERID' => ) do
      shipment.packages.each_with_index do |package, index|
        package_options = options.options_for_package(package)
        xml.Package('ID' => index) do
          xml.Service(package_options.service_code)
          if package_options.first_class_mail_type
            xml.FirstClassMailType(package_options.first_class_mail_type_code)
          end
          xml.ZipOrigination(shipment.origin.zip)
          xml.ZipDestination(shipment.destination.zip)
          xml.Pounds(0)
          xml.Ounces(ounces_for(package))
          size_code = size_code_for(package)
          xml.Container(package_options.container_code)
          xml.Size(size_code)
          if package_options.transmit_dimensions && package_options.container_code == 'VARIABLE'
            xml.Width("%<width>0.2f" % { width: package.width.convert_to(:inches).value.to_f })
            xml.Length("%<length>0.2f" % { length: package.length.convert_to(:inches).value.to_f })
            xml.Height("%<height>0.2f" % { height: package.height.convert_to(:inches).value.to_f })

            # When girth is present, the package is treated as non-rectangular
            # when calculating dimensional weight. This results in a smaller
            # dimensional weight than a rectangular package would have.
            unless package_options.rectangular
              xml.Girth("%<girth>0.2f" % { girth: girth(package) })
            end
          end
          xml.Machinable(machinable(package))
          xml.ReturnDimensionalWeight(true) if package_options.return_dimensional_weight
          xml.ReturnFees(true) if package_options.return_fees
        end
      end
    end
  end
  xml_builder.to_xml
end