Sha256: 2242f11e4703251527a5f6e422375c600b93a4f8811e5cfe2d6e242c2f3ed3a4

Contents?: true

Size: 1.35 KB

Versions: 3

Compression:

Stored size: 1.35 KB

Contents

= 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

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
jnunemaker-httparty-0.1.1 README.txt
httparty-0.1.1 README.txt
httparty-0.1.0 README.txt