Created
October 4, 2008 01:29
-
-
Save snaka/14695 to your computer and use it in GitHub Desktop.
simplest twitter client (post only)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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