Class: Shippinglogic::UPS

Inherits:
Object
  • Object
show all
Defined in:
lib/shippinglogic/ups.rb,
lib/shippinglogic/ups/rate.rb,
lib/shippinglogic/ups/error.rb,
lib/shippinglogic/ups/label.rb,
lib/shippinglogic/ups/track.rb,
lib/shippinglogic/ups/cancel.rb,
lib/shippinglogic/ups/request.rb,
lib/shippinglogic/ups/service.rb,
lib/shippinglogic/ups/response.rb,
lib/shippinglogic/ups/ship_accept.rb,
lib/shippinglogic/ups/enumerations.rb,
lib/shippinglogic/ups/ship_confirm.rb

Defined Under Namespace

Modules: Enumerations, Request, Response Classes: Cancel, Error, Label, Rate, Service, ShipAccept, ShipConfirm, Track

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, password, account, number, options = {}) ⇒ UPS

Before you can use the UPS web services you need to provide 4 credentials:

  1. Your UPS access key

  2. Your UPS password

  3. Your UPS user ID

  4. Your 6-character UPS account number

TODO Explain how to acquire those 4 credentials.

The last parameter allows you to modify the class options on an instance level. It accepts the same options that the class level method #options accepts. If you don’t want to change any of them, don’t supply this parameter.



42
43
44
45
46
47
48
# File 'lib/shippinglogic/ups.rb', line 42

def initialize(key, password, , number, options = {})
  self.key = key
  self.password = password
  self. = 
  self.number = number
  self.options = self.class.options.merge(options)
end

Instance Attribute Details

#accountObject

Returns the value of attribute account.



28
29
30
# File 'lib/shippinglogic/ups.rb', line 28

def 
  @account
end

#keyObject

Returns the value of attribute key.



28
29
30
# File 'lib/shippinglogic/ups.rb', line 28

def key
  @key
end

#numberObject

Returns the value of attribute number.



28
29
30
# File 'lib/shippinglogic/ups.rb', line 28

def number
  @number
end

#optionsObject

Returns the value of attribute options.



28
29
30
# File 'lib/shippinglogic/ups.rb', line 28

def options
  @options
end

#passwordObject

Returns the value of attribute password.



28
29
30
# File 'lib/shippinglogic/ups.rb', line 28

def password
  @password
end

Class Method Details

.optionsObject

A hash representing default the options. If you are using this in a Rails app the best place to modify or change these options is either in an initializer or your specific environment file. Keep in mind that these options can be modified on the instance level when creating an object. See #initialize for more details.

Options

  • :test - this basically tells us which url to use. If set to true we will use the UPS test URL, if false we will use the production URL. If you are using this in a rails app, unless you are in your production environment, this will default to true automatically.

  • :test_url - the test URL for UPS’s webservices. (default: wwwcie.ups.com:443/ups.app/xml)

  • :production_url - the production URL for UPS’s webservices. (default: www.ups.com:443/ups.app/xml)



20
21
22
23
24
25
26
# File 'lib/shippinglogic/ups.rb', line 20

def self.options
  @options ||= {
    :test => !!(defined?(Rails) && !Rails.env.production?),
    :production_url => "https://www.ups.com:443/ups.app/xml",
    :test_url => "https://wwwcie.ups.com:443/ups.app/xml"
  }
end

Instance Method Details

#cancel(attributes = {}) ⇒ Object



55
56
57
# File 'lib/shippinglogic/ups.rb', line 55

def cancel(attributes = {})
  @cancel ||= Cancel.new(self, attributes)
end

#label(attributes = {}) ⇒ Object



79
80
81
# File 'lib/shippinglogic/ups.rb', line 79

def label(attributes = {})
  @label ||= Label.new(self, attributes)
end

#rate(attributes = {}) ⇒ Object



59
60
61
# File 'lib/shippinglogic/ups.rb', line 59

def rate(attributes = {})
  @rate ||= Rate.new(self, attributes)
end

#ship(attributes = {}) ⇒ Object



71
72
73
# File 'lib/shippinglogic/ups.rb', line 71

def ship(attributes = {})
  @ship ||= ship_accept(:digest => ship_confirm(attributes).digest)
end

#ship_accept(attributes = {}) ⇒ Object



67
68
69
# File 'lib/shippinglogic/ups.rb', line 67

def ship_accept(attributes = {})
  @ship_accept ||= ShipAccept.new(self, attributes)
end

#ship_confirm(attributes = {}) ⇒ Object



63
64
65
# File 'lib/shippinglogic/ups.rb', line 63

def ship_confirm(attributes = {})
  @ship_confirm ||= ShipConfirm.new(self, attributes)
end

#track(attributes = {}) ⇒ Object



75
76
77
# File 'lib/shippinglogic/ups.rb', line 75

def track(attributes = {})
  @track ||= Track.new(self, attributes)
end

#urlObject

A convenience method for accessing the endpoint URL for the UPS API.



51
52
53
# File 'lib/shippinglogic/ups.rb', line 51

def url
  options[:test] ? options[:test_url] : options[:production_url]
end