Skip to content
Browse files

added support for Site Stream friends list

  • Loading branch information...
1 parent a5101f9 commit 58d5bf3df5124f2463ee6828de39c6e557001f5e @stve stve committed
Showing with 54 additions and 22 deletions.
  1. +12 −0 lib/tweetstream/client.rb
  2. +42 −22 spec/tweetstream/client_site_stream_spec.rb
View
12 lib/tweetstream/client.rb
@@ -335,6 +335,16 @@ def on_user_withheld(&block)
on('user_withheld', &block)
end
+ # Set a Proc to be run when a Site Stream friends list is received.
+ #
+ # @client = TweetStream::Client.new
+ # @client.on_friends do |friends|
+ # # do something with the friends list
+ # end
+ def on_friends(&block)
+ on('friends', &block)
+ end
+
# Set a Proc to be run on userstream events
#
# @client = TweetStream::Client.new
@@ -440,6 +450,8 @@ def respond_to(hash, callbacks, &block)
invoke_callback(callbacks['user_withheld'], hash[:user_withheld])
elsif hash[:event]
invoke_callback(callbacks[hash[:event].to_s], hash)
+ elsif hash[:friends]
+ invoke_callback(callbacks['friends'], hash[:friends])
elsif hash[:text] && hash[:user]
@last_status = Twitter::Tweet.new(hash)
yield_message_to(callbacks['timeline_status'], @last_status)
View
64 spec/tweetstream/client_site_stream_spec.rb
@@ -58,7 +58,7 @@
@client.sitestream(['115192457'], :replies => 'all')
end
- context 'control management' do
+ describe 'control management' do
before do
@control_response = {"control" =>
{
@@ -92,31 +92,51 @@
end
end
- context 'data handling' do
- before do
- tweet = sample_tweets[0]
- @ss_message = {'for_user' => '12345', 'message' => {'id' => 123, 'user' => {'screen_name' => 'monkey'}, 'text' => 'Oo oo aa aa'}}
- end
+ describe 'data handling' do
+ context 'messages' do
+ before do
+ @ss_message = {'for_user' => '12345', 'message' => {'id' => 123, 'user' => {'screen_name' => 'monkey'}, 'text' => 'Oo oo aa aa'}}
+ end
- it 'yields a site stream message' do
- @stream.should_receive(:each).and_yield(@ss_message.to_json)
- yielded_status = nil
- @client.sitestream do |message|
- yielded_status = message
+ it 'yields a site stream message' do
+ @stream.should_receive(:each).and_yield(@ss_message.to_json)
+ yielded_status = nil
+ @client.sitestream do |message|
+ yielded_status = message
+ end
+ yielded_status.should_not be_nil
+ yielded_status[:for_user].should == '12345'
+ yielded_status[:message][:user][:screen_name].should == 'monkey'
+ yielded_status[:message][:text].should == 'Oo oo aa aa'
+ end
+ it 'yields itself if block has an arity of 2' do
+ @stream.should_receive(:each).and_yield(@ss_message.to_json)
+ yielded_client = nil
+ @client.sitestream do |_, client|
+ yielded_client = client
+ end
+ yielded_client.should_not be_nil
+ yielded_client.should == @client
end
- yielded_status.should_not be_nil
- yielded_status[:for_user].should == '12345'
- yielded_status[:message][:user][:screen_name].should == 'monkey'
- yielded_status[:message][:text].should == 'Oo oo aa aa'
end
- it 'yields itself if block has an arity of 2' do
- @stream.should_receive(:each).and_yield(@ss_message.to_json)
- yielded_client = nil
- @client.sitestream do |_, client|
- yielded_client = client
+
+ context 'friends list' do
+ before do
+ @friends_list = { 'friends' => [123, 456] }
+ end
+
+ it 'yields a friends list array' do
+ @stream.should_receive(:each).and_yield(@friends_list.to_json)
+ yielded_list = nil
+ @client.on_friends do |friends|
+ yielded_list = friends
+ end
+ @client.sitestream
+
+ yielded_list.should_not be_nil
+ yielded_list.should be_an(Array)
+ yielded_list.first.should eq(123)
end
- yielded_client.should_not be_nil
- yielded_client.should == @client
end
end
end

0 comments on commit 58d5bf3

Please sign in to comment.
Something went wrong with that request. Please try again.