Class: SimpleShipping::Ups::ShipmentBuilder
- Inherits:
-
Abstract::Builder
- Object
- Abstract::Builder
- SimpleShipping::Ups::ShipmentBuilder
- Defined in:
- lib/simple_shipping/ups/shipment_builder.rb
Overview
Builds shipment element for UPS SOAP service.
Constant Summary collapse
- PAYMENT_TYPE =
The type of payment for this shipment.
'01'
- SERVICE_TYPES =
Service codes in UPS terminology.
{:next_day_air => '01', :second_day_air => '02', :ground => '03', :express => '07', :expedited => '08', :standard => '11', :three_day_select => '12', :next_day_air_saver => '13', :next_day_air_early_am => '14', :express_plus => '54', :second_day_air_am => '59', :saver => '65', :today_standard => '82', :today_dedicated_courier => '83', :today_intercity => '84', :today_express => '85', :today_express_saver => '86'}
Instance Method Summary collapse
-
#build ⇒ Object
Return a hash for Savon representing a shipment model.
-
#build_payment_info ⇒ Object
Return the PaymentInformation hash.
-
#build_service ⇒ Object
Return the hash representing the Service.
-
#build_shipment_charge ⇒ Object
Return the shipment charge for the PaymentInformation hash.
-
#validate ⇒ Object
Validate that the service type is included.
Methods inherited from Abstract::Builder
Instance Method Details
#build ⇒ Object
Return a hash for Savon representing a shipment model.
29 30 31 32 33 34 35 36 |
# File 'lib/simple_shipping/ups/shipment_builder.rb', line 29 def build { 'Shipper' => PartyBuilder.build(@model.shipper, :shipper => true), 'ShipTo' => PartyBuilder.build(@model.recipient), 'PaymentInformation' => build_payment_info, 'Service' => build_service, 'Package' => PackageBuilder.build(@model.package), :order! => ['Shipper', 'ShipTo', 'PaymentInformation', 'Service', 'Package'] } end |
#build_payment_info ⇒ Object
Return the PaymentInformation hash.
39 40 41 |
# File 'lib/simple_shipping/ups/shipment_builder.rb', line 39 def build_payment_info {'ShipmentCharge' => build_shipment_charge } end |
#build_service ⇒ Object
Return the hash representing the Service.
57 58 59 |
# File 'lib/simple_shipping/ups/shipment_builder.rb', line 57 def build_service {'Code' => SERVICE_TYPES[@opts[:service_type]]} end |
#build_shipment_charge ⇒ Object
Return the shipment charge for the PaymentInformation hash.
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/simple_shipping/ups/shipment_builder.rb', line 44 def build_shipment_charge result = {'Type' => PAYMENT_TYPE, :order! => ['Type']} if @model.payor == :shipper result['BillShipper'] = {'AccountNumber' => @model.shipper.account_number} result[:order!] << 'BillShipper' else result['BillReceiver'] = {'AccountNumber' => @model.recipient.account_number} result[:order!] << 'BillReceiver' end result end |
#validate ⇒ Object
Validate that the service type is included.
62 63 64 |
# File 'lib/simple_shipping/ups/shipment_builder.rb', line 62 def validate validate_inclusion_of(:service_type, SERVICE_TYPES) end |