Search code examples
rubygoogle-api-clientgoogle-api-ruby-client

How to send params to a method?


I am trying to make a query to Webmaster Tool api using the Ruby Client.

params = {
  start_date: "2015-01-14",
  end_date: "2015-01-14"
}

AuthWebmastersService.query_search_analytics("http://www.ex.com/", params)

When I'm trying to make that request I get ArgumentError (unknown keywords: start_date, end_date), why is this happening?

Here is the method definition.


Solution

  • It doesn't work as expected, because Ruby converts your hash to keyword arguments, i.e.

    query_search_analytics("...", {start_date: "2015-01-14", end_date: "2015-01-14"})
    

    becomes:

    query_search_analytics("...", start_date: "2015-01-14", end_date: "2015-01-14")
    

    To get the expected result, you have to append an empty hash:

    query_search_analytics("http://www.ex.com/", params, {})