Skip to content
Newer
Older
100644 170 lines (128 sloc) 8.51 KB
0eebee7 @jamesmacaulay first commit
jamesmacaulay authored
1 # Active Shipping
2
3 This library is meant to interface 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.
4
5 We are starting out by only implementing the ability to list available shipping rates for a particular origin, destination, and set of packages. Further development could take advantage of other common features of carriers' web services such as tracking orders and printing labels.
6
7 Active Shipping is currently being used and improved in a production environment for the e-commerce application [Shopify][]. Development is being done by [James MacAulay][] (<james@jadedpixel.com>). Discussion is welcome in the [Active Merchant Google Group][discuss].
8
9 [Active Merchant]:http://www.activemerchant.org
10 [Shopify]:http://www.shopify.com
11 [James MacAulay]:http://jmacaulay.net
12 [discuss]:http://groups.google.com/group/activemerchant
13
14 ## Supported Shipping Carriers
15
16 * [UPS](http://www.ups.com)
17 * [USPS](http://www.usps.com)
18 * more soon!
19
20 ## Prerequisites
21
22 * [active_support](http://github.com/rails/rails/tree/master/activesupport)
23 * [xml_node](http://github.com/tobi/xml_node/) (right now a version of it is actually included in this library, so you don't need to worry about it yet)
24 * [mocha](http://mocha.rubyforge.org/) for the tests
25
26 ## Download & Installation
27
28 Currently this library is available on GitHub:
29
7f06401 @jamesmacaulay Proper git clone URL
jamesmacaulay authored
30 <http://github.com/Shopify/active_shipping>
0eebee7 @jamesmacaulay first commit
jamesmacaulay authored
31
32 You will need to get [Git][] if you don't have it. Then:
33
7f06401 @jamesmacaulay Proper git clone URL
jamesmacaulay authored
34 > git clone git://github.com/Shopify/active_shipping.git
35
36 (That URL is case-sensitive, so watch out.)
0eebee7 @jamesmacaulay first commit
jamesmacaulay authored
37
38 Active Shipping includes an init.rb file. This means that Rails will automatically load it on startup. Check out [git-archive][] for exporting the file tree from your repository to your vendor directory.
39
40 Gem and tarball forthcoming on rubyforge.
41
42 [Git]:http://git.or.cz/
43 [git-archive]:http://www.kernel.org/pub/software/scm/git/docs/git-archive.html
44
45 ## Sample Usage
46
47 require 'active_shipping'
48 include ActiveMerchant::Shipping
49
50 # Package up a poster and a Wii for your nephew.
51 packages = [
52 Package.new( 100, # 100 grams
53 [93,10], # 93 cm long, 10 cm diameter
54 :cylinder => true), # cylinders have different volume calculations
55
56 Package.new( (7.5 * 16), # 7.5 lbs, times 16 oz/lb.
57 [15, 10, 4.5], # 15x10x4.5 inches
58 :units => :imperial) # not grams, not centimetres
59 ]
60
61 # You live in Beverly Hills, he lives in Ottawa
62 origin = Location.new( :country => 'US',
63 :state => 'CA',
64 :city => 'Beverly Hills',
65 :zip => '90210')
66
67 destination = Location.new( :country => 'CA',
68 :province => 'ON',
69 :city => 'Ottawa',
70 :postal_code => 'K1P 1J1')
71
72 # Find out how much it'll be.
73 ups = UPS.new(:login => 'auntjudy', :password => 'secret', :key => 'xml-access-key')
74 response = ups.find_rates(origin, destination, packages)
75
76 ups_rates = response.rates.sort_by(&:price).collect {|rate| [rate.service_name, rate.price]}
77 # => [["UPS Standard", 3936],
78 # ["UPS Worldwide Expedited", 8682],
79 # ["UPS Saver", 9348],
80 # ["UPS Express", 9702],
81 # ["UPS Worldwide Express Plus", 14502]]
82
83 # Check out USPS for comparison...
84 usps = USPS.new(:login => 'developer-key')
85 response = usps.find_rates(origin, destination, packages)
86
87 usps_rates = response.rates.sort_by(&:price).collect {|rate| [rate.service_name, rate.price]}
88 # => [["USPS Priority Mail International", 4110],
89 # ["USPS Express Mail International (EMS)", 5750],
90 # ["USPS Global Express Guaranteed Non-Document Non-Rectangular", 9400],
91 # ["USPS GXG Envelopes", 9400],
92 # ["USPS Global Express Guaranteed Non-Document Rectangular", 9400],
93 # ["USPS Global Express Guaranteed", 9400]]
64a1348 FedEx carrier class now returns rates for both Ground and Express ser…
Jimmy Baker authored
94
95 # FedEx
6cd0129 FedEx#find_tracking_info is working. Added Sample Usage to the README.
Jimmy Baker authored
96 fdx = FedEx.new(:login => 'Your 9-digit FedEx Account #', :password => 'Your Meter Number')
64a1348 FedEx carrier class now returns rates for both Ground and Express ser…
Jimmy Baker authored
97 response = fdx.find_rates(origin, destination, packages, :test => true)
98 response.rates.sort_by(&:price).collect {|rate| [rate.service_name, rate.price]}
1c84842 Updated README documentation for FedEx usage.
Jimmy Baker authored
99 # => [["FedEx Ground", 977],
100 # ["FedEx Ground Home Delivery", 1388],
101 # ["FedEx Express Saver", 2477],
102 # ["FedEx 2 Day", 2718],
103 # ["FedEx Standard Overnight", 4978],
104 # ["FedEx Priority Overnight", 8636],
105 # ["FedEx First Overnight", 12306]]
64a1348 FedEx carrier class now returns rates for both Ground and Express ser…
Jimmy Baker authored
106
6cd0129 FedEx#find_tracking_info is working. Added Sample Usage to the README.
Jimmy Baker authored
107 # FedEx Tracking
108 fdx = FedEx.new(:login => '999999999', :password => '7777777')
109 tracking_info = fdx.find_tracking_info('tracking number here', :carrier_code => 'fedex_ground') # Ground package
110
111 tracking_info.shipment_events.each do |event|
112 puts "#{event.name} at #{event.location.city}, #{event.location.state} on #{event.time}. #{event.message}"
113 end
114 # => Package information transmitted to FedEx at NASHVILLE LOCAL, TN on Thu Oct 23 00:00:00 UTC 2008.
115 # Picked up by FedEx at NASHVILLE LOCAL, TN on Thu Oct 23 17:30:00 UTC 2008.
116 # Scanned at FedEx sort facility at NASHVILLE, TN on Thu Oct 23 18:50:00 UTC 2008.
117 # Departed FedEx sort facility at NASHVILLE, TN on Thu Oct 23 22:33:00 UTC 2008.
118 # Arrived at FedEx sort facility at KNOXVILLE, TN on Fri Oct 24 02:45:00 UTC 2008.
119 # Scanned at FedEx sort facility at KNOXVILLE, TN on Fri Oct 24 05:56:00 UTC 2008.
120 # Delivered at Knoxville, TN on Fri Oct 24 16:45:00 UTC 2008. Signed for by: T.BAKER
121
122 tracking_info = fdx.find_tracking_info('tracking number here', :carrier_code => 'fedex_express') # Express package
123
124 tracking_info.shipment_events.each do |event|
125 puts "#{event.name} at #{event.location.city}, #{event.location.state} on #{event.time}. #{event.message}"
126 end
127 # => Picked up by FedEx at NASHVILLE, TN on Wed Dec 03 16:46:00 UTC 2008.
128 # Package status at MISSISSAUGA, ON on Wed Dec 03 18:00:00 UTC 2008.
129 # Left FedEx Origin Location at NASHVILLE, TN on Wed Dec 03 20:27:00 UTC 2008.
130 # Arrived at FedEx Ramp at NASHVILLE, TN on Wed Dec 03 20:43:00 UTC 2008.
131 # Left FedEx Ramp at NASHVILLE, TN on Wed Dec 03 22:30:00 UTC 2008.
132 # Arrived at Sort Facility at INDIANAPOLIS, IN on Thu Dec 04 00:31:00 UTC 2008.
133 # Left FedEx Sort Facility at INDIANAPOLIS, IN on Thu Dec 04 01:14:00 UTC 2008.
134 # Left FedEx Sort Facility at INDIANAPOLIS, IN on Thu Dec 04 04:48:00 UTC 2008.
135 # Arrived at FedEx Ramp at MISSISSAUGA, ON on Thu Dec 04 06:26:00 UTC 2008.
136 # Package status at MISSISSAUGA, ON on Thu Dec 04 07:03:00 UTC 2008.
137 # Left FedEx Ramp at MISSISSAUGA, ON on Thu Dec 04 07:37:00 UTC 2008.
138 # Arrived at FedEx Destination Location at TORONTO, ON on Thu Dec 04 08:42:00 UTC 2008.
139 # On FedEx vehicle for delivery at TORONTO, ON on Thu Dec 04 09:04:00 UTC 2008.
140 # Delivered to Non-FedEx clearance broker at TORONTO, ON on Thu Dec 04 10:15:00 UTC 2008.
0eebee7 @jamesmacaulay first commit
jamesmacaulay authored
141
142 ## TODO
143
144 * proper documentation
145 * proper offline testing for carriers in addition to the remote tests
146 * package into a gem
147 * carrier code template generator
148 * more carriers
149 * integrate with ActiveMerchant
150 * support more features for existing carriers
151 * bin-packing algorithm (preferably implemented in ruby)
152 * order tracking
153 * label printing
154
155 ## Contributing
156
157 Yes, please! Take a look at the tests and the implementation of the Carrier class to see how the basics work. At some point soon there will be a carrier template generator along the lines of the gateway generator included in Active Merchant, but carrier.rb outlines most of what's necessary. The other main classes that would be good to familiarize yourself with are Location, Package, and Response.
158
159 The nicest way to submit changes would be to set up a GitHub account and fork this project, then initiate a pull request when you want your changes looked at. You can also make a patch (preferably with [git-diff][]) and email to james@jadedpixel.com.
160
161 [git-diff]:http://www.kernel.org/pub/software/scm/git/docs/git-diff.html
162
163 ## Contributors
164
165 * Tobias Luetke (<http://blog.leetsoft.com>)
166 * Cody Fauser (<http://codyfauser.com>)
167
168 ## Legal Mumbo Jumbo
169
170 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.
Something went wrong with that request. Please try again.