Class: ActiveMerchant::Shipping::Carrier
- Includes:
- PostsData, RequiresParameters, Quantified
- Defined in:
- lib/active_shipping/shipping/carrier.rb
Direct Known Subclasses
BogusCarrier, CanadaPost, FedEx, Kunaki, NewZealandPost, Shipwire, UPS, USPS
Instance Attribute Summary collapse
-
#last_request ⇒ Object
readonly
Returns the value of attribute last_request.
-
#test_mode ⇒ Object
(also: #test_mode?)
Returns the value of attribute test_mode.
Instance Method Summary collapse
-
#find_rates(origin, destination, packages, options = {}) ⇒ Object
Override with whatever you need to get the rates.
-
#initialize(options = {}) ⇒ Carrier
constructor
Credentials should be in options hash under keys :login, :password and/or :key.
- #maximum_weight ⇒ Object
-
#requirements ⇒ Object
Override to return required keys in options hash for initialize method.
-
#valid_credentials? ⇒ Boolean
Validate credentials with a call to the API.
Methods included from PostsData
included, #raw_ssl_request, #ssl_get, #ssl_post, #ssl_request
Methods included from RequiresParameters
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( = {}) requirements.each {|key| requires!(, key)} @options = @last_request = nil @test_mode = @options[:test] end |
Instance Attribute Details
#last_request ⇒ Object (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_mode ⇒ Object 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, = {}) end |
#maximum_weight ⇒ Object
42 43 44 |
# File 'lib/active_shipping/shipping/carrier.rb', line 42 def maximum_weight Mass.new(150, :pounds) end |
#requirements ⇒ Object
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.
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 |