Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit 0eebee7474e06c90ab3842e5e530837fbc93f9a7 James MacAulay committed Apr 21, 2008
Showing with 10,955 additions and 0 deletions.
  1. +5 −0 .gitignore
  2. +20 −0 MIT-LICENSE
  3. +121 −0 README.markdown
  4. +49 −0 Rakefile
  5. +1 −0 init.rb
  6. +44 −0 lib/active_shipping.rb
  7. +297 −0 lib/active_shipping/lib/country.rb
  8. +83 −0 lib/active_shipping/lib/posts_data.rb
  9. +17 −0 lib/active_shipping/lib/requires_parameters.rb
  10. +15 −0 lib/active_shipping/shipping/base.rb
  11. +73 −0 lib/active_shipping/shipping/carrier.rb
  12. +15 −0 lib/active_shipping/shipping/carriers.rb
  13. +16 −0 lib/active_shipping/shipping/carriers/bogus_carrier.rb
  14. +260 −0 lib/active_shipping/shipping/carriers/ups.rb
  15. +375 −0 lib/active_shipping/shipping/carriers/usps.rb
  16. +92 −0 lib/active_shipping/shipping/location.rb
  17. +134 −0 lib/active_shipping/shipping/package.rb
  18. +52 −0 lib/active_shipping/shipping/rate_estimate.rb
  19. +55 −0 lib/active_shipping/shipping/response.rb
  20. +7,815 −0 lib/certs/cacert.pem
  21. +13 −0 lib/vendor/test_helper.rb
  22. +36 −0 lib/vendor/xml_node/README
  23. +21 −0 lib/vendor/xml_node/Rakefile
  24. +32 −0 lib/vendor/xml_node/benchmark/bench_generation.rb
  25. +1 −0 lib/vendor/xml_node/init.rb
  26. +220 −0 lib/vendor/xml_node/lib/xml_node.rb
  27. +94 −0 lib/vendor/xml_node/test/test_generating.rb
  28. +43 −0 lib/vendor/xml_node/test/test_parsing.rb
  29. +6 −0 test/fixtures.yml
  30. +85 −0 test/fixtures/xml/usps/beverly_hills_to_ottawa_book_rate_response.xml
  31. +168 −0 test/fixtures/xml/usps/beverly_hills_to_ottawa_book_wii_rate_response.xml
  32. +85 −0 test/fixtures/xml/usps/beverly_hills_to_ottawa_wii_rate_response.xml
  33. +76 −0 test/remote/ups_test.rb
  34. +123 −0 test/remote/usps_test.rb
  35. +110 −0 test/test_helper.rb
  36. +18 −0 test/unit/base_test.rb
  37. +19 −0 test/unit/carriers/ups_test.rb
  38. +130 −0 test/unit/carriers/usps_test.rb
  39. +44 −0 test/unit/location_test.rb
  40. +74 −0 test/unit/package_test.rb
  41. +18 −0 test/unit/response_test.rb
@@ -0,0 +1,5 @@
+.DS_Store
+
+*.orig
+
+.dotest
@@ -0,0 +1,20 @@
+Copyright (c) 2008 James MacAulay
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOa AND
+NONINFRINGEMENT. IN NO EVENT SaALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,121 @@
+# Active Shipping
+
+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.
+
+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.
+
+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].
+
+[Active Merchant]:http://www.activemerchant.org
+[Shopify]:http://www.shopify.com
+[James MacAulay]:http://jmacaulay.net
+[discuss]:http://groups.google.com/group/activemerchant
+
+## Supported Shipping Carriers
+
+* [UPS](http://www.ups.com)
+* [USPS](http://www.usps.com)
+* more soon!
+
+## Prerequisites
+
+* [active_support](http://github.com/rails/rails/tree/master/activesupport)
+* [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)
+* [mocha](http://mocha.rubyforge.org/) for the tests
+
+## Download & Installation
+
+Currently this library is available on GitHub:
+
+ <http://github.com/jamesmacaulay/active_shipping>
+
+You will need to get [Git][] if you don't have it. Then:
+
+ > git clone git://github.com/jamesmacaulay/active_shipping.git
+
+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.
+
+Gem and tarball forthcoming on rubyforge.
+
+[Git]:http://git.or.cz/
+[git-archive]:http://www.kernel.org/pub/software/scm/git/docs/git-archive.html
+
+## Sample Usage
+
+ require 'active_shipping'
+ include ActiveMerchant::Shipping
+
+ # Package up a poster and a Wii for your nephew.
+ packages = [
+ Package.new( 100, # 100 grams
+ [93,10], # 93 cm long, 10 cm diameter
+ :cylinder => true), # cylinders have different volume calculations
+
+ Package.new( (7.5 * 16), # 7.5 lbs, times 16 oz/lb.
+ [15, 10, 4.5], # 15x10x4.5 inches
+ :units => :imperial) # not grams, not centimetres
+ ]
+
+ # You live in Beverly Hills, he lives in Ottawa
+ origin = Location.new( :country => 'US',
+ :state => 'CA',
+ :city => 'Beverly Hills',
+ :zip => '90210')
+
+ destination = Location.new( :country => 'CA',
+ :province => 'ON',
+ :city => 'Ottawa',
+ :postal_code => 'K1P 1J1')
+
+ # Find out how much it'll be.
+ ups = UPS.new(:login => 'auntjudy', :password => 'secret', :key => 'xml-access-key')
+ response = ups.find_rates(origin, destination, packages)
+
+ ups_rates = response.rates.sort_by(&:price).collect {|rate| [rate.service_name, rate.price]}
+ # => [["UPS Standard", 3936],
+ # ["UPS Worldwide Expedited", 8682],
+ # ["UPS Saver", 9348],
+ # ["UPS Express", 9702],
+ # ["UPS Worldwide Express Plus", 14502]]
+
+ # Check out USPS for comparison...
+ usps = USPS.new(:login => 'developer-key')
+ response = usps.find_rates(origin, destination, packages)
+
+ usps_rates = response.rates.sort_by(&:price).collect {|rate| [rate.service_name, rate.price]}
+ # => [["USPS Priority Mail International", 4110],
+ # ["USPS Express Mail International (EMS)", 5750],
+ # ["USPS Global Express Guaranteed Non-Document Non-Rectangular", 9400],
+ # ["USPS GXG Envelopes", 9400],
+ # ["USPS Global Express Guaranteed Non-Document Rectangular", 9400],
+ # ["USPS Global Express Guaranteed", 9400]]
+
+## TODO
+
+* proper documentation
+* proper offline testing for carriers in addition to the remote tests
+* package into a gem
+* carrier code template generator
+* more carriers
+* integrate with ActiveMerchant
+* support more features for existing carriers
+* bin-packing algorithm (preferably implemented in ruby)
+* order tracking
+* label printing
+
+## Contributing
+
+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.
+
+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.
+
+[git-diff]:http://www.kernel.org/pub/software/scm/git/docs/git-diff.html
+
+## Contributors
+
+* Tobias Luetke (<http://blog.leetsoft.com>)
+* Cody Fauser (<http://codyfauser.com>)
+
+## Legal Mumbo Jumbo
+
+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.
@@ -0,0 +1,49 @@
+require 'rubygems'
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+require 'rake/gempackagetask'
+require 'rake/contrib/rubyforgepublisher'
+
+
+PKG_VERSION = "0.0.1"
+PKG_NAME = "activeshipping"
+PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
+
+PKG_FILES = FileList[
+ "lib/**/*", "examples/**/*", "[A-Z]*", "Rakefile"
+].exclude(/\.svn$/)
+
+
+desc "Default Task"
+task :default => 'test:units'
+task :test => ['test:units','test:remote']
+
+# Run the unit tests
+
+namespace :test do
+ Rake::TestTask.new(:units) do |t|
+ t.pattern = 'test/unit/**/*_test.rb'
+ t.ruby_opts << '-rubygems'
+ t.verbose = true
+ end
+
+ Rake::TestTask.new(:remote) do |t|
+ t.pattern = 'test/remote/*_test.rb'
+ t.ruby_opts << '-rubygems'
+ t.verbose = true
+ end
+end
+
+# Genereate the RDoc documentation
+Rake::RDocTask.new do |rdoc|
+ rdoc.rdoc_dir = 'doc'
+ rdoc.title = "ActiveShipping library"
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README', 'CHANGELOG')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
+
+task :install => [:package] do
+ `gem install pkg/#{PKG_FILE_NAME}.gem`
+end
@@ -0,0 +1 @@
+require 'active_shipping'
@@ -0,0 +1,44 @@
+#--
+# Copyright (c) 2007 Jaded Pixel
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#++
+
+$:.unshift File.dirname(__FILE__)
+
+
+
+require 'rubygems'
+require 'active_support'
+
+require 'vendor/xml_node/lib/xml_node'
+
+require 'net/https'
+require 'active_shipping/lib/requires_parameters'
+require 'active_shipping/lib/posts_data'
+require 'active_shipping/lib/country'
+
+require 'active_shipping/shipping/base'
+require 'active_shipping/shipping/response'
+require 'active_shipping/shipping/package'
+require 'active_shipping/shipping/location'
+require 'active_shipping/shipping/rate_estimate'
+require 'active_shipping/shipping/carrier'
+require 'active_shipping/shipping/carriers'
Oops, something went wrong.

0 comments on commit 0eebee7

Please sign in to comment.