1
0
Fork 0
mirror of https://github.com/jnunemaker/httparty synced 2023-03-27 23:23:07 -04:00
🎉 Makes http fun again!
Find a file
2008-07-31 00:24:29 -04:00
config Made sure I got the manifest and gem stuff all right. 2008-07-28 16:50:17 -04:00
examples :body and :query now both take either a hash or a query string [#4 state:resolved] 2008-07-31 00:22:59 -04:00
lib Updated history, version and gemspec. 2008-07-31 00:24:29 -04:00
script Renamed to HTTParty which is way more fun and unique than boring old web. 2008-07-28 10:49:53 -04:00
spec :body and :query now both take either a hash or a query string [#4 state:resolved] 2008-07-31 00:22:59 -04:00
tasks Initial commit 2008-07-27 11:52:18 -04:00
website Added website files 2008-07-29 12:16:01 -04:00
.gitignore Initial commit 2008-07-27 11:52:18 -04:00
History.txt Updated history, version and gemspec. 2008-07-31 00:24:29 -04:00
httparty.gemspec Updated history, version and gemspec. 2008-07-31 00:24:29 -04:00
License.txt Tweaking information and readme. 2008-07-28 13:20:03 -04:00
Manifest.txt Updated gemspec to include website files 2008-07-29 12:17:12 -04:00
PostInstall.txt Adjusted post install. Tweaked example. Created gemspec for github. Uncommented extra dependencies in hoe. 2008-07-28 16:48:22 -04:00
Rakefile Initial commit 2008-07-27 11:52:18 -04:00
README.txt Adjusted post install. Tweaked example. Created gemspec for github. Uncommented extra dependencies in hoe. 2008-07-28 16:48:22 -04:00
setup.rb Initial commit 2008-07-27 11:52:18 -04:00

= 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