PackageTracker¶ ↑
PackageTracker is a ruby gem for fetching the status of a packages(UPS, FedEx, etc…) with a simple API. Currently only UPS, FedEx and USPS are supported. More docs and carrier support to come soon…
Installation¶ ↑
To install:
gem install package_tracker
Usage¶ ↑
client = PackageTracker::Client.new(Yaml.load_file("credentials.yaml")) fedex_package = client.track("999999999999") # => PackageTracker::Response fedex_package.delivered? # => true fedex_package.statuses # => [{:message => "DELIVERED", :location => "San Francsico, CA, USA", :time => 2011-04-22 00:00:00 -0700}, ...] ups_package = client.track("1Z9999999999999999") # and so on...
Configuration¶ ↑
PackageTracker::Client::new takes a hash of credentials with the following parameters:
{ :ups => { :key => "key" :user_id => "user id" :password => "password" }, :fedex => { :password => "password", :key => "key", :account => "account", :meter => "meter number" }, :usps => { :username => "username", :password => "password" } }
It’s usually easiest to put those credentials in a YAML file and load them in. That makes it easy to keep your sensitive password info out of version control as well.
If you don’t want to use the built in tracking number detection, you can specify which carrier to use with a tracking request:
client.track("999999999999", :ups) # Sent directly to ups api
If you just want to hit the carriers’ test servers, you can set your client to test mode:
client = PackageTracker::Client.new(Yaml.load_file("credentials.yaml")) client.test_mode! # all requests will now to to the carriers' test servers