Class: UPS::Builders::ShipperBuilder

Inherits:
BuilderBase show all
Includes:
Ox
Defined in:
lib/ups/builders/shipper_builder.rb

Overview

The ShipperBuilder class builds UPS XML Organization Objects.

Author:

  • Paul Trippett

Since:

  • 0.1.0

Instance Attribute Summary collapse

Attributes inherited from BuilderBase

#access_request, #document, #license_number, #password, #root, #shipment_root, #user_id

Instance Method Summary collapse

Methods inherited from BuilderBase

#add_access_request, #add_insurance_charge, #add_itemized_payment_information, #add_master_carton_id, #add_master_carton_indicator, #add_package, #add_payment_information, #add_rate_information, #add_request, #add_ship_from, #add_ship_to, #add_shipment_delivery_confirmation, #add_shipment_direct_delivery_only, #add_shipper, #add_sold_to

Constructor Details

#initialize(opts = {}) ⇒ ShipperBuilder

Initializes a new UPS::Builders::ShipperBuilder object

Parameters:

  • opts (Hash) (defaults to: {})

    The Shipper and Address Parts

Options Hash (opts):

  • :company_name (String)

    Company Name

  • :phone_number (String)

    Phone Number

  • :address_line_1 (String)

    Address Line 1

  • :city (String)

    City

  • :state (String)

    State

  • :postal_code (String)

    Zip or Postal Code

  • :country (String)

    Country

Since:

  • 0.1.0



26
27
28
29
# File 'lib/ups/builders/shipper_builder.rb', line 26

def initialize(opts = {})
  self.name = name
  self.opts = opts
end

Instance Attribute Details

#nameString

The Containing XML Element Name

Returns:

  • (String)

    the current value of name

Since:

  • 0.1.0



11
12
13
# File 'lib/ups/builders/shipper_builder.rb', line 11

def name
  @name
end

#optsHash

The Shipper and Address Parts

Returns:

  • (Hash)

    the current value of opts

Since:

  • 0.1.0



11
12
13
# File 'lib/ups/builders/shipper_builder.rb', line 11

def opts
  @opts
end

Instance Method Details

#addressOx::Element

Returns an XML representation of the associated Address

Returns:

  • (Ox::Element)

    XML object of the associated Address

Since:

  • 0.1.0



62
63
64
# File 'lib/ups/builders/shipper_builder.rb', line 62

def address
  AddressBuilder.new(opts).to_xml
end

#attention_nameOx::Element

Returns an XML representation of attention_name

Returns:

  • (Ox::Element)

    XML representation of attention_name

Since:

  • 0.1.0



69
70
71
# File 'lib/ups/builders/shipper_builder.rb', line 69

def attention_name
  element_with_value('AttentionName', opts[:attention_name] || '')
end

#company_nameOx::Element

Returns an XML representation of company_name

Returns:

  • (Ox::Element)

    XML representation of company_name

Since:

  • 0.1.0



41
42
43
# File 'lib/ups/builders/shipper_builder.rb', line 41

def company_name
  element_with_value('CompanyName', opts[:company_name])
end

#phone_numberOx::Element

Returns an XML representation of company_name

Returns:

  • (Ox::Element)

    XML representation of phone_number

Since:

  • 0.1.0



48
49
50
# File 'lib/ups/builders/shipper_builder.rb', line 48

def phone_number
  element_with_value('PhoneNumber', opts[:phone_number])
end

#shipper_nameOx::Element

Returns an XML representation of shipper_name

Returns:

  • (Ox::Element)

    XML representation of shipper_name

Since:

  • 0.1.0



34
35
36
# File 'lib/ups/builders/shipper_builder.rb', line 34

def shipper_name
  element_with_value('Name', opts[:company_name])
end

#shipper_numberOx::Element

Returns an XML representation of company_name

Returns:

  • (Ox::Element)

    XML representation of shipper_number

Since:

  • 0.1.0



55
56
57
# File 'lib/ups/builders/shipper_builder.rb', line 55

def shipper_number
  element_with_value('ShipperNumber', opts[:shipper_number] || '')
end

#tax_identification_numberOx::Element

Returns an XML representation of sender_vat_number

Returns:

  • (Ox::Element)

    XML representation of sender_vat_number

Since:

  • 0.1.0



76
77
78
# File 'lib/ups/builders/shipper_builder.rb', line 76

def tax_identification_number
  element_with_value('TaxIdentificationNumber', opts[:sender_vat_number] || '')
end

#to_xmlOx::Element

Returns an XML representation of the current object

Returns:

  • (Ox::Element)

    XML representation of the current object

Since:

  • 0.1.0



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/ups/builders/shipper_builder.rb', line 83

def to_xml
  Element.new('Shipper').tap do |org|
    org << shipper_name
    org << attention_name
    org << company_name
    org << phone_number
    org << shipper_number
    org << address
    org << tax_identification_number
  end
end