Skip to content

Instantly share code, notes, and snippets.

@tily
Created May 6, 2010 14:55
Show Gist options
  • Select an option

  • Save tily/392211 to your computer and use it in GitHub Desktop.

Select an option

Save tily/392211 to your computer and use it in GitHub Desktop.
rubytter4twitter4.rb
require 'rubygems'
require 'oauth'
require 'rubytter'
require 'mechanize'
module Twitter
class Client
def initialize(config)
@config = config
@rubytter = OAuthRubytter.new(access_token)
end
def access_token
browser = WWW::Mechanize.new
browser.get('https://twitter.com')
browser.page.form_with(:action => 'https://twitter.com/sessions') do |f|
f.field_with(:name => 'session[username_or_email]').value = @config[:login]
f.field_with(:name => 'session[password]').value = @config[:password]
f.click_button
end
consumer = OAuth::Consumer.new(
'l8Zu0kP7Mz1xDz1Ok6Ylyw',
'4IRJW7QGXMHdyaqgdRIU21JcGGnpNVM9pIRPbsbqAls',
:site => 'http://twitter.com'
)
request_token = consumer.get_request_token
browser.get(request_token.authorize_url)
browser.page.form_with(:action => 'http://twitter.com/oauth/authorize') do |f|
f.click_button(f.buttons[1])
end
oauth_verifier = browser.page.search('//div[@id="oauth_pin"]/text()').to_s.gsub(/\s/, '')
request_token.get_access_token(:oauth_verifier => oauth_verifier)
end
def status(type, content)
if(type == :post)
@rubytter.update(content)
end
end
end
end
client = Twitter::Client.new({:login => '', :password => ''})
client.status(:post, 'hello from rubytter4twitter4r.rb')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment