class UPS::Builders::ShipConfirmBuilder

The {ShipConfirmBuilder} class builds UPS XML ShipConfirm Objects.

@author Paul Trippett @since 0.1.0 @attr [String] name The Containing XML Element Name @attr [Hash] opts The Organization and Address Parts

Public Class Methods

new() click to toggle source

Initializes a new {ShipConfirmBuilder} object

Calls superclass method UPS::Builders::BuilderBase::new
# File lib/ups/builders/ship_confirm_builder.rb, line 16
def initialize
  super 'ShipmentConfirmRequest'

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

Public Instance Methods

add_description(description) click to toggle source

Adds Description to XML document being built

@param [String] description The description for goods being sent

@return [void]

# 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 = {}) click to toggle source

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

@return [void]

# 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) click to toggle source
# 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) click to toggle source

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

@return [void]

# 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 = {}) click to toggle source

Adds ReferenceNumber to the XML document being built

@param [Hash] opts A Hash of data to build the requested section @option opts [String] :code Code @option opts [String] :value Value

@return [void]

# 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 = '') click to toggle source

Adds a Service section to the XML document being built

@param [String] service_code The Service code for the choosen Shipping

method

@param [optional, String] service_description A description for the

choosen Shipping Method

@return [void]

# 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!() click to toggle source
# 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')

  bill_shipper_account_number = 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 bill_shipper_account_number.to_s.length > 0
    raise InvalidAttributeError,
      'Worldwide Economy shipment must have "Bill Shipper" Itemized Payment Information'
  end
end

Private Instance Methods

gif?(string) click to toggle source
# File lib/ups/builders/ship_confirm_builder.rb, line 108
def gif?(string)
  string.downcase == 'gif'
end
http_user_agent() click to toggle source
# File lib/ups/builders/ship_confirm_builder.rb, line 112
def http_user_agent
  element_with_value('HTTPUserAgent', version_string)
end
invoice_line_total(value, currency_code) click to toggle source
# File lib/ups/builders/ship_confirm_builder.rb, line 140
def invoice_line_total(value, currency_code)
  multi_valued('InvoiceLineTotal',
               'CurrencyCode' => currency_code.to_s,
               'MonetaryValue' => value.to_s)
end
label_image_format(format) click to toggle source
# File lib/ups/builders/ship_confirm_builder.rb, line 124
def label_image_format(format)
  code_description 'LabelImageFormat', "#{format}", "#{format}"
end
label_print_method(format) click to toggle source
# File lib/ups/builders/ship_confirm_builder.rb, line 120
def label_print_method(format)
  code_description 'LabelPrintMethod', "#{format}", "#{format} file"
end
label_stock_size(size) click to toggle source
# File lib/ups/builders/ship_confirm_builder.rb, line 128
def label_stock_size(size)
  multi_valued('LabelStockSize',
               'Height' => size[:height].to_s,
               'Width' => size[:width].to_s)
end
reference_number(code, value) click to toggle source
# File lib/ups/builders/ship_confirm_builder.rb, line 134
def reference_number(code, value)
  multi_valued('ReferenceNumber',
               'Code' => code.to_s,
               'Value' => value.to_s)
end
service_code() click to toggle source
# File lib/ups/builders/ship_confirm_builder.rb, line 146
def service_code
  document.locate('ShipmentConfirmRequest/Shipment/Service/Code/*').first
end
version_string() click to toggle source
# File lib/ups/builders/ship_confirm_builder.rb, line 116
def version_string
  "RubyUPS/#{UPS::Version::STRING}"
end