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_itemized_payment_information(ship_number) ⇒ Object

Since:

  • 0.1.0



167
168
169
170
171
# File 'lib/ups/builders/builder_base.rb', line 167

def add_itemized_payment_information(ship_number)
  shipment_charge << Element.new('BillShipper').tap do |bill_shipper|
    bill_shipper << element_with_value('AccountNumber', ship_number)
  end
end

#add_master_carton_id(master_carton_id) ⇒ void

This method returns an undefined value.

Adds MasterCartonID to the shipment

Since:

  • 0.1.0



211
212
213
# File 'lib/ups/builders/builder_base.rb', line 211

def add_master_carton_id(master_carton_id)
  shipment_root << element_with_value('MasterCartonID', master_carton_id)
end

#add_master_carton_indicatorvoid

This method returns an undefined value.

Adds MasterCartonIndicator to the shipment

Since:

  • 0.1.0



204
205
206
# File 'lib/ups/builders/builder_base.rb', line 204

def add_master_carton_indicator
  shipment_root << Element.new('MasterCartonIndicator')
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



149
150
151
# File 'lib/ups/builders/builder_base.rb', line 149

def add_package(opts = {})
  shipment_root << PackageBuilder.new('Package', opts).to_xml
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



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

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



177
178
179
180
181
# File 'lib/ups/builders/builder_base.rb', line 177

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, sub_version: nil) ⇒ 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
78
79
80
81
# File 'lib/ups/builders/builder_base.rb', line 72

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

    unless sub_version.nil?
      request << element_with_value('SubVersion', sub_version)
    end
  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



141
142
143
# File 'lib/ups/builders/builder_base.rb', line 141

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



110
111
112
# File 'lib/ups/builders/builder_base.rb', line 110

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



187
188
189
190
191
192
# File 'lib/ups/builders/builder_base.rb', line 187

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



197
198
199
# File 'lib/ups/builders/builder_base.rb', line 197

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



95
96
97
# File 'lib/ups/builders/builder_base.rb', line 95

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



125
126
127
# File 'lib/ups/builders/builder_base.rb', line 125

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



218
219
220
# File 'lib/ups/builders/builder_base.rb', line 218

def to_xml
  Ox.to_xml document
end