class SimpleShipping::Ups::ShipmentBuilder

Builds shipment element for UPS SOAP service.

Constants

PAYMENT_TYPE

The type of payment for this shipment.

SERVICE_TYPES

Service codes in UPS terminology.

Public Instance Methods

build() click to toggle source

Return a hash for Savon representing a shipment model.

# 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() click to toggle source

Return the PaymentInformation hash.

# File lib/simple_shipping/ups/shipment_builder.rb, line 39
def build_payment_info
  {'ShipmentCharge' => build_shipment_charge }
end
build_service() click to toggle source

Return the hash representing the Service.

# File lib/simple_shipping/ups/shipment_builder.rb, line 57
def build_service
  {'Code' => SERVICE_TYPES[@opts[:service_type]]}
end
build_shipment_charge() click to toggle source

Return the shipment charge for the PaymentInformation hash.

# 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() click to toggle source

Validate that the service type is included.

# File lib/simple_shipping/ups/shipment_builder.rb, line 62
def validate
  validate_inclusion_of(:service_type, SERVICE_TYPES)
end