-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_search.rb
62 lines (53 loc) · 1.31 KB
/
test_search.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env ruby
require 'rubygems'
require 'collecta'
#Jabber::debug = true
@debug = true
#@notify = ["windows", "vista"]
settings = YAML.load(File.read("test_config.yml"))
@client = Collecta::Client.new(settings["collecta.apikey"])
@client.anonymous_connect
puts "Connected: #{@client.jid.to_s}" if @debug
while @query = ARGV.pop
# Let's connect to the Pubsub service
if @client.subscribe(@query, @notify) and @debug
msg = "Subscribed "
msg += " query: '#{@query}'" if @query
msg += " , notify: #{@notify.inspect}" if @notify
puts msg
end
end
@client.add_message_callback do |msg|
begin
next unless payload = Collecta::Payload.new(msg)
next if payload.type == :unknown
m = "#{payload.type}: #{payload.meta} "
if payload.type == :notify
m += " -> #{payload.body}"
elsif payload.type == :query
m += "\n---\n"
m += "#{payload.category}: #{payload.title}\n"
m += payload.body
if payload.links
m += "\n---\n"
m += payload.links.inspect
end
else
next
end
m += "\n===============\n\n"
puts m
rescue Exception => e
puts "[E] #{e.to_s}"
end
end
# register a handler for SIGINTs
trap(:INT) do
exit
end
at_exit do
@client.unsubscribe
puts "UnSubscribed." if @debug
@client.close
end
Thread.stop