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, PackageBuilder, RateBuilder, ShipAcceptBuilder, ShipConfirmBuilder, ShipperBuilder, TrackBuilder
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_itemized_payment_information(ship_number) ⇒ Object
-
#add_master_carton_id(master_carton_id) ⇒ void
Adds MasterCartonID to the shipment.
-
#add_master_carton_indicator ⇒ void
Adds MasterCartonIndicator to the shipment.
-
#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, sub_version: nil) ⇒ 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_itemized_payment_information(ship_number) ⇒ Object
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
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_indicator ⇒ void
This method returns an undefined value.
Adds MasterCartonIndicator to the shipment
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
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
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_information ⇒ void
This method returns an undefined value.
Adds a RateInformation/NegotiatedRatesIndicator section to the XML document being built
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
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
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
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
187 188 189 190 191 192 |
# File 'lib/ups/builders/builder_base.rb', line 187 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
197 198 199 |
# File 'lib/ups/builders/builder_base.rb', line 197 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
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
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_xml ⇒ String
Returns a String representation of the XML document being built
218 219 220 |
# File 'lib/ups/builders/builder_base.rb', line 218 def to_xml Ox.to_xml document end |