Created
May 7, 2010 06:09
-
-
Save sugamasao/393126 to your computer and use it in GitHub Desktop.
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
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
require 'net/http' | |
require 'uri' | |
require 'pp' | |
require 'kconv' | |
require 'rubygems' | |
require 'pit' | |
require 'json' | |
def user(status) | |
#puts "[Tweet]#{status['user']['screen_name']} : #{status['text'].tosjis}" | |
end | |
def friends(status) | |
end | |
def event(status) | |
end | |
def target_object(status) | |
retweet status if status["event"] == "retweet" | |
favorite status if status["event"] == "favorite" | |
end | |
def favorite(status) | |
puts "[fav] #{status['source']['screen_name']} => #{status['target']['screen_name']} / #{status['target_object']['user']['screen_name']} : #{status['target_object']['text'].tosjis}" | |
end | |
def retweet(status) | |
puts "[RT] #{status['source']['screen_name']} => #{status['target']['screen_name']} / #{status['target_object']['user']['screen_name']} : #{status['target_object']['text'].tosjis}" | |
end | |
USERNAME = Pit.get("twitter")["username"] | |
PASSWORD = Pit.get("twitter")["password"] | |
#URL = 'http://twitter.com/account/verify_credentials.json' | |
URL = 'http://chirpstream.twitter.com/2b/user.json' | |
uri = URI.parse(URL) | |
Net::HTTP.start(uri.host, uri.port) do |http| | |
request = Net::HTTP::Get.new(uri.path) | |
request.basic_auth(USERNAME, PASSWORD) | |
http.request(request) do |res| | |
# puts "chunked? => #{res.chunked?}" | |
data = "" | |
res.read_body do |chunk| | |
# puts "************************ reading..." | |
begin | |
status = JSON.parse(chunk) | |
rescue | |
data << chunk | |
status = JSON.parse(data) rescue next | |
data = "" | |
end | |
# puts "---------------------------" | |
friends status if status["friends"] | |
user status if status["user"] | |
event status if status["event"] | |
target_object status if status["target_object"] | |
end | |
#status = JSON.parse(res.body) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment