From aa7a254d23f202a19d3ef81d8073affc77e29b38 Mon Sep 17 00:00:00 2001 From: Steven Bazyl Date: Mon, 13 May 2013 15:19:25 -0700 Subject: [PATCH] Allow options when executing batch requests (#48) --- lib/google/api_client.rb | 7 +++---- spec/google/api_client_spec.rb | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/google/api_client.rb b/lib/google/api_client.rb index 4fa598345..1895431ec 100644 --- a/lib/google/api_client.rb +++ b/lib/google/api_client.rb @@ -542,10 +542,9 @@ module Google # # @see Google::APIClient#generate_request def execute(*params) - if params.last.kind_of?(Google::APIClient::Request) && - params.size == 1 - request = params.pop - options = {} + if params.first.kind_of?(Google::APIClient::Request) + request = params.shift + options = params.shift || {} else # This block of code allows us to accept multiple parameter passing # styles, and maintaining some backwards compatibility. diff --git a/spec/google/api_client_spec.rb b/spec/google/api_client_spec.rb index a89ab10ae..fb222cc29 100644 --- a/spec/google/api_client_spec.rb +++ b/spec/google/api_client_spec.rb @@ -143,6 +143,21 @@ describe Google::APIClient do ) end + it 'should accept options with batch/request style execute' do + client.authorization.access_token = "abcdef" + new_auth = Signet::OAuth2::Client.new(:access_token => '12345') + request = client.generate_request( + :api_method => @prediction.training.insert, + :parameters => {'data' => '12345'} + ) + client.execute( + request, + :authorization => new_auth, + :connection => @connection + ) + end + + it 'should accept options in array style execute' do client.authorization.access_token = "abcdef" new_auth = Signet::OAuth2::Client.new(:access_token => '12345')