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-27 18:05:31 -04:00
|
|
|
def initialize(user, pass)
|
|
|
|
self.class.basic_auth user, pass
|
|
|
|
end
|
|
|
|
|
2008-07-27 19:13:44 -04:00
|
|
|
def timeline(which=:friends, options={})
|
|
|
|
self.class.get("/statuses/#{which}_timeline.xml", options)['statuses'].map(&:to_struct)
|
|
|
|
end
|
|
|
|
|
|
|
|
def post(text)
|
|
|
|
self.class.post('/statuses/update.xml', :query => {:status => text})['status'].to_struct
|
2008-07-27 18:05:31 -04:00
|
|
|
end
|
2008-07-27 14:44:18 -04:00
|
|
|
end
|
|
|
|
|
2008-07-27 19:13:44 -04:00
|
|
|
|
2008-07-27 18:05:31 -04:00
|
|
|
twitter = Twitter.new(config['email'], config['password'])
|
|
|
|
|
2008-07-27 19:13:44 -04:00
|
|
|
twitter.timeline.each do |s|
|
|
|
|
puts s.user.name, s.text, "#{s.created_at} #{s.id}", ''
|
|
|
|
end
|
|
|
|
|
|
|
|
# twitter.timeline(:friends, :query => {:since_id => 868482746}).each do |s|
|
|
|
|
# puts s.user.name, s.text, "#{s.created_at} #{s.id}", ''
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# pp twitter.post('this is a test')
|