class Omniship::Carrier

Attributes

last_request[R]
test_mode[RW]
test_mode?[RW]

Public Class Methods

new(options = {}) click to toggle source

Credentials should be in options hash under keys :login, :password and/or :key.

# File lib/omniship/carrier.rb, line 13
def initialize(options = {})
  #requirements.each {|key| requires!(options, key)}
  @options = options
  @last_request = nil
  @test_mode = @options[:test]
                    @config = Omniship.setup
end

Protected Class Methods

default_location() click to toggle source

Override in subclasses for non-U.S.-based carriers.

# File lib/omniship/carrier.rb, line 53
def self.default_location
  Address.new( :country => 'US',
                :state => 'CA',
                :city => 'Beverly Hills',
                :address1 => '455 N. Rexford Dr.',
                :address2 => '3rd Floor',
                :zip => '90210',
                :phone => '1-310-285-1013',
                :fax => '1-310-275-8159')
end

Public Instance Methods

find_rates(origin, destination, packages, options = {}) click to toggle source

Override with whatever you need to get the rates

# File lib/omniship/carrier.rb, line 27
def find_rates(origin, destination, packages, options = {})
end
maximum_weight() click to toggle source
# File lib/omniship/carrier.rb, line 42
def maximum_weight
  Mass.new(150, :pounds)
end
requirements() click to toggle source

Override to return required keys in options hash for initialize method.

# File lib/omniship/carrier.rb, line 22
def requirements
  []
end
valid_credentials?() click to toggle source

Validate credentials with a call to the API. By default this just does a find_rates call with the orgin and destination both as the carrier’s default_location. Override to provide alternate functionality, such as checking for test_mode to use test servers, etc.

# File lib/omniship/carrier.rb, line 33
def valid_credentials?
  location = self.class.default_location
  find_rates(location,location,Package.new(100, [5,15,30]), :test => test_mode)
rescue Omniship::ResponseError
  false
else
  true
end

Protected Instance Methods

node_text_or_nil(xml_node) click to toggle source
# File lib/omniship/carrier.rb, line 48
def node_text_or_nil(xml_node)
  xml_node ? xml_node.text : nil
end
save_request(r) click to toggle source

Use after building the request to save for later inspection. Probably won’t ever be overridden.

# File lib/omniship/carrier.rb, line 65
def save_request(r)
  @last_request = r
end