Class: UPS::Builders::BuilderBase Abstract
- Inherits:
-
Object
- Object
- UPS::Builders::BuilderBase
- Includes:
- Ox, Exceptions
- Defined in:
- lib/ups/builders/builder_base.rb
Overview
The BuilderBase class builds UPS XML Address Objects.
Direct Known Subclasses
AddressBuilder, InternationalInvoiceBuilder, InternationalInvoiceProductBuilder, OrganisationBuilder, RateBuilder, ShipAcceptBuilder, ShipConfirmBuilder, ShipperBuilder
Instance Attribute Summary collapse
-
#access_request ⇒ Ox::Element
The XML AccessRequest Element.
-
#document ⇒ Ox::Document
The XML Document being built.
-
#license_number ⇒ String
The UPS API Key.
-
#password ⇒ String
The UPS Password.
-
#root ⇒ Ox::Element
The XML Root.
-
#shipment_root ⇒ Ox::Element
The XML Shipment Element.
-
#user_id ⇒ String
The UPS Username.
Instance Method Summary collapse
-
#add_access_request(license_number, user_id, password) ⇒ void
Initializes a new BuilderBase object.
-
#add_insurance_charge(value) ⇒ void
Adds an InsuranceCharges section to the XML document being built.
-
#add_package(opts = {}) ⇒ void
Adds a Package section to the XML document being built.
-
#add_payment_information(ship_number) ⇒ void
Adds a PaymentInformation section to the XML document being built.
-
#add_rate_information ⇒ void
Adds a RateInformation/NegotiatedRatesIndicator section to the XML document being built.
-
#add_request(action, option) ⇒ void
Adds a Request section to the XML document being built.
-
#add_ship_from(opts = {}) ⇒ void
Adds a ShipFrom section to the XML document being built.
-
#add_ship_to(opts = {}) ⇒ void
Adds a ShipTo section to the XML document being built.
-
#add_shipment_delivery_confirmation(dcis_type) ⇒ void
Adds a Delivery Confirmation DCIS Type to the shipment service options.
-
#add_shipment_direct_delivery_only ⇒ void
Adds Direct Delivery Only indicator to the shipment service options.
-
#add_shipper(opts = {}) ⇒ void
Adds a Shipper section to the XML document being built.
-
#add_sold_to(opts = {}) ⇒ void
Adds a SoldTo section to the XML document being built.
-
#initialize(root_name) {|_self| ... } ⇒ void
constructor
Initializes a new BuilderBase object.
-
#to_xml ⇒ String
Returns a String representation of the XML document being built.
Constructor Details
#initialize(root_name) {|_self| ... } ⇒ void
Initializes a new UPS::Builders::BuilderBase object
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_request ⇒ Ox::Element
The XML AccessRequest Element
17 18 19 |
# File 'lib/ups/builders/builder_base.rb', line 17 def access_request @access_request end |
#document ⇒ Ox::Document
The XML Document being built
17 18 19 |
# File 'lib/ups/builders/builder_base.rb', line 17 def document @document end |
#license_number ⇒ String
The UPS API Key
17 18 19 |
# File 'lib/ups/builders/builder_base.rb', line 17 def license_number @license_number end |
#password ⇒ String
The UPS Password
17 18 19 |
# File 'lib/ups/builders/builder_base.rb', line 17 def password @password end |
#root ⇒ Ox::Element
The XML Root
17 18 19 |
# File 'lib/ups/builders/builder_base.rb', line 17 def root @root end |
#shipment_root ⇒ Ox::Element
The XML Shipment Element
17 18 19 |
# File 'lib/ups/builders/builder_base.rb', line 17 def shipment_root @shipment_root end |
#user_id ⇒ String
The UPS Username
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
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
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
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
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_information ⇒ void
This method returns an undefined value.
Adds a RateInformation/NegotiatedRatesIndicator section to the XML document being built
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
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
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
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
182 183 184 185 186 187 |
# File 'lib/ups/builders/builder_base.rb', line 182 def add_shipment_delivery_confirmation(dcis_type) << Element.new('DeliveryConfirmation').tap do |delivery_confirmation| delivery_confirmation << element_with_value('DCISType', dcis_type) end end |
#add_shipment_direct_delivery_only ⇒ void
This method returns an undefined value.
Adds Direct Delivery Only indicator to the shipment service options
192 193 194 |
# File 'lib/ups/builders/builder_base.rb', line 192 def add_shipment_direct_delivery_only << Element.new('DirectDeliveryOnlyIndicator') end |
#add_shipper(opts = {}) ⇒ void
This method returns an undefined value.
Adds a Shipper section to the XML document being built
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
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_xml ⇒ String
Returns a String representation of the XML document being built
199 200 201 |
# File 'lib/ups/builders/builder_base.rb', line 199 def to_xml Ox.to_xml document end |