Class: SimpleShipping::Ups::PartyBuilder
- Inherits:
-
Abstract::Builder
- Object
- Abstract::Builder
- SimpleShipping::Ups::PartyBuilder
- Defined in:
- lib/simple_shipping/ups/party_builder.rb
Overview
Knows how to convert Party model to SOAP element for UPS.
Instance Method Summary collapse
-
#build ⇒ Object
Builds a hash for Savon which represents party.
-
#build_address ⇒ Hash
Build address element.
-
#validate ⇒ void
Validate presence of account_number.
Methods inherited from Abstract::Builder
Instance Method Details
#build ⇒ Object
Builds a hash for Savon which represents party.
5 6 7 8 9 10 11 12 13 |
# File 'lib/simple_shipping/ups/party_builder.rb', line 5 def build contact = @model.contact {'Name' => (contact.person_name || contact.company_name), 'Phone' => {'Number' => contact.phone_number}, 'ShipperNumber' => @model.account_number, 'Address' => build_address, :order! => ['Name', 'Phone', 'ShipperNumber', 'Address'] } end |
#build_address ⇒ Hash
Build address element.
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/simple_shipping/ups/party_builder.rb', line 18 def build_address addr = @model.address {'AddressLine' => [addr.street_line, addr.street_line_2, addr.street_line_3].compact, 'City' => addr.city, 'StateProvinceCode' => addr.state_code, 'PostalCode' => addr.postal_code, 'CountryCode' => addr.country_code, :order! => ['AddressLine', 'City', 'StateProvinceCode', 'PostalCode', 'CountryCode'] } end |
#validate ⇒ void
This method returns an undefined value.
Validate presence of account_number.
32 33 34 35 36 |
# File 'lib/simple_shipping/ups/party_builder.rb', line 32 def validate if @opts[:shipper] && !@model.account_number raise SimpleShipping::ValidationError.new("account_number is required for party who is shipper") end end |