chirpstream 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/Gemfile +2 -1
  2. data/Rakefile +2 -1
  3. data/Readme.rdoc +14 -0
  4. data/VERSION +1 -1
  5. data/lib/chirpstream.rb +56 -15
  6. metadata +18 -3
data/Gemfile CHANGED
@@ -2,5 +2,6 @@
2
2
  source :gemcutter
3
3
  gem "eventmachine", ">= 0.12.10"
4
4
  gem "em-http-request", ">= 0.2.7"
5
- gem "json", ">= 1.2.4"
5
+ gem "yajl-ruby", ">= 0.7.5"
6
6
  gem "load_path_find", ">= 0.0.5"
7
+ gem "oauth", ">= 0.4.0"
data/Rakefile CHANGED
@@ -5,12 +5,13 @@ begin
5
5
  s.description = s.summary = "Eventmachine-based Chirpstream client"
6
6
  s.email = "joshbuddy@gmail.com"
7
7
  s.homepage = "http://github.com/joshbuddy/chirpstream"
8
- s.authors = ["Joshua Hull"]
8
+ s.authors = ["Joshua Hull", "Fabien Penso"]
9
9
  s.files = FileList["[A-Z]*", "{lib}/**/*", "{bin}/**/*", "{image}/**/*"]
10
10
  s.add_dependency 'eventmachine', ">= 0.12.10"
11
11
  s.add_dependency 'em-http-request', ">= 0.2.7"
12
12
  s.add_dependency 'yajl-ruby', ">= 0.7.5"
13
13
  s.add_dependency 'load_path_find', ">= 0.0.5"
14
+ s.add_dependency 'oauth', ">= 0.4.0"
14
15
  s.executables = ['chirp_growl']
15
16
  end
16
17
  Jeweler::GemcutterTasks.new
data/Readme.rdoc CHANGED
@@ -28,3 +28,17 @@ Wow! It's growling my tweets! How meta.
28
28
  chirp.direct_message {|t| puts "DM : #{t.text} (from #{t.sender.name.foreground(:red)} (#{('@' + t.sender.screen_name).foreground(:green)}))" }
29
29
  chirp.connect
30
30
 
31
+ == Oauth Usage
32
+
33
+ chirp = Chirpstream.new
34
+ chirp.consumer_token = "XXX"
35
+ chirp.consumer_secret = "XXX"
36
+ chirp.access_token = "XXX"
37
+ chirp.access_secret = "XXX"
38
+ chirp.reconnect{ puts "reconnecting..." }
39
+ chirp.tweet {|t| puts "#{t.text} (from #{t.user.name.foreground(:red)} (#{('@' + t.user.screen_name).foreground(:green)}))" }
40
+ chirp.follow {|t| puts "#{t.source.screen_name.foreground(:green)} following #{t.target.screen_name.foreground(:green)}" }
41
+ chirp.favorite {|t| puts "#{t.source.screen_name.foreground(:green)} <3 -> #{t.target_object.text}" }
42
+ chirp.retweet {|t| puts "#{t.source.screen_name.foreground(:green)} RT -> #{t.target_object.text}" }
43
+ chirp.direct_message {|t| puts "DM : #{t.text} (from #{t.sender.name.foreground(:red)} (#{('@' + t.sender.screen_name).foreground(:green)}))" }
44
+ chirp.connect_oauth
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.6
1
+ 0.0.7
data/lib/chirpstream.rb CHANGED
@@ -4,6 +4,9 @@ require 'yajl'
4
4
  require 'pp'
5
5
  require 'load_path_find'
6
6
 
7
+ require 'oauth'
8
+ require 'oauth/client/em_http'
9
+
7
10
  $LOAD_PATH.add_current
8
11
 
9
12
  require 'chirpstream/twitter_object'
@@ -23,8 +26,10 @@ class Chirpstream
23
26
  Handlers = Struct.new(:friend, :tweet, :follow, :favorite, :retweet, :delete, :reconnect, :direct_message)
24
27
 
25
28
  attr_reader :username, :password
29
+ attr_accessor :consumer_token, :consumer_secret, :access_token, :access_secret
26
30
 
27
- def initialize(username, password)
31
+ def initialize(username=nil, password=nil, fill_in = true)
32
+ @fill_in = fill_in
28
33
  @username = username
29
34
  @password = password
30
35
  @connect_url = "http://chirpstream.twitter.com/2b/user.json"
@@ -73,7 +78,7 @@ class Chirpstream
73
78
  @handlers.friend.each{|h| h.call(friend)}
74
79
  end
75
80
  }
76
- friend_http = EM::HttpRequest.new("http://api.twitter.com/1/users/lookup.json").post(:body => {'user_id' => friend_ids.join(',')}, :head => {'authorization' => [@username, @password]}, :timeout => 0)
81
+ friend_http = EM::HttpRequest.new("http://api.twitter.com/1/users/lookup.json").post(:body => {'user_id' => friend_ids.join(',')}, :head => {'authorization' => [@username, @password]})
77
82
  http.stream { |chunk|
78
83
  parser << chunk
79
84
  }
@@ -84,54 +89,54 @@ class Chirpstream
84
89
  def dispatch_tweet(data)
85
90
  unless @handlers.tweet.empty?
86
91
  tweet = Tweet.new(self, data)
87
- tweet.load_all { |t|
92
+ @fill_in ? tweet.load_all { |t|
88
93
  @handlers.tweet.each{|h| h.call(tweet)}
89
- }
94
+ } : @handlers.tweet.each{|h| h.call(tweet)}
90
95
  end
91
96
  end
92
97
 
93
98
  def dispatch_follow(data)
94
99
  unless @handlers.follow.empty?
95
100
  follow = Follow.new(self, data)
96
- follow.load_all { |f|
101
+ @fill_in ? follow.load_all { |f|
97
102
  @handlers.follow.each{|h| h.call(f)}
98
- }
103
+ } : @handlers.follow.each{|h| h.call(follow)}
99
104
  end
100
105
  end
101
106
 
102
107
  def dispatch_direct_message(data)
103
108
  unless @handlers.direct_message.empty?
104
109
  dm = DirectMessage.new(self, data)
105
- dm.load_all { |f|
110
+ @fill_in ? dm.load_all { |f|
106
111
  @handlers.direct_message.each{|h| h.call(f)}
107
- }
112
+ } : @handlers.direct_message.each{|h| h.call(dm)}
108
113
  end
109
114
  end
110
115
 
111
116
  def dispatch_favorite(data)
112
117
  unless @handlers.favorite.empty?
113
118
  favorite = Favorite.new(self, data)
114
- favorite.load_all { |f|
119
+ @fill_in ? favorite.load_all { |f|
115
120
  @handlers.favorite.each{|h| h.call(f)}
116
- }
121
+ } : @handlers.favorite.each{|h| h.call(favorite)}
117
122
  end
118
123
  end
119
124
 
120
125
  def dispatch_retweet(data)
121
126
  unless @handlers.retweet.empty?
122
127
  retweet = Retweet.new(self, data)
123
- retweet.load_all { |f|
128
+ @fill_in ? retweet.load_all { |f|
124
129
  @handlers.retweet.each{|h| h.call(f)}
125
- }
130
+ } : @handlers.retweet.each{|h| h.call(retweet)}
126
131
  end
127
132
  end
128
133
 
129
134
  def dispatch_delete(data)
130
135
  unless @handlers.delete.empty?
131
136
  delete = Delete.new(self, data)
132
- delete.load_all { |f|
137
+ @fill_in ? delete.load_all { |f|
133
138
  @handlers.delete.each{|h| h.call(f)}
134
- }
139
+ } : @handlers.delete.each{|h| h.call(delete)}
135
140
  end
136
141
  end
137
142
 
@@ -173,7 +178,7 @@ class Chirpstream
173
178
  else
174
179
  parser = Yajl::Parser.new
175
180
  parser.on_parse_complete = method(:handle_tweet)
176
- http = EM::HttpRequest.new(@connect_url).get :head => {'authorization' => [@username, @password]}
181
+ http = EM::HttpRequest.new(@connect_url).get :head => {'authorization' => [@username, @password]}, :timeout => 0
177
182
  http.errback { |e, err|
178
183
  dispatch_reconnect
179
184
  connect
@@ -187,4 +192,40 @@ class Chirpstream
187
192
  }
188
193
  end
189
194
  end
195
+
196
+ #
197
+ # Oauth example
198
+ #
199
+ def twitter_oauth_consumer
200
+ @twitter_oauth_consumer ||= OAuth::Consumer.new(consumer_token, consumer_secret, :site => "http://twitter.com")
201
+ end
202
+
203
+ def twitter_oauth_access_token
204
+ @twitter_oauth_access_token ||= OAuth::AccessToken.new(twitter_oauth_consumer, access_token, access_secret)
205
+ end
206
+
207
+ def connect_oauth
208
+ unless EM.reactor_running?
209
+ EM.run { connect_oauth }
210
+ else
211
+ parser = Yajl::Parser.new
212
+ parser.on_parse_complete = method(:handle_tweet)
213
+
214
+ request = EM::HttpRequest.new(@connect_url)
215
+ http = request.get do |client|
216
+ twitter_oauth_consumer.sign!(client, twitter_oauth_access_token)
217
+ end
218
+ http.errback { |e, err|
219
+ dispatch_reconnect
220
+ connect_oauth
221
+ }
222
+ http.stream { |chunk|
223
+ begin
224
+ parser << chunk
225
+ rescue Yajl::ParseError
226
+ puts "bad chunk: #{chunk.inspect}"
227
+ end
228
+ }
229
+ end
230
+ end
190
231
  end
metadata CHANGED
@@ -5,16 +5,17 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 6
9
- version: 0.0.6
8
+ - 7
9
+ version: 0.0.7
10
10
  platform: ruby
11
11
  authors:
12
12
  - Joshua Hull
13
+ - Fabien Penso
13
14
  autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-05-19 00:00:00 -04:00
18
+ date: 2010-05-20 00:00:00 -04:00
18
19
  default_executable: chirp_growl
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
@@ -73,6 +74,20 @@ dependencies:
73
74
  version: 0.0.5
74
75
  type: :runtime
75
76
  version_requirements: *id004
77
+ - !ruby/object:Gem::Dependency
78
+ name: oauth
79
+ prerelease: false
80
+ requirement: &id005 !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ segments:
85
+ - 0
86
+ - 4
87
+ - 0
88
+ version: 0.4.0
89
+ type: :runtime
90
+ version_requirements: *id005
76
91
  description: Eventmachine-based Chirpstream client
77
92
  email: joshbuddy@gmail.com
78
93
  executables: