Skip to content

Commit aa7a254

Browse files
committed
Allow options when executing batch requests (googleapis#48)
1 parent 794c6a9 commit aa7a254

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

lib/google/api_client.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -542,10 +542,9 @@ def generate_request(options={})
542542
#
543543
# @see Google::APIClient#generate_request
544544
def execute(*params)
545-
if params.last.kind_of?(Google::APIClient::Request) &&
546-
params.size == 1
547-
request = params.pop
548-
options = {}
545+
if params.first.kind_of?(Google::APIClient::Request)
546+
request = params.shift
547+
options = params.shift || {}
549548
else
550549
# This block of code allows us to accept multiple parameter passing
551550
# styles, and maintaining some backwards compatibility.

spec/google/api_client_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,21 @@
143143
)
144144
end
145145

146+
it 'should accept options with batch/request style execute' do
147+
client.authorization.access_token = "abcdef"
148+
new_auth = Signet::OAuth2::Client.new(:access_token => '12345')
149+
request = client.generate_request(
150+
:api_method => @prediction.training.insert,
151+
:parameters => {'data' => '12345'}
152+
)
153+
client.execute(
154+
request,
155+
:authorization => new_auth,
156+
:connection => @connection
157+
)
158+
end
159+
160+
146161
it 'should accept options in array style execute' do
147162
client.authorization.access_token = "abcdef"
148163
new_auth = Signet::OAuth2::Client.new(:access_token => '12345')

0 commit comments

Comments
 (0)