0.0
No commit activity in last 3 years
No release in over 3 years
A simple Ruby API wrapper for the USPS price calculator API
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.13
~> 0
~> 10.0
~> 3.0

Runtime

~> 2.0
>= 1.4.1, ~> 1.4
>= 0.1.18, ~> 0.1
 Project Readme

ShippingScale

ShippingScale is a simple interface with the USPS Price Calculator API. With it, you can quickly and easily calculate postage prices for packages.

Installation

Add this line to your application's Gemfile:

gem 'shipping-scale'

# or from the github repository
gem 'shipping-scale', :git => 'https://github.com/jereinhardt/shipping-scale.git'

And then execute:

$ bundle

Or install it yourself as:

$ gem install shipping-scale

Setup

In order to properly configure your interface, you must first have a registered developer account with the US Postal Service.

Add an initializer to your application and configure it to use your API USER ID

ShippingScale.configure do |config|
  config.user_id = ENV["USPS_USER_ID"]
  config.timeout = 5
  config.testing = false
end

Usage

If you have all of the necessary information for the package you want to ship, using the gem is as simple as creating an instance of ShipingScale::Package and using #get_price!. Other details are also returned with this method.

package_options = { 
  pounds: 1,
  ounces: 8, # or weight: 1.5
  zip_origin: "66204",
  zip_destination: "63501" 
}

package = ShippingScale::Package.new(package_options)

# for the value of postage on a single package
package.price # => 15

# for other details sent back from the request
package.details # => { zip_origination: "66204", zip_destination: "63501", pounds: "1", ... }

You can also get the price of multiple packages sent in the same shipment.

packages = [
  {pounds: 1, ...},
  {pounds: 5, ...}
]

shipment = ShippingScale::Package.shipment(packages)

# for the total price of the shipment
shipment.price # => 25

# for the price of each individual package in the shipment, by package ID
shipment.prices # => {"1" => 10, "2" => 15}

# for details sent back by the request
shipment.details # => { zip_origination: "66204", ... }

Currently, all rates retreived from the USPS API are for 2-day Priority Mail only.

License

The gem is available as open source under the terms of the MIT License.

Bug reports and pull requests are welcome on GitHub at https://github.com/jereinhardt/shipping-scale.