jnunemaker / httparty
- Source
- Commits
- Network (94)
- Issues (15)
- Downloads (2)
- Wiki (1)
- Graphs
-
Tree:
9543593
commit 9543593d74193ae1ef7a1767a3007dc02c619066
tree 57432639b9dbe93f5f6e23c3abf0358e5f65c613
parent b70ce56092dd355b2dc73f0151861099bc81cfb2
tree 57432639b9dbe93f5f6e23c3abf0358e5f65c613
parent b70ce56092dd355b2dc73f0151861099bc81cfb2
httparty /
| name | age | message | |
|---|---|---|---|
| |
.gitignore | Sun Jul 27 08:52:18 -0700 2008 | |
| |
History.txt | ||
| |
License.txt | Fri Dec 05 14:11:58 -0800 2008 | |
| |
Manifest.txt | ||
| |
PostInstall.txt | Mon Jul 28 13:48:22 -0700 2008 | |
| |
README.txt | ||
| |
Rakefile | ||
| |
config/ | Mon Jul 28 13:50:17 -0700 2008 | |
| |
examples/ | ||
| |
httparty.gemspec | ||
| |
lib/ | ||
| |
script/ | Mon Jul 28 07:49:53 -0700 2008 | |
| |
setup.rb | Fri Dec 05 14:23:26 -0800 2008 | |
| |
spec/ | ||
| |
tasks/ | ||
| |
website/ |
README.txt
= httparty
== DESCRIPTION:
Makes http fun again!
== FEATURES/PROBLEMS:
* Easy get, post, put, delete requests
* Basic http authentication
* Default request query string parameters (ie: for api keys that are needed on each request)
* Automatic parsing of JSON and XML into ruby hashes
== SYNOPSIS:
The following is a simple example of wrapping Twitter's API for posting updates.
class Twitter
include HTTParty
base_uri 'twitter.com'
basic_auth 'username', 'password'
end
Twitter.post('/statuses/update.json', :query => {:status => "It's an HTTParty and everyone is invited!"})
That is really it! The object returned is a ruby hash that is decoded from Twitter's json response. JSON parsing is used
because of the .json extension in the path of the request. You can also explicitly set a format (see the examples).
That works and all but what if you don't want to embed your username and password in the class? Below is an example to
fix that:
class Twitter
include HTTParty
base_uri 'twitter.com'
def initialize(user, pass)
self.class.basic_auth user, pass
end
def post(text)
self.class.post('/statuses/update.json', :query => {:status => text})
end
end
Twitter.new('username', 'password').post("It's an HTTParty and everyone is invited!")
== REQUIREMENTS:
* Active Support >= 2.1
== INSTALL:
* sudo gem install httparty

