Skip to content

Instantly share code, notes, and snippets.

@snaka
Created October 4, 2008 01:29
Show Gist options
  • Save snaka/14695 to your computer and use it in GitHub Desktop.
Save snaka/14695 to your computer and use it in GitHub Desktop.
simplest twitter client (post only)
# Simplest twitter client (only for posts)
require 'net/http'
require 'kconv'
require 'rubygems'
require 'snarl'
require 'json'
user = ARGV.shift
pass = ARGV.shift
status = ARGV.join(" ") || ""
status << "[twitty]"
status_utf8 = status.kconv(Kconv::UTF8, Kconv::SJIS);
Net::HTTP.version_1_2
req = Net::HTTP::Post.new('/statuses/update.json')
req.basic_auth user, pass
req.body = 'status=' + URI.encode(status_utf8)
Net::HTTP.start('twitter.com',80, 'proxy.server_or_addres.here', 8080) {|http|
res = http.request(req)
print res.code
print res.body
if res.code == '200'
result = JSON.parser.new(res.body).parse()
text = result["text"]
posted_at = result["created_at"]
Snarl.show_message('Twitty', "#{text} -- (posted @ #{posted_at})", nil, 10)
else
Snarl.show_message('Twitty', "response {code : #{res.code}, body: #{res.body}}", nil, Snarl::NO_TIMEOUT)
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment