Skip to content

Instantly share code, notes, and snippets.

@dmichael
Created June 11, 2009 15:29
Show Gist options
  • Select an option

  • Save dmichael/127985 to your computer and use it in GitHub Desktop.

Select an option

Save dmichael/127985 to your computer and use it in GitHub Desktop.
# Both of these examples are taken from John's examples
require 'httparty'
# Basic usage
# You can also use post, put, delete in the same fashion
response = HTTParty.get('http://twitter.com/statuses/public_timeline.json')
puts response.body, response.code, response.message, response.headers.inspect
# ... or mixed in
class Delicious
include HTTParty
base_uri 'https://api.del.icio.us/v1'
def initialize(u, p)
@auth = {:username => u, :password => p}
end
def posts(options={})
options.merge!({:basic_auth => @auth})
self.class.get('/posts/get', options)
end
end
delicious = Delicious.new('hksintl', 'wouldntyouliketoknow')
p delicious.posts(:query => {:tag => 'nethttp'})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment