Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Print stamps with Ruby!

License

NotificationsYou must be signed in to change notification settings

mattsears/stamps

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

72 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Stamps is Stamps.com backed library for creating postage labels,calculate the shipping cost of packages, standardize domesticaddresses via USPS CASS certified Address Matching Software, and trackshipments.

Main Features

  1. Create postage stamp labels in png and pdf formats.

  2. Standardizes shipping address that complies with the USPS addressformatting guidelines.

  3. Validates city, state, and postal code combinations.

  4. Calculate shipping rates based on distance and package weight.

  5. Request USPS carrier pick ups.

  6. Track shipment history.

  7. Purchase postage.

Pre-requisites

Register for the Stamps.comDeveloperProgram to receive a freetest account.

Sample Workflow

  1. Standardize Shipping Address - Ship-to addresses must bestandardized based on USPS rules for proper address conventions beforea shipping label can be issued.

  2. Get Rates - allow users to view and select the best shippingservice for their needs.

  3. Generate the Shipping Label - after choosing a shippingservice and ship-to address is standardized, theStamps.create methodwill generate the indicium required to ship the item. Ifthe customer changes their mind, they may want to select an optionthat initiates aStamps.cancel.Stamps.cancel refunds postage andvoids the shipping label.

  4. Print the Shipping Label - Call the returned URL to obtain the shipping label image.A URL is returned by theStamps.create call in the :url item. Theintegration will connect to this URL to retrieve their shipping labeland customs forms for printing.

Getting Started

Once you have a test account with integration id, we can simple passthem to the configure block:

# Authenticate you stamps.com credentialsStamps.configure do |config|  config.integration_id = 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXXX'  config.username       = 'STAMPS USERNAME'  config.password       = 'STAMPS PASSWORD'end

Now we can now be able to retrieve information about our account:

Stamps.account

Standardized Shipping Address

Standardizes shipping address that complies with the USPS addressformatting guidelines

standardized_address = Stamps.clean_address(  :address => {    :full_name => 'The White House',    :address1  => '1600 Pennsylvania Avenue, NW',    :city      => 'Washington',    :state     => 'DC',    :zip_code  => '20500'})

Get Rates

To get a list of rates for all available USPS services based on theZIP Code or the foreign country being shipped to for a given packageweight and size.

rates = Stamps.get_rates(  :from_zip_code => '45440',  :to_zip_code   => '20500',  :weight_lb     => '0.5',  :ship_date     => '2011-04-07')

Creating a shipping label

To generate the postage based on the shipping information provided in the request.Thecreate! method will return a URL that references either an image of thedomestic shipping label or a multi-page PDF document for internationallabels with customs forms.

stamp = Stamps.create!(    :tracking_number => true,    :rate          => rates.first,    :to            => standardized_address,    :from => {      :full_name   => 'Littlelines',      :address1    => '50 Chestnut Street',      :address2    => 'Suite 234',      :city        => 'Beavervcreek',      :state       => 'OH',      :zip_code    => '45440'    },    :memo => 'Thanks for shopping with us!')

Now we can view or print the postage label:

stamp.url

General Configuration

If you want to see the data logged to and from the api:

Stamps.configure do |config|  config.log_messages = trueend

By default Stamps will return responses as a Hash. To make Stampsreturn a Hashie instead:

Stamps.configure do |config|  config.format = :hashieend

A return address can be specified in the configuration block aswell. This address will be used when the :from address is not specifiedwhen creating new stamps

Stamps.configure do |config|  config.return_address = {    :full_name    => 'Littlelines',    :address1     => '50 Chestnut Street',    :address2     => 'Suite 234',    :city         => 'Beavercreek',    :state        => 'OH',    :zip_code     => '45440',    :phone_number => '9375545027'  }end

Installation Steps

First install the gem:

gem install stamps

Add it to your Gemfile:

gem 'stamps'

Development

Pull requests are very welcome! Make sure your patches are well tested. Please create a topic branch for every separate changeyou make.

Author

Matt Sears

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp