Class: FriendlyShipping::Services::UpsJson::GenerateTimingsPayload
- Inherits:
-
Object
- Object
- FriendlyShipping::Services::UpsJson::GenerateTimingsPayload
- Defined in:
- lib/friendly_shipping/services/ups_json/generate_timings_payload.rb
Class Method Summary collapse
- .call(shipment:, options:) ⇒ Object
- .region_name_or_code(location, region) ⇒ Object
- .shipment_contents_value(shipment) ⇒ Object
Class Method Details
.call(shipment:, options:) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/friendly_shipping/services/ups_json/generate_timings_payload.rb', line 7 def self.call(shipment:, options:) { originCountryCode: shipment.origin.country.code, originStateProvince: region_name_or_code(shipment.origin, shipment.origin.region), originCityName: shipment.origin.city, originPostalCode: shipment.origin.zip, destinationCountryCode: shipment.destination.country.code, destinationStateProvince: region_name_or_code(shipment.destination, shipment.destination.region), destinationCityName: shipment.destination.city, destinationPostalCode: shipment.destination.zip, residentialIndicator: shipment.destination.commercial? ? '02' : '01', shipDate: .pickup.strftime('%Y-%m-%d'), shipmentContentsCurrencyCode: 'USD', shipmentContentsValue: shipment_contents_value(shipment), weight: shipment.packages.sum(&:weight).value.to_s, weightUnitOfMeasure: 'LBS', billType: '02', numberOfPackages: shipment.packages.size.to_s } end |
.region_name_or_code(location, region) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/friendly_shipping/services/ups_json/generate_timings_payload.rb', line 34 def self.region_name_or_code(location, region) if location.country == "US" region.name else region.code end end |
.shipment_contents_value(shipment) ⇒ Object
28 29 30 31 32 |
# File 'lib/friendly_shipping/services/ups_json/generate_timings_payload.rb', line 28 def self.shipment_contents_value(shipment) shipment.packages.map do |package| package.items.sum { |item| item.cost || 0 } end.sum.to_d end |