Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Uses the userstream urls

  • Loading branch information...
commit b0721f2c9e79d7c303d91c150abd222dc3aadc23 1 parent b50aefc
Corey Haines coreyhaines authored
23 lib/tweetstream/client.rb
View
@@ -128,7 +128,7 @@ def filter(query_params = {}, &block)
# method is provided separately for cases when it would conserve the
# number of HTTP connections to combine track and follow.
def user_stream(&block)
- start('', &block)
+ start('', :extra_stream_parameters => {:host => "userstream.twitter.com", :path => "/2/user.json"}, &block)
end
# Set a Proc to be run when a deletion notice is received
@@ -243,18 +243,21 @@ def start(path, query_parameters = {}, &block) #:nodoc:
params = normalize_filter_parameters(query_parameters)
+ extra_stream_parameters = query_parameters.delete(:extra_stream_parameters) || {}
+
uri = method == :get ? build_uri(path, params) : build_uri(path)
+ stream_params = {
+ :path => uri,
+ :method => method.to_s.upcase,
+ :user_agent => user_agent,
+ :on_inited => inited_proc,
+ :filters => params.delete(:track),
+ :params => params,
+ :ssl => true
+ }.merge(auth_params).merge(extra_stream_parameters)
+
EventMachine::run {
- stream_params = {
- :path => uri,
- :method => method.to_s.upcase,
- :user_agent => user_agent,
- :on_inited => inited_proc,
- :filters => params.delete(:track),
- :params => params,
- :ssl => true
- }.merge(auth_params)
@stream = Twitter::JSONStream.connect(stream_params)
@stream.each_item do |item|
1  spec/data/direct_messages.json
View
@@ -0,0 +1 @@
+{"direct_message":{"created_at":"Sat Sep 24 18:59:38 +0000 2011", "id_str":"4227325281", "sender_screen_name":"coreyhaines", "sender":{"name":"Corey Haines", "profile_sidebar_fill_color":"DAECF4", "profile_sidebar_border_color":"C6E2EE", "profile_background_tile":false, "profile_image_url":"http://a0.twimg.com/profile_images/1508969901/Photo_on_2011-08-22_at_19.15__3_normal.jpg", "created_at":"Sun Dec 23 18:11:29 +0000 2007", "location":"Chicago, IL", "follow_request_sent":false, "id_str":"11458102", "is_translator":false, "profile_link_color":"1F98C7", "default_profile":false, "favourites_count":122, "contributors_enabled":false, "url":"http://www.coreyhaines.com", "id":11458102, "profile_image_url_https":"https://si0.twimg.com/profile_images/1508969901/Photo_on_2011-08-22_at_19.15__3_normal.jpg", "utc_offset":-21600, "profile_use_background_image":true, "listed_count":593, "lang":"en", "followers_count":5764, "protected":false, "profile_text_color":"663B12", "notifications":false, "description":"Software Journeyman, Coderetreat Facilitator, Cofounder of MercuryApp.com, Awesome....\r\nI make magic!", "verified":false, "profile_background_color":"C6E2EE", "geo_enabled":false, "profile_background_image_url_https":"https://si0.twimg.com/images/themes/theme2/bg.gif", "time_zone":"Central Time (US & Canada)", "profile_background_image_url":"http://a1.twimg.com/images/themes/theme2/bg.gif", "default_profile_image":false, "friends_count":423, "statuses_count":35950, "following":false, "screen_name":"coreyhaines", "show_all_inline_media":false}, "recipient_screen_name":"coreyhainestest", "text":"waddup gain", "id":4227325281, "recipient":{"name":"Corey's Test Account", "profile_sidebar_fill_color":"DDEEF6", "profile_sidebar_border_color":"C0DEED", "profile_background_tile":false, "profile_image_url":"http://a2.twimg.com/sticky/default_profile_images/default_profile_3_normal.png", "created_at":"Sat Sep 24 13:04:56 +0000 2011", "location":null, "follow_request_sent":false, "id_str":"379145826", "is_translator":false, "profile_link_color":"0084B4", "default_profile":true, "favourites_count":0, "contributors_enabled":false, "url":null, "id":379145826, "profile_image_url_https":"https://si0.twimg.com/sticky/default_profile_images/default_profile_3_normal.png", "utc_offset":null, "profile_use_background_image":true, "listed_count":0, "lang":"en", "followers_count":1, "protected":false, "profile_text_color":"333333", "notifications":false, "description":null, "verified":false, "profile_background_color":"C0DEED", "geo_enabled":false, "profile_background_image_url_https":"https://si0.twimg.com/images/themes/theme1/bg.png", "time_zone":null, "profile_background_image_url":"http://a0.twimg.com/images/themes/theme1/bg.png", "default_profile_image":true, "friends_count":1, "statuses_count":21, "following":true, "screen_name":"coreyhainestest", "show_all_inline_media":false}, "recipient_id":379145826, "sender_id":11458102}}
12 spec/tweetstream/client_spec.rb
View
@@ -301,6 +301,18 @@
@client.track('monday')
end
+
+ context "when calling #user_stream" do
+ it "sends the userstream host" do
+ Twitter::JSONStream.should_receive(:connect).with(hash_including(:host => "userstream.twitter.com")).and_return(@stream)
+ @client.user_stream
+ end
+
+ it "uses the userstream uri" do
+ Twitter::JSONStream.should_receive(:connect).with(hash_including(:path => "/2/user.json")).and_return(@stream)
+ @client.user_stream
+ end
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.