Class: Omniship::Carrier
- Includes:
- ActiveUtils::PostsData, ActiveUtils::RequiresParameters, Quantified
- Defined in:
- lib/omniship/carrier.rb
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.
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( = {}) #requirements.each {|key| requires!(options, key)} @options = @last_request = nil @test_mode = @options[:test] @config = Omniship.setup end |
Instance Attribute Details
#last_request ⇒ Object (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_mode ⇒ Object 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, = {}) end |
#maximum_weight ⇒ Object
42 43 44 |
# File 'lib/omniship/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/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.
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 |