bhauman-twroute 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -33
- data/VERSION +1 -1
- data/app_generators/twroute/templates/Rakefile +30 -0
- data/app_generators/twroute/templates/config.yml +16 -0
- data/app_generators/twroute/templates/test_helper.rb +21 -0
- data/app_generators/twroute/templates/twroutes.rb +22 -0
- data/app_generators/twroute/templates/twroutes_test.rb +10 -0
- data/app_generators/twroute/twroute_generator.rb +31 -0
- data/bin/twroute +7 -0
- data/bin/twroute_gen +6 -0
- data/{example_app/scripts/twrouter.rb → bin/twroute_runner} +2 -1
- data/bin/twroute_worker +12 -0
- data/example_app/Rakefile +25 -0
- data/example_app/config/twroutes.rb +17 -1
- data/example_app/test/test_helper.rb +21 -0
- data/example_app/test/troutes_test.rb +10 -0
- data/lib/twroute/application/generator.rb +16 -0
- data/lib/twroute/dispatcher.rb +1 -0
- data/lib/twroute/parser/regex.rb +12 -3
- data/lib/twroute/routes.rb +3 -0
- data/lib/twroute/tweet_route.rb +5 -5
- data/test/dispatcher_test.rb +46 -7
- data/test/reqex_parser_test.rb +9 -3
- data/test/tweet_route_test.rb +4 -2
- data/twroute.gemspec +19 -3
- metadata +30 -5
data/Rakefile
CHANGED
@@ -3,38 +3,6 @@ require 'rake'
|
|
3
3
|
|
4
4
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
|
5
5
|
|
6
|
-
|
7
|
-
namespace :jobs do
|
8
|
-
desc "Clear the delayed_job queue."
|
9
|
-
task :clear do
|
10
|
-
|
11
|
-
Delayed::Job.delete_all
|
12
|
-
end
|
13
|
-
|
14
|
-
desc "Start a delayed_job worker."
|
15
|
-
task :work do
|
16
|
-
#require 'twroute'
|
17
|
-
#require 'twroute/requester/delayed'
|
18
|
-
#require 'twroute/requester/delayed/create_delayed_jobs'
|
19
|
-
Delayed::Worker.new(:min_priority => ENV['MIN_PRIORITY'], :max_priority => ENV['MAX_PRIORITY']).start
|
20
|
-
end
|
21
|
-
|
22
|
-
desc 'creates delayed job database: not implemented'
|
23
|
-
desc :create_database do
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
desc "Create delayed_job table"
|
28
|
-
task :create_table do
|
29
|
-
CreateDelayedJobs.migrate(:up)
|
30
|
-
end
|
31
|
-
|
32
|
-
desc "Create delayed_job table"
|
33
|
-
task :drop_table do
|
34
|
-
CreateDelayedJobs.migrate(:down)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
6
|
begin
|
39
7
|
require 'jeweler'
|
40
8
|
Jeweler::Tasks.new do |gem|
|
@@ -47,7 +15,7 @@ begin
|
|
47
15
|
gem.add_dependency('activerecord', '>= 2.1.0')
|
48
16
|
gem.add_dependency('tobi-delayed_job', '>= 1.7.0')
|
49
17
|
gem.add_dependency('brianmario-yajl-ruby', '>= 0.5.12')
|
50
|
-
gem.add_dependency('
|
18
|
+
gem.add_dependency('daemons', '>= 1.0.10')
|
51
19
|
end
|
52
20
|
|
53
21
|
rescue LoadError
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'twroute'
|
2
|
+
require 'twroute/tasks'
|
3
|
+
|
4
|
+
Twroute::Tasks.new
|
5
|
+
|
6
|
+
namespace :twroute do
|
7
|
+
task :cd_app_root do
|
8
|
+
Dir.chdir(File.dirname(__FILE__))
|
9
|
+
end
|
10
|
+
desc "Start twroute up"
|
11
|
+
task :start => :cd_app_root do
|
12
|
+
`twroute_runner start`
|
13
|
+
`twroute_worker start`
|
14
|
+
end
|
15
|
+
|
16
|
+
desc "Stop twroute"
|
17
|
+
task :stop => :cd_app_root do
|
18
|
+
`twroute_runner stop`
|
19
|
+
`twroute_worker stop`
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'rake/testtask'
|
24
|
+
Rake::TestTask.new(:test) do |test|
|
25
|
+
test.libs << 'lib' << 'test'
|
26
|
+
test.pattern = 'test/**/*_test.rb'
|
27
|
+
test.verbose = true
|
28
|
+
end
|
29
|
+
|
30
|
+
task :default => :test
|
@@ -0,0 +1,16 @@
|
|
1
|
+
submit_to:
|
2
|
+
host: 'localhost'
|
3
|
+
port: 3000
|
4
|
+
# http_auth_user: ''
|
5
|
+
# http_auth_password: ''
|
6
|
+
twitter:
|
7
|
+
user: ''
|
8
|
+
password: ''
|
9
|
+
stream_api: 'track'
|
10
|
+
stream_api_args:
|
11
|
+
track: twitter
|
12
|
+
database:
|
13
|
+
adapter: sqlite3
|
14
|
+
database: db/twroute.sqlite3
|
15
|
+
pool: 5
|
16
|
+
timeout: 5000
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'shoulda'
|
4
|
+
require 'matchy'
|
5
|
+
require 'stump'
|
6
|
+
|
7
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
8
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
9
|
+
|
10
|
+
require 'twroute'
|
11
|
+
|
12
|
+
class Test::Unit::TestCase
|
13
|
+
def self.should_route_to(tweet, path)
|
14
|
+
should "route to #{path}" do
|
15
|
+
dispatcher = ::Twroute::Dispatcher.new({ :host => 'test_host.com'}, *::Twroute::Routes.routes)
|
16
|
+
route = dispatcher.find_route({ :text => tweet})
|
17
|
+
val = route ? route.path : nil
|
18
|
+
val.should == path
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
Twroute::Routes.draw do |map|
|
2
|
+
map.regex( {:tweet_text => /^@tweetmaster\s.*/,
|
3
|
+
:action => /\screate\s+account/},
|
4
|
+
'/accounts/create' )
|
5
|
+
map.regex( {:tweet_text => /^@tweetmaster\s.*/,
|
6
|
+
:action => /\sdestroy\s+account/},
|
7
|
+
'/accounts/destroy' )
|
8
|
+
map.regex( {:tweet_text => /^@tweetmaster\s.*/,
|
9
|
+
:action => /\spost\s+create/},
|
10
|
+
'/posts/create' )
|
11
|
+
map.regex( {:tweet_text => /^@tweetmaster\s.*/,
|
12
|
+
:action => /\spost\s+destroy/,
|
13
|
+
:post_id => [ /\sid\:(\d+)/, 1]},
|
14
|
+
'/post/:post_id/destroy' )
|
15
|
+
map.regex( {:tweet_text => /^@tweetmaster\s.*/,
|
16
|
+
:action => /\spost\s+update/,
|
17
|
+
:post_id => [ /\sid\:(\d+)/ , 1 ]},
|
18
|
+
'/post/:post_id/update' )
|
19
|
+
# this will catch all the tweets
|
20
|
+
map.regex( {:tweet_text => /.*/ },
|
21
|
+
'/tweets/create')
|
22
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require File.join(File.dirname(__FILE__), '..', 'config', 'twroutes.rb')
|
3
|
+
|
4
|
+
class TwroutesTest < Test::Unit::TestCase
|
5
|
+
should_route_to "@tweetmaster create account", '/accounts/create'
|
6
|
+
should_route_to "@tweetmaster destroy account", '/accounts/destroy'
|
7
|
+
should_route_to "@tweetmaster post create this is a post that says little", '/posts/create'
|
8
|
+
should_route_to "@tweetmaster post destroy id:34", '/post/34/destroy'
|
9
|
+
should_route_to "@tweetmaster post update id:34 now the post says this", '/post/34/update'
|
10
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class TwrouteGenerator < RubiGen::Base
|
2
|
+
attr_reader :app_name, :module_name
|
3
|
+
|
4
|
+
def initialize(runtime_args, runtime_options = {})
|
5
|
+
super
|
6
|
+
usage if args.empty?
|
7
|
+
@destination_root = args.shift
|
8
|
+
@app_name = File.basename(File.expand_path(@destination_root))
|
9
|
+
@module_name = app_name.camelize
|
10
|
+
end
|
11
|
+
|
12
|
+
def manifest
|
13
|
+
record do |m|
|
14
|
+
m.directory 'config'
|
15
|
+
m.directory 'test'
|
16
|
+
m.directory 'log'
|
17
|
+
m.directory 'db'
|
18
|
+
m.file 'Rakefile', 'Rakefile'
|
19
|
+
m.file 'config.yml', 'config/config.yml'
|
20
|
+
m.file 'twroutes.rb', 'config/twroutes.rb'
|
21
|
+
m.file 'twroutes_test.rb', 'test/twroutes_test.rb'
|
22
|
+
m.file 'test_helper.rb', 'test/test_helper.rb'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
protected
|
27
|
+
def banner
|
28
|
+
"Create a stub for \#{File.basename $0} to get started.\n\nUsage: \#{File.basename $0} /path/to/your/app [options]\"\n"
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
data/bin/twroute
ADDED
data/bin/twroute_gen
ADDED
@@ -4,7 +4,8 @@ require 'daemons'
|
|
4
4
|
require 'twroute'
|
5
5
|
require 'twroute/application'
|
6
6
|
|
7
|
-
Daemons.run_proc('
|
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
9
|
Twroute::Application.run
|
10
10
|
end
|
11
|
+
|
data/bin/twroute_worker
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'daemons'
|
4
|
+
require 'twroute'
|
5
|
+
require 'twroute/application'
|
6
|
+
|
7
|
+
Daemons.run_proc('twroute_worker.rb', :dir_mode => :normal, :dir => 'log') do
|
8
|
+
ActiveRecord::Base.logger = Logger.new(File.open(File.join(::Twroute::Application.root_dir, 'log/delayed.log'), 'a'))
|
9
|
+
::Delayed::Worker.new(:min_priority => ENV['MIN_PRIORITY'],
|
10
|
+
:max_priority => ENV['MAX_PRIORITY']).start
|
11
|
+
end
|
12
|
+
|
data/example_app/Rakefile
CHANGED
@@ -3,3 +3,28 @@ require 'twroute/tasks'
|
|
3
3
|
|
4
4
|
Twroute::Tasks.new
|
5
5
|
|
6
|
+
namespace :twroute do
|
7
|
+
task :cd_app_root do
|
8
|
+
Dir.chdir(File.dirname(__FILE__))
|
9
|
+
end
|
10
|
+
desc "Start twroute up"
|
11
|
+
task :start => :cd_app_root do
|
12
|
+
`twroute_runner start`
|
13
|
+
`twroute_worker start`
|
14
|
+
end
|
15
|
+
|
16
|
+
desc "Stop twroute"
|
17
|
+
task :stop => :cd_app_root do
|
18
|
+
`twroute_runner stop`
|
19
|
+
`twroute_worker stop`
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'rake/testtask'
|
24
|
+
Rake::TestTask.new(:test) do |test|
|
25
|
+
test.libs << 'lib' << 'test'
|
26
|
+
test.pattern = 'test/**/*_test.rb'
|
27
|
+
test.verbose = true
|
28
|
+
end
|
29
|
+
|
30
|
+
task :default => :test
|
@@ -1,3 +1,19 @@
|
|
1
1
|
Twroute::Routes.draw do |map|
|
2
|
-
map.regex( {:tweet_text =>
|
2
|
+
map.regex( {:tweet_text => /^@tweetmaster\s.*/,
|
3
|
+
:action => /\screate\s+account/},
|
4
|
+
'/accounts/create' )
|
5
|
+
map.regex( {:tweet_text => /^@tweetmaster\s.*/,
|
6
|
+
:action => /\sdestroy\s+account/},
|
7
|
+
'/accounts/destroy' )
|
8
|
+
map.regex( {:tweet_text => /^@tweetmaster\s.*/,
|
9
|
+
:action => /\spost\s+create/},
|
10
|
+
'/posts/create' )
|
11
|
+
map.regex( {:tweet_text => /^@tweetmaster\s.*/,
|
12
|
+
:action => /\spost\s+destroy/,
|
13
|
+
:post_id => [ /\sid\:(\d+)/, 1]},
|
14
|
+
'/post/:post_id/destroy' )
|
15
|
+
map.regex( {:tweet_text => /^@tweetmaster\s.*/,
|
16
|
+
:action => /\spost\s+update/,
|
17
|
+
:post_id => [ /\sid\:(\d+)/ , 1 ]},
|
18
|
+
'/post/:post_id/update' )
|
3
19
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'shoulda'
|
4
|
+
require 'matchy'
|
5
|
+
require 'stump'
|
6
|
+
|
7
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
8
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
9
|
+
|
10
|
+
require 'twroute'
|
11
|
+
|
12
|
+
class Test::Unit::TestCase
|
13
|
+
def self.should_route_to(tweet, path)
|
14
|
+
should "route to #{path}" do
|
15
|
+
dispatcher = ::Twroute::Dispatcher.new({ :host => 'test_host.com'}, *::Twroute::Routes.routes)
|
16
|
+
route = dispatcher.find_route({ :text => tweet})
|
17
|
+
val = route ? route.path : nil
|
18
|
+
val.should == path
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require File.join(File.dirname(__FILE__), '..', 'config', 'twroutes.rb')
|
3
|
+
|
4
|
+
class TwroutesTest < Test::Unit::TestCase
|
5
|
+
should_route_to "@tweetmaster create account", '/accounts/create'
|
6
|
+
should_route_to "@tweetmaster destroy account", '/accounts/destroy'
|
7
|
+
should_route_to "@tweetmaster post create this is a post that says little", '/posts/create'
|
8
|
+
should_route_to "@tweetmaster post destroy id:34", '/post/34/destroy'
|
9
|
+
should_route_to "@tweetmaster post update id:34 now the post says this", '/post/34/update'
|
10
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rails_generator'
|
2
|
+
|
3
|
+
module Twroute
|
4
|
+
module Application
|
5
|
+
class Generator < ::Rails::Generator::Base
|
6
|
+
def manifest
|
7
|
+
record do |m|
|
8
|
+
m.directory 'twroute_app'
|
9
|
+
m.directory 'twroute_app/config'
|
10
|
+
m.directory 'twroute_app/test'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
data/lib/twroute/dispatcher.rb
CHANGED
data/lib/twroute/parser/regex.rb
CHANGED
@@ -20,8 +20,17 @@ module Twroute
|
|
20
20
|
|
21
21
|
def parse_to_hash(tweet_text)
|
22
22
|
regex_hash.inject({ }) do |accum, key_val|
|
23
|
-
|
24
|
-
|
23
|
+
val = key_val.last
|
24
|
+
case val
|
25
|
+
when Regexp
|
26
|
+
match_data = tweet_text.match(key_val.last)
|
27
|
+
when Proc
|
28
|
+
match_data = val.call(tweet_text)
|
29
|
+
when Array
|
30
|
+
res = tweet_text.match(val.first)
|
31
|
+
match_data = res ? res[val.last] : res
|
32
|
+
end
|
33
|
+
accum[key_val.first] = (match_data ? process_data(match_data.to_s) : nil)
|
25
34
|
accum
|
26
35
|
end
|
27
36
|
end
|
@@ -29,7 +38,7 @@ module Twroute
|
|
29
38
|
# delayed job can't unmarshal things that have lines that end in :
|
30
39
|
def process_data(data)
|
31
40
|
if(data && data.is_a?(String))
|
32
|
-
data.gsub(
|
41
|
+
data.gsub(/:+$/m, '')
|
33
42
|
else
|
34
43
|
data
|
35
44
|
end
|
data/lib/twroute/routes.rb
CHANGED
data/lib/twroute/tweet_route.rb
CHANGED
@@ -9,7 +9,7 @@ module Twroute
|
|
9
9
|
def tweet(tweet_hash)
|
10
10
|
reset
|
11
11
|
@tweet_hash = tweet_hash
|
12
|
-
@sender_hash = tweet_hash
|
12
|
+
@sender_hash = tweet_hash[:user]
|
13
13
|
parse_tweet(tweet_hash[:text])
|
14
14
|
end
|
15
15
|
|
@@ -38,9 +38,9 @@ module Twroute
|
|
38
38
|
end
|
39
39
|
|
40
40
|
tweet_h = @tweet_hash.merge({ })
|
41
|
-
tweet_h.delete(:user)
|
41
|
+
# tweet_h.delete(:user)
|
42
42
|
tweet_h.keys.each do |key|
|
43
|
-
pattern.gsub!(':tweet[' + key.to_s + ']', @tweet_hash[key].to_s)
|
43
|
+
pattern.gsub!(':tweet[' + key.to_s + ']', @tweet_hash[key].to_s) if key != :user
|
44
44
|
end
|
45
45
|
|
46
46
|
pattern
|
@@ -49,13 +49,13 @@ module Twroute
|
|
49
49
|
def get_post_args
|
50
50
|
post_hash = { }
|
51
51
|
@parsed_hash.keys.each do |key|
|
52
|
-
post_hash[key.to_s] = @parsed_hash[key]
|
52
|
+
post_hash["parsed[#{key.to_s}]"] = @parsed_hash[key]
|
53
53
|
end
|
54
54
|
@sender_hash.keys.each do |key|
|
55
55
|
post_hash["sender[#{key.to_s}]"] = @sender_hash[key]
|
56
56
|
end
|
57
57
|
@tweet_hash.keys.each do |key|
|
58
|
-
post_hash["tweet[#{key.to_s}]"] = @tweet_hash[key]
|
58
|
+
post_hash["tweet[#{key.to_s}]"] = @tweet_hash[key] if key != :user
|
59
59
|
end
|
60
60
|
post_hash
|
61
61
|
end
|
data/test/dispatcher_test.rb
CHANGED
@@ -9,8 +9,8 @@ class DispatcherTest < Test::Unit::TestCase
|
|
9
9
|
@tweet_route_user = TweetRoute.new(Parser::Regex.new({:user => /\@\w+/}), '/my_test_path/:user')
|
10
10
|
@tweet_route_tag = TweetRoute.new(Parser::Regex.new({:tag => /\#\w+/}), '/my_test_path/:tag')
|
11
11
|
@tweet_route_user_and_tag = TweetRoute.new(Parser::Regex.new({:tag => /\#\w+/,
|
12
|
-
|
13
|
-
|
12
|
+
:user => /\@\w+/ }),
|
13
|
+
'/my_test_path/:tag/:user')
|
14
14
|
@dispatcher = Dispatcher.new( {:host => 'test-host.com'},
|
15
15
|
@tweet_route_user_and_tag,
|
16
16
|
@tweet_route_user,
|
@@ -20,20 +20,59 @@ class DispatcherTest < Test::Unit::TestCase
|
|
20
20
|
@match_tag_tweet = TweetMaker.make_tweet :text => "#this is cool too here 3about_it"
|
21
21
|
@match_user_and_tag_tweet = TweetMaker.make_tweet :text => "@random #this is cool too here 3about_it"
|
22
22
|
end
|
23
|
+
|
24
|
+
should "be able to detect multiple routes" do
|
25
|
+
Twroute::Routes.draw do |map|
|
26
|
+
map.regex( {:tweet_text => /^@tweetmaster\s.*/,
|
27
|
+
:action => /\screate\s+account/},
|
28
|
+
'/accounts/create' )
|
29
|
+
map.regex( {:tweet_text => /^@tweetmaster\s.*/,
|
30
|
+
:action => /\sdestroy\s+account/},
|
31
|
+
'/accounts/destroy' )
|
32
|
+
map.regex( {:tweet_text => /^@tweetmaster\s.*/,
|
33
|
+
:action => /\spost\s+create/},
|
34
|
+
'/posts/create' )
|
35
|
+
map.regex( {:tweet_text => /^@tweetmaster\s.*/,
|
36
|
+
:action => /\spost\s+destroy/,
|
37
|
+
:post_id => [ /\sid\:(\d+)/, 1]},
|
38
|
+
'/post/:post_id/destroy' )
|
39
|
+
map.regex( {:tweet_text => /^@tweetmaster\s.*/,
|
40
|
+
:action => /\spost\s+update/,
|
41
|
+
:post_id => [ /\sid\:(\d+)/ , 1 ]},
|
42
|
+
'/post/:post_id/update' )
|
43
|
+
map.regex({ :tweet_text => /.*/},
|
44
|
+
'/create/account')
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
dispatcher = Dispatcher.new( {:host => 'test-host.com'},
|
49
|
+
*Twroute::Routes.routes)
|
50
|
+
Twroute::Routes.clear_routes
|
51
|
+
route = dispatcher.find_route(@match_user_and_tag_tweet)
|
52
|
+
|
53
|
+
route.get_post_args
|
54
|
+
route.get_post_args.should_not == nil
|
55
|
+
|
56
|
+
|
57
|
+
end
|
23
58
|
|
24
59
|
should "match be able to get the first matched route" do
|
25
60
|
@dispatcher.tweet_routes.length.should == 3
|
26
61
|
|
27
62
|
@dispatcher.find_route(@match_user_and_tag_tweet).should == @tweet_route_user_and_tag
|
28
63
|
@dispatcher.find_route(@match_user_tweet).should == @tweet_route_user
|
29
|
-
@dispatcher.find_route(@match_tag_tweet).should == @tweet_route_tag
|
30
|
-
|
64
|
+
@dispatcher.find_route(@match_tag_tweet).should == @tweet_route_tag
|
65
|
+
end
|
66
|
+
|
67
|
+
should "match be able to dispatch route" do
|
68
|
+
route = @dispatcher.find_route(@match_user_and_tag_tweet)
|
69
|
+
route.get_post_args.should_not == nil
|
31
70
|
end
|
32
71
|
|
33
72
|
should "be able to handle one route" do
|
34
73
|
disp = Dispatcher.new( {:host => 'test-host.com'},
|
35
74
|
@tweet_route_user
|
36
|
-
|
75
|
+
)
|
37
76
|
disp.find_route(@match_user_tweet).should == @tweet_route_user
|
38
77
|
end
|
39
78
|
|
@@ -43,7 +82,7 @@ class DispatcherTest < Test::Unit::TestCase
|
|
43
82
|
route = stub(:path, :return => '/path')
|
44
83
|
disp.get_uri(route).to_s.should == 'http://test-host.com/path'
|
45
84
|
disp = Dispatcher.new({:host => 'test-host.com',
|
46
|
-
|
85
|
+
:http_auth_user => 'jay'},
|
47
86
|
@tweet_route_user)
|
48
87
|
disp.get_uri(route).to_s.should == 'http://test-host.com/path'
|
49
88
|
disp = Dispatcher.new({:host => 'test-host.com',
|
@@ -52,7 +91,7 @@ class DispatcherTest < Test::Unit::TestCase
|
|
52
91
|
@tweet_route_user)
|
53
92
|
disp.get_uri(route).to_s.should == 'http://jay:man@test-host.com/path'
|
54
93
|
disp = Dispatcher.new({:host => 'test-host.com',
|
55
|
-
|
94
|
+
:port => '3000'},
|
56
95
|
@tweet_route_user)
|
57
96
|
disp.get_uri(route).to_s.should == 'http://test-host.com:3000/path'
|
58
97
|
end
|
data/test/reqex_parser_test.rb
CHANGED
@@ -4,9 +4,12 @@ class RegexParserTest < Test::Unit::TestCase
|
|
4
4
|
context "with regex parser" do
|
5
5
|
setup do
|
6
6
|
@regex_parser = Twroute::Parser::Regex.new(:whole => /\@\w+\s+(\#\w+\s)+for\s+(\d+)\s+(day|week|month|year)s{0,1}\s+.*/,
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
:user => /\@\w+/,
|
8
|
+
:tags => /(\#\w+\s)+/,
|
9
|
+
:time => /for\s+(\d+)\s+(day|week|month|year)s{0,1}/,
|
10
|
+
:time2 => lambda { |tweet| tweet.gsub( /.*for\s+(\d+)\s+(day|week|month|year)s{0,1}.*/, '\1')},
|
11
|
+
:time3 => [ /for\s+(\d+)\s+(day|week|month|year)s{0,1}/, 1 ]
|
12
|
+
)
|
10
13
|
@tweet_str = "@johnny #this #is #cool for 17 days yeah buddy"
|
11
14
|
end
|
12
15
|
|
@@ -17,6 +20,9 @@ class RegexParserTest < Test::Unit::TestCase
|
|
17
20
|
hash[:user].should == '@johnny'
|
18
21
|
hash[:tags].should == '#this #is #cool '
|
19
22
|
hash[:time].should == 'for 17 days'
|
23
|
+
hash[:time2].should == '17'
|
24
|
+
hash[:time3].should == '17'
|
25
|
+
hash[:time3].should_not == '18'
|
20
26
|
end
|
21
27
|
|
22
28
|
should "return false if all regexes don't match" do
|
data/test/tweet_route_test.rb
CHANGED
@@ -13,7 +13,7 @@ class TweetRouteTest < Test::Unit::TestCase
|
|
13
13
|
end
|
14
14
|
|
15
15
|
should "be able to fill in a url_pattern" do
|
16
|
-
@tweet_route.tweet({ :text => @tweet_str, :sender => 'charlie'
|
16
|
+
@tweet_route.tweet(TweetMaker.make_tweet({ :text => @tweet_str, :sender => 'charlie'}))
|
17
17
|
@tweet_route.fill_in_url_pattern.should == '/user/charlie/tags/this-is-too'
|
18
18
|
end
|
19
19
|
|
@@ -22,7 +22,9 @@ class TweetRouteTest < Test::Unit::TestCase
|
|
22
22
|
post_args = @tweet_route.get_post_args
|
23
23
|
post_args['sender[screen_name]'].should == 'RoseD1st'
|
24
24
|
post_args['tweet[text]'].should == 'this is a #test #tweet'
|
25
|
-
post_args['tags'].should == 'test-tweet'
|
25
|
+
post_args['parsed[tags]'].should == 'test-tweet'
|
26
|
+
|
27
|
+
post_args['tweet[user]'].should == nil
|
26
28
|
end
|
27
29
|
|
28
30
|
end
|
data/twroute.gemspec
CHANGED
@@ -2,13 +2,14 @@
|
|
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.1"
|
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-08-
|
9
|
+
s.date = %q{2009-08-14}
|
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
|
+
s.executables = ["twroute", "twroute_gen", "twroute_runner", "twroute_worker"]
|
12
13
|
s.extra_rdoc_files = [
|
13
14
|
"README.rdoc"
|
14
15
|
]
|
@@ -18,13 +19,25 @@ Gem::Specification.new do |s|
|
|
18
19
|
"README.rdoc",
|
19
20
|
"Rakefile",
|
20
21
|
"VERSION",
|
22
|
+
"app_generators/twroute/templates/Rakefile",
|
23
|
+
"app_generators/twroute/templates/config.yml",
|
24
|
+
"app_generators/twroute/templates/test_helper.rb",
|
25
|
+
"app_generators/twroute/templates/twroutes.rb",
|
26
|
+
"app_generators/twroute/templates/twroutes_test.rb",
|
27
|
+
"app_generators/twroute/twroute_generator.rb",
|
28
|
+
"bin/twroute",
|
29
|
+
"bin/twroute_gen",
|
30
|
+
"bin/twroute_runner",
|
31
|
+
"bin/twroute_worker",
|
21
32
|
"example_app/Rakefile",
|
22
33
|
"example_app/config/config.yml.sample",
|
23
34
|
"example_app/config/twroutes.rb",
|
24
|
-
"example_app/
|
35
|
+
"example_app/test/test_helper.rb",
|
36
|
+
"example_app/test/troutes_test.rb",
|
25
37
|
"lib/twroute.rb",
|
26
38
|
"lib/twroute/application.rb",
|
27
39
|
"lib/twroute/application/config.rb",
|
40
|
+
"lib/twroute/application/generator.rb",
|
28
41
|
"lib/twroute/application/twrouter.rb",
|
29
42
|
"lib/twroute/dispatcher.rb",
|
30
43
|
"lib/twroute/parser/regex.rb",
|
@@ -83,14 +96,17 @@ Gem::Specification.new do |s|
|
|
83
96
|
s.add_runtime_dependency(%q<activerecord>, [">= 2.1.0"])
|
84
97
|
s.add_runtime_dependency(%q<tobi-delayed_job>, [">= 1.7.0"])
|
85
98
|
s.add_runtime_dependency(%q<brianmario-yajl-ruby>, [">= 0.5.12"])
|
99
|
+
s.add_runtime_dependency(%q<daemons>, [">= 1.0.10"])
|
86
100
|
else
|
87
101
|
s.add_dependency(%q<activerecord>, [">= 2.1.0"])
|
88
102
|
s.add_dependency(%q<tobi-delayed_job>, [">= 1.7.0"])
|
89
103
|
s.add_dependency(%q<brianmario-yajl-ruby>, [">= 0.5.12"])
|
104
|
+
s.add_dependency(%q<daemons>, [">= 1.0.10"])
|
90
105
|
end
|
91
106
|
else
|
92
107
|
s.add_dependency(%q<activerecord>, [">= 2.1.0"])
|
93
108
|
s.add_dependency(%q<tobi-delayed_job>, [">= 1.7.0"])
|
94
109
|
s.add_dependency(%q<brianmario-yajl-ruby>, [">= 0.5.12"])
|
110
|
+
s.add_dependency(%q<daemons>, [">= 1.0.10"])
|
95
111
|
end
|
96
112
|
end
|
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.1
|
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-08-
|
12
|
+
date: 2009-08-14 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -42,10 +42,23 @@ dependencies:
|
|
42
42
|
- !ruby/object:Gem::Version
|
43
43
|
version: 0.5.12
|
44
44
|
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: daemons
|
47
|
+
type: :runtime
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.0.10
|
54
|
+
version:
|
45
55
|
description: Twroute listens for Twitter updates and redirects them to HTTP post requests
|
46
56
|
email: bhauman@gmail.com
|
47
|
-
executables:
|
48
|
-
|
57
|
+
executables:
|
58
|
+
- twroute
|
59
|
+
- twroute_gen
|
60
|
+
- twroute_runner
|
61
|
+
- twroute_worker
|
49
62
|
extensions: []
|
50
63
|
|
51
64
|
extra_rdoc_files:
|
@@ -56,13 +69,25 @@ files:
|
|
56
69
|
- README.rdoc
|
57
70
|
- Rakefile
|
58
71
|
- VERSION
|
72
|
+
- app_generators/twroute/templates/Rakefile
|
73
|
+
- app_generators/twroute/templates/config.yml
|
74
|
+
- app_generators/twroute/templates/test_helper.rb
|
75
|
+
- app_generators/twroute/templates/twroutes.rb
|
76
|
+
- app_generators/twroute/templates/twroutes_test.rb
|
77
|
+
- app_generators/twroute/twroute_generator.rb
|
78
|
+
- bin/twroute
|
79
|
+
- bin/twroute_gen
|
80
|
+
- bin/twroute_runner
|
81
|
+
- bin/twroute_worker
|
59
82
|
- example_app/Rakefile
|
60
83
|
- example_app/config/config.yml.sample
|
61
84
|
- example_app/config/twroutes.rb
|
62
|
-
- example_app/
|
85
|
+
- example_app/test/test_helper.rb
|
86
|
+
- example_app/test/troutes_test.rb
|
63
87
|
- lib/twroute.rb
|
64
88
|
- lib/twroute/application.rb
|
65
89
|
- lib/twroute/application/config.rb
|
90
|
+
- lib/twroute/application/generator.rb
|
66
91
|
- lib/twroute/application/twrouter.rb
|
67
92
|
- lib/twroute/dispatcher.rb
|
68
93
|
- lib/twroute/parser/regex.rb
|