Reputation: 2309
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.
Upvotes: 3
Views: 282
Reputation: 11672
This is a ruby issue with auto-expanding the last argument if is a hash.
Two workarounds:
params = Google::Apis::WebmastersV3::SearchAnalyticsQueryRequest.new(
start_date: "2015-01-14",
end_date: "2015-01-14"
)
AuthWebmastersService.query_search_analytics("http://www.ex.com/", params)
params = {
start_date: "2015-01-14",
end_date: "2015-01-14"
}
AuthWebmastersService.query_search_analytics("http://www.ex.com/", params, {})
Upvotes: 1
Reputation: 114178
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, {})
Upvotes: 3
Reputation: 103733
This error:
ArgumentError (unknown keywords: start_date, end_date)
is telling you that you specified the wrong keyword attributes.
Your method takes:
def query_search_analytics(site_url, search_analytics_query_request_object = nil, fields: nil, quota_user: nil, user_ip: nil, options: nil, &block)
When you call your method like you wrote:
What you need to do is to:
query_search_analytics("http://www.ex.com/", options: params)
Upvotes: 0
Reputation: 168101
Because it only takes the keyword arguments fields
, quota_user
, user_ip
, options
, and start_date
, end_date
are not among them.
Upvotes: -2