public
Description: Makes http fun! Also, makes consuming restful web services dead easy.
Homepage:
Clone URL: git://github.com/jnunemaker/httparty.git
Click here to lend your support to: httparty and make a donation at www.pledgie.com !
name age message
file .gitignore Sun Jul 27 08:52:18 -0700 2008 Initial commit [jnunemaker]
file History.txt Loading commit data...
file License.txt Fri Dec 05 14:11:58 -0800 2008 Removing .txt from files (it has always annoyed... [jnunemaker]
file Manifest.txt Tue Jul 29 09:17:12 -0700 2008 Updated gemspec to include website files [jnunemaker]
file PostInstall.txt Mon Jul 28 13:48:22 -0700 2008 Adjusted post install. Tweaked example. Created... [jnunemaker]
file README.txt Wed Jul 30 21:29:17 -0700 2008 Updated readme and website. [jnunemaker]
file Rakefile Sun Jul 27 08:52:18 -0700 2008 Initial commit [jnunemaker]
directory config/ Mon Jul 28 13:50:17 -0700 2008 Made sure I got the manifest and gem stuff all ... [jnunemaker]
directory examples/
file httparty.gemspec
directory lib/
directory script/ Mon Jul 28 07:49:53 -0700 2008 Renamed to HTTParty which is way more fun and u... [jnunemaker]
file setup.rb Sun Jul 27 08:52:18 -0700 2008 Initial commit [jnunemaker]
directory spec/ Wed Jul 30 21:22:59 -0700 2008 :body and :query now both take either a hash or... [jnunemaker]
directory tasks/ Sat Aug 09 12:20:32 -0700 2008 Updated for new release. Added rake task to hel... [jnunemaker]
directory website/ Wed Jul 30 21:29:17 -0700 2008 Updated readme and website. [jnunemaker]
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(u, p)
      @auth = {:username => u, :password => p}
    end

    def post(text)
      options = { :query => {:status => text}, :basic_auth => @auth }
      self.class.post('/statuses/update.json', options)
    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