Installation:
To use this gem, add this line to your Gemfile
gem 'trackerific'
and then run
bundle install
Usage:
# Track a FedEx package: fedex = Trackerific::FedEx.new :account => '123456789', :meter => '123456789' tracking_info = fedex.track_package('183689015000001') # Track a USPS package: usps = Trackerific::USPS.new :user_id => '123USERID4567' tracking_info = usps.track_package('EJ958083578US') # Track a UPS package: ups = Trackerific::UPS.new :user_id => 'userid', :key => 'kQdEJwuHBjtQ7g2', :password => 'secret' tracking_info = ups.track_package('1Z12345E0291980793')
Tracking Results
The tracking results for all three providers are returned in a Hash in this format:
{ :package_id => 'the package id being tracked', :summary => 'summary of the tracking results', :details => ['array containing each tracking status by date'] }
Here’s an example of how to print the tracking results out in a readable format:
puts "Tracking information for package ID: %s" % tracking_info[:package_id] puts tracking_info[:summary] puts " * %s" % tracking_info[:details].join("\n * ")
The above code would yield something that looks like this:
Tracking information for package ID: EJ958083578US Your item was delivered at 8:10 am on June 1 in Wilmington DE 19801. * May 30 11:07 am NOTICE LEFT WILMINGTON DE 19801. * May 30 10:08 am ARRIVAL AT UNIT WILMINGTON DE 19850. * May 29 9:55 am ACCEPT OR PICKUP EDGEWATER NJ 07020.
Finding a Tracking Service Provider
If you do not know the tracking service provider of a package id, you can use the tracking_service helper method to get a Trackerific class that most likely will be able to track the given package id.
include Trackerific tracking_service "183689015000001" # => Trackerific::FedEx tracking_service "1Z12345E0291980793" # => Trackerific::UPS tracking_service "EJ958083578US" # => Trackerific::USPS tracking_service "unknown package id" # => nil
Exception handling:
Exception handling is esssential for tracking packages. If, for example, you enter the wrong number, or the tracking provider has yet to have added the tracking number to their system, a Trackerific::Error will be raised. Here’s an example on how to handle Trackerific::Errors:
begin usps.track_package('EJ958083578US') rescue Trackerific::Error => e puts e. end
Contributing to trackerific
Check out the latest master to make sure the feature hasn’t been implemented
or the bug hasn’t been fixed yet
Check out the issue tracker to make sure someone already hasn’t requested it
and/or contributed it
Fork the project
Start a feature/bugfix branch
Commit and push until you are happy with your contribution
Make sure to add tests for it. This is important so I don’t break it in a
future version unintentionally.
Please try not to mess with the Rakefile, version, or history. If you want to
have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
Copyright
Copyright © 2011 Travis Haynes. See LICENSE.txt for further details.