class SimpleShipping::Fedex::ShipmentBuilder
Builds a shipment element for FedEx SOAP service.
Constants
- DROPOFF_TYPES
Mapping for dropoff types.
- PACKAGE_COUNT
Number of packages.
- PACKAGING_TYPES
Mapping for package types
- RATE_REQUEST_TYPE
Value for RateRequestTypes XML element.
- SERVICE_TYPES
Mapping for service types
Public Instance Methods
build()
click to toggle source
Build the shipment representation as a hash for the Savon client.
# File lib/simple_shipping/fedex/shipment_builder.rb, line 59 def build {'ShipTimestamp' => ship_timestamp, 'DropoffType' => DROPOFF_TYPES[@opts[:dropoff_type]], 'ServiceType' => SERVICE_TYPES[@opts[:service_type]], 'PackagingType' => PACKAGING_TYPES[@model.package.packaging_type], 'Shipper' => PartyBuilder.build(@model.shipper), 'Recipient' => PartyBuilder.build(@model.recipient), 'ShippingChargesPayment' => shipping_charges_payment, 'LabelSpecification' => label_specification, 'RateRequestTypes' => RATE_REQUEST_TYPE, 'PackageCount' => PACKAGE_COUNT, 'RequestedPackageLineItems' => PackageBuilder.build(@model.package), :order! => ['ShipTimestamp' , 'DropoffType' , 'ServiceType' , 'PackagingType', 'Shipper' , 'Recipient' , 'ShippingChargesPayment', 'LabelSpecification', 'RateRequestTypes', 'PackageCount' , 'RequestedPackageLineItems'] } end
validate()
click to toggle source
Perform validations.
# File lib/simple_shipping/fedex/shipment_builder.rb, line 78 def validate validate_inclusion_of(:dropoff_type , DROPOFF_TYPES) validate_inclusion_of(:service_type , SERVICE_TYPES) end
Private Instance Methods
label_specification()
click to toggle source
Build the label parameters according to FedEx’s API.
@return [Hash]
# File lib/simple_shipping/fedex/shipment_builder.rb, line 115 def label_specification { 'LabelFormatType' => 'COMMON2D', 'ImageType' => 'PNG', 'LabelStockType' => 'PAPER_4X6', :order! => ['LabelFormatType', 'ImageType', 'LabelStockType'] } end
payment_type()
click to toggle source
Get the payment type.
@return [String]
# File lib/simple_shipping/fedex/shipment_builder.rb, line 107 def payment_type (@model.payor == :shipper) ? 'SENDER' : 'RECIPIENT' end
ship_timestamp()
click to toggle source
Get the shipping timestamps in a specific format.
@example
ship_timestamp # => "2014-01-08T14:41:53+02:00"
@return [String]
# File lib/simple_shipping/fedex/shipment_builder.rb, line 89 def ship_timestamp Time.new.strftime('%Y-%m-%dT%H:%M:%S%z').tap{|str| str[-2,0] = ':' } end
shipping_charges_payment()
click to toggle source
Build the hash for the ShippingChargesPayment element.
@return [Hash]
# File lib/simple_shipping/fedex/shipment_builder.rb, line 97 def shipping_charges_payment {'PaymentType' => payment_type, 'Payor' => {'AccountNumber' => @model.payor_account_number}, :order! => ['PaymentType', 'Payor']} end