public
Description: Makes http fun! Also, makes consuming restful web services dead easy.
Homepage:
Clone URL: git://github.com/jnunemaker/httparty.git
Click here to lend your support to: httparty and make a donation at www.pledgie.com !
httparty / examples / twitter.rb
8e143785 » jnunemaker 2008-07-27 get, post, put and delete n... 1 dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
1d48da03 » jnunemaker 2008-07-28 Renamed to HTTParty which i... 2 require File.join(dir, 'httparty')
de9b4fb6 » jnunemaker 2008-07-27 Put in first wave of parsin... Comment 3 require 'pp'
8e143785 » jnunemaker 2008-07-27 get, post, put and delete n... 4 config = YAML::load(File.read(File.join(ENV['HOME'], '.twitter')))
5
6 class Twitter
1d48da03 » jnunemaker 2008-07-28 Renamed to HTTParty which i... 7 include HTTParty
8e143785 » jnunemaker 2008-07-27 get, post, put and delete n... 8 base_uri 'twitter.com'
de9b4fb6 » jnunemaker 2008-07-27 Put in first wave of parsin... Comment 9
3a8ad1da » jnunemaker 2008-07-30 Added :basic_auth as an opt... 10 def initialize(u, p)
11 @auth = {:username => u, :password => p}
13620e30 » jnunemaker 2008-07-27 Added Hash#to_struct for ma... 12 end
13
aafde867 » jnunemaker 2008-07-28 Documented and tweaked the ... 14 # which can be :friends, :user or :public
15 # options[:query] can be things like since, since_id, count, etc.
99cd89d3 » jnunemaker 2008-07-27 added delicious example and... 16 def timeline(which=:friends, options={})
3a8ad1da » jnunemaker 2008-07-30 Added :basic_auth as an opt... 17 options.merge!({:basic_auth => @auth})
18 self.class.get("/statuses/#{which}_timeline.json", options)
99cd89d3 » jnunemaker 2008-07-27 added delicious example and... 19 end
20
21 def post(text)
3a8ad1da » jnunemaker 2008-07-30 Added :basic_auth as an opt... 22 options = { :query => {:status => text}, :basic_auth => @auth }
23 self.class.post('/statuses/update.json', options)
13620e30 » jnunemaker 2008-07-27 Added Hash#to_struct for ma... 24 end
8e143785 » jnunemaker 2008-07-27 get, post, put and delete n... 25 end
26
13620e30 » jnunemaker 2008-07-27 Added Hash#to_struct for ma... 27 twitter = Twitter.new(config['email'], config['password'])
3a8ad1da » jnunemaker 2008-07-30 Added :basic_auth as an opt... 28 pp twitter.timeline
29 # pp twitter.timeline(:friends, :query => {:since_id => 868482746})
9b423a22 » jnunemaker 2008-07-30 :body and :query now both t... 30 # pp twitter.timeline(:friends, :query => 'since_id=868482746')
05c388dc » jnunemaker 2008-12-06 Added to_s when doing Hash#... 31 # pp twitter.post('this is a test of 0.2.0')