Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use HTTP POST for users/lookup endpoint

"You are strongly encouraged to use a POST for larger requests."
https://dev.twitter.com/docs/api/1.1/get/users/lookup
  • Loading branch information...
commit ff68ff81a8586d70fa021afaed6ff261d2a4b178 1 parent e112ce6
@sferik authored
View
2  lib/twitter/api.rb
@@ -2372,7 +2372,7 @@ def suggest_users(slug, options={})
def users(*args)
options = args.extract_options!
args.flatten.each_slice(MAX_USERS_PER_REQUEST).threaded_map do |users|
- collection_from_response(Twitter::User, :get, "/1.1/users/lookup.json", options.merge_users(users))
+ collection_from_response(Twitter::User, :post, "/1.1/users/lookup.json", options.merge_users(users))
end.flatten
end
View
24 spec/twitter/api/friendships_spec.rb
@@ -251,8 +251,8 @@
stub_get("/1.1/friends/ids.json").
with(:query => {:cursor => "-1"}).
to_return(:body => fixture("id_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
- stub_get("/1.1/users/lookup.json").
- with(:query => {:screen_name => "sferik,pengwynn"}).
+ stub_post("/1.1/users/lookup.json").
+ with(:body => {:screen_name => "sferik,pengwynn"}).
to_return(:body => fixture("friendships.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_post("/1.1/friendships/create.json").
with(:body => {:user_id => "7505382", :follow => "true"}).
@@ -263,8 +263,8 @@
a_get("/1.1/friends/ids.json").
with(:query => {:cursor => "-1"}).
should have_been_made
- a_get("/1.1/users/lookup.json").
- with(:query => {:screen_name => "sferik,pengwynn"}).
+ a_post("/1.1/users/lookup.json").
+ with(:body => {:screen_name => "sferik,pengwynn"}).
should have_been_made
a_post("/1.1/friendships/create.json").
with(:body => {:user_id => "7505382", :follow => "true"}).
@@ -282,8 +282,8 @@
stub_get("/1.1/friends/ids.json").
with(:query => {:cursor => "-1"}).
to_return(:body => fixture("id_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
- stub_get("/1.1/users/lookup.json").
- with(:query => {:screen_name => "sferik,pengwynn"}).
+ stub_post("/1.1/users/lookup.json").
+ with(:body => {:screen_name => "sferik,pengwynn"}).
to_return(:body => fixture("friendships.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_post("/1.1/friendships/create.json").
with(:body => {:user_id => "7505382"}).
@@ -294,8 +294,8 @@
a_get("/1.1/friends/ids.json").
with(:query => {:cursor => "-1"}).
should have_been_made
- a_get("/1.1/users/lookup.json").
- with(:query => {:screen_name => "sferik,pengwynn"}).
+ a_post("/1.1/users/lookup.json").
+ with(:body => {:screen_name => "sferik,pengwynn"}).
should have_been_made
a_post("/1.1/friendships/create.json").
with(:body => {:user_id => "7505382"}).
@@ -313,8 +313,8 @@
stub_get("/1.1/friends/ids.json").
with(:query => {:cursor => "-1"}).
to_return(:body => fixture("id_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
- stub_get("/1.1/users/lookup.json").
- with(:query => {:screen_name => "sferik,pengwynn"}).
+ stub_post("/1.1/users/lookup.json").
+ with(:body => {:screen_name => "sferik,pengwynn"}).
to_return(:body => fixture("friendships.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_post("/1.1/friendships/create.json").
with(:body => {:user_id => "7505382"}).
@@ -325,8 +325,8 @@
a_get("/1.1/friends/ids.json").
with(:query => {:cursor => "-1"}).
should have_been_made
- a_get("/1.1/users/lookup.json").
- with(:query => {:screen_name => "sferik,pengwynn"}).
+ a_post("/1.1/users/lookup.json").
+ with(:body => {:screen_name => "sferik,pengwynn"}).
should have_been_made
a_post("/1.1/friendships/create.json").
with(:body => {:user_id => "7505382"}).
View
40 spec/twitter/api/users_spec.rb
@@ -65,14 +65,14 @@
describe "#users" do
context "with screen names passed" do
before do
- stub_get("/1.1/users/lookup.json").
- with(:query => {:screen_name => "sferik,pengwynn"}).
+ stub_post("/1.1/users/lookup.json").
+ with(:body => {:screen_name => "sferik,pengwynn"}).
to_return(:body => fixture("users.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "requests the correct resource" do
@client.users("sferik", "pengwynn")
- a_get("/1.1/users/lookup.json").
- with(:query => {:screen_name => "sferik,pengwynn"}).
+ a_post("/1.1/users/lookup.json").
+ with(:body => {:screen_name => "sferik,pengwynn"}).
should have_been_made
end
it "returns up to 100 users worth of extended information" do
@@ -84,55 +84,55 @@
end
context "with numeric screen names passed" do
before do
- stub_get("/1.1/users/lookup.json").
- with(:query => {:screen_name => "0,311"}).
+ stub_post("/1.1/users/lookup.json").
+ with(:body => {:screen_name => "0,311"}).
to_return(:body => fixture("users.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "requests the correct resource" do
@client.users("0", "311")
- a_get("/1.1/users/lookup.json").
- with(:query => {:screen_name => "0,311"}).
+ a_post("/1.1/users/lookup.json").
+ with(:body => {:screen_name => "0,311"}).
should have_been_made
end
end
context "with user IDs passed" do
before do
- stub_get("/1.1/users/lookup.json").
- with(:query => {:user_id => "7505382,14100886"}).
+ stub_post("/1.1/users/lookup.json").
+ with(:body => {:user_id => "7505382,14100886"}).
to_return(:body => fixture("users.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "requests the correct resource" do
@client.users(7505382, 14100886)
- a_get("/1.1/users/lookup.json").
- with(:query => {:user_id => "7505382,14100886"}).
+ a_post("/1.1/users/lookup.json").
+ with(:body => {:user_id => "7505382,14100886"}).
should have_been_made
end
end
context "with both screen names and user IDs passed" do
before do
- stub_get("/1.1/users/lookup.json").
- with(:query => {:screen_name => "sferik", :user_id => "14100886"}).
+ stub_post("/1.1/users/lookup.json").
+ with(:body => {:screen_name => "sferik", :user_id => "14100886"}).
to_return(:body => fixture("users.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "requests the correct resource" do
@client.users("sferik", 14100886)
- a_get("/1.1/users/lookup.json").
- with(:query => {:screen_name => "sferik", :user_id => "14100886"}).
+ a_post("/1.1/users/lookup.json").
+ with(:body => {:screen_name => "sferik", :user_id => "14100886"}).
should have_been_made
end
end
context "with user objects passed" do
before do
- stub_get("/1.1/users/lookup.json").
- with(:query => {:user_id => "7505382,14100886"}).
+ stub_post("/1.1/users/lookup.json").
+ with(:body => {:user_id => "7505382,14100886"}).
to_return(:body => fixture("users.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "requests the correct resource" do
user1 = Twitter::User.new(:id => '7505382')
user2 = Twitter::User.new(:id => '14100886')
@client.users(user1, user2)
- a_get("/1.1/users/lookup.json").
- with(:query => {:user_id => "7505382,14100886"}).
+ a_post("/1.1/users/lookup.json").
+ with(:body => {:user_id => "7505382,14100886"}).
should have_been_made
end
end
View
4 spec/twitter/error/client_error_spec.rb
@@ -26,8 +26,8 @@
context "when response status is 404 from lookup" do
before do
- stub_get("/1.1/users/lookup.json").
- with(:query => {:screen_name => "not_on_twitter"}).
+ stub_post("/1.1/users/lookup.json").
+ with(:body => {:screen_name => "not_on_twitter"}).
to_return(:status => 404, :body => fixture('no_user_matches.json'))
end
it "raises Twitter::Error::NotFound" do
Please sign in to comment.
Something went wrong with that request. Please try again.