bhauman-twroute 0.1.10 → 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,7 @@
1
1
  = Twroute - Route Twitter status updates over http to your web app
2
2
 
3
3
  Twroute uses the {Twitter Stream API}[http://apiwiki.twitter.com/Streaming-API-Documentation]
4
+ or the more stable {Twitter Search API}[http://apiwiki.twitter.com/Twitter-Search-API-Method%3A-search]
4
5
  to watch status updates and convert them to HTTP post requests.
5
6
 
6
7
  Twoute uses {Delayed Job}[http://github.com/tobi/delayed_job/tree/master]
@@ -65,8 +66,10 @@ at +tweetrecorder+.+com+, the config would look like:
65
66
  ==== Twitter section
66
67
 
67
68
  This is where you specify the username and password for the twitter
68
- account that is requesting the Twitter Stream and making the replies
69
- to the senders.
69
+ account that is making the requests to the Twitter Stream or Rest Search
70
+ API and also authoring the replies to the senders.
71
+
72
+ ===== Twitter Stream Api Configuration
70
73
 
71
74
  This section also specifies which Twitter stream api to use. Most
72
75
  likely +spritzer+, +follow+ or +track+ unless you are privileged.
@@ -86,6 +89,25 @@ tweets that have the word +shoot+ in them.
86
89
  stream_api_args:
87
90
  track: shoot
88
91
 
92
+ ===== Twitter Search API Configuration
93
+
94
+ See the {Twitter Search API}[http://apiwiki.twitter.com/Twitter-Search-API-Method%3A-search]
95
+ for more information.
96
+
97
+ This section the post query parameters that you want to
98
+ send to the Twitter +search+ api call.
99
+
100
+ The following is an example configuration if you want to see all the
101
+ tweets that have the word +shoot+ in them.
102
+
103
+ twitter:
104
+ user: example_account_name
105
+ password: example_password
106
+ search_params:
107
+ q: 'shoot' # search for updates with the text 'shoot'
108
+ rpp: '99' # return 99 results on one page : limit is 100
109
+
110
+
89
111
  ==== Database section
90
112
 
91
113
  This section should be ready to go as is. If you want to use MySQL
@@ -264,6 +286,7 @@ the routes are ignored.
264
286
  When a route is finally selected and a path is chosen three hashes get
265
287
  posted to the selected url:
266
288
 
289
+
267
290
  ==== The Parsed Hash
268
291
 
269
292
  In our example this will be:
@@ -272,7 +295,19 @@ In our example this will be:
272
295
  parsed[who_got_shot]: johnny
273
296
  parsed[shot_where]: wild
274
297
 
275
- ==== The Twitter Tweet Hash
298
+ ==== The Twitter Tweet Hash - for Search API
299
+
300
+ tweet[id]: 3317086732
301
+ tweet[source]: web
302
+ tweet[profile_image_url]: http://s.twimg.com/a/1252620925/images/default_profile_normal.png
303
+ tweet[to_user_id]:
304
+ tweet[from_user]: dailydid_dev
305
+ tweet[iso_language_code]: en
306
+ tweet[text]: #test 123 #dailydid
307
+ tweet[from_user_id]: 50354397
308
+ tweet[created_at]: Fri, 04 Sep 2009 17:03:56 +0000
309
+
310
+ ==== The Twitter Tweet Hash - for Stream API
276
311
 
277
312
  For example:
278
313
 
@@ -286,7 +321,7 @@ For example:
286
321
  tweet[in_reply_to_status_id]:
287
322
  tweet[text]: shoot @johnny in the wild
288
323
 
289
- ==== The Twitter User Hash
324
+ ==== The Twitter User Hash - for Stream API only
290
325
 
291
326
  We pull this out of the tweet[:user] and post it as the sender[] hash:
292
327
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.10
1
+ 0.1.13
@@ -8,7 +8,14 @@ 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.logger = Logger.new(File.open(File.join(::Twroute::Application.root_dir, 'log/twroute.log'), 'a'))
10
10
  loop do
11
- Twroute::Application.run
11
+ begin
12
+ Twroute::Application.run
13
+ rescue => e
14
+ puts e.to_s
15
+ Twroute::Application.logger.info e.to_s
16
+ Twroute::Application.logger.info "Application Error sleeping 30 seconds before restart"
17
+ sleep 30
18
+ end
12
19
  end
13
20
  end
14
21
 
@@ -1,7 +1,6 @@
1
- require 'yajl'
2
- require 'yajl/http_stream'
3
1
  require 'observer'
4
2
  require 'uri'
3
+ require 'grackle'
5
4
 
6
5
  module Twroute
7
6
  class PollingSearch
@@ -12,21 +11,21 @@ module Twroute
12
11
  @user = user
13
12
  @password = password
14
13
  @post_arg_hash = post_arg_hash
14
+ @grackle_client = Grackle::Client.new(:auth=>{:type=>:basic,:username=>@user,:password=>@password})
15
15
  end
16
16
 
17
- def twitter_search_uri
18
- URI.parse("http://#{@user}:#{@password}@search.twitter.com/search.json?#{self.query_string}")
17
+ def query_hash
18
+ @post_arg_hash['since_id'] = @since_id if @since_id
19
+ @post_arg_hash
19
20
  end
20
21
 
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('&')
22
+ def grack_to_hash(grack)
23
+ res = grack.marshal_dump
24
+ res[:id] = grack.id
25
+ res
26
26
  end
27
27
 
28
28
  def start
29
- puts twitter_search_uri.to_s
30
29
  loop do
31
30
  send_query
32
31
  sleep 30
@@ -34,15 +33,14 @@ module Twroute
34
33
  end
35
34
 
36
35
  def send_query
37
- results = Yajl::HttpStream.get( twitter_search_uri,
38
- :symbolize_keys => true)
39
- results = results[:results] || []
36
+ results = @grackle_client[:search].search? query_hash
37
+ results = results.results || []
40
38
  results.reverse!
41
39
  return if results.empty?
42
- @since_id = results.last[:id]
40
+ @since_id = results.last.id
43
41
  results.each do |tweet|
44
42
  changed
45
- notify_observers( tweet )
43
+ notify_observers( grack_to_hash tweet )
46
44
  end
47
45
  end
48
46
 
@@ -29,13 +29,6 @@ class PollingSearchTest < Test::Unit::TestCase
29
29
  { :q => 'twitter', :rpp => 20 })
30
30
  end
31
31
 
32
- should "be able to create query string" do
33
- @tweeter.query_string.should == 'q=twitter&rpp=20'
34
- end
35
-
36
- should "be able to create a twitter search url" do
37
- @tweeter.twitter_search_uri.to_s.should == 'http://bhauman:watertank@search.twitter.com/search.json?q=twitter&rpp=20'
38
- end
39
32
 
40
33
  should "be able to send query and get results" do
41
34
  @listen = TestObserver.new
@@ -46,7 +39,7 @@ class PollingSearchTest < Test::Unit::TestCase
46
39
 
47
40
  @tweeter.since_id.should_not be_nil
48
41
  @tweeter.since_id.should == @listen.results.last[:id]
49
- @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]}"
42
+ @listen.results.first[:id].should_not be_nil
50
43
 
51
44
  @listen.results.first[:id].should <= @listen.results.last[:id]
52
45
 
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{twroute}
5
- s.version = "0.1.10"
5
+ s.version = "0.1.13"
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-09-11}
9
+ s.date = %q{2009-09-16}
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"]
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.10
4
+ version: 0.1.13
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-09-11 00:00:00 -07:00
12
+ date: 2009-09-16 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency