nervion 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore CHANGED
@@ -4,3 +4,5 @@
4
4
  coverage
5
5
  doc
6
6
  examples
7
+ Gemfile.lock
8
+ pkg
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # version 0.0.3
2
+
3
+ - Allow Nervion to run without being responsible for EventMachine's event loop
4
+
1
5
  # version 0.0.2
2
6
 
3
7
  - Support for firehose endpoint
@@ -14,8 +14,12 @@ module Nervion
14
14
  end
15
15
 
16
16
  def stop
17
- @stream.close
17
+ close_stream
18
18
  EM.stop
19
19
  end
20
+
21
+ def close_stream
22
+ @stream.close
23
+ end
20
24
  end
21
25
  end
@@ -88,12 +88,18 @@ module Nervion
88
88
  stream firehose_endpoint(params), callback
89
89
  end
90
90
 
91
- # Stops streaming
91
+ # Stops streaming and stops EventMachine's event loop
92
92
  def self.stop
93
- raise 'Nervion is not running' if @client.nil?
93
+ check_for_running_client
94
94
  @client.stop
95
95
  end
96
96
 
97
+ # Stops streaming but keeps EventMachine's event loop running
98
+ def self.close_stream
99
+ check_for_running_client
100
+ @client.close_stream
101
+ end
102
+
97
103
  private
98
104
 
99
105
  def self.callback_table
@@ -131,6 +137,10 @@ module Nervion
131
137
  raise "You have to setup a message callback. Please, check out #{MSG_CALLBACK_README_URL}"
132
138
  end
133
139
 
140
+ def self.check_for_running_client
141
+ raise 'Nervion is not running' if @client.nil?
142
+ end
143
+
134
144
  STREAM_API_HOST = 'stream.twitter.com'
135
145
  STREAM_API_PORT = 443
136
146
  SAMPLE_ENDPOINT = "https://#{STREAM_API_HOST}/1/statuses/sample.json"
@@ -46,6 +46,7 @@ module Nervion
46
46
 
47
47
  def close
48
48
  @close_stream = true
49
+ close_connection
49
50
  end
50
51
 
51
52
  private
@@ -1,3 +1,3 @@
1
1
  module Nervion
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/nervion.gemspec CHANGED
@@ -4,7 +4,7 @@ require File.expand_path('../lib/nervion/version', __FILE__)
4
4
  Gem::Specification.new do |gem|
5
5
  gem.authors = ["Javier Acero"]
6
6
  gem.email = ["j4cegu@gmail.com"]
7
- gem.description = %q{A minimalistic Twitter Stream API Ruby client}
7
+ gem.description = %q{A minimalistic Ruby client for the Public Streams of Twitter Streaming API}
8
8
  gem.summary = %q{}
9
9
  gem.homepage = "https://github.com/jacegu/nervion"
10
10
 
@@ -15,7 +15,7 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = Nervion::VERSION
17
17
 
18
- gem.add_runtime_dependency 'eventmachine', '~> 1.0.0.beta.4'
18
+ gem.add_runtime_dependency 'eventmachine', '~> 1.0.0.rc.4'
19
19
  gem.add_runtime_dependency 'http_parser.rb', '~> 0.5.3'
20
20
  gem.add_runtime_dependency 'yajl-ruby', '~> 1.1.0'
21
21
  gem.add_development_dependency 'cucumber'
@@ -43,11 +43,19 @@ describe Nervion::Client do
43
43
  subject.stream(request, callbacks)
44
44
  end
45
45
 
46
- it 'stops streaming' do
46
+ it 'closes the stream and stops the event loop' do
47
47
  EM.stub(:connect).and_return(stream)
48
48
  stream.should_receive(:close).ordered
49
49
  EM.should_receive(:stop).ordered
50
50
  subject.stream(request, callbacks)
51
51
  subject.stop
52
52
  end
53
+
54
+ it 'closes the stream' do
55
+ EM.stub(:connect).and_return(stream)
56
+ stream.should_receive(:close)
57
+ EM.should_not_receive(:stop)
58
+ subject.stream(request, callbacks)
59
+ subject.close_stream
60
+ end
53
61
  end
@@ -98,7 +98,7 @@ describe "Facade that exposes Nervion's API" do
98
98
  end
99
99
 
100
100
  context 'stoping' do
101
- it 'can stop the streaming' do
101
+ it 'stops the client and the event loop' do
102
102
  client.should_receive(:stop)
103
103
  Nervion.sample{}
104
104
  Nervion.stop
@@ -109,6 +109,20 @@ describe "Facade that exposes Nervion's API" do
109
109
  expect { Nervion.stop }.to raise_error
110
110
  end
111
111
  end
112
+
113
+ context 'closing the stream' do
114
+ it 'closes the stream but keeps the event loop running' do
115
+ client.should_receive(:close_stream)
116
+ Nervion.sample{}
117
+ Nervion.close_stream
118
+ end
119
+
120
+ it 'raises an error if it is not streaming' do
121
+ Nervion.instance_variable_set(:@client, nil)
122
+ expect { Nervion.close_stream }.to raise_error
123
+ end
124
+ end
125
+
112
126
  end
113
127
 
114
128
  end
@@ -48,6 +48,7 @@ describe Nervion::Stream do
48
48
 
49
49
  it 'can be closed' do
50
50
  subject.close_requested?.should be_false
51
+ subject.should_receive(:close_connection)
51
52
  subject.close
52
53
  subject.close_requested?.should be_true
53
54
  end
@@ -91,6 +92,7 @@ describe Nervion::Stream do
91
92
  handler.should_not_receive(:handle_network_error)
92
93
  scheduler.should_not_receive(:reconnect_after_http_error_in)
93
94
  scheduler.should_not_receive(:reconnect_after_network_error_in)
95
+ subject.stub(:close_connection)
94
96
  subject.close
95
97
  subject.unbind
96
98
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nervion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-27 00:00:00.000000000 Z
12
+ date: 2012-07-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: eventmachine
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 1.0.0.beta.4
21
+ version: 1.0.0.rc.4
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 1.0.0.beta.4
29
+ version: 1.0.0.rc.4
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: http_parser.rb
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -139,7 +139,8 @@ dependencies:
139
139
  - - ! '>='
140
140
  - !ruby/object:Gem::Version
141
141
  version: '0'
142
- description: A minimalistic Twitter Stream API Ruby client
142
+ description: A minimalistic Ruby client for the Public Streams of Twitter Streaming
143
+ API
143
144
  email:
144
145
  - j4cegu@gmail.com
145
146
  executables: []
@@ -152,7 +153,6 @@ files:
152
153
  - .travis.yml
153
154
  - CHANGELOG.md
154
155
  - Gemfile
155
- - Gemfile.lock
156
156
  - LICENSE
157
157
  - README.md
158
158
  - Rakefile
data/Gemfile.lock DELETED
@@ -1,50 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- nervion (0.0.1)
5
- eventmachine (~> 1.0.0.beta.4)
6
- http_parser.rb (~> 0.5.3)
7
- yajl-ruby (~> 1.1.0)
8
-
9
- GEM
10
- remote: https://rubygems.org/
11
- specs:
12
- builder (3.0.0)
13
- cucumber (1.2.1)
14
- builder (>= 2.1.2)
15
- diff-lcs (>= 1.1.3)
16
- gherkin (~> 2.11.0)
17
- json (>= 1.4.6)
18
- diff-lcs (1.1.3)
19
- eventmachine (1.0.0.beta.4)
20
- gherkin (2.11.0)
21
- json (>= 1.4.6)
22
- http_parser.rb (0.5.3)
23
- json (1.7.3)
24
- multi_json (1.3.6)
25
- rake (0.9.2.2)
26
- rspec (2.9.0)
27
- rspec-core (~> 2.9.0)
28
- rspec-expectations (~> 2.9.0)
29
- rspec-mocks (~> 2.9.0)
30
- rspec-core (2.9.0)
31
- rspec-expectations (2.9.1)
32
- diff-lcs (~> 1.1.3)
33
- rspec-mocks (2.9.0)
34
- simplecov (0.6.4)
35
- multi_json (~> 1.0)
36
- simplecov-html (~> 0.5.3)
37
- simplecov-html (0.5.3)
38
- yajl-ruby (1.1.0)
39
- yard (0.8.2.1)
40
-
41
- PLATFORMS
42
- ruby
43
-
44
- DEPENDENCIES
45
- cucumber
46
- nervion!
47
- rake
48
- rspec
49
- simplecov
50
- yard