active_shipping 0.12.6 → 1.0.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +2 -0
  3. data.tar.gz.sig +0 -0
  4. data/{CHANGELOG → CHANGELOG.md} +6 -2
  5. data/CONTRIBUTING.md +32 -0
  6. data/{README.markdown → README.md} +45 -61
  7. data/lib/active_shipping.rb +20 -28
  8. data/lib/active_shipping/carrier.rb +82 -0
  9. data/lib/active_shipping/carriers.rb +33 -0
  10. data/lib/active_shipping/carriers/benchmark_carrier.rb +31 -0
  11. data/lib/active_shipping/carriers/bogus_carrier.rb +12 -0
  12. data/lib/active_shipping/carriers/canada_post.rb +253 -0
  13. data/lib/active_shipping/carriers/canada_post_pws.rb +870 -0
  14. data/lib/active_shipping/carriers/fedex.rb +579 -0
  15. data/lib/active_shipping/carriers/kunaki.rb +164 -0
  16. data/lib/active_shipping/carriers/new_zealand_post.rb +262 -0
  17. data/lib/active_shipping/carriers/shipwire.rb +181 -0
  18. data/lib/active_shipping/carriers/stamps.rb +861 -0
  19. data/lib/active_shipping/carriers/ups.rb +648 -0
  20. data/lib/active_shipping/carriers/usps.rb +642 -0
  21. data/lib/active_shipping/errors.rb +7 -0
  22. data/lib/active_shipping/label_response.rb +23 -0
  23. data/lib/active_shipping/location.rb +149 -0
  24. data/lib/active_shipping/package.rb +241 -0
  25. data/lib/active_shipping/rate_estimate.rb +64 -0
  26. data/lib/active_shipping/rate_response.rb +13 -0
  27. data/lib/active_shipping/response.rb +41 -0
  28. data/lib/active_shipping/shipment_event.rb +17 -0
  29. data/lib/active_shipping/shipment_packer.rb +73 -0
  30. data/lib/active_shipping/shipping_response.rb +12 -0
  31. data/lib/active_shipping/tracking_response.rb +52 -0
  32. data/lib/active_shipping/version.rb +1 -1
  33. data/lib/vendor/quantified/test/length_test.rb +2 -2
  34. data/lib/vendor/xml_node/test/test_parsing.rb +1 -1
  35. metadata +58 -36
  36. metadata.gz.sig +0 -0
  37. data/lib/active_shipping/shipping/base.rb +0 -13
  38. data/lib/active_shipping/shipping/carrier.rb +0 -84
  39. data/lib/active_shipping/shipping/carriers.rb +0 -23
  40. data/lib/active_shipping/shipping/carriers/benchmark_carrier.rb +0 -33
  41. data/lib/active_shipping/shipping/carriers/bogus_carrier.rb +0 -14
  42. data/lib/active_shipping/shipping/carriers/canada_post.rb +0 -257
  43. data/lib/active_shipping/shipping/carriers/canada_post_pws.rb +0 -874
  44. data/lib/active_shipping/shipping/carriers/fedex.rb +0 -581
  45. data/lib/active_shipping/shipping/carriers/kunaki.rb +0 -166
  46. data/lib/active_shipping/shipping/carriers/new_zealand_post.rb +0 -262
  47. data/lib/active_shipping/shipping/carriers/shipwire.rb +0 -184
  48. data/lib/active_shipping/shipping/carriers/stamps.rb +0 -864
  49. data/lib/active_shipping/shipping/carriers/ups.rb +0 -650
  50. data/lib/active_shipping/shipping/carriers/usps.rb +0 -649
  51. data/lib/active_shipping/shipping/errors.rb +0 -9
  52. data/lib/active_shipping/shipping/label_response.rb +0 -25
  53. data/lib/active_shipping/shipping/location.rb +0 -152
  54. data/lib/active_shipping/shipping/package.rb +0 -243
  55. data/lib/active_shipping/shipping/rate_estimate.rb +0 -66
  56. data/lib/active_shipping/shipping/rate_response.rb +0 -15
  57. data/lib/active_shipping/shipping/response.rb +0 -43
  58. data/lib/active_shipping/shipping/shipment_event.rb +0 -19
  59. data/lib/active_shipping/shipping/shipment_packer.rb +0 -75
  60. data/lib/active_shipping/shipping/shipping_response.rb +0 -14
  61. data/lib/active_shipping/shipping/tracking_response.rb +0 -54
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 715dd60ad9d4a6fbe5c9ba36834326fa383c4ee4
4
- data.tar.gz: 1f1991bf39492b70a068e92e52bb687f4b3526b4
3
+ metadata.gz: 8664d2221411bccc635ba71eae6bb4262d369753
4
+ data.tar.gz: b468c066831f372867d0cd3ecd70ed04069a4d08
5
5
  SHA512:
6
- metadata.gz: 725e84ee191ce38e56e89a3af8ff0592c21a5e6bc6f584edf9cfdcc4fbb01a5532bc999ae28dfc07045fa403cb8f86c363b8d62e12441fc488efe0e863c33645
7
- data.tar.gz: db8156ebcbd65a863f222b7bdfb26b37ac3fbd5a6b4e9036fc499488133a7075ec9906f996cafdce5b4ccc002b2e08fabdeffaabf59c82c7da26430ce4519a6a
6
+ metadata.gz: 4e7eb03007d6327ab42ee8aa9af0adfe741542769231354058a2cfbffa40399ef2ab7ab9eaf39c1f57b3e9ae2f12568c8156dd4c49be9769f149e974960f8149
7
+ data.tar.gz: 6d3b6f02166d9eed86426e74d1fca59f6737d21dc4410e36c0d1f65eb815d93fbf4587610c6889af02646e3f83f9b37b8df23f4fcddb56b6def3d09659f98b62
@@ -0,0 +1,2 @@
1
+ /6l8��'���M��j��x�oc��+0G./V^�3:"�x� ���D����_�}���n(�b�K��э,�I(�Ђ���z��ƟL-���t�o-�� �h�h�x�
2
+ ��ܰ[�Z5�7�l⢢�=�E+/Q������M� �R+0�n7�̜~�
Binary file
@@ -1,17 +1,21 @@
1
+ # ActiveShipping CHANGELOG
2
+
1
3
  ### v0.10.1
4
+
2
5
  - Canada Post PWS: Makes wrapper act more consistently with the rest of the API [jnormore]
3
6
  - UPS: Adds insurance charge to package object declarations [pbonnell]
4
7
  - USPS: Improves how unavailable delivery information is handled [cyu]
5
8
  - Shipment Packer: Prevents packing errors and consistently return an array when packing [christianblais]
6
9
  - General: Improves tests such that they work with ruby 2.0 [Sirupsen]
7
10
 
11
+ ### 2011/04/21
8
12
 
9
- 2011/04/21:
10
13
  * USPS updated to use new APIs [james]
11
14
  * new :gift boolean option for Package [james]
12
15
  * Location's :address_type can be "po_box" [james]
13
16
 
14
- Earlier:
17
+ ### Earlier
18
+
15
19
  * New Zealand Post [AbleTech]
16
20
  * Include address name for rate requests to Shipwire if provided [dennis]
17
21
  * Add support for address name to Location [dennis]
@@ -0,0 +1,32 @@
1
+ # Contributing to ActiveShipping
2
+
3
+ We welcome fixes and additions to this project. Please use clean, concise code that follows Ruby community standards. For example:
4
+
5
+ * Be consistent
6
+ * Don't use too much white space
7
+ ** Use 2 space indent, no tabs.
8
+ ** No spaces after (, [ and before ],)
9
+ * Nor too little
10
+ ** Use spaces around operators and after commas, colons and semicolons
11
+ ** Indent when as deep as case
12
+ * Write lucid code in lieu of adding comments
13
+
14
+ ## Contributors
15
+
16
+ * James MacAulay (<http://jmacaulay.net>)
17
+ * Tobias Luetke (<http://blog.leetsoft.com>)
18
+ * Cody Fauser (<http://codyfauser.com>)
19
+ * Jimmy Baker (<http://jimmyville.com/>)
20
+ * William Lang (<http://williamlang.net/>)
21
+ * Cameron Fowler
22
+ * Christopher Saunders (<http://christophersaunders.ca>)
23
+ * Denis Odorcic
24
+ * Dennis O'Connor
25
+ * Dennis Theisen
26
+ * Edward Ocampo-Gooding
27
+ * Isaac Kearse
28
+ * John Duff
29
+ * Nigel Ramsay
30
+ * Philip Arndt
31
+ * Vikram Oberoi
32
+ * Willem van Bergen
@@ -2,11 +2,13 @@
2
2
 
3
3
  [![Build Status](https://travis-ci.org/Shopify/active_shipping.png)](https://travis-ci.org/Shopify/active_shipping)
4
4
 
5
- This library interfaces with the web services of various shipping carriers. The goal is to abstract the features that are most frequently used into a pleasant and consistent Ruby API. Active Shipping is an extension of [Active Merchant][], and as such, it borrows heavily from conventions used in the latter.
5
+ This library interfaces with the web services of various shipping carriers. The goal is to abstract the features that are most frequently used into a pleasant and consistent Ruby API.
6
+
7
+ - Finding shipping rates
8
+ - Tracking shipments
6
9
 
7
10
  Active Shipping is currently being used and improved in a production environment for [Shopify][]. Development is being done by the Shopify integrations team (<integrations-team@shopify.com>). Discussion is welcome in the [Active Merchant Google Group][discuss].
8
11
 
9
- [Active Merchant]:http://www.activemerchant.org
10
12
  [Shopify]:http://www.shopify.com
11
13
  [discuss]:http://groups.google.com/group/activemerchant
12
14
 
@@ -17,58 +19,59 @@ Active Shipping is currently being used and improved in a production environment
17
19
  * [FedEx](http://www.fedex.com)
18
20
  * [Canada Post](http://www.canadapost.ca)
19
21
  * [New Zealand Post](http://www.nzpost.co.nz)
20
- * more soon!
22
+ * [Shipwire](http://www.shipwire.com)
23
+ * [Stamps](http://www.stamps.com)
24
+ * [Kunaki](http://www.kunaki.com)
21
25
 
22
26
  ## Installation
23
27
 
24
28
  gem install active_shipping
25
29
 
26
- ...or add it to your [Gemfile](http://gembundler.com/).
30
+ ...or add it to your project's [Gemfile](http://bundler.io/).
27
31
 
28
32
  ## Sample Usage
29
33
 
30
34
  ### Compare rates from different carriers
31
35
 
32
36
  require 'active_shipping'
33
- include ActiveMerchant::Shipping
34
-
37
+
35
38
  # Package up a poster and a Wii for your nephew.
36
39
  packages = [
37
- Package.new( 100, # 100 grams
38
- [93,10], # 93 cm long, 10 cm diameter
39
- :cylinder => true), # cylinders have different volume calculations
40
-
41
- Package.new( (7.5 * 16), # 7.5 lbs, times 16 oz/lb.
42
- [15, 10, 4.5], # 15x10x4.5 inches
43
- :units => :imperial) # not grams, not centimetres
40
+ ActiveShipping::Package.new( 100, # 100 grams
41
+ [93,10], # 93 cm long, 10 cm diameter
42
+ :cylinder => true), # cylinders have different volume calculations
43
+
44
+ ActiveShipping::Package.new( 7.5 * 16, # 7.5 lbs, times 16 oz/lb.
45
+ [15, 10, 4.5], # 15x10x4.5 inches
46
+ :units => :imperial) # not grams, not centimetres
44
47
  ]
45
-
48
+
46
49
  # You live in Beverly Hills, he lives in Ottawa
47
- origin = Location.new( :country => 'US',
48
- :state => 'CA',
49
- :city => 'Beverly Hills',
50
- :zip => '90210')
51
-
52
- destination = Location.new( :country => 'CA',
53
- :province => 'ON',
54
- :city => 'Ottawa',
55
- :postal_code => 'K1P 1J1')
56
-
50
+ origin = ActiveShipping::Location.new( :country => 'US',
51
+ :state => 'CA',
52
+ :city => 'Beverly Hills',
53
+ :zip => '90210')
54
+
55
+ destination = ActiveShipping::Location.new( :country => 'CA',
56
+ :province => 'ON',
57
+ :city => 'Ottawa',
58
+ :postal_code => 'K1P 1J1')
59
+
57
60
  # Find out how much it'll be.
58
- ups = UPS.new(:login => 'auntjudy', :password => 'secret', :key => 'xml-access-key')
61
+ ups = ActiveShipping::UPS.new(:login => 'auntjudy', :password => 'secret', :key => 'xml-access-key')
59
62
  response = ups.find_rates(origin, destination, packages)
60
-
63
+
61
64
  ups_rates = response.rates.sort_by(&:price).collect {|rate| [rate.service_name, rate.price]}
62
65
  # => [["UPS Standard", 3936],
63
66
  # ["UPS Worldwide Expedited", 8682],
64
67
  # ["UPS Saver", 9348],
65
68
  # ["UPS Express", 9702],
66
69
  # ["UPS Worldwide Express Plus", 14502]]
67
-
70
+
68
71
  # Check out USPS for comparison...
69
- usps = USPS.new(:login => 'developer-key')
72
+ usps = ActiveShipping::USPS.new(:login => 'developer-key')
70
73
  response = usps.find_rates(origin, destination, packages)
71
-
74
+
72
75
  usps_rates = response.rates.sort_by(&:price).collect {|rate| [rate.service_name, rate.price]}
73
76
  # => [["USPS Priority Mail International", 4110],
74
77
  # ["USPS Express Mail International (EMS)", 5750],
@@ -76,26 +79,26 @@ Active Shipping is currently being used and improved in a production environment
76
79
  # ["USPS GXG Envelopes", 9400],
77
80
  # ["USPS Global Express Guaranteed Non-Document Rectangular", 9400],
78
81
  # ["USPS Global Express Guaranteed", 9400]]
79
-
82
+
80
83
  ### Track a FedEx package
81
84
 
82
- fedex = FedEx.new(:login => '999999999', :password => '7777777', key: '1BXXXXXXXXXxrcB', account: '51XXXXX20')
85
+ fedex = ActiveShipping::FedEx.new(login: '999999999', password: '7777777', key: '1BXXXXXXXXXxrcB', account: '51XXXXX20')
83
86
  tracking_info = fedex.find_tracking_info('tracking-number', :carrier_code => 'fedex_ground') # Ground package
84
-
87
+
85
88
  tracking_info.shipment_events.each do |event|
86
89
  puts "#{event.name} at #{event.location.city}, #{event.location.state} on #{event.time}. #{event.message}"
87
90
  end
88
- # => Package information transmitted to FedEx at NASHVILLE LOCAL, TN on Thu Oct 23 00:00:00 UTC 2008.
89
- # Picked up by FedEx at NASHVILLE LOCAL, TN on Thu Oct 23 17:30:00 UTC 2008.
90
- # Scanned at FedEx sort facility at NASHVILLE, TN on Thu Oct 23 18:50:00 UTC 2008.
91
- # Departed FedEx sort facility at NASHVILLE, TN on Thu Oct 23 22:33:00 UTC 2008.
92
- # Arrived at FedEx sort facility at KNOXVILLE, TN on Fri Oct 24 02:45:00 UTC 2008.
93
- # Scanned at FedEx sort facility at KNOXVILLE, TN on Fri Oct 24 05:56:00 UTC 2008.
91
+ # => Package information transmitted to FedEx at NASHVILLE LOCAL, TN on Thu Oct 23 00:00:00 UTC 2008.
92
+ # Picked up by FedEx at NASHVILLE LOCAL, TN on Thu Oct 23 17:30:00 UTC 2008.
93
+ # Scanned at FedEx sort facility at NASHVILLE, TN on Thu Oct 23 18:50:00 UTC 2008.
94
+ # Departed FedEx sort facility at NASHVILLE, TN on Thu Oct 23 22:33:00 UTC 2008.
95
+ # Arrived at FedEx sort facility at KNOXVILLE, TN on Fri Oct 24 02:45:00 UTC 2008.
96
+ # Scanned at FedEx sort facility at KNOXVILLE, TN on Fri Oct 24 05:56:00 UTC 2008.
94
97
  # Delivered at Knoxville, TN on Fri Oct 24 16:45:00 UTC 2008. Signed for by: T.BAKER
95
98
 
96
99
  ## Running the tests
97
100
 
98
- After installing dependencies with `bundle install`, you can run the unit tests with `rake test:units` and the remote tests with `rake test:remote`. The unit tests mock out requests and responses so that everything runs locally, while the remote tests actually hit the carrier servers. For the remote tests, you'll need valid test credentials for any carriers' tests you want to run. The credentials should go in ~/.active_merchant/fixtures.yml, and the format of that file can be seen in the included [fixtures.yml](https://github.com/Shopify/active_shipping/blob/master/test/fixtures.yml).
101
+ After installing dependencies with `bundle install`, you can run the unit tests with `rake test:units` and the remote tests with `rake test:remote`. The unit tests mock out requests and responses so that everything runs locally, while the remote tests actually hit the carrier servers. For the remote tests, you'll need valid test credentials for any carriers' tests you want to run. The credentials should go in ~/.active_shipping/credentials.yml, and the format of that file can be seen in the included [credentials.yml](https://github.com/Shopify/active_shipping/blob/master/test/credentials.yml).
99
102
 
100
103
  ## Contributing
101
104
 
@@ -109,31 +112,12 @@ https://github.com/Shopify/active_shipping/tree/master/test/fixtures/xml/usps
109
112
 
110
113
  To log requests and responses, just set the `logger` on your carrier class to some kind of `Logger` object:
111
114
 
112
- USPS.logger = Logger.new($stdout)
115
+ ActiveShipping::USPS.logger = Logger.new($stdout)
113
116
 
114
- (This logging functionality is provided by the [`PostsData` module](https://github.com/Shopify/active_utils/blob/master/lib/active_utils/common/posts_data.rb) in the `active_utils` dependency.)
117
+ (This logging functionality is provided by the [`PostsData` module](https://github.com/Shopify/active_utils/blob/master/lib/active_utils/posts_data.rb) in the `active_utils` dependency.)
115
118
 
116
119
  After you've pushed your well-tested changes to your github fork, make a pull request and we'll take it from there!
117
120
 
118
- ## Contributors
119
-
120
- * James MacAulay (<http://jmacaulay.net>)
121
- * Tobias Luetke (<http://blog.leetsoft.com>)
122
- * Cody Fauser (<http://codyfauser.com>)
123
- * Jimmy Baker (<http://jimmyville.com/>)
124
- * William Lang (<http://williamlang.net/>)
125
- * Cameron Fowler
126
- * Christopher Saunders (<http://christophersaunders.ca>)
127
- * Denis Odorcic
128
- * Dennis O'Connor
129
- * Dennis Theisen
130
- * Edward Ocampo-Gooding
131
- * Isaac Kearse
132
- * John Duff
133
- * Nigel Ramsay
134
- * Philip Arndt
135
- * Vikram Oberoi
136
-
137
121
  ## Legal Mumbo Jumbo
138
122
 
139
- Unless otherwise noted in specific files, all code in the Active Shipping project is under the copyright and license described in the included MIT-LICENSE file.
123
+ Unless otherwise noted in specific files, all code in the ActiveShipping project is under the copyright and license described in the included MIT-LICENSE file.
@@ -21,33 +21,25 @@
21
21
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  #++
23
23
 
24
- $:.unshift File.dirname(__FILE__)
25
-
26
- begin
27
- require 'active_support/all'
28
- rescue LoadError
29
- require 'rubygems'
30
- gem "activesupport", ">= 2.3.5"
31
- require "active_support/all"
32
- end
33
-
34
- autoload :XmlNode, 'vendor/xml_node/lib/xml_node'
35
- autoload :Quantified, 'vendor/quantified/lib/quantified'
36
-
37
- require 'net/https'
24
+ require 'active_support'
25
+ require 'active_support/json'
26
+ require 'active_support/core_ext/enumerable'
27
+ require 'active_support/core_ext/class/attribute_accessors'
38
28
  require 'active_utils'
39
29
 
40
- require 'active_shipping/shipping/base'
41
- require 'active_shipping/shipping/response'
42
- require 'active_shipping/shipping/rate_response'
43
- require 'active_shipping/shipping/tracking_response'
44
- require 'active_shipping/shipping/shipping_response'
45
- require 'active_shipping/shipping/label_response'
46
- require 'active_shipping/shipping/package'
47
- require 'active_shipping/shipping/location'
48
- require 'active_shipping/shipping/rate_estimate'
49
- require 'active_shipping/shipping/shipment_event'
50
- require 'active_shipping/shipping/shipment_packer'
51
- require 'active_shipping/shipping/carrier'
52
- require 'active_shipping/shipping/carriers'
53
- require 'active_shipping/shipping/errors'
30
+ require 'vendor/quantified/lib/quantified'
31
+ require 'vendor/xml_node/lib/xml_node'
32
+
33
+ require 'active_shipping/response'
34
+ require 'active_shipping/rate_response'
35
+ require 'active_shipping/tracking_response'
36
+ require 'active_shipping/shipping_response'
37
+ require 'active_shipping/label_response'
38
+ require 'active_shipping/package'
39
+ require 'active_shipping/location'
40
+ require 'active_shipping/rate_estimate'
41
+ require 'active_shipping/shipment_event'
42
+ require 'active_shipping/shipment_packer'
43
+ require 'active_shipping/carrier'
44
+ require 'active_shipping/carriers'
45
+ require 'active_shipping/errors'
@@ -0,0 +1,82 @@
1
+ module ActiveShipping
2
+ class Carrier
3
+ include ActiveUtils::RequiresParameters
4
+ include ActiveUtils::PostsData
5
+ include Quantified
6
+
7
+ attr_reader :last_request
8
+ attr_accessor :test_mode
9
+ alias_method :test_mode?, :test_mode
10
+
11
+ # Credentials should be in options hash under keys :login, :password and/or :key.
12
+ def initialize(options = {})
13
+ requirements.each { |key| requires!(options, key) }
14
+ @options = options
15
+ @last_request = nil
16
+ @test_mode = @options[:test]
17
+ end
18
+
19
+ # Override to return required keys in options hash for initialize method.
20
+ def requirements
21
+ []
22
+ end
23
+
24
+ # Override with whatever you need to get the rates
25
+ def find_rates(origin, destination, packages, options = {})
26
+ end
27
+
28
+ # Override with whatever you need to get a shipping label
29
+ def create_shipment(origin, destination, packages, options = {})
30
+ end
31
+
32
+ # Validate credentials with a call to the API. By default this just does a find_rates call
33
+ # with the orgin and destination both as the carrier's default_location. Override to provide
34
+ # alternate functionality, such as checking for test_mode to use test servers, etc.
35
+ def valid_credentials?
36
+ location = self.class.default_location
37
+ find_rates(location, location, Package.new(100, [5, 15, 30]), :test => test_mode)
38
+ rescue ActiveShipping::ResponseError
39
+ false
40
+ else
41
+ true
42
+ end
43
+
44
+ def maximum_weight
45
+ Mass.new(150, :pounds)
46
+ end
47
+
48
+ protected
49
+
50
+ def node_text_or_nil(xml_node)
51
+ xml_node ? xml_node.text : nil
52
+ end
53
+
54
+ # Override in subclasses for non-U.S.-based carriers.
55
+ def self.default_location
56
+ Location.new( :country => 'US',
57
+ :state => 'CA',
58
+ :city => 'Beverly Hills',
59
+ :address1 => '455 N. Rexford Dr.',
60
+ :address2 => '3rd Floor',
61
+ :zip => '90210',
62
+ :phone => '1-310-285-1013',
63
+ :fax => '1-310-275-8159')
64
+ end
65
+
66
+ # Use after building the request to save for later inspection. Probably won't ever be overridden.
67
+ def save_request(r)
68
+ @last_request = r
69
+ end
70
+
71
+ def timestamp_from_business_day(days)
72
+ return unless days
73
+ date = DateTime.now.utc
74
+ days.times do
75
+ begin
76
+ date = date + 1
77
+ end while [0, 6].include?(date.wday)
78
+ end
79
+ date
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,33 @@
1
+ module ActiveShipping
2
+ module Carriers
3
+ extend self
4
+
5
+ attr_reader :registered
6
+ @registered = []
7
+
8
+ def register(class_name, autoload_require)
9
+ ActiveShipping.autoload(class_name, autoload_require)
10
+ self.registered << class_name
11
+ end
12
+
13
+ def all
14
+ ActiveShipping::Carriers.registered.map { |name| ActiveShipping.const_get(name) }
15
+ end
16
+
17
+ def find(name)
18
+ all.find { |c| c.name.downcase == name.to_s.downcase } or raise NameError, "unknown carrier #{name}"
19
+ end
20
+ end
21
+ end
22
+
23
+ ActiveShipping::Carriers.register :BenchmarkCarrier, 'active_shipping/carriers/benchmark_carrier'
24
+ ActiveShipping::Carriers.register :BogusCarrier, 'active_shipping/carriers/bogus_carrier'
25
+ ActiveShipping::Carriers.register :UPS, 'active_shipping/carriers/ups'
26
+ ActiveShipping::Carriers.register :USPS, 'active_shipping/carriers/usps'
27
+ ActiveShipping::Carriers.register :FedEx, 'active_shipping/carriers/fedex'
28
+ ActiveShipping::Carriers.register :Shipwire, 'active_shipping/carriers/shipwire'
29
+ ActiveShipping::Carriers.register :Kunaki, 'active_shipping/carriers/kunaki'
30
+ ActiveShipping::Carriers.register :CanadaPost, 'active_shipping/carriers/canada_post'
31
+ ActiveShipping::Carriers.register :NewZealandPost, 'active_shipping/carriers/new_zealand_post'
32
+ ActiveShipping::Carriers.register :CanadaPostPWS, 'active_shipping/carriers/canada_post_pws'
33
+ ActiveShipping::Carriers.register :Stamps, 'active_shipping/carriers/stamps'
@@ -0,0 +1,31 @@
1
+ # The time a 3rd-party shipping provider takes to respond to a request varies greatly.
2
+ # This class simulates these unpredictable delays in shipping rate retrieval so that
3
+ # load-testing tools run into situations that more accurately reflect the real world.
4
+
5
+ module ActiveShipping
6
+ class BenchmarkCarrier < Carrier
7
+ cattr_reader :name
8
+ @@name = "Benchmark Carrier"
9
+
10
+ def find_rates(origin, destination, packages, options = {})
11
+ origin = Location.from(origin)
12
+ destination = Location.from(destination)
13
+ packages = Array(packages)
14
+
15
+ delay_time = generate_simulated_lag
16
+
17
+ bogus_estimate = RateEstimate.new(
18
+ origin, destination, @@name,
19
+ "Free Benchmark Shipping", :total_price => 0, :currency => 'USD',
20
+ :packages => packages, :delivery_range => [Time.now.utc.strftime("%Y-%d-%m"), Time.now.utc.strftime("%Y-%d-%m")]
21
+ )
22
+ RateResponse.new(true, "Success (delayed #{delay_time} seconds)", {:rate => 'free'}, :rates => [bogus_estimate], :xml => "<rate>free</rate>")
23
+ end
24
+
25
+ private
26
+
27
+ def generate_simulated_lag(max_delay = 30)
28
+ sleep Random.rand * max_delay
29
+ end
30
+ end
31
+ end