Class: SimpleShipping::Ups::PackageBuilder
- Inherits:
-
Abstract::Builder
- Object
- Abstract::Builder
- SimpleShipping::Ups::PackageBuilder
- Defined in:
- lib/simple_shipping/ups/package_builder.rb
Overview
Builds hash structure for Savon that represents package element in UPS’s API.
Constant Summary collapse
- PACKAGING_TYPES =
Mapping for UPS packaging types Not all UPS values listed here in order to provide common interface with FedEx.
{ :envelope => '01', # letter :your => '02', # customer supplied :tube => '03', # tube :pak => '04', # UPS Packaging :box => '2b', # medium box :box_10kg => '25', :box_10kg => '24' }
- WEIGHT_UNITS =
Mapping for UPS weight units.
{ :kg => 'KGS', :lb => 'LBS' }
- DIMENSION_UNITS =
Mapping for UPS dimension units.
{ :in => 'IN', :cm => 'CM' }
- CUSTOM_PACKAGE_ORDER =
Custom package order.
%w(Packaging PackageServiceOptions Dimensions PackageWeight)
- STANDARD_PACKAGE_ORDER =
Standard package order.
%w(Packaging PackageServiceOptions PackageWeight)
Instance Method Summary collapse
-
#base_package ⇒ Hash
Build basic skeleton for package element.
-
#build ⇒ Object
Build the package, whether custom or standard.
-
#custom_package ⇒ Object
Build a hash from a custom package which will be used by Savon.
-
#standard_package ⇒ Object
Build a hash from a standard package which will be used by Savon.
Methods inherited from Abstract::Builder
build, set_default_opts, #validate
Instance Method Details
#base_package ⇒ Hash
Build basic skeleton for package element. It can be customized by overriding some subelements.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/simple_shipping/ups/package_builder.rb', line 39 def base_package base = { 'Packaging' => { 'Code' => PACKAGING_TYPES[@model.packaging_type] }, 'PackageWeight' => { 'UnitOfMeasurement' => { 'Code' => WEIGHT_UNITS[@model.weight_units] }, 'Weight' => @model.weight, :order! => ['UnitOfMeasurement', 'Weight'] }, 'PackageServiceOptions' => {} } if @model.insured_value base['PackageServiceOptions']['InsuredValue'] = { 'CurrencyCode' => 'USD', 'MonetaryValue' => @model.insured_value } end if @model.declared_value base['PackageServiceOptions']['DeclaredValue'] = { 'CurrencyCode' => 'USD', 'MonetaryValue' => @model.declared_value } end base end |
#build ⇒ Object
Build the package, whether custom or standard.
97 98 99 |
# File 'lib/simple_shipping/ups/package_builder.rb', line 97 def build @model.custom_package? ? custom_package : standard_package end |
#custom_package ⇒ Object
Build a hash from a custom package which will be used by Savon. A custom package requires specification of LWH dimensions.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/simple_shipping/ups/package_builder.rb', line 73 def custom_package base_package.tap do |package| package['Dimensions'] = { 'UnitOfMeasurement' => { 'Code' => DIMENSION_UNITS[@model.dimension_units].clone }, 'Length' => @model.length, 'Width' => @model.width, 'Height' => @model.height, :order! => ['UnitOfMeasurement', 'Length', 'Width', 'Height'] } package[:order!] = CUSTOM_PACKAGE_ORDER.clone end end |
#standard_package ⇒ Object
Build a hash from a standard package which will be used by Savon. A standard package requires no specification of LWH dimensions.
90 91 92 93 94 |
# File 'lib/simple_shipping/ups/package_builder.rb', line 90 def standard_package base_package.tap do |package| package[:order!] = STANDARD_PACKAGE_ORDER.clone end end |