Class: Omniship::Carrier

Inherits:
Object show all
Includes:
ActiveUtils::PostsData, ActiveUtils::RequiresParameters, Quantified
Defined in:
lib/omniship/carrier.rb

Direct Known Subclasses

FedEx, UPS, USPS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Carrier

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



13
14
15
16
17
18
19
# 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

Instance Attribute Details

#last_requestObject (readonly)

Returns the value of attribute last_request.



8
9
10
# File 'lib/omniship/carrier.rb', line 8

def last_request
  @last_request
end

#test_modeObject Also known as: test_mode?

Returns the value of attribute test_mode.



9
10
11
# File 'lib/omniship/carrier.rb', line 9

def test_mode
  @test_mode
end

Instance Method Details

#find_rates(origin, destination, packages, options = {}) ⇒ Object

Override with whatever you need to get the rates



27
28
# File 'lib/omniship/carrier.rb', line 27

def find_rates(origin, destination, packages, options = {})
end

#maximum_weightObject



42
43
44
# File 'lib/omniship/carrier.rb', line 42

def maximum_weight
  Mass.new(150, :pounds)
end

#requirementsObject

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



22
23
24
# File 'lib/omniship/carrier.rb', line 22

def requirements
  []
end

#valid_credentials?Boolean

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.

Returns:

  • (Boolean)


33
34
35
36
37
38
39
40
# 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