Class: UPS::Builders::OrganisationBuilder

Inherits:
BuilderBase
  • Object
show all
Includes:
Ox
Defined in:
lib/ups/builders/organisation_builder.rb

Overview

The OrganisationBuilder class builds UPS XML Organization 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

Constructor Details

#initialize(name, opts = {}) ⇒ OrganisationBuilder

Initializes a new AddressBuilder object

Parameters:

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

    The Organization and Address Parts

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



26
27
28
29
30
# File 'lib/ups/builders/organisation_builder.rb', line 26

def initialize(name, opts = {})
  self.name = name
  self.opts = opts
  self.opts[:skip_ireland_state_validation] = (name == 'SoldTo')
end

Instance Attribute Details

#nameString

The Containing XML Element Name

Returns:

  • (String)

    the current value of name

Since:

  • 0.1.0



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

def name
  @name
end

#optsHash

The Organization and Address Parts

Returns:

  • (Hash)

    the current value of opts

Since:

  • 0.1.0



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

def opts
  @opts
end

Instance Method Details

#addressOx::Element

Returns an XML representation of address

Returns:

  • (Ox::Element)

    An instance of AddressBuilder containing the address

Since:

  • 0.1.0



72
73
74
# File 'lib/ups/builders/organisation_builder.rb', line 72

def address
  AddressBuilder.new(opts).to_xml
end

#attention_nameOx::Element

Returns an XML representation of AttentionName for which we use company name

Returns:

  • (Ox::Element)

    XML representation of company_name part

Since:

  • 0.1.0



50
51
52
# File 'lib/ups/builders/organisation_builder.rb', line 50

def attention_name
  element_with_value('AttentionName', opts[:attention_name][0..34])
end

#company_nameOx::Element

Returns an XML representation of company_name

Returns:

  • (Ox::Element)

    XML representation of company_name

Since:

  • 0.1.0



35
36
37
# File 'lib/ups/builders/organisation_builder.rb', line 35

def company_name
  element_with_value('CompanyName', opts[:company_name][0..34])
end

#email_addressOx::Element

Returns an XML representation of the email address of the company

Returns:

  • (Ox::Element)

    XML representation of email address

Since:

  • 0.1.0



64
65
66
# File 'lib/ups/builders/organisation_builder.rb', line 64

def email_address
  element_with_value('EMailAddress', opts[:email_address].to_s[0..50])
end

#phone_numberOx::Element

Returns an XML representation of phone_number

Returns:

  • (Ox::Element)

    XML representation of phone_number

Since:

  • 0.1.0



42
43
44
# File 'lib/ups/builders/organisation_builder.rb', line 42

def phone_number
  element_with_value('PhoneNumber', opts[:phone_number][0..14])
end

#tax_identification_numberOx::Element

Returns an XML representation of sender_vat_number of the company

Returns:

  • (Ox::Element)

    XML representation of sender_vat_number

Since:

  • 0.1.0



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

def tax_identification_number
  element_with_value('TaxIdentificationNumber', opts[:sender_vat_number] || '')
end

#to_xmlOx::Element

Returns an XML representation of a UPS Organization

Returns:

  • (Ox::Element)

    XML representation of the current object

Since:

  • 0.1.0



92
93
94
95
96
97
98
99
100
101
102
# File 'lib/ups/builders/organisation_builder.rb', line 92

def to_xml
  Element.new(name).tap do |org|
    org << company_name
    org << phone_number
    org << attention_name
    org << address
    org << tax_identification_number
    org << email_address
    org << vendor_info unless opts[:sender_ioss_number].to_s.empty?
  end
end

#vendor_infoOx::Element

Returns an XML representation of vendor info (ioss number and more) of the company

Returns:

  • (Ox::Element)

    XML representation of sender_ioss_number

Since:

  • 0.1.0



79
80
81
82
83
84
85
86
87
# File 'lib/ups/builders/organisation_builder.rb', line 79

def vendor_info
  ioss_vendor_collect_id = '0356'

  Element.new('VendorInfo').tap do |vendor_info|
    vendor_info << element_with_value('VendorCollectIDNumber', opts[:sender_ioss_number] || '')
    vendor_info << element_with_value('VendorCollectIDTypeCode', ioss_vendor_collect_id)
    vendor_info << element_with_value('ConsigneeType', '02')
  end
end