Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: tweetstream/tweetstream
base: 9a8be618e4
...
head fork: tweetstream/tweetstream
compare: 17ae38e883
Checking mergeability… Don't worry, you can still create the pull request.
  • 5 commits
  • 7 files changed
  • 0 commit comments
  • 2 contributors
View
73 lib/tweetstream/client.rb
@@ -10,7 +10,7 @@ module TweetStream
#
# Basic usage of the library is to call one of the provided
# methods and provide a block that will perform actions on
- # a yielded Twitter::Status. For example:
+ # a yielded Twitter::Tweet. For example:
#
# TweetStream::Client.new.track('fail') do |status|
# puts "[#{status.user.screen_name}] #{status.text}"
@@ -55,7 +55,7 @@ def initialize(options={})
# Creative use of a combination of other resources and various access
# levels can satisfy nearly every application use case.
def firehose(query_parameters = {}, &block)
- start('/1/statuses/firehose.json', query_parameters, &block)
+ start('/1.1/statuses/firehose.json', query_parameters, &block)
end
# Returns all statuses containing http: and https:. The links stream is
@@ -63,7 +63,7 @@ def firehose(query_parameters = {}, &block)
# of access. Creative use of a combination of other resources and various
# access levels can satisfy nearly every application use case.
def links(query_parameters = {}, &block)
- start('/1/statuses/links.json', query_parameters, &block)
+ start('/1.1/statuses/links.json', query_parameters, &block)
end
# Returns all retweets. The retweet stream is not a generally available
@@ -73,7 +73,7 @@ def links(query_parameters = {}, &block)
# the site-wide retweet feature has not yet launched,
# so there are currently few, if any, retweets on this stream.
def retweet(query_parameters = {}, &block)
- start('/1/statuses/retweet.json', query_parameters, &block)
+ start('/1.1/statuses/retweet.json', query_parameters, &block)
end
# Returns a random sample of all public statuses. The default access level
@@ -82,7 +82,7 @@ def retweet(query_parameters = {}, &block)
# research applications that desire a larger proportion to be statistically
# significant sample.
def sample(query_parameters = {}, &block)
- start('/1/statuses/sample.json', query_parameters, &block)
+ start('/1.1/statuses/sample.json', query_parameters, &block)
end
# Specify keywords to track. Queries are subject to Track Limitations,
@@ -125,14 +125,14 @@ def locations(*locations_map, &block)
# method is provided separately for cases when it would conserve the
# number of HTTP connections to combine track and follow.
def filter(query_params = {}, &block)
- start('/1/statuses/filter.json', query_params.merge(:method => :post), &block)
+ start('/1.1/statuses/filter.json', query_params.merge(:method => :post), &block)
end
# Make a call to the userstream api for currently authenticated user
def userstream(query_params = {}, &block)
stream_params = { :host => "userstream.twitter.com" }
query_params.merge!(:extra_stream_parameters => stream_params)
- start('/2/user.json', query_params, &block)
+ start('/1.1/user.json', query_params, &block)
end
# Make a call to the userstream api
@@ -144,7 +144,7 @@ def sitestream(user_ids = [], query_params = {}, &block)
:extra_stream_parameters => stream_params
})
query_params.merge!(:with => 'followings') if query_params.delete(:followings)
- start('/2b/site.json', query_params, &block)
+ start('/1.1/site.json', query_params, &block)
end
# Set a Proc to be run when a deletion notice is received
@@ -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
@@ -370,26 +380,9 @@ def start(path, query_parameters = {}, &block)
# connect to twitter without starting a new EventMachine run loop
def connect(path, options = {}, &block)
- request_method = options.delete(:method) || :get
- warn_if_callbacks(options)
-
- callbacks = @callbacks.dup
- OPTION_CALLBACKS.each do |callback|
- callbacks.merge(callback.to_s => options.delete(callback)) if options[callback]
- end
-
- inited_proc = options.delete(:inited) || @callbacks['inited']
- extra_stream_parameters = options.delete(:extra_stream_parameters) || {}
-
- stream_params = {
- :path => path,
- :method => request_method.to_s.upcase,
- :user_agent => user_agent,
- :on_inited => inited_proc,
- :params => normalize_filter_parameters(options)
- }.merge(extra_stream_parameters).merge(auth_params)
+ stream_parameters, callbacks = connection_options(path, options)
- @stream = EM::Twitter::Client.connect(stream_params)
+ @stream = EM::Twitter::Client.connect(stream_parameters)
@stream.each do |item|
begin
hash = MultiJson.decode(item, :symbolize_keys => true)
@@ -457,8 +450,10 @@ 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::Status.new(hash)
+ @last_status = Twitter::Tweet.new(hash)
yield_message_to(callbacks['timeline_status'], @last_status)
yield_message_to(block, @last_status) if block_given?
@@ -529,6 +524,28 @@ def yield_message_to(procedure, message)
end
end
+ def connection_options(path, options)
+ warn_if_callbacks(options)
+
+ callbacks = @callbacks.dup
+ OPTION_CALLBACKS.each do |callback|
+ callbacks.merge(callback.to_s => options.delete(callback)) if options[callback]
+ end
+
+ inited_proc = options.delete(:inited) || @callbacks['inited']
+ extra_stream_parameters = options.delete(:extra_stream_parameters) || {}
+
+ stream_params = {
+ :path => path,
+ :method => (options.delete(:method) || 'get').to_s.upcase,
+ :user_agent => user_agent,
+ :on_inited => inited_proc,
+ :params => normalize_filter_parameters(options)
+ }.merge(extra_stream_parameters).merge(auth_params)
+
+ [stream_params, callbacks]
+ end
+
def warn_if_callbacks(options={})
if OPTION_CALLBACKS.select { |callback| options[callback] }.size > 0
Kernel.warn("Passing callbacks via the options hash is deprecated and will be removed in TweetStream 3.0")
View
2  lib/tweetstream/version.rb
@@ -1,3 +1,3 @@
module TweetStream
- VERSION = '2.1.0' unless defined?(TweetStream::VERSION)
+ VERSION = '2.2.0' unless defined?(TweetStream::VERSION)
end
View
4 spec/tweetstream/client_authentication_spec.rb
@@ -31,7 +31,7 @@
it 'should try to connect via a JSON stream with basic auth' do
EM::Twitter::Client.should_receive(:connect).with(
- :path => '/1/statuses/filter.json',
+ :path => '/1.1/statuses/filter.json',
:method => 'POST',
:user_agent => TweetStream::Configuration::DEFAULT_USER_AGENT,
:on_inited => nil,
@@ -61,7 +61,7 @@
it 'should try to connect via a JSON stream with oauth' do
EM::Twitter::Client.should_receive(:connect).with(
- :path => '/1/statuses/filter.json',
+ :path => '/1.1/statuses/filter.json',
:method => 'POST',
:user_agent => TweetStream::Configuration::DEFAULT_USER_AGENT,
:on_inited => nil,
View
78 spec/tweetstream/client_site_stream_spec.rb
@@ -34,35 +34,35 @@
end
it "uses the sitestream uri" do
- @client.should_receive(:start).once.with('/2b/site.json', an_instance_of(Hash)).and_return(@stream)
+ @client.should_receive(:start).once.with('/1.1/site.json', an_instance_of(Hash)).and_return(@stream)
@client.sitestream
end
it 'supports "with followings" when followings set as a boolean' do
- @client.should_receive(:start).once.with('/2b/site.json', hash_including(:with => 'followings')).and_return(@stream)
+ @client.should_receive(:start).once.with('/1.1/site.json', hash_including(:with => 'followings')).and_return(@stream)
@client.sitestream(['115192457'], :followings => true)
end
it 'supports "with followings" when followings set as an option' do
- @client.should_receive(:start).once.with('/2b/site.json', hash_including(:with => 'followings')).and_return(@stream)
+ @client.should_receive(:start).once.with('/1.1/site.json', hash_including(:with => 'followings')).and_return(@stream)
@client.sitestream(['115192457'], :with => 'followings')
end
it 'supports "with user"' do
- @client.should_receive(:start).once.with('/2b/site.json', hash_including(:with => 'user')).and_return(@stream)
+ @client.should_receive(:start).once.with('/1.1/site.json', hash_including(:with => 'user')).and_return(@stream)
@client.sitestream(['115192457'], :with => 'user')
end
it 'supports "replies all"' do
- @client.should_receive(:start).once.with('/2b/site.json', hash_including(:replies => 'all')).and_return(@stream)
+ @client.should_receive(:start).once.with('/1.1/site.json', hash_including(:replies => 'all')).and_return(@stream)
@client.sitestream(['115192457'], :replies => 'all')
end
- context 'control management' do
+ describe 'control management' do
before do
@control_response = {"control" =>
{
- "control_uri" =>"/2b/site/c/01_225167_334389048B872A533002B34D73F8C29FD09EFC50"
+ "control_uri" =>"/1.1/site/c/01_225167_334389048B872A533002B34D73F8C29FD09EFC50"
}
}
end
@@ -70,7 +70,7 @@
@stream.should_receive(:each).and_yield(@control_response.to_json)
@client.sitestream
- @client.control_uri.should eq("/2b/site/c/01_225167_334389048B872A533002B34D73F8C29FD09EFC50")
+ @client.control_uri.should eq("/1.1/site/c/01_225167_334389048B872A533002B34D73F8C29FD09EFC50")
end
it 'instantiates a SiteStreamClient' do
@@ -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
View
26 spec/tweetstream/client_spec.rb
@@ -52,9 +52,9 @@
@client.track('abc','def')
end
- it 'yields a Twitter::Status' do
+ it 'yields a Twitter::Tweet' do
@stream.should_receive(:each).and_yield(sample_tweets[0].to_json)
- @client.track('abc'){|s| s.should be_kind_of(Twitter::Status)}
+ @client.track('abc'){|s| s.should be_kind_of(Twitter::Tweet)}
end
it 'yields the client if a block with arity 2 is given' do
@@ -241,64 +241,64 @@
describe 'API methods' do
%w(firehose retweet sample links).each do |method|
it "##{method} should make a call to start with \"statuses/#{method}\"" do
- @client.should_receive(:start).once.with('/1/statuses/' + method + '.json', {})
+ @client.should_receive(:start).once.with('/1.1/statuses/' + method + '.json', {})
@client.send(method)
end
end
describe '#filter' do
it 'makes a call to "statuses/filter" with the query params provided' do
- @client.should_receive(:start).once.with('/1/statuses/filter.json', :follow => 123, :method => :post)
+ @client.should_receive(:start).once.with('/1.1/statuses/filter.json', :follow => 123, :method => :post)
@client.filter(:follow => 123)
end
it 'makes a call to "statuses/filter" with the query params provided longitude/latitude pairs, separated by commas ' do
- @client.should_receive(:start).once.with('/1/statuses/filter.json', :locations => '-122.75,36.8,-121.75,37.8,-74,40,-73,41', :method => :post)
+ @client.should_receive(:start).once.with('/1.1/statuses/filter.json', :locations => '-122.75,36.8,-121.75,37.8,-74,40,-73,41', :method => :post)
@client.filter(:locations => '-122.75,36.8,-121.75,37.8,-74,40,-73,41')
end
end
describe '#follow' do
it 'makes a call to start with "statuses/filter" and a follow query parameter' do
- @client.should_receive(:start).once.with('/1/statuses/filter.json', :follow => [123], :method => :post)
+ @client.should_receive(:start).once.with('/1.1/statuses/filter.json', :follow => [123], :method => :post)
@client.follow(123)
end
it 'comma-joins multiple arguments' do
- @client.should_receive(:start).once.with('/1/statuses/filter.json', :follow => [123,456], :method => :post)
+ @client.should_receive(:start).once.with('/1.1/statuses/filter.json', :follow => [123,456], :method => :post)
@client.follow(123, 456)
end
end
describe '#locations' do
it 'should call #start with "statuses/filter" with the query params provided longitude/latitude pairs' do
- @client.should_receive(:start).once.with('/1/statuses/filter.json', :locations => ['-122.75,36.8,-121.75,37.8,-74,40,-73,41'], :method => :post)
+ @client.should_receive(:start).once.with('/1.1/statuses/filter.json', :locations => ['-122.75,36.8,-121.75,37.8,-74,40,-73,41'], :method => :post)
@client.locations('-122.75,36.8,-121.75,37.8,-74,40,-73,41')
end
it 'should call #start with "statuses/filter" with the query params provided longitude/latitude pairs and additional filter' do
- @client.should_receive(:start).once.with('/1/statuses/filter.json', :locations => ['-122.75,36.8,-121.75,37.8,-74,40,-73,41'], :track => 'rock', :method => :post)
+ @client.should_receive(:start).once.with('/1.1/statuses/filter.json', :locations => ['-122.75,36.8,-121.75,37.8,-74,40,-73,41'], :track => 'rock', :method => :post)
@client.locations('-122.75,36.8,-121.75,37.8,-74,40,-73,41', :track => 'rock')
end
end
describe '#track' do
it 'makes a call to start with "statuses/filter" and a track query parameter' do
- @client.should_receive(:start).once.with('/1/statuses/filter.json', :track => ['test'], :method => :post)
+ @client.should_receive(:start).once.with('/1.1/statuses/filter.json', :track => ['test'], :method => :post)
@client.track('test')
end
it 'comma-joins multiple arguments' do
- @client.should_receive(:start).once.with('/1/statuses/filter.json', :track => ['foo', 'bar', 'baz'], :method => :post)
+ @client.should_receive(:start).once.with('/1.1/statuses/filter.json', :track => ['foo', 'bar', 'baz'], :method => :post)
@client.track('foo', 'bar', 'baz')
end
it 'comma-joins an array of arguments' do
- @client.should_receive(:start).once.with('/1/statuses/filter.json', :track => [['foo','bar','baz']], :method => :post)
+ @client.should_receive(:start).once.with('/1.1/statuses/filter.json', :track => [['foo','bar','baz']], :method => :post)
@client.track(['foo','bar','baz'])
end
it 'should call #start with "statuses/filter" and the provided queries' do
- @client.should_receive(:start).once.with('/1/statuses/filter.json', :track => ['rock'], :method => :post)
+ @client.should_receive(:start).once.with('/1.1/statuses/filter.json', :track => ['rock'], :method => :post)
@client.track('rock')
end
end
View
10 spec/tweetstream/client_userstream_spec.rb
@@ -34,27 +34,27 @@
end
it "uses the userstream uri" do
- @client.should_receive(:start).once.with("/2/user.json", an_instance_of(Hash)).and_return(@stream)
+ @client.should_receive(:start).once.with("/1.1/user.json", an_instance_of(Hash)).and_return(@stream)
@client.userstream
end
it 'supports "replies"' do
- @client.should_receive(:start).once.with("/2/user.json", hash_including(:replies => 'all')).and_return(@stream)
+ @client.should_receive(:start).once.with("/1.1/user.json", hash_including(:replies => 'all')).and_return(@stream)
@client.userstream(:replies => 'all')
end
it 'supports "stall_warnings"' do
- @client.should_receive(:start).once.with("/2/user.json", hash_including(:stall_warnings => 'true')).and_return(@stream)
+ @client.should_receive(:start).once.with("/1.1/user.json", hash_including(:stall_warnings => 'true')).and_return(@stream)
@client.userstream(:stall_warnings => 'true')
end
it 'supports "with followings"' do
- @client.should_receive(:start).once.with("/2/user.json", hash_including(:with => 'followings')).and_return(@stream)
+ @client.should_receive(:start).once.with("/1.1/user.json", hash_including(:with => 'followings')).and_return(@stream)
@client.userstream(:with => 'followings')
end
it 'supports "with user"' do
- @client.should_receive(:start).once.with("/2/user.json", hash_including(:with => 'user')).and_return(@stream)
+ @client.should_receive(:start).once.with("/1.1/user.json", hash_including(:with => 'user')).and_return(@stream)
@client.userstream(:with => 'user')
end
View
2  tweetstream.gemspec
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
s.homepage = 'http://github.com/intridea/tweetstream'
s.add_dependency 'em-twitter', '~> 0.1'
- s.add_dependency 'twitter', '~> 3.2'
+ s.add_dependency 'twitter', '~> 4.0'
s.add_dependency 'daemons', '~> 1.1'
s.add_dependency 'multi_json', '~> 1.3'
s.add_dependency 'em-http-request', '~> 1.0.2'

No commit comments for this range

Something went wrong with that request. Please try again.