chirpstream 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -4,4 +4,5 @@ gem "eventmachine", ">= 0.12.10"
4
4
  gem "em-http-request", ">= 0.2.7"
5
5
  gem "yajl-ruby", ">= 0.7.5"
6
6
  gem "load_path_find", ">= 0.0.5"
7
- gem "oauth", ">= 0.4.0"
7
+ gem "oauth", ">= 0.4.0"
8
+ gem 'rainbow'
@@ -0,0 +1,47 @@
1
+ ---
2
+ dependencies:
3
+ oauth:
4
+ group:
5
+ - :default
6
+ version: ">= 0.4.0"
7
+ rainbow:
8
+ group:
9
+ - :default
10
+ version: ">= 0"
11
+ em-http-request:
12
+ group:
13
+ - :default
14
+ version: ">= 0.2.7"
15
+ eventmachine:
16
+ group:
17
+ - :default
18
+ version: ">= 0.12.10"
19
+ load_path_find:
20
+ group:
21
+ - :default
22
+ version: ">= 0.0.5"
23
+ yajl-ruby:
24
+ group:
25
+ - :default
26
+ version: ">= 0.7.5"
27
+ specs:
28
+ - addressable:
29
+ version: 2.1.2
30
+ - dirge:
31
+ version: 0.0.4
32
+ - eventmachine:
33
+ version: 0.12.10
34
+ - em-http-request:
35
+ version: 0.2.7
36
+ - load_path_find:
37
+ version: 0.0.5
38
+ - oauth:
39
+ version: 0.4.0
40
+ - rainbow:
41
+ version: 1.0.4
42
+ - yajl-ruby:
43
+ version: 0.7.6
44
+ hash: d6cefb455573e16292480b49ad20114ca5876dac
45
+ sources:
46
+ - Rubygems:
47
+ uri: http://gemcutter.org
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.7
1
+ 0.0.8
@@ -26,7 +26,22 @@ class Chirpstream
26
26
  Handlers = Struct.new(:friend, :tweet, :follow, :favorite, :retweet, :delete, :reconnect, :direct_message)
27
27
 
28
28
  attr_reader :username, :password
29
- attr_accessor :consumer_token, :consumer_secret, :access_token, :access_secret
29
+ attr_accessor :consumer_token, :consumer_secret, :access_token, :access_secret, :fill_in
30
+
31
+ def self.basic(username, password, options = nil)
32
+ chirpstream = new(username, password)
33
+ chirpstream.fill_in = options[:fill_in] if options && options.key?(:fill_in)
34
+ end
35
+
36
+ def self.oauth(consumer_token, consumer_secret, access_token, access_secret, options = nil)
37
+ chirpstream = new
38
+ chirpstream.consumer_token = consumer_token
39
+ chirpstream.consumer_secret = consumer_secret
40
+ chirpstream.access_token = access_token
41
+ chirpstream.access_secret = access_secret
42
+ chirpstream.fill_in = options[:fill_in] if options && options.key?(:fill_in)
43
+ chirpstream
44
+ end
30
45
 
31
46
  def initialize(username=nil, password=nil, fill_in = true)
32
47
  @fill_in = fill_in
@@ -178,7 +193,7 @@ class Chirpstream
178
193
  else
179
194
  parser = Yajl::Parser.new
180
195
  parser.on_parse_complete = method(:handle_tweet)
181
- http = EM::HttpRequest.new(@connect_url).get :head => {'authorization' => [@username, @password]}, :timeout => 0
196
+ http = new_client(@connect_url, :get)
182
197
  http.errback { |e, err|
183
198
  dispatch_reconnect
184
199
  connect
@@ -204,28 +219,15 @@ class Chirpstream
204
219
  @twitter_oauth_access_token ||= OAuth::AccessToken.new(twitter_oauth_consumer, access_token, access_secret)
205
220
  end
206
221
 
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|
222
+ def new_client(url, method, extras = nil)
223
+ options = extras ? extras.merge(:timeout => 0) : {:timeout => 0}
224
+ if consumer_token
225
+ request = EM::HttpRequest.new(url)
226
+ request.send(method, options) do |client|
216
227
  twitter_oauth_consumer.sign!(client, twitter_oauth_access_token)
217
228
  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
+ else
230
+ http = EM::HttpRequest.new(url).send(method, options.merge(:head => {'authorization' => [@username, @password]}))
229
231
  end
230
232
  end
231
233
  end
@@ -99,7 +99,7 @@ class TwitterObject
99
99
  data[id] = parsed
100
100
  load_tweet_data(ids, data, &block)
101
101
  }
102
- http = EM::HttpRequest.new("http://api.twitter.com/1/statuses/show/%s.json" % id).get :head => {'authorization' => [base.username, base.password]}
102
+ http = base.new_client("http://api.twitter.com/1/statuses/show/%s.json" % id, :get)
103
103
  http.stream { |chunk|
104
104
  parser << chunk
105
105
  }
@@ -126,7 +126,7 @@ class TwitterObject
126
126
  end
127
127
  yield
128
128
  }
129
- http = EM::HttpRequest.new("http://api.twitter.com/1/users/lookup.json").post :head => {'authorization' => [base.username, base.password]}, :body => {'user_id' => ids.join(',')}
129
+ http = base.new_client("http://api.twitter.com/1/users/lookup.json", :post, :body => {'user_id' => ids.join(',')})
130
130
  http.stream { |chunk|
131
131
  parser << chunk
132
132
  }
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 7
9
- version: 0.0.7
8
+ - 8
9
+ version: 0.0.8
10
10
  platform: ruby
11
11
  authors:
12
12
  - Joshua Hull
@@ -98,6 +98,7 @@ extra_rdoc_files: []
98
98
 
99
99
  files:
100
100
  - Gemfile
101
+ - Gemfile.lock
101
102
  - Rakefile
102
103
  - Readme.rdoc
103
104
  - VERSION