Skip to content

Instantly share code, notes, and snippets.

@alpicola
Created October 3, 2010 16:58
Show Gist options
  • Select an option

  • Save alpicola/608720 to your computer and use it in GitHub Desktop.

Select an option

Save alpicola/608720 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'twitter'
require 'yaml'
if ARGV.length != 1
puts 'usage: ./tweet.rb Hello!'
exit
end
config = YAML.load(DATA.read)
oauth = Twitter::OAuth.new(config[:ctoken], config[:csecret])
unless config[:atoken] && config[:asecret]
puts 'redirecting to twitter to authorize...'
`open #{oauth.request_token.authorize_url}`
print 'Enter the PIN number: '
pin = STDIN.gets.chomp
atoken = oauth.request_token.get_access_token(:oauth_verifier => pin)
config[:atoken] = atoken.token
config[:asecret] = atoken.secret
File.open(__FILE__, 'r+') {|f|
while line = f.gets
break if line == "__END__\n"
end
f << YAML.dump(config)
f.truncate(f.tell)
}
end
oauth.authorize_from_access(config[:atoken], config[:asecret])
twitter = Twitter::Base.new(oauth)
twitter.update(ARGV[0])
puts 'Status updated!'
__END__
---
:ctoken: yI6eHp6FBwQSbGdHOOg
:csecret: WWIgAXZ3mjgxGxYbKp0ukVFFfrxCAVFrWyDdj94Q9U
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment