Skip to content

Commit 0eebee7

Browse files
committed
first commit
0 parents  commit 0eebee7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+10955
-0
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.DS_Store
2+
3+
*.orig
4+
5+
.dotest

MIT-LICENSE

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2008 James MacAulay
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOa AND
17+
NONINFRINGEMENT. IN NO EVENT SaALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.markdown

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
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+
30+
<http://github.com/jamesmacaulay/active_shipping>
31+
32+
You will need to get [Git][] if you don't have it. Then:
33+
34+
> git clone git://github.com/jamesmacaulay/active_shipping.git
35+
36+
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.
37+
38+
Gem and tarball forthcoming on rubyforge.
39+
40+
[Git]:http://git.or.cz/
41+
[git-archive]:http://www.kernel.org/pub/software/scm/git/docs/git-archive.html
42+
43+
## Sample Usage
44+
45+
require 'active_shipping'
46+
include ActiveMerchant::Shipping
47+
48+
# Package up a poster and a Wii for your nephew.
49+
packages = [
50+
Package.new( 100, # 100 grams
51+
[93,10], # 93 cm long, 10 cm diameter
52+
:cylinder => true), # cylinders have different volume calculations
53+
54+
Package.new( (7.5 * 16), # 7.5 lbs, times 16 oz/lb.
55+
[15, 10, 4.5], # 15x10x4.5 inches
56+
:units => :imperial) # not grams, not centimetres
57+
]
58+
59+
# You live in Beverly Hills, he lives in Ottawa
60+
origin = Location.new( :country => 'US',
61+
:state => 'CA',
62+
:city => 'Beverly Hills',
63+
:zip => '90210')
64+
65+
destination = Location.new( :country => 'CA',
66+
:province => 'ON',
67+
:city => 'Ottawa',
68+
:postal_code => 'K1P 1J1')
69+
70+
# Find out how much it'll be.
71+
ups = UPS.new(:login => 'auntjudy', :password => 'secret', :key => 'xml-access-key')
72+
response = ups.find_rates(origin, destination, packages)
73+
74+
ups_rates = response.rates.sort_by(&:price).collect {|rate| [rate.service_name, rate.price]}
75+
# => [["UPS Standard", 3936],
76+
# ["UPS Worldwide Expedited", 8682],
77+
# ["UPS Saver", 9348],
78+
# ["UPS Express", 9702],
79+
# ["UPS Worldwide Express Plus", 14502]]
80+
81+
# Check out USPS for comparison...
82+
usps = USPS.new(:login => 'developer-key')
83+
response = usps.find_rates(origin, destination, packages)
84+
85+
usps_rates = response.rates.sort_by(&:price).collect {|rate| [rate.service_name, rate.price]}
86+
# => [["USPS Priority Mail International", 4110],
87+
# ["USPS Express Mail International (EMS)", 5750],
88+
# ["USPS Global Express Guaranteed Non-Document Non-Rectangular", 9400],
89+
# ["USPS GXG Envelopes", 9400],
90+
# ["USPS Global Express Guaranteed Non-Document Rectangular", 9400],
91+
# ["USPS Global Express Guaranteed", 9400]]
92+
93+
## TODO
94+
95+
* proper documentation
96+
* proper offline testing for carriers in addition to the remote tests
97+
* package into a gem
98+
* carrier code template generator
99+
* more carriers
100+
* integrate with ActiveMerchant
101+
* support more features for existing carriers
102+
* bin-packing algorithm (preferably implemented in ruby)
103+
* order tracking
104+
* label printing
105+
106+
## Contributing
107+
108+
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.
109+
110+
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.
111+
112+
[git-diff]:http://www.kernel.org/pub/software/scm/git/docs/git-diff.html
113+
114+
## Contributors
115+
116+
* Tobias Luetke (<http://blog.leetsoft.com>)
117+
* Cody Fauser (<http://codyfauser.com>)
118+
119+
## Legal Mumbo Jumbo
120+
121+
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.

Rakefile

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
require 'rubygems'
2+
require 'rake'
3+
require 'rake/testtask'
4+
require 'rake/rdoctask'
5+
require 'rake/gempackagetask'
6+
require 'rake/contrib/rubyforgepublisher'
7+
8+
9+
PKG_VERSION = "0.0.1"
10+
PKG_NAME = "activeshipping"
11+
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
12+
13+
PKG_FILES = FileList[
14+
"lib/**/*", "examples/**/*", "[A-Z]*", "Rakefile"
15+
].exclude(/\.svn$/)
16+
17+
18+
desc "Default Task"
19+
task :default => 'test:units'
20+
task :test => ['test:units','test:remote']
21+
22+
# Run the unit tests
23+
24+
namespace :test do
25+
Rake::TestTask.new(:units) do |t|
26+
t.pattern = 'test/unit/**/*_test.rb'
27+
t.ruby_opts << '-rubygems'
28+
t.verbose = true
29+
end
30+
31+
Rake::TestTask.new(:remote) do |t|
32+
t.pattern = 'test/remote/*_test.rb'
33+
t.ruby_opts << '-rubygems'
34+
t.verbose = true
35+
end
36+
end
37+
38+
# Genereate the RDoc documentation
39+
Rake::RDocTask.new do |rdoc|
40+
rdoc.rdoc_dir = 'doc'
41+
rdoc.title = "ActiveShipping library"
42+
rdoc.options << '--line-numbers' << '--inline-source'
43+
rdoc.rdoc_files.include('README', 'CHANGELOG')
44+
rdoc.rdoc_files.include('lib/**/*.rb')
45+
end
46+
47+
task :install => [:package] do
48+
`gem install pkg/#{PKG_FILE_NAME}.gem`
49+
end

init.rb

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require 'active_shipping'

lib/active_shipping.rb

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#--
2+
# Copyright (c) 2007 Jaded Pixel
3+
#
4+
# Permission is hereby granted, free of charge, to any person obtaining
5+
# a copy of this software and associated documentation files (the
6+
# "Software"), to deal in the Software without restriction, including
7+
# without limitation the rights to use, copy, modify, merge, publish,
8+
# distribute, sublicense, and/or sell copies of the Software, and to
9+
# permit persons to whom the Software is furnished to do so, subject to
10+
# the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be
13+
# included in all copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
#++
23+
24+
$:.unshift File.dirname(__FILE__)
25+
26+
27+
28+
require 'rubygems'
29+
require 'active_support'
30+
31+
require 'vendor/xml_node/lib/xml_node'
32+
33+
require 'net/https'
34+
require 'active_shipping/lib/requires_parameters'
35+
require 'active_shipping/lib/posts_data'
36+
require 'active_shipping/lib/country'
37+
38+
require 'active_shipping/shipping/base'
39+
require 'active_shipping/shipping/response'
40+
require 'active_shipping/shipping/package'
41+
require 'active_shipping/shipping/location'
42+
require 'active_shipping/shipping/rate_estimate'
43+
require 'active_shipping/shipping/carrier'
44+
require 'active_shipping/shipping/carriers'

0 commit comments

Comments
 (0)