tweetstream 0.1.5 → 0.1.7

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

Potentially problematic release.


This version of tweetstream might be problematic. Click here for more details.

data/README.rdoc CHANGED
@@ -90,6 +90,24 @@ Twitter recommends honoring deletions as quickly as possible, and
90
90
  you would likely be wise to integrate this functionality into your
91
91
  application.
92
92
 
93
+ == Terminating a TweetStream
94
+
95
+ It is often the case that you will need to change the parameters of your
96
+ track or follow tweet streams. In the case that you need to terminate
97
+ a stream, simply call <tt>TweetStream::Client.stop from within your
98
+ loop:
99
+
100
+ # Stop after collecting 10 statuses
101
+ @statuses = []
102
+ TweetStream::Client.new('username','password').track('term1', 'term2') do |status|
103
+ @statuses << status
104
+ TweetStream::Client.stop if @statuses.size >= 10
105
+ end
106
+
107
+ When <tt>stop</tt> is called, TweetStream will return from the block
108
+ the last successfully yielded status, allowing you to make note of
109
+ it in your application as necessary.
110
+
93
111
  == Daemonizing
94
112
 
95
113
  It is also possible to create a daemonized script quite easily
data/Rakefile CHANGED
@@ -16,10 +16,18 @@ begin
16
16
  gem.add_dependency 'daemons'
17
17
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
18
  end
19
+ Jeweler::GemcutterTasks.new
19
20
  rescue LoadError
20
21
  puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
21
22
  end
22
23
 
24
+ namespace :release do
25
+ %w(patch minor major).each do |level|
26
+ desc "Tag a #{level} version and push it to Gemcutter."
27
+ multitask level.to_sym => %w(version:bump:patch release gemcutter:release)
28
+ end
29
+ end
30
+
23
31
  require 'spec/rake/spectask'
24
32
  Spec::Rake::SpecTask.new(:spec) do |spec|
25
33
  spec.libs << 'lib' << 'spec'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.5
1
+ 0.1.7
@@ -148,9 +148,19 @@ module TweetStream
148
148
  elsif hash[:limit] && hash[:limit][:track]
149
149
  limit_proc.call(hash[:limit][:track]) if limit_proc.is_a?(Proc)
150
150
  elsif hash[:text] && hash[:user]
151
- yield TweetStream::Status.new(hash)
151
+ @last_status = TweetStream::Status.new(hash)
152
+ yield @last_status
152
153
  end
153
154
  end
155
+ rescue TweetStream::Terminated
156
+ return @last_status
157
+ rescue Yajl::HttpStream::InvalidContentType
158
+ raise TweetStream::ConnectionError, "There was an error connecting to the Twitter streaming service. Please check your credentials and the current status of the Streaming API."
159
+ end
160
+
161
+ # Terminate the currently running TweetStream.
162
+ def self.stop
163
+ raise TweetStream::Terminated
154
164
  end
155
165
 
156
166
  protected
data/lib/tweetstream.rb CHANGED
@@ -3,3 +3,9 @@ require 'tweetstream/hash'
3
3
  require 'tweetstream/status'
4
4
  require 'tweetstream/user'
5
5
  require 'tweetstream/daemon'
6
+
7
+ module TweetStream
8
+ class Terminated < ::StandardError; end
9
+ class Error < ::StandardError; end
10
+ class ConnectionError < TweetStream::Error; end
11
+ end
@@ -75,6 +75,11 @@ describe TweetStream::Client do
75
75
  @yielded.should be_true
76
76
  end
77
77
 
78
+ it 'should wrap Yajl errors in TweetStream errors' do
79
+ Yajl::HttpStream.should_receive(:get).once.with(URI.parse('http://abc:def@stream.twitter.com/1/cool.json'), :symbolize_keys => true).and_raise(Yajl::HttpStream::InvalidContentType)
80
+ lambda{@client.start('cool')}.should raise_error(TweetStream::ConnectionError)
81
+ end
82
+
78
83
  {
79
84
  :delete => {:delete => {:status => {:id => 1234, :user_id => 3}}},
80
85
  :limit => {:limit => {:track => 1234}}
@@ -160,4 +165,21 @@ describe TweetStream::Client do
160
165
  @client.track('rock')
161
166
  end
162
167
  end
168
+
169
+ describe '.stop' do
170
+ it 'should raise a TweetStream::Terminated error' do
171
+ lambda{ TweetStream::Client.stop }.should raise_error(TweetStream::Terminated)
172
+ end
173
+
174
+ it 'should not cause a TweetStream to crash with a real exception' do
175
+ @client = TweetStream::Client.new('abc','def')
176
+ @statuses = []
177
+ Yajl::HttpStream.should_receive(:get).once.with(URI.parse('http://abc:def@stream.twitter.com/1/statuses/filter.json?track=musicmonday'), :symbolize_keys => true).and_yield(sample_tweets[0])
178
+ @client.track('musicmonday') do |status|
179
+ @statuses << status
180
+ TweetStream::Client.stop
181
+ end.should == @statuses.first
182
+ @statuses.size.should == 1
183
+ end
184
+ end
163
185
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tweetstream
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Bleigh
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-26 00:00:00 -04:00
12
+ date: 2009-10-20 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency