Simple Ruby HTTP/REST client with a sane API
Nestful is a simple Ruby HTTP/REST client with a sane API.
sudo gem install nestfulNestful.get 'http://example.com' #=> "body"# url-encoded form POST
Nestful.post 'http://example.com', :foo => 'bar'
# JSON POST
Nestful.post 'http://example.com', {:foo => 'bar'}, :format => :json# You can also provide nestled params
Nestful.get 'http://example.com', :nestled => {:vars => 1}Request is the base class for making HTTP requests - everthing else is just an abstraction upon it.
Nestful::Request.new(url, options).execute #=> Valid Request options are:
Requests are run via the execute method.
The Endpoint class provides a single object to work with restful services. The following example does a GET request to the URL; http://example.com/assets/1/
Nestful::Endpoint.new('http://example.com')['assets'][1].get #=> Nestful::ResponseIf you're building a binding for a REST API, then you should consider using the Resource class.
class Charge :bearer, :password => 'sk_bar'
def self.all
self.new(get)
end
def self.find(id)
self.new(get(id))
end
def refund
post(:refund)
end
end
Charge.all #=> []
Charge.find('ch_bar').amountAll HTTP responses are in the form of a Nestful::Response instance. This contains the raw HTTP response, body, headers and a few helper methods:
response = Nestful.get('http://www.google.com')
response.body #=> '...'
response.headers #=> {'Content-Type' => 'text/html'}
response.status #=> 200You can also access the decoded body if available, such as for JSON responses:
response = Nestful.get('http://api.stripe.com/v1/charges')
charges = response.decodedAll calls are proxied to the decoded body, so you can access JSON properties like this:
charges = Nestful.get('http://api.stripe.com/v1/charges')['data']Parts of the connection code were inspired from ActiveResource.
No open issues yet, or sync has not completed.