bhauman-twroute 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bin/twroute_runner +4 -2
- data/lib/twroute.rb +1 -0
- data/lib/twroute/application/twrouter.rb +10 -4
- data/lib/twroute/polling_search.rb +48 -0
- data/lib/twroute/tweet_route.rb +2 -2
- data/test/polling_search_test.rb +50 -0
- data/test/test_helper.rb +1 -1
- data/test/tweet_route_test.rb +13 -0
- data/twroute.gemspec +5 -2
- metadata +5 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.8
|
data/bin/twroute_runner
CHANGED
@@ -6,7 +6,9 @@ require 'twroute/application'
|
|
6
6
|
|
7
7
|
Daemons.run_proc('twroute_runner.rb', :dir_mode => :normal, :dir => 'log') do
|
8
8
|
ActiveRecord::Base.logger = Logger.new(File.open(File.join(::Twroute::Application.root_dir, 'log/database.log'), 'a'))
|
9
|
-
Twroute::Application.logger = Logger.new(File.open(File.join(::Twroute::Application.root_dir, 'log/twroute.log'), 'a'))
|
10
|
-
|
9
|
+
Twroute::Application.logger = Logger.new(File.open(File.join(::Twroute::Application.root_dir, 'log/twroute.log'), 'a'))
|
10
|
+
loop do
|
11
|
+
Twroute::Application.run
|
12
|
+
end
|
11
13
|
end
|
12
14
|
|
data/lib/twroute.rb
CHANGED
@@ -11,10 +11,16 @@ module Twroute
|
|
11
11
|
setup
|
12
12
|
end
|
13
13
|
def setup
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
if self.config.twitter.search_params
|
15
|
+
@tweeter = ::Twroute::PollingSearch.new(config.twitter.user,
|
16
|
+
config.twitter.password,
|
17
|
+
config.twitter.search_params.marshal_dump)
|
18
|
+
else
|
19
|
+
@tweeter = ::Twroute::Tweeter.new(config.twitter.user,
|
20
|
+
config.twitter.password,
|
21
|
+
config.twitter.stream_api,
|
22
|
+
config.twitter.stream_api_args.marshal_dump)
|
23
|
+
end
|
18
24
|
@dispatcher = ::Twroute::Dispatcher.new( config.submit_to.marshal_dump,
|
19
25
|
*::Twroute::Routes.routes )
|
20
26
|
@requester = ::Twroute::Requester::Delayed.new
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'yajl'
|
2
|
+
require 'yajl/http_stream'
|
3
|
+
require 'observer'
|
4
|
+
require 'uri'
|
5
|
+
|
6
|
+
module Twroute
|
7
|
+
class PollingSearch
|
8
|
+
include Observable
|
9
|
+
attr_accessor :since_id
|
10
|
+
|
11
|
+
def initialize(user, password, post_arg_hash = {})
|
12
|
+
@user = user
|
13
|
+
@password = password
|
14
|
+
@post_arg_hash = post_arg_hash
|
15
|
+
end
|
16
|
+
|
17
|
+
def twitter_search_uri
|
18
|
+
URI.parse("http://#{@user}:#{@password}@search.twitter.com/search.json?#{self.query_string}")
|
19
|
+
end
|
20
|
+
|
21
|
+
def query_string
|
22
|
+
@post_arg_hash['since_id'] = @since_id if @since_id
|
23
|
+
@post_arg_hash.keys.collect do |key|
|
24
|
+
"#{key}=#{URI.escape(@post_arg_hash[key].to_s)}"
|
25
|
+
end.sort_by { |x| x }.join('&')
|
26
|
+
end
|
27
|
+
|
28
|
+
def start
|
29
|
+
puts twitter_search_uri.to_s
|
30
|
+
loop do
|
31
|
+
send_query
|
32
|
+
sleep 30
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def send_query
|
37
|
+
results = Yajl::HttpStream.get( twitter_search_uri,
|
38
|
+
:symbolize_keys => true)
|
39
|
+
@since_id = results[:results].last[:id]
|
40
|
+
results[:results].each do |tweet|
|
41
|
+
changed
|
42
|
+
notify_observers( tweet )
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
data/lib/twroute/tweet_route.rb
CHANGED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'test_helper.rb'
|
2
|
+
require 'twroute/polling_search'
|
3
|
+
|
4
|
+
class TestObserver
|
5
|
+
attr_accessor :results
|
6
|
+
def update(tweet_hash)
|
7
|
+
@results ||= []
|
8
|
+
@results << tweet_hash
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
class PollingSearchTest < Test::Unit::TestCase
|
14
|
+
def setup
|
15
|
+
end
|
16
|
+
|
17
|
+
def teardown
|
18
|
+
end
|
19
|
+
|
20
|
+
context "with tweeter" do
|
21
|
+
setup do
|
22
|
+
@tweeter = Twroute::PollingSearch.new('bhauman',
|
23
|
+
'watertank',
|
24
|
+
{ :q => 'twitter', :rpp => 20 })
|
25
|
+
end
|
26
|
+
|
27
|
+
should "be able to create query string" do
|
28
|
+
@tweeter.query_string.should == 'q=twitter&rpp=20'
|
29
|
+
end
|
30
|
+
|
31
|
+
should "be able to create a twitter search url" do
|
32
|
+
@tweeter.twitter_search_uri.to_s.should == 'http://bhauman:watertank@search.twitter.com/search.json?q=twitter&rpp=20'
|
33
|
+
end
|
34
|
+
|
35
|
+
should "be able to send query and get results" do
|
36
|
+
@listen = TestObserver.new
|
37
|
+
@tweeter.add_observer @listen
|
38
|
+
@tweeter.send_query
|
39
|
+
|
40
|
+
@listen.results.length.should == 20
|
41
|
+
|
42
|
+
@tweeter.since_id.should_not be_nil
|
43
|
+
@tweeter.since_id.should == @listen.results.last[:id]
|
44
|
+
@tweeter.twitter_search_uri.to_s.should == "http://bhauman:watertank@search.twitter.com/search.json?q=twitter&rpp=20&since_id=#{@listen.results.last[:id]}"
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
data/test/test_helper.rb
CHANGED
data/test/tweet_route_test.rb
CHANGED
@@ -5,6 +5,8 @@ class TweetRouteTest < Test::Unit::TestCase
|
|
5
5
|
@tweet_route = Twroute::TweetRoute.new(Twroute::Parser::Tags.new, '/user/:tweet[sender]/tags/:tags')
|
6
6
|
@tweet_str = "#this #is cool #too"
|
7
7
|
@tweet = {:source=>"<a href=\"http://twitterfox.net/\">TwitterFox</a>", :user=>{:url=>"http://rosed1st.multiply.com/", :friends_count=>275, :time_zone=>"Central Time (US & Canada)", :screen_name=>"RoseD1st", :notifications=>nil, :utc_offset=>-21600, :profile_image_url=>"http://s3.amazonaws.com/twitter_production/profile_images/352932267/twitterProfilePhoto_normal.jpg", :protected=>false, :verified=>false, :profile_text_color=>"000000", :name=>"RoseD1st", :profile_sidebar_border_color=>"D5D39E", :statuses_count=>625, :profile_link_color=>"B4C67C", :location=>"Mad as Hell!", :following=>nil, :profile_background_image_url=>"http://s3.amazonaws.com/twitter_production/profile_background_images/2475770/background.png", :description=>"A conservatve whos had it with Obamas lies!I'm a proud \342\200\234Birther\342\200\235 and only those who haven't looked at the facts think there's no problem", :followers_count=>211, :created_at=>"Thu May 01 02:11:28 +0000 2008", :profile_background_tile=>true, :id=>14609143, :profile_background_color=>"9ae4e8", :profile_sidebar_fill_color=>"778F5F", :favourites_count=>19}, :text=>"this is a #test #tweet", :favorited=>false, :in_reply_to_screen_name=>nil, :in_reply_to_status_id=>nil, :created_at=>"Sun Aug 09 00:25:46 +0000 2009", :id=>3199928174, :in_reply_to_user_id=>nil, :truncated=>false}
|
8
|
+
|
9
|
+
@search_tweet = {:profile_image_url=>"http://a1.twimg.com/profile_images/49018042/Tom_Icon_64x64_normal.png", :source=>"<a href="http://twitter.com/">web</a>", :text=>"this is a #test #tweet", :created_at=>"Fri, 11 Sep 2009 20:28:32 +0000", :to_user_id=>nil, :from_user=>"tmornini", :from_user_id=>168963, :iso_language_code=>"en", :id=>3918907432}
|
8
10
|
end
|
9
11
|
|
10
12
|
should "be able to determine if the required hash keys have been met" do
|
@@ -26,6 +28,17 @@ class TweetRouteTest < Test::Unit::TestCase
|
|
26
28
|
|
27
29
|
post_args['tweet[user]'].should == nil
|
28
30
|
end
|
31
|
+
|
32
|
+
should "be able to handle search result tweet" do
|
33
|
+
@tweet_route.tweet(@search_tweet)
|
34
|
+
post_args = @tweet_route.get_post_args
|
35
|
+
post_args['tweet[from_user]'].should == 'tmornini'
|
36
|
+
post_args['tweet[text]'].should == 'this is a #test #tweet'
|
37
|
+
post_args['parsed[tags]'].should == 'test-tweet'
|
38
|
+
|
39
|
+
post_args['sender'].should == nil
|
40
|
+
@tweet_route.fill_in_url_pattern.should == "/user/:tweet[sender]/tags/test-tweet"
|
41
|
+
end
|
29
42
|
|
30
43
|
end
|
31
44
|
|
data/twroute.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{twroute}
|
5
|
-
s.version = "0.1.
|
5
|
+
s.version = "0.1.8"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["bhauman"]
|
9
|
-
s.date = %q{2009-
|
9
|
+
s.date = %q{2009-09-11}
|
10
10
|
s.description = %q{Twroute listens for Twitter updates and redirects them to HTTP post requests}
|
11
11
|
s.email = %q{bhauman@gmail.com}
|
12
12
|
s.executables = ["twroute", "twroute_runner", "twroute_worker"]
|
@@ -42,6 +42,7 @@ Gem::Specification.new do |s|
|
|
42
42
|
"lib/twroute/parser/regex.rb",
|
43
43
|
"lib/twroute/parser/tags.rb",
|
44
44
|
"lib/twroute/parser/users.rb",
|
45
|
+
"lib/twroute/polling_search.rb",
|
45
46
|
"lib/twroute/requester/basic.rb",
|
46
47
|
"lib/twroute/requester/delayed.rb",
|
47
48
|
"lib/twroute/requester/delayed/create_delayed_jobs.rb",
|
@@ -58,6 +59,7 @@ Gem::Specification.new do |s|
|
|
58
59
|
"test/fixtures/non_twitter_response.yaml",
|
59
60
|
"test/fixtures/twitter_response.yaml",
|
60
61
|
"test/fixtures/twitter_response_bad_status.yaml",
|
62
|
+
"test/polling_search_test.rb",
|
61
63
|
"test/reqex_parser_test.rb",
|
62
64
|
"test/routes_test.rb",
|
63
65
|
"test/tags_parser_test.rb",
|
@@ -80,6 +82,7 @@ Gem::Specification.new do |s|
|
|
80
82
|
"test/config_test.rb",
|
81
83
|
"test/delayed_request_test.rb",
|
82
84
|
"test/dispatcher_test.rb",
|
85
|
+
"test/polling_search_test.rb",
|
83
86
|
"test/reqex_parser_test.rb",
|
84
87
|
"test/routes_test.rb",
|
85
88
|
"test/tags_parser_test.rb",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bhauman-twroute
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bhauman
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-09-11 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -141,6 +141,7 @@ files:
|
|
141
141
|
- lib/twroute/parser/regex.rb
|
142
142
|
- lib/twroute/parser/tags.rb
|
143
143
|
- lib/twroute/parser/users.rb
|
144
|
+
- lib/twroute/polling_search.rb
|
144
145
|
- lib/twroute/requester/basic.rb
|
145
146
|
- lib/twroute/requester/delayed.rb
|
146
147
|
- lib/twroute/requester/delayed/create_delayed_jobs.rb
|
@@ -157,6 +158,7 @@ files:
|
|
157
158
|
- test/fixtures/non_twitter_response.yaml
|
158
159
|
- test/fixtures/twitter_response.yaml
|
159
160
|
- test/fixtures/twitter_response_bad_status.yaml
|
161
|
+
- test/polling_search_test.rb
|
160
162
|
- test/reqex_parser_test.rb
|
161
163
|
- test/routes_test.rb
|
162
164
|
- test/tags_parser_test.rb
|
@@ -199,6 +201,7 @@ test_files:
|
|
199
201
|
- test/config_test.rb
|
200
202
|
- test/delayed_request_test.rb
|
201
203
|
- test/dispatcher_test.rb
|
204
|
+
- test/polling_search_test.rb
|
202
205
|
- test/reqex_parser_test.rb
|
203
206
|
- test/routes_test.rb
|
204
207
|
- test/tags_parser_test.rb
|