diff --git a/lib/twitter/api/lists.rb b/lib/twitter/api/lists.rb index 6829af25d..7ef921734 100644 --- a/lib/twitter/api/lists.rb +++ b/lib/twitter/api/lists.rb @@ -13,6 +13,7 @@ module API module Lists include Twitter::API::Utils MAX_USERS_PER_REQUEST = 100 + URI_SUBSTRING = "://" # Returns all lists the authenticating or specified user subscribes to, including their own # @@ -591,7 +592,13 @@ def merge_list!(hash, list) when Integer hash[:list_id] = list when String - hash[:slug] = list + if list[URI_SUBSTRING] + list = list.split("/") + hash[:slug] = list.pop + hash[:owner_screen_name] = list.pop + else + hash[:slug] = list + end when URI list = list.path.split("/") hash[:slug] = list.pop diff --git a/lib/twitter/api/utils.rb b/lib/twitter/api/utils.rb index b74f556ce..d24755083 100644 --- a/lib/twitter/api/utils.rb +++ b/lib/twitter/api/utils.rb @@ -8,6 +8,7 @@ module API module Utils DEFAULT_CURSOR = -1 + URI_SUBSTRING = "://" private @@ -163,7 +164,11 @@ def merge_user!(hash, user, prefix=nil) when Integer hash[[prefix, "user_id"].compact.join("_").to_sym] = user when String - hash[[prefix, "screen_name"].compact.join("_").to_sym] = user + if user[URI_SUBSTRING] + hash[[prefix, "screen_name"].compact.join("_").to_sym] = user.split("/").last + else + hash[[prefix, "screen_name"].compact.join("_").to_sym] = user + end when URI hash[[prefix, "screen_name"].compact.join("_").to_sym] = user.path.split("/").last when Twitter::User @@ -193,7 +198,11 @@ def merge_users!(hash, users) when Integer user_ids << user when String - screen_names << user + if user[URI_SUBSTRING] + screen_names << user.split("/").last + else + screen_names << user + end when URI screen_names << user.path.split("/").last when Twitter::User diff --git a/spec/twitter/api/direct_messages_spec.rb b/spec/twitter/api/direct_messages_spec.rb index c4be6dd2a..a252034a1 100644 --- a/spec/twitter/api/direct_messages_spec.rb +++ b/spec/twitter/api/direct_messages_spec.rb @@ -122,6 +122,12 @@ expect(a_post("/1.1/direct_messages/new.json").with(:body => {:screen_name => "pengwynn", :text => "Creating a fixture for the Twitter gem"})).to have_been_made end end + context "with a URI string passed" do + it "requests the correct resource" do + @client.direct_message_create("https://twitter.com/pengwynn", "Creating a fixture for the Twitter gem") + expect(a_post("/1.1/direct_messages/new.json").with(:body => {:screen_name => "pengwynn", :text => "Creating a fixture for the Twitter gem"})).to have_been_made + end + end end end diff --git a/spec/twitter/api/favorites_spec.rb b/spec/twitter/api/favorites_spec.rb index d3fb9c9f8..687501ca3 100644 --- a/spec/twitter/api/favorites_spec.rb +++ b/spec/twitter/api/favorites_spec.rb @@ -28,6 +28,12 @@ expect(a_get("/1.1/favorites/list.json").with(:query => {:screen_name => "sferik"})).to have_been_made end end + context "with a URI string passed" do + it "requests the correct resource" do + @client.favorites("https://twitter.com/sferik") + expect(a_get("/1.1/favorites/list.json").with(:query => {:screen_name => "sferik"})).to have_been_made + end + end end context "without arguments passed" do before do diff --git a/spec/twitter/api/lists_spec.rb b/spec/twitter/api/lists_spec.rb index a2f414657..a2c2aa779 100644 --- a/spec/twitter/api/lists_spec.rb +++ b/spec/twitter/api/lists_spec.rb @@ -44,6 +44,12 @@ expect(a_get("/1.1/lists/statuses.json").with(:query => {:owner_screen_name => "sferik", :slug => "presidents"})).to have_been_made end end + context "with a URI string passed" do + it "requests the correct resource" do + @client.list_timeline("https://twitter.com/sferik/presidents") + expect(a_get("/1.1/lists/statuses.json").with(:query => {:owner_screen_name => "sferik", :slug => "presidents"})).to have_been_made + end + end context "with URI objects passed" do it "requests the correct resource" do user = URI.parse("https://twitter.com/sferik") @@ -52,6 +58,12 @@ expect(a_get("/1.1/lists/statuses.json").with(:query => {:owner_screen_name => "sferik", :slug => "presidents"})).to have_been_made end end + context "with URI strings passed" do + it "requests the correct resource" do + @client.list_timeline("https://twitter.com/sferik", "https://twitter.com/sferik/presidents") + expect(a_get("/1.1/lists/statuses.json").with(:query => {:owner_screen_name => "sferik", :slug => "presidents"})).to have_been_made + end + end end context "without a screen name passed" do before do diff --git a/spec/twitter/api/users_spec.rb b/spec/twitter/api/users_spec.rb index 71de071f0..32c481bd4 100644 --- a/spec/twitter/api/users_spec.rb +++ b/spec/twitter/api/users_spec.rb @@ -328,6 +328,12 @@ expect(a_post("/1.1/users/lookup.json").with(:body => {:screen_name => "sferik,pengwynn"})).to have_been_made end end + context "with URI strings passed" do + it "requests the correct resource" do + @client.users("https://twitter.com/sferik", "https://twitter.com/pengwynn") + expect(a_post("/1.1/users/lookup.json").with(:body => {:screen_name => "sferik,pengwynn"})).to have_been_made + end + end end context "with numeric screen names passed" do before do @@ -391,6 +397,12 @@ expect(a_get("/1.1/users/lookup.json").with(:query => {:screen_name => "sferik,pengwynn"})).to have_been_made end end + context "with URI objects passed" do + it "requests the correct resource" do + @client.users("https://twitter.com/sferik", "https://twitter.com/pengwynn", :method => :get) + expect(a_get("/1.1/users/lookup.json").with(:query => {:screen_name => "sferik,pengwynn"})).to have_been_made + end + end end context "with numeric screen names passed" do before do