Instruction
- Make a few line code with Ruby.
- Use Runny plugin.
This file contains 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 | |
} |
- User accout.
- Password.
- Tweet
No comments:
Post a Comment