Class: FriendlyShipping::Services::Usps::SerializeRateRequest
- Inherits:
-
Object
- Object
- FriendlyShipping::Services::Usps::SerializeRateRequest
- 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
-
.call(shipment:, login:, options:) ⇒ Array<FriendlyShipping::Rate>
A set of Rates that this package may be sent with.
Class Method Details
.call(shipment:, login:, options:) ⇒ Array<FriendlyShipping::Rate>
Returns A set of Rates that this package may be sent with.
17 18 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 |
# File 'lib/friendly_shipping/services/usps/serialize_rate_request.rb', line 17 def call(shipment:, login:, options:) xml_builder = Nokogiri::XML::Builder.new do |xml| xml.RateV4Request('USERID' => login) do shipment.packages.each_with_index do |package, index| = .(package) xml.Package('ID' => index) do xml.Service(.service_code) if .first_class_mail_type && .first_class_mail_type_code xml.FirstClassMailType(.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(.container_code) xml.Size(size_code) if .transmit_dimensions && .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 .rectangular xml.Girth("%<girth>0.2f" % { girth: girth(package) }) end end xml.Machinable(machinable(package)) xml.ReturnDimensionalWeight(true) if .return_dimensional_weight xml.ReturnFees(true) if .return_fees end end end end xml_builder.to_xml end |