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_package, #add_payment_information, #add_rate_information, #add_request, #add_ship_from, #add_ship_to, #add_shipper

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


28
29
30
31
# File 'lib/ups/builders/shipper_builder.rb', line 28

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


13
14
15
# File 'lib/ups/builders/shipper_builder.rb', line 13

def name
  @name
end

#optsHash

The Shipper and Address Parts

Returns:

  • (Hash)

    the current value of opts

Since:

  • 0.1.0


13
14
15
# File 'lib/ups/builders/shipper_builder.rb', line 13

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


64
65
66
# File 'lib/ups/builders/shipper_builder.rb', line 64

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


71
72
73
# File 'lib/ups/builders/shipper_builder.rb', line 71

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


43
44
45
# File 'lib/ups/builders/shipper_builder.rb', line 43

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


50
51
52
# File 'lib/ups/builders/shipper_builder.rb', line 50

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


36
37
38
# File 'lib/ups/builders/shipper_builder.rb', line 36

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


57
58
59
# File 'lib/ups/builders/shipper_builder.rb', line 57

def shipper_number
  element_with_value('ShipperNumber', opts[:shipper_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


78
79
80
81
82
83
84
85
86
87
# File 'lib/ups/builders/shipper_builder.rb', line 78

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
  end
end