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



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

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



17
18
19
# File 'lib/ups/builders/builder_base.rb', line 17

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



17
18
19
# File 'lib/ups/builders/builder_base.rb', line 17

def document
  @document
end

#license_numberString

The UPS API Key

Returns:

  • (String)

    the current value of license_number

Since:

  • 0.1.0



17
18
19
# File 'lib/ups/builders/builder_base.rb', line 17

def license_number
  @license_number
end

#passwordString

The UPS Password

Returns:

  • (String)

    the current value of password

Since:

  • 0.1.0



17
18
19
# File 'lib/ups/builders/builder_base.rb', line 17

def password
  @password
end

#rootOx::Element

The XML Root

Returns:

  • (Ox::Element)

    the current value of root

Since:

  • 0.1.0



17
18
19
# File 'lib/ups/builders/builder_base.rb', line 17

def root
  @root
end

#shipment_rootOx::Element

The XML Shipment Element

Returns:

  • (Ox::Element)

    the current value of shipment_root

Since:

  • 0.1.0



17
18
19
# File 'lib/ups/builders/builder_base.rb', line 17

def shipment_root
  @shipment_root
end

#user_idString

The UPS Username

Returns:

  • (String)

    the current value of user_id

Since:

  • 0.1.0



17
18
19
# File 'lib/ups/builders/builder_base.rb', line 17

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



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

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_insurance_charge(value) ⇒ void

This method returns an undefined value.

Adds an InsuranceCharges section to the XML document being built

Parameters:

  • value (String)

    The MonetaryValue of the InsuranceCharge

Since:

  • 0.1.0



63
64
65
# File 'lib/ups/builders/builder_base.rb', line 63

def add_insurance_charge(value)
  shipment_root << insurance_charge(value)
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



145
146
147
148
149
150
151
152
# File 'lib/ups/builders/builder_base.rb', line 145

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])
    org << package_dimensions(opts[:dimensions]) if opts[:dimensions]
  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



158
159
160
161
162
163
164
165
166
# File 'lib/ups/builders/builder_base.rb', line 158

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



172
173
174
175
176
# File 'lib/ups/builders/builder_base.rb', line 172

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



72
73
74
75
76
77
# File 'lib/ups/builders/builder_base.rb', line 72

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



137
138
139
# File 'lib/ups/builders/builder_base.rb', line 137

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



106
107
108
# File 'lib/ups/builders/builder_base.rb', line 106

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

#add_shipment_delivery_confirmation(dcis_type) ⇒ void

This method returns an undefined value.

Adds a Delivery Confirmation DCIS Type to the shipment service options

Parameters:

  • dcis_type (String)

    DCIS type

Since:

  • 0.1.0



182
183
184
185
186
187
# File 'lib/ups/builders/builder_base.rb', line 182

def add_shipment_delivery_confirmation(dcis_type)
  shipment_service_options <<
    Element.new('DeliveryConfirmation').tap do |delivery_confirmation|
      delivery_confirmation << element_with_value('DCISType', dcis_type)
    end
end

#add_shipment_direct_delivery_onlyvoid

This method returns an undefined value.

Adds Direct Delivery Only indicator to the shipment service options

Since:

  • 0.1.0



192
193
194
# File 'lib/ups/builders/builder_base.rb', line 192

def add_shipment_direct_delivery_only
  shipment_service_options << Element.new('DirectDeliveryOnlyIndicator')
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



91
92
93
# File 'lib/ups/builders/builder_base.rb', line 91

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

#add_sold_to(opts = {}) ⇒ void

This method returns an undefined value.

Adds a SoldTo 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



121
122
123
# File 'lib/ups/builders/builder_base.rb', line 121

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

#to_xmlString

Returns a String representation of the XML document being built

Returns:

  • (String)

Since:

  • 0.1.0



199
200
201
# File 'lib/ups/builders/builder_base.rb', line 199

def to_xml
  Ox.to_xml document
end