Class: ActiveMerchant::Shipping::Carrier

Inherits:
Object
  • Object
show all
Includes:
PostsData, Quantified, RequiresParameters
Defined in:
lib/active_shipping/shipping/carrier.rb

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.



14
15
16
17
18
19
# File 'lib/active_shipping/shipping/carrier.rb', line 14

def initialize(options = {})
  requirements.each {|key| requires!(options, key)}
  @options = options
  @last_request = nil
  @test_mode = @options[:test]
end

Instance Attribute Details

#last_requestObject (readonly)

Returns the value of attribute last_request.



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

def last_request
  @last_request
end

#test_modeObject Also known as: test_mode?

Returns the value of attribute test_mode.



10
11
12
# File 'lib/active_shipping/shipping/carrier.rb', line 10

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/active_shipping/shipping/carrier.rb', line 27

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

#maximum_weightObject



42
43
44
# File 'lib/active_shipping/shipping/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/active_shipping/shipping/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/active_shipping/shipping/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 ActiveMerchant::Shipping::ResponseError
  false
else
  true
end