public
Fork of pezra/resourceful
Description: An HTTP library for Ruby that takes advantage of everything HTTP has to offer.
Homepage: http://absolute-performance.com/open-source/resourceful
Clone URL: git://github.com/paul/resourceful.git
paul (author)
Mon Jun 23 16:57:57 -0700 2008
commit  e4ea4f881ec8bbaf70e50f9635379dbd8b167a71
tree    3000c0feafac55870a206aaf03f47e2e5f5f517c
parent  094ca8a17fc8284e485b1b4ab125ddc79a3eed05
name age message
file .autotest Mon May 12 17:18:16 -0700 2008 Refactor redirects [paul]
file .gitignore Loading commit data...
file MIT-LICENSE
file README.markdown
file Rakefile
directory lib/
directory spec/
README.markdown

Resourceful

Resourceful provides a convenient Ruby API for making HTTP requests.

Features:

  • GET, PUT, POST and DELETE HTTP requests
  • HTTP Basic and Digest authentication
  • HTTP Caching with pluggable backends
  • Follow redirects based on the results of a callback

More Info

Examples

Getting started

gem install resourceful

Simplest example

require 'resourceful'
http = Resourceful::HttpAccessor.new
resp = http.resource('http://rubyforge.org').get
puts resp.body

Get a page requiring HTTP Authentication

basic_handler = Resourceful::BasicAuthenticator.new('My Realm', 'admin', 'secret')
http.auth_manager.add_auth_hander(basic_handler)
resp = http.resource('http://example.com/').get
puts resp.body

Redirection based on callback results

Resourceful will by default follow redirects on read requests (GET and HEAD), but not for POST, etc. If you want to follow a redirect after a post, you will need to set the resource#on_redirect callback. If the callback evaluates to true, it will follow the redirect.

resource = http.resource('http://example.com/redirect_me')
resource.on_redirect { |req, resp| resp.header['Location'] =~ /example.com/ }
resource.get  # Will only follow the redirect if the new location is example.com

Copyright (c) 2008 Absolute Performance, Inc, released under the MIT License.