tappy 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/tappy +16 -3
- data/lib/tappy/filter/agent_filter.rb +15 -7
- data/lib/tappy.rb +1 -1
- metadata +2 -2
data/bin/tappy
CHANGED
@@ -1,8 +1,21 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
+
require 'rubygems'
|
3
4
|
require 'tappy'
|
4
5
|
|
5
|
-
host = ARGV[
|
6
|
-
port = ARGV[
|
6
|
+
host = ARGV[0] || "localhost"
|
7
|
+
port = ARGV[1].to_i
|
8
|
+
port = 9090 if port == 0
|
9
|
+
filter_option = ARGV[2] || "foursquare"
|
7
10
|
|
8
|
-
Tappy
|
11
|
+
module Tappy
|
12
|
+
class MyTappy < TappyBase
|
13
|
+
set :twitter_host, "http://api.twitter.com"
|
14
|
+
set :filter, "Tappy::AgentFilter"
|
15
|
+
set :filter_options, filter_option
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
puts "Start Tappy server on #{host}:#{port}, options: #{filter_option}"
|
20
|
+
|
21
|
+
Tappy::TappyBase.run! :host => host, :port => port
|
@@ -2,15 +2,23 @@ module Tappy
|
|
2
2
|
class AgentFilter < Filter
|
3
3
|
def filter(response)
|
4
4
|
json = JSON.parse(response.body)
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
begin
|
6
|
+
if json.class == Array
|
7
|
+
json.each do |item|
|
8
|
+
source = item["source"]
|
9
|
+
if source.nil?
|
10
|
+
elsif source.match(options)
|
11
|
+
puts "filterer: #{item["source"]}"
|
12
|
+
json.delete(item)
|
13
|
+
else
|
14
|
+
puts "not filtered: #{source}"
|
15
|
+
end
|
10
16
|
end
|
17
|
+
statues.to_s
|
18
|
+
else
|
19
|
+
response.body
|
11
20
|
end
|
12
|
-
|
13
|
-
else
|
21
|
+
rescue
|
14
22
|
response.body
|
15
23
|
end
|
16
24
|
end
|
data/lib/tappy.rb
CHANGED