Class: UPS::Builders::ShipConfirmBuilder

Inherits:
BuilderBase show all
Includes:
Ox
Defined in:
lib/ups/builders/ship_confirm_builder.rb

Overview

The ShipConfirmBuilder class builds UPS XML ShipConfirm Objects.

Author:

  • Paul Trippett

Since:

  • 0.1.0

Instance Attribute Summary collapse

Attributes inherited from BuilderBase

#access_request, #document, #license_number, #password, #root, #shipment_root, #user_id

Instance Method Summary collapse

Methods inherited from BuilderBase

#add_access_request, #add_insurance_charge, #add_itemized_payment_information, #add_master_carton_id, #add_master_carton_indicator, #add_package, #add_payment_information, #add_rate_information, #add_request, #add_ship_from, #add_ship_to, #add_shipment_delivery_confirmation, #add_shipment_direct_delivery_only, #add_shipper, #add_sold_to, #to_xml

Constructor Details

#initializeShipConfirmBuilder

Initializes a new UPS::Builders::ShipConfirmBuilder object

Since:

  • 0.1.0



16
17
18
19
20
# File 'lib/ups/builders/ship_confirm_builder.rb', line 16

def initialize
  super 'ShipmentConfirmRequest'

  add_request 'ShipConfirm', 'validate', sub_version: '1807'
end

Instance Attribute Details

#nameString

The Containing XML Element Name

Returns:

  • (String)

    the current value of name



11
12
13
# File 'lib/ups/builders/ship_confirm_builder.rb', line 11

def name
  @name
end

#optsHash

The Organization and Address Parts

Returns:

  • (Hash)

    the current value of opts



11
12
13
# File 'lib/ups/builders/ship_confirm_builder.rb', line 11

def opts
  @opts
end

Instance Method Details

#add_description(description) ⇒ void

This method returns an undefined value.

Adds Description to XML document being built

Parameters:

  • description (String)

    The description for goods being sent

Since:

  • 0.1.0



66
67
68
# File 'lib/ups/builders/ship_confirm_builder.rb', line 66

def add_description(description)
  shipment_root << element_with_value('Description', description)
end

#add_international_invoice(opts = {}) ⇒ void

This method returns an undefined value.

Adds a InternationalForms section to the XML document being built according to user inputs

Since:

  • 0.1.0



39
40
41
42
# File 'lib/ups/builders/ship_confirm_builder.rb', line 39

def add_international_invoice(opts = {})
  shipment_service_options <<
    InternationalInvoiceBuilder.new('InternationalForms', opts).to_xml
end

#add_invoice_line_total(value, currency_code) ⇒ Object

Since:

  • 0.1.0



57
58
59
# File 'lib/ups/builders/ship_confirm_builder.rb', line 57

def add_invoice_line_total(value, currency_code)
  shipment_root << invoice_line_total(value, currency_code)
end

#add_label_specification(format, size) ⇒ void

This method returns an undefined value.

Adds a LabelSpecification section to the XML document being built according to user inputs

Since:

  • 0.1.0



26
27
28
29
30
31
32
33
# File 'lib/ups/builders/ship_confirm_builder.rb', line 26

def add_label_specification(format, size)
  root << Element.new('LabelSpecification').tap do |label_spec|
    label_spec << label_print_method(format)
    label_spec << label_image_format(format)
    label_spec << label_stock_size(size)
    label_spec << http_user_agent if gif?(format)
  end
end

#add_reference_number(opts = {}) ⇒ void

This method returns an undefined value.

Adds ReferenceNumber to the XML document being built

Parameters:

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

    A Hash of data to build the requested section

Options Hash (opts):

  • :code (String)

    Code

  • :value (String)

    Value

Since:

  • 0.1.0



77
78
79
# File 'lib/ups/builders/ship_confirm_builder.rb', line 77

def add_reference_number(opts = {})
  shipment_root << reference_number(opts[:code], opts[:value])
end

#add_service(service_code, service_description = '') ⇒ void

This method returns an undefined value.

Adds a Service section to the XML document being built

Parameters:

  • service_code (String)

    The Service code for the choosen Shipping method

  • service_description (optional, String) (defaults to: '')

    A description for the choosen Shipping Method

Since:

  • 0.1.0



51
52
53
54
55
# File 'lib/ups/builders/ship_confirm_builder.rb', line 51

def add_service(service_code, service_description = '')
  shipment_root << code_description('Service',
                                    service_code,
                                    service_description)
end

#update_and_validate_for_worldwide_economy!Object

Since:

  • 0.1.0



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/ups/builders/ship_confirm_builder.rb', line 81

def update_and_validate_for_worldwide_economy!
  shipment_charge << element_with_value('Type', '01')

  packages = document.locate('ShipmentConfirmRequest/Shipment/Package')

   = document.locate(
    'ShipmentConfirmRequest/Shipment/ItemizedPaymentInformation/ShipmentCharge/BillShipper/AccountNumber/*'
  ).first

  unless packages.count == 1
    raise InvalidAttributeError,
      'Worldwide Economy shipment must be single-piece'
  end

  unless packages.first.locate('PackagingType/Code/*').first == '02'
    raise InvalidAttributeError,
      'Worldwide Economy shipment must use Customer Supplied Package'
  end

  unless .to_s.length > 0
    raise InvalidAttributeError,
      'Worldwide Economy shipment must have "Bill Shipper" Itemized Payment Information'
  end
end