Class: SimpleShipping::Fedex::ShipmentBuilder

Inherits:
Abstract::Builder show all
Defined in:
lib/simple_shipping/fedex/shipment_builder.rb

Overview

Builds a shipment element for FedEx SOAP service.

Constant Summary collapse

RATE_REQUEST_TYPE =

Value for RateRequestTypes XML element.

'ACCOUNT'
PACKAGE_COUNT =

Number of packages.

'1'
PACKAGING_TYPES =

Mapping for package types

{
  :box_10kg => 'FEDEX_10KG_BOX',
  :box_25kg => 'FEDEX_25KG_BOX',
  :box      => 'FEDEX_BOX',
  :envelope => 'FEDEX_ENVELOPE',
  :pak      => 'FEDEX_PAK',
  :tube     => 'FEDEX_TUBE',
  :your     => 'YOUR_PACKAGING'
}
SERVICE_TYPES =

Mapping for service types

{
  :europe_first_international_priority => 'EUROPE_FIRST_INTERNATIONAL_PRIORITY',
  :fedex_1_day_freight                 => 'FEDEX_1_DAY_FREIGHT',
  :fedex_2_day_am                      => 'FEDEX_2_DAY',
  :fedex_2_day_freight                 => 'FEDEX_2_DAY_AM',
  :fedex_3_day_freight                 => 'FEDEX_2_DAY_FREIGHT',
  :fedex_3_day_freight                 => 'FEDEX_3_DAY_FREIGHT',
  :fedex_express_saver                 => 'FEDEX_EXPRESS_SAVER',
  :fedex_freight_economy               => 'FEDEX_FIRST_FREIGHT',
  :fedex_freight_economy               => 'FEDEX_FREIGHT_ECONOMY',
  :fedex_freight_priority              => 'FEDEX_FREIGHT_PRIORITY',
  :fedex_ground                        => 'FEDEX_GROUND',
  :first_overnight                     => 'FIRST_OVERNIGHT',
  :ground_home_delivery                => 'GROUND_HOME_DELIVERY',
  :international_economy               => 'INTERNATIONAL_ECONOMY',
  :international_economy_freight       => 'INTERNATIONAL_ECONOMY_FREIGHT',
  :international_first                 => 'INTERNATIONAL_FIRST',
  :international_priority              => 'INTERNATIONAL_PRIORITY',
  :international_priority_freight      => 'INTERNATIONAL_PRIORITY_FREIGHT',
  :priority_overnight                  => 'PRIORITY_OVERNIGHT',
  :smart_post                          => 'SMART_POST',
  :standard_overnight                  => 'STANDARD_OVERNIGHT'
}
DROPOFF_TYPES =

Mapping for dropoff types.

{
  :business_service_center => 'BUSINESS_SERVICE_CENTER',
  :drop_box                => 'DROP_BOX',
  :regular_pickup          => 'REGULAR_PICKUP',
  :request_courier         => 'REQUEST_COURIER',
  :station                 => 'STATION'
}

Instance Method Summary collapse

Methods inherited from Abstract::Builder

build, set_default_opts

Instance Method Details

#buildObject

Build the shipment representation as a hash for the Savon client.



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# 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

#validateObject

Perform validations.



78
79
80
81
# 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