Skip to content

Instantly share code, notes, and snippets.

@sorah sorah/delete.rb
Created Jun 30, 2010

Embed
What would you like to do?
#-*- 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
You can’t perform that action at this time.