Class: SimpleShipping::Ups::PartyBuilder

Inherits:
Abstract::Builder show all
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

Methods inherited from Abstract::Builder

build, set_default_opts

Instance Method Details

#buildObject

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.,
   'Address'       => build_address,
   :order!         => ['Name', 'Phone', 'ShipperNumber', 'Address']
  }
end

#build_addressHash

Build address element.

Returns:

  • (Hash)


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

#validatevoid

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.
    raise SimpleShipping::ValidationError.new("account_number is required for party who is shipper")
  end
end