Skip to content

Instantly share code, notes, and snippets.

@sorah
Created June 30, 2010 06:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sorah/458321 to your computer and use it in GitHub Desktop.
Save sorah/458321 to your computer and use it in GitHub Desktop.
#-*- coding: utf-8 -*-
require 'net/http'
require 'uri'
require 'json'
Net::HTTP.version_1_2
def chirp(id, pass)
uri = URI('http://chirpstream.twitter.com/2b/user.json')
buf = ""
http = Net::HTTP.start(uri.host, uri.port)
req = Net::HTTP::Get.new(uri.request_uri)
req.basic_auth id, pass
http.request(req) do |res|
res.read_body do |body|
buf += body
while i = buf.index("\r\n") # nil is same as false in ruby, so use "while" and remove "nil?" method
str = buf.slice!(0, i + 2).chomp
yield JSON.parse(str) unless str.size.zero?
end
end
end
end
s = [] #Array.new is *migurushi-*
if $0 == __FILE__
chirp('Twitter ID', 'PASS') do |h|
s << h
if h['delete']
puts (did = h['delete']['status']['id'].to_s) # If you want String, use to_s method.
s.each do |tweet|
ssid = tweet['id'].to_s # Same as line30
puts "#{tweet['user']['screen_name']} has deleted '#{tweet['text']}'" if did == ssid # () isn't needed
end
puts "#{h['user']['screen_name']}: #{h['text']}" if h['text']
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment