Created
January 14, 2010 03:36
-
-
Save paulsingh/276826 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://rdoc.info/projects/archiloque/rest-client | |
require 'rest_client' | |
########################################## | |
# Get all my letters | |
# curl -X GET http://localhost:3000/letters.xml?api_key=1b9884c66a | |
# curl -X GET http://localhost:3000/letters.json?api_key=1b9884c66a | |
RestClient.get 'http://localhost:3000/letters.xml?api_key=1b9884c66a' | |
########################################## | |
# Create a new letter | |
data = Hash.new | |
data[:letter] = Hash.new | |
data[:letter][:sender_attributes] = Hash.new | |
data[:letter][:recipient_attributes] = Hash.new | |
data[:api_key]="1b9884c66a" | |
data[:mailing_year]="2011" | |
data[:mailing_month]="01" | |
data[:mailing_day]="01" | |
data[:letter][:pdf_remote_url]="http://www.irs.gov/pub/irs-pdf/fw4.pdf" | |
data[:letter][:sender_attributes][:name]="Some Dude" | |
data[:letter][:sender_attributes][:street1]="123 Any Street" | |
data[:letter][:sender_attributes][:city]="Ashburn" | |
data[:letter][:sender_attributes][:state]="VA" | |
data[:letter][:sender_attributes][:zip]="20148" | |
data[:letter][:recipient_attributes][:name]="That Guy" | |
data[:letter][:recipient_attributes][:street1]="789 Some Dr" | |
data[:letter][:recipient_attributes][:city]="San Antonio" | |
data[:letter][:recipient_attributes][:state]="TX" | |
data[:letter][:recipient_attributes][:zip]="99999" | |
# curl -X POST -H "Content-Type: application/xml" -d data.to_xml http://localhost:3000/letters.xml | |
# RestClient.post 'http://localhost:3000/letters.xml', data.to_xml, :content_type => :xml | |
RestClient.post 'http://localhost:3000/letters.json', data.to_json, :content_type => :json | |
########################################## | |
# Get an existing letter with an ID=1 | |
# curl -X GET http://localhost:3000/letters/1.xml?api_key=1b9884c66a | |
# RestClient.get 'http://localhost:3000/letters/1.json?api_key=1b9884c66a' | |
RestClient.get 'http://localhost:3000/letters/1.xml?api_key=1b9884c66a' | |
########################################## | |
# Update an existing letter with an ID=1 | |
data = Hash.new | |
data[:letter] = Hash.new | |
data[:api_key]="1b9884c66a" | |
data[:mailing_year]="2011" | |
data[:mailing_month]="01" | |
data[:mailing_day]="15" | |
data[:letter][:country]="USA" | |
# curl -X PUT -H "Content-Type: application/xml" -d data.to_xml http://localhost:3000/letters/1.xml | |
# RestClient.put 'http://localhost:3000/letters/1.xml', data.to_xml, :content_type => :xml | |
RestClient.put 'http://localhost:3000/letters/1.json', data.to_json, :content_type => :json | |
########################################## | |
# Purchase my letter with an ID=1 | |
# curl -X GET http://localhost:3000/letters/1/purchase.xml?api_key=1b9884c66a | |
# curl -X GET http://localhost:3000/letters/1/purchase.json?api_key=1b9884c66a | |
RestClient.get 'http://localhost:3000/letters/1/purchase.xml?api_key=1b9884c66a' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment