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.


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

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


8
9
10
# File 'lib/active_shipping/shipping/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/active_shipping/shipping/carrier.rb', line 9

def test_mode
  @test_mode
end

Instance Method Details

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

Override with whatever you need to get a shipping label


30
31
# File 'lib/active_shipping/shipping/carrier.rb', line 30

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

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

Override with whatever you need to get the rates


26
27
# File 'lib/active_shipping/shipping/carrier.rb', line 26

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

#maximum_weightObject


45
46
47
# File 'lib/active_shipping/shipping/carrier.rb', line 45

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

#requirementsObject

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


21
22
23
# File 'lib/active_shipping/shipping/carrier.rb', line 21

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)

36
37
38
39
40
41
42
43
# File 'lib/active_shipping/shipping/carrier.rb', line 36

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