Skip to content

Commit

Permalink
Uses the userstream urls
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyhaines committed Sep 24, 2011
1 parent b50aefc commit b0721f2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
23 changes: 13 additions & 10 deletions lib/tweetstream/client.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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|
Expand Down
1 change: 1 addition & 0 deletions spec/data/direct_messages.json
@@ -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 changes: 12 additions & 0 deletions spec/tweetstream/client_spec.rb
Expand Up @@ -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

Expand Down

0 comments on commit b0721f2

Please sign in to comment.