0

I am using the twitter gem for ruby and need to send a POST request to users/lookup endpoint. As per the gem source code documentation(https://github.com/sferik/twitter/blob/4e8c6dce258073c4ba64f7abdcf604570043af71/lib/twitter/rest/users.rb), the request should be POST by default, unless I pass :get :

@option options [Symbol, String] :method Requests users via a GET request instead of the standard POST request if set to ':get'.

def users(*args)
    arguments = Twitter::Arguments.new(args)
    request_method = arguments.options.delete(:method) || :post
    flat_pmap(arguments.each_slice(MAX_USERS_PER_REQUEST)) do |users|
      perform_with_objects(request_method, '/1.1/users/lookup.json', merge_users(arguments.options, users), Twitter::User)
    end
  end

I am calling it as follows:

users = @client.users(twitter_screen_names_arr, [:method, :post])

However, I am not sure if this is actually resulting in a POST request / a GET request. How can I make sure if this is a POST/GET? I would like to print the request that is being made to get a clarity on what actually gets sent.

Thanks!

user_stackoverflow
  • 734
  • 2
  • 10
  • 18
  • `request.post?` or `request.get?` can be used to test if the `request` is a POST or GET request. Or you can use `request.method` to get the type of request. – maček Jul 10 '14 at 04:34

1 Answers1

1

As you can see from the code it uses POST by default. This behavior is also specified with RSpec.

You can invoke the users method like this:

@client.users(twitter_screen_names_arr, :method => :post)

or simply

@client.users(twitter_screen_names_arr)

since POST is the default request method.

If you don’t trust the code or the specs, you could run the request through a proxy to verify this behavior manually.

sferik
  • 1,795
  • 2
  • 15
  • 22
  • Thank you for the response sferik. I do trust the code, but I was not sure if I am calling it correct. Also, I was more curious to know what the request looks like. – user_stackoverflow Jul 10 '14 at 16:54