2008-07-27 14:44:18 -04:00
|
|
|
dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2008-07-28 10:49:53 -04:00
|
|
|
require File.join(dir, 'httparty')
|
2008-07-27 16:35:31 -04:00
|
|
|
require 'pp'
|
2008-07-27 14:44:18 -04:00
|
|
|
config = YAML::load(File.read(File.join(ENV['HOME'], '.twitter')))
|
|
|
|
|
|
|
|
class Twitter
|
2008-07-28 10:49:53 -04:00
|
|
|
include HTTParty
|
2008-07-27 14:44:18 -04:00
|
|
|
base_uri 'twitter.com'
|
2008-07-27 16:35:31 -04:00
|
|
|
|
2008-07-31 00:05:36 -04:00
|
|
|
def initialize(u, p)
|
|
|
|
@auth = {:username => u, :password => p}
|
2008-07-27 18:05:31 -04:00
|
|
|
end
|
|
|
|
|
2008-07-28 12:58:40 -04:00
|
|
|
# which can be :friends, :user or :public
|
|
|
|
# options[:query] can be things like since, since_id, count, etc.
|
2008-07-27 19:13:44 -04:00
|
|
|
def timeline(which=:friends, options={})
|
2008-07-31 00:05:36 -04:00
|
|
|
options.merge!({:basic_auth => @auth})
|
|
|
|
self.class.get("/statuses/#{which}_timeline.json", options)
|
2008-07-27 19:13:44 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def post(text)
|
2008-07-31 00:05:36 -04:00
|
|
|
options = { :query => {:status => text}, :basic_auth => @auth }
|
|
|
|
self.class.post('/statuses/update.json', options)
|
2008-07-27 18:05:31 -04:00
|
|
|
end
|
2008-07-27 14:44:18 -04:00
|
|
|
end
|
|
|
|
|
2008-07-27 18:05:31 -04:00
|
|
|
twitter = Twitter.new(config['email'], config['password'])
|
2008-07-31 00:05:36 -04:00
|
|
|
pp twitter.timeline
|
|
|
|
# pp twitter.timeline(:friends, :query => {:since_id => 868482746})
|
2008-07-31 00:22:59 -04:00
|
|
|
# pp twitter.timeline(:friends, :query => 'since_id=868482746')
|
2008-12-06 23:54:40 -05:00
|
|
|
# pp twitter.post('this is a test of 0.2.0')
|