Class: UPS::Builders::BuilderBase Abstract

Inherits:
Object
  • Object
show all
Includes:
Ox, Exceptions
Defined in:
lib/ups/builders/builder_base.rb

Overview

This class is abstract.

The BuilderBase class builds UPS XML Address Objects.

Author:

  • Paul Trippett

Since:

  • 0.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root_name) {|_self| ... } ⇒ void

Initializes a new UPS::Builders::BuilderBase object

Parameters:

  • root_name (String)

    The Name of the XML Root

Yields:

  • (_self)

Yield Parameters:

Since:

  • 0.1.0


35
36
37
38
39
40
41
42
# File 'lib/ups/builders/builder_base.rb', line 35

def initialize(root_name)
  initialize_xml_roots root_name

  document << access_request
  document << root

  yield self if block_given?
end

Instance Attribute Details

#access_requestOx::Element

The XML AccessRequest Element

Returns:

  • (Ox::Element)

    the current value of access_request

Since:

  • 0.1.0


19
20
21
# File 'lib/ups/builders/builder_base.rb', line 19

def access_request
  @access_request
end

#documentOx::Document

The XML Document being built

Returns:

  • (Ox::Document)

    the current value of document

Since:

  • 0.1.0


19
20
21
# File 'lib/ups/builders/builder_base.rb', line 19

def document
  @document
end

#license_numberString

The UPS API Key

Returns:

  • (String)

    the current value of license_number

Since:

  • 0.1.0


19
20
21
# File 'lib/ups/builders/builder_base.rb', line 19

def license_number
  @license_number
end

#passwordString

The UPS Password

Returns:

  • (String)

    the current value of password

Since:

  • 0.1.0


19
20
21
# File 'lib/ups/builders/builder_base.rb', line 19

def password
  @password
end

#rootOx::Element

The XML Root

Returns:

  • (Ox::Element)

    the current value of root

Since:

  • 0.1.0


19
20
21
# File 'lib/ups/builders/builder_base.rb', line 19

def root
  @root
end

#shipment_rootOx::Element

The XML Shipment Element

Returns:

  • (Ox::Element)

    the current value of shipment_root

Since:

  • 0.1.0


19
20
21
# File 'lib/ups/builders/builder_base.rb', line 19

def shipment_root
  @shipment_root
end

#user_idString

The UPS Username

Returns:

  • (String)

    the current value of user_id

Since:

  • 0.1.0


19
20
21
# File 'lib/ups/builders/builder_base.rb', line 19

def user_id
  @user_id
end

Instance Method Details

#add_access_request(license_number, user_id, password) ⇒ void

This method returns an undefined value.

Initializes a new UPS::Builders::BuilderBase object

Parameters:

  • license_number (String)

    The UPS API Key

  • user_id (String)

    The UPS Username

  • password (String)

    The UPS Password

Since:

  • 0.1.0


50
51
52
53
54
55
56
57
58
59
# File 'lib/ups/builders/builder_base.rb', line 50

def add_access_request(license_number, user_id, password)
  self.license_number = license_number
  self.user_id = user_id
  self.password = password

  access_request << element_with_value('AccessLicenseNumber',
                                       license_number)
  access_request << element_with_value('UserId', user_id)
  access_request << element_with_value('Password', password)
end

#add_package(opts = {}) ⇒ void

This method returns an undefined value.

Adds a Package section to the XML document being built

Parameters:

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

    A Hash of data to build the requested section

Since:

  • 0.1.0


124
125
126
127
128
129
130
# File 'lib/ups/builders/builder_base.rb', line 124

def add_package(opts = {})
  shipment_root << Element.new('Package').tap do |org|
    org << packaging_type
    org << element_with_value('Description', 'Rate')
    org << package_weight(opts[:weight], opts[:unit])
  end
end

#add_payment_information(ship_number) ⇒ void

This method returns an undefined value.

Adds a PaymentInformation section to the XML document being built

Parameters:

  • ship_number (String)

    The UPS Shipper Number

Since:

  • 0.1.0


136
137
138
139
140
141
142
143
144
# File 'lib/ups/builders/builder_base.rb', line 136

def add_payment_information(ship_number)
  shipment_root << Element.new('PaymentInformation').tap do |payment|
    payment << Element.new('Prepaid').tap do |prepaid|
      prepaid << Element.new('BillShipper').tap do |bill_shipper|
        bill_shipper << element_with_value('AccountNumber', ship_number)
      end
    end
  end
end

#add_rate_informationvoid

This method returns an undefined value.

Adds a RateInformation/NegotiatedRatesIndicator section to the XML document being built

Since:

  • 0.1.0


150
151
152
153
154
# File 'lib/ups/builders/builder_base.rb', line 150

def add_rate_information
  shipment_root << Element.new('RateInformation').tap do |rate_info|
    rate_info << element_with_value('NegotiatedRatesIndicator', '1')
  end
end

#add_request(action, option) ⇒ void

This method returns an undefined value.

Adds a Request section to the XML document being built

Parameters:

  • action (String)

    The UPS API Action requested

  • option (String)

    The UPS API Option

Since:

  • 0.1.0


66
67
68
69
70
71
# File 'lib/ups/builders/builder_base.rb', line 66

def add_request(action, option)
  root << Element.new('Request').tap do |request|
    request << element_with_value('RequestAction', action)
    request << element_with_value('RequestOption', option)
  end
end

#add_ship_from(opts = {}) ⇒ void

This method returns an undefined value.

Adds a ShipFrom section to the XML document being built

Parameters:

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

    A Hash of data to build the requested section

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

  • :shipper_number (String)

    UPS Account Number

Since:

  • 0.1.0


116
117
118
# File 'lib/ups/builders/builder_base.rb', line 116

def add_ship_from(opts = {})
  shipment_root << OrganisationBuilder.new('ShipFrom', opts).to_xml
end

#add_ship_to(opts = {}) ⇒ void

This method returns an undefined value.

Adds a ShipTo section to the XML document being built

Parameters:

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

    A Hash of data to build the requested section

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


100
101
102
# File 'lib/ups/builders/builder_base.rb', line 100

def add_ship_to(opts = {})
  shipment_root << OrganisationBuilder.new('ShipTo', opts).to_xml
end

#add_shipper(opts = {}) ⇒ void

This method returns an undefined value.

Adds a Shipper section to the XML document being built

Parameters:

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

    A Hash of data to build the requested section

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

  • :shipper_number (String)

    UPS Account Number

Since:

  • 0.1.0


85
86
87
# File 'lib/ups/builders/builder_base.rb', line 85

def add_shipper(opts = {})
  shipment_root << ShipperBuilder.new(opts).to_xml
end

#to_xmlString

Returns a String representation of the XML document being built

Returns:

  • (String)

Since:

  • 0.1.0


159
160
161
# File 'lib/ups/builders/builder_base.rb', line 159

def to_xml
  Ox.to_xml document
end