This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
| name | age | message | |
|---|---|---|---|
| |
.autotest | Mon May 12 17:18:16 -0700 2008 | |
| |
.gitignore | Mon Feb 16 12:36:15 -0800 2009 | |
| |
History.txt | Sun Aug 23 22:42:49 -0700 2009 | |
| |
MIT-LICENSE | Tue Jun 24 08:18:11 -0700 2008 | |
| |
Manifest | Tue Aug 25 14:22:55 -0700 2009 | |
| |
README.markdown | Fri Aug 14 08:07:30 -0700 2009 | |
| |
Rakefile | Tue Oct 06 07:59:35 -0700 2009 | |
| |
lib/ | Tue Oct 06 08:20:17 -0700 2009 | |
| |
resourceful.gemspec | Tue Oct 06 08:20:17 -0700 2009 | |
| |
spec/ | Tue Aug 25 14:52:17 -0700 2009 |
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
- Source: Github
- Bug Tracking: Lighthouse
- Project Page: Rubyforge
- Documentation: API Docs
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
my_realm_authenticator = Resourceful::BasicAuthenticator.new('My Realm', 'admin', 'secret')
http = Resourceful::HttpAccessor.new(:authenticator => my_realm_authenticator)
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
Post a URL encoded form
require 'resourceful'
http = Resourceful::HttpAccessor.new
resp = http.resource('http://mysite.example/service').
post(Resourceful::UrlencodedFormData.new(:hostname => 'test', :level => 'super'))
Post a Mulitpart form with a file
require 'resourceful'
http = Resourceful::HttpAccessor.new
form_data = Resourceful::MultipartFormData.new(:username => 'me')
form_data.add_file('avatar', '/tmp/my_avatar.png', 'image/png')
resp = http.resource('http://mysite.example/service').post(form_data)
Put an XML document
require 'resourceful'
http = Resourceful::HttpAccessor.new
resp = http.resource('http://mysite.example/service').
put('<?xml version="1.0"?><test/>', :content_type => 'application/xml')
Delete a resource
require 'resourceful'
http = Resourceful::HttpAccessor.new
resp = http.resource('http://mysite.example/service').delete
Copyright
Copyright (c) 2008 Absolute Performance, Inc, Peter Williams. Released under the MIT License.







