Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
require 'net/http'
require 'base64'
require 'cgi'
require 'json'
class CoBot
HEADERS = {
'Accept' => 'application/json',
'Content-Type' => 'application/json; charset=utf-8',
'User-Agent' => 'Harvest Twitter Script' }
def initialize(group_id, group_key)
@group_id = group_id
@group_key = group_key
@connection = Net::HTTP.new("coopapp.com", 80)
@connection.open_timeout = 10
end
def post(message, message_id)
message_id_pattern = /#{Regexp.escape(message_id)}$/
unless statuses.any?{|m| message_id_pattern =~ m}
status = "#{message} - #{key}"
@connection.post("/groups/#{@group_id}/notes", {:status => status, :key => @group_key}.to_json, HEADERS)
statuses << status
end
end
private
def statuses
@statuses ||= retrieve_statuses
end
def retrieve_statuses
response = @connection.get("/groups/#{@group_id}/users/cobot?key=#{@group_key}", HEADERS)
JSON.parse(response.body).map{|s| s['text']}
end
end
#!/usr/bin/env ruby
$KCODE = 'U'
require 'rubygems'
require 'twitter'
require 'cobot'
MAX_TWEETS = 3
cobot = CoBot.new(<group_id>, <group_secret>)
%w{mobalean kanjidamage keitai-dev}.each do |keyword|
Twitter::Search.new(keyword).per_page(MAX_TWEETS).each do |r|
cobot.post("@#{r['from_user']} mentioned #{keyword}: \"#{r['text']}\"",
"from: http://twitter.com/#{r['from_user']}/status/#{r['id']}")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.