twitter-stream 0.1.14 → 0.1.15

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of twitter-stream might be problematic. Click here for more details.

data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Vladimir Kolesnikov, twitter-stream
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,7 +1,7 @@
1
1
  # twitter-stream
2
2
 
3
- Simple Ruby client library for [twitter streaming API](http://apiwiki.twitter.com/Streaming-API-Documentation).
4
- Uses [EventMachine](http://rubyeventmachine.com/) for connection handling. Adheres to twitter's [reconnection guidline](http://apiwiki.twitter.com/Streaming-API-Documentation#Connecting).
3
+ Simple Ruby client library for [twitter streaming API](http://apiwiki.twitter.com/Streaming-API-Documentation).
4
+ Uses [EventMachine](http://rubyeventmachine.com/) for connection handling. Adheres to twitter's [reconnection guidline](https://dev.twitter.com/docs/streaming-api/concepts#connecting).
5
5
 
6
6
  JSON format only.
7
7
 
@@ -13,7 +13,7 @@ JSON format only.
13
13
 
14
14
  require 'rubygems'
15
15
  require 'twitter/json_stream'
16
-
16
+
17
17
  EventMachine::run {
18
18
  stream = Twitter::JSONStream.connect(
19
19
  :path => '/1/statuses/filter.json?track=football',
@@ -25,15 +25,15 @@ JSON format only.
25
25
  end
26
26
 
27
27
  stream.on_error do |message|
28
- # No need to worry here. It might be an issue with Twitter.
28
+ # No need to worry here. It might be an issue with Twitter.
29
29
  # Log message for future reference. JSONStream will try to reconnect after a timeout.
30
30
  end
31
-
31
+
32
32
  stream.on_max_reconnects do |timeout, retries|
33
33
  # Something is wrong on your side. Send yourself an email.
34
34
  end
35
35
  }
36
-
36
+
37
37
 
38
38
  ## Examples
39
39
 
@@ -27,8 +27,8 @@ module Twitter
27
27
  :content => '',
28
28
  :path => '/1/statuses/filter.json',
29
29
  :host => 'stream.twitter.com',
30
- :port => 80,
31
- :ssl => false,
30
+ :port => 443,
31
+ :ssl => true,
32
32
  :user_agent => 'TwitterStream',
33
33
  :timeout => 0,
34
34
  :proxy => ENV['HTTP_PROXY'],
@@ -60,7 +60,6 @@ module Twitter
60
60
  end
61
61
 
62
62
  connection = EventMachine.connect host, port, self, options
63
- connection.start_tls if options[:ssl]
64
63
  connection
65
64
  end
66
65
 
@@ -122,6 +121,7 @@ module Twitter
122
121
  end
123
122
 
124
123
  def connection_completed
124
+ start_tls if @options[:ssl]
125
125
  send_request
126
126
  end
127
127
 
@@ -248,7 +248,7 @@ module Twitter
248
248
  if @proxy && @proxy.user
249
249
  data << "Proxy-Authorization: Basic " + ["#{@proxy.user}:#{@proxy.password}"].pack('m').delete("\r\n")
250
250
  end
251
- if @options[:method] == 'POST'
251
+ if ['POST', 'PUT'].include?(@options[:method])
252
252
  data << "Content-type: #{@options[:content_type]}"
253
253
  data << "Content-length: #{content.length}"
254
254
  end
@@ -311,7 +311,9 @@ module Twitter
311
311
  :token_secret => @options[:oauth][:access_secret]
312
312
  }
313
313
 
314
- SimpleOAuth::Header.new(@options[:method], uri, params, oauth)
314
+ data = ['POST', 'PUT'].include?(@options[:method]) ? params : {}
315
+
316
+ SimpleOAuth::Header.new(@options[:method], uri, data, oauth)
315
317
  end
316
318
 
317
319
  # Scheme (https if ssl, http otherwise) and host part of URL
@@ -1,5 +1,4 @@
1
1
  require 'rubygems'
2
- $:.unshift File.expand_path("../../lib", __FILE__)
3
2
 
4
3
  gem 'rspec', '>= 2.5.0'
5
4
  require 'rspec'
@@ -51,4 +50,4 @@ end
51
50
  def http_chunk(data)
52
51
  # See http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.6.1
53
52
  "#{data.length.to_s(16)}\r\n#{data}\r\n"
54
- end
53
+ end
@@ -1,5 +1,4 @@
1
- $:.unshift "."
2
- require File.dirname(__FILE__) + '/../spec_helper.rb'
1
+ require 'spec_helper.rb'
3
2
  require 'twitter/json_stream'
4
3
 
5
4
  include Twitter
@@ -24,7 +23,7 @@ describe JSONStream do
24
23
 
25
24
  context "authentication" do
26
25
  it "should connect with basic auth credentials" do
27
- connect_stream :auth => "username:password"
26
+ connect_stream :auth => "username:password", :ssl => false
28
27
  $recieved_data.should include('Authorization: Basic')
29
28
  end
30
29
 
@@ -35,7 +34,7 @@ describe JSONStream do
35
34
  :access_key => 'ohai',
36
35
  :access_secret => 'ohno'
37
36
  }
38
- connect_stream :oauth => oauth
37
+ connect_stream :oauth => oauth, :ssl => false
39
38
  $recieved_data.should include('Authorization: OAuth')
40
39
  end
41
40
  end
@@ -51,7 +50,7 @@ describe JSONStream do
51
50
  it "should define default properties" do
52
51
  EM.should_receive(:connect).with do |host, port, handler, opts|
53
52
  host.should == 'stream.twitter.com'
54
- port.should == 80
53
+ port.should == 443
55
54
  opts[:path].should == '/1/statuses/filter.json'
56
55
  opts[:method].should == 'GET'
57
56
  end
@@ -63,12 +62,19 @@ describe JSONStream do
63
62
  host.should == 'my-proxy'
64
63
  port.should == 8080
65
64
  opts[:host].should == 'stream.twitter.com'
66
- opts[:port].should == 80
65
+ opts[:port].should == 443
67
66
  opts[:proxy].should == 'http://my-proxy:8080'
68
67
  end
69
68
  stream = JSONStream.connect(:proxy => "http://my-proxy:8080") {}
70
69
  end
71
70
 
71
+ it "should not trigger SSL until connection is established" do
72
+ connection = stub('connection')
73
+ EM.should_receive(:connect).and_return(connection)
74
+ stream = JSONStream.connect(:ssl => true)
75
+ stream.should == connection
76
+ end
77
+
72
78
  end
73
79
 
74
80
  context "on valid stream" do
@@ -76,46 +82,46 @@ describe JSONStream do
76
82
  before :each do
77
83
  $body = File.readlines(fixture_path("twitter/tweets.txt"))
78
84
  $body.each {|tweet| tweet.strip!; tweet << "\r" }
79
- $data_to_send = http_response(200,"OK",{},$body)
85
+ $data_to_send = http_response(200, "OK", {}, $body)
80
86
  $recieved_data = ''
81
87
  $close_connection = false
82
88
  end
83
89
 
84
90
  it "should add no params" do
85
- connect_stream
91
+ connect_stream :ssl => false
86
92
  $recieved_data.should include('/1/statuses/filter.json HTTP')
87
93
  end
88
94
 
89
95
  it "should add custom params" do
90
- connect_stream :params => {:name => 'test'}
96
+ connect_stream :params => {:name => 'test'}, :ssl => false
91
97
  $recieved_data.should include('?name=test')
92
98
  end
93
99
 
94
100
  it "should parse headers" do
95
- connect_stream
101
+ connect_stream :ssl => false
96
102
  stream.code.should == 200
97
103
  stream.headers.keys.map{|k| k.downcase}.should include('content-type')
98
104
  end
99
105
 
100
106
  it "should parse headers even after connection close" do
101
- connect_stream
107
+ connect_stream :ssl => false
102
108
  stream.code.should == 200
103
109
  stream.headers.keys.map{|k| k.downcase}.should include('content-type')
104
110
  end
105
111
 
106
112
  it "should extract records" do
107
- connect_stream :user_agent => 'TEST_USER_AGENT'
113
+ connect_stream :user_agent => 'TEST_USER_AGENT', :ssl => false
108
114
  $recieved_data.upcase.should include('USER-AGENT: TEST_USER_AGENT')
109
115
  end
110
116
 
111
117
  it 'should allow custom headers' do
112
- connect_stream :headers => { 'From' => 'twitter-stream' }
118
+ connect_stream :headers => { 'From' => 'twitter-stream' }, :ssl => false
113
119
  $recieved_data.upcase.should include('FROM: TWITTER-STREAM')
114
120
  end
115
121
 
116
122
  it "should deliver each item" do
117
123
  items = []
118
- connect_stream do
124
+ connect_stream :ssl => false do
119
125
  stream.each_item do |item|
120
126
  items << item
121
127
  end
@@ -198,6 +204,12 @@ describe JSONStream do
198
204
  end
199
205
  end
200
206
 
207
+ it "should reconnect with SSL if enabled" do
208
+ connect_stream :ssl => true do
209
+ stream.should_receive(:start_tls).twice
210
+ end
211
+ end
212
+
201
213
  it_should_behave_like "network failure"
202
214
  end
203
215
 
@@ -225,26 +237,26 @@ describe JSONStream do
225
237
  end
226
238
 
227
239
  it "should reconnect on application failure 10 at base" do
228
- connect_stream do
240
+ connect_stream :ssl => false do
229
241
  stream.should_receive(:reconnect_after).with(10)
230
242
  end
231
243
  end
232
244
 
233
245
  it "should not reconnect on application failure 10 at base when not configured to auto reconnect" do
234
- connect_stream(:auto_reconnect => false) do
246
+ connect_stream :ssl => false, :auto_reconnect => false do
235
247
  stream.should_receive(:reconnect_after).never
236
248
  end
237
249
  end
238
250
 
239
251
  it "should reconnect with exponential timeout" do
240
- connect_stream do
252
+ connect_stream :ssl => false do
241
253
  stream.af_last_reconnect = 160
242
254
  stream.should_receive(:reconnect_after).with(320)
243
255
  end
244
256
  end
245
257
 
246
258
  it "should not try to reconnect after limit is reached" do
247
- connect_stream do
259
+ connect_stream :ssl => false do
248
260
  stream.af_last_reconnect = 320
249
261
  stream.should_not_receive(:reconnect_after)
250
262
  end
@@ -262,7 +274,7 @@ describe JSONStream do
262
274
  body_chunks = ["{\"screen"+"_name\"",":\"user1\"}\r\r\r{","\"id\":9876}\r\r"]
263
275
  $data_to_send = http_response(200,"OK",{},body_chunks)
264
276
  items = []
265
- connect_stream do
277
+ connect_stream :ssl => false do
266
278
  stream.each_item do |item|
267
279
  items << item
268
280
  end
@@ -276,7 +288,7 @@ describe JSONStream do
276
288
  body_chunks = ["{\"id\"",":1234}\r{","\"id\":9876}"]
277
289
  $data_to_send = http_response(200,"OK",{},body_chunks)
278
290
  items = []
279
- connect_stream do
291
+ connect_stream :ssl => false do
280
292
  stream.each_item do |item|
281
293
  items << item
282
294
  end
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{twitter-stream}
5
- s.version = "0.1.14"
5
+ s.version = "0.1.15"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Vladimir Kolesnikov"]
9
- s.date = %q{2010-10-05}
9
+ s.date = %q{2012-04-10}
10
10
  s.description = %q{Simple Ruby client library for twitter streaming API. Uses EventMachine for connection handling. Adheres to twitter's reconnection guidline. JSON format only.}
11
11
  s.summary = %q{Twitter realtime API client}
12
12
  s.homepage = %q{http://github.com/voloko/twitter-stream}
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
17
17
  s.required_rubygems_version = Gem::Requirement.new(">= 1.3.6") if s.respond_to? :required_rubygems_version=
18
18
 
19
19
  s.rdoc_options = ["--charset=UTF-8"]
20
- s.extra_rdoc_files = ["README.markdown"]
20
+ s.extra_rdoc_files = ["README.markdown", "LICENSE"]
21
21
 
22
22
  s.add_runtime_dependency('eventmachine', ">= 0.12.8")
23
23
  s.add_runtime_dependency('simple_oauth', '~> 0.1.4')
metadata CHANGED
@@ -1,96 +1,70 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: twitter-stream
3
- version: !ruby/object:Gem::Version
4
- hash: 7
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 1
9
- - 14
10
- version: 0.1.14
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.15
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Vladimir Kolesnikov
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2010-10-05 00:00:00 -07:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2012-04-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: eventmachine
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70312242841020 !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 63
30
- segments:
31
- - 0
32
- - 12
33
- - 8
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
34
21
  version: 0.12.8
35
22
  type: :runtime
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: simple_oauth
39
23
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *70312242841020
25
+ - !ruby/object:Gem::Dependency
26
+ name: simple_oauth
27
+ requirement: &70312242839900 !ruby/object:Gem::Requirement
41
28
  none: false
42
- requirements:
29
+ requirements:
43
30
  - - ~>
44
- - !ruby/object:Gem::Version
45
- hash: 19
46
- segments:
47
- - 0
48
- - 1
49
- - 4
31
+ - !ruby/object:Gem::Version
50
32
  version: 0.1.4
51
33
  type: :runtime
52
- version_requirements: *id002
53
- - !ruby/object:Gem::Dependency
54
- name: http_parser.rb
55
34
  prerelease: false
56
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *70312242839900
36
+ - !ruby/object:Gem::Dependency
37
+ name: http_parser.rb
38
+ requirement: &70312242838600 !ruby/object:Gem::Requirement
57
39
  none: false
58
- requirements:
40
+ requirements:
59
41
  - - ~>
60
- - !ruby/object:Gem::Version
61
- hash: 9
62
- segments:
63
- - 0
64
- - 5
65
- - 1
42
+ - !ruby/object:Gem::Version
66
43
  version: 0.5.1
67
44
  type: :runtime
68
- version_requirements: *id003
69
- - !ruby/object:Gem::Dependency
70
- name: rspec
71
45
  prerelease: false
72
- requirement: &id004 !ruby/object:Gem::Requirement
46
+ version_requirements: *70312242838600
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: &70312242837520 !ruby/object:Gem::Requirement
73
50
  none: false
74
- requirements:
51
+ requirements:
75
52
  - - ~>
76
- - !ruby/object:Gem::Version
77
- hash: 27
78
- segments:
79
- - 2
80
- - 5
81
- - 0
53
+ - !ruby/object:Gem::Version
82
54
  version: 2.5.0
83
55
  type: :development
84
- version_requirements: *id004
85
- description: Simple Ruby client library for twitter streaming API. Uses EventMachine for connection handling. Adheres to twitter's reconnection guidline. JSON format only.
56
+ prerelease: false
57
+ version_requirements: *70312242837520
58
+ description: Simple Ruby client library for twitter streaming API. Uses EventMachine
59
+ for connection handling. Adheres to twitter's reconnection guidline. JSON format
60
+ only.
86
61
  email: voloko@gmail.com
87
62
  executables: []
88
-
89
63
  extensions: []
90
-
91
- extra_rdoc_files:
64
+ extra_rdoc_files:
92
65
  - README.markdown
93
- files:
66
+ - LICENSE
67
+ files:
94
68
  - .gemtest
95
69
  - .gitignore
96
70
  - .rspec
@@ -104,42 +78,32 @@ files:
104
78
  - spec/spec_helper.rb
105
79
  - spec/twitter/json_stream_spec.rb
106
80
  - twitter-stream.gemspec
107
- has_rdoc: true
81
+ - LICENSE
108
82
  homepage: http://github.com/voloko/twitter-stream
109
83
  licenses: []
110
-
111
84
  post_install_message:
112
- rdoc_options:
85
+ rdoc_options:
113
86
  - --charset=UTF-8
114
- require_paths:
87
+ require_paths:
115
88
  - lib
116
- required_ruby_version: !ruby/object:Gem::Requirement
89
+ required_ruby_version: !ruby/object:Gem::Requirement
117
90
  none: false
118
- requirements:
119
- - - ">="
120
- - !ruby/object:Gem::Version
121
- hash: 3
122
- segments:
123
- - 0
124
- version: "0"
125
- required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
96
  none: false
127
- requirements:
128
- - - ">="
129
- - !ruby/object:Gem::Version
130
- hash: 23
131
- segments:
132
- - 1
133
- - 3
134
- - 6
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
135
100
  version: 1.3.6
136
101
  requirements: []
137
-
138
102
  rubyforge_project:
139
- rubygems_version: 1.3.7
103
+ rubygems_version: 1.8.15
140
104
  signing_key:
141
105
  specification_version: 3
142
106
  summary: Twitter realtime API client
143
- test_files:
107
+ test_files:
144
108
  - spec/spec_helper.rb
145
109
  - spec/twitter/json_stream_spec.rb