#159 - Excute batch requests using the service's connection
This commit is contained in:
parent
2622ebf8dc
commit
d999033fd6
|
@ -139,14 +139,17 @@ module Google
|
||||||
# the HTTP response.
|
# the HTTP response.
|
||||||
def process_http_response(response)
|
def process_http_response(response)
|
||||||
content_type = find_header('Content-Type', response.headers)
|
content_type = find_header('Content-Type', response.headers)
|
||||||
boundary = /.*boundary=(.+)/.match(content_type)[1]
|
m = /.*boundary=(.+)/.match(content_type)
|
||||||
parts = response.body.split(/--#{Regexp.escape(boundary)}/)
|
if m
|
||||||
parts = parts[1...-1]
|
boundary = m[1]
|
||||||
parts.each do |part|
|
parts = response.body.split(/--#{Regexp.escape(boundary)}/)
|
||||||
call_response = deserialize_call_response(part)
|
parts = parts[1...-1]
|
||||||
_, call, callback = @calls.assoc(call_response.call_id)
|
parts.each do |part|
|
||||||
result = Google::APIClient::Result.new(call, call_response)
|
call_response = deserialize_call_response(part)
|
||||||
callback.call(result) if callback
|
_, call, callback = @calls.assoc(call_response.call_id)
|
||||||
|
result = Google::APIClient::Result.new(call, call_response)
|
||||||
|
callback.call(result) if callback
|
||||||
|
end
|
||||||
end
|
end
|
||||||
Google::APIClient::Result.new(self, response)
|
Google::APIClient::Result.new(self, response)
|
||||||
end
|
end
|
||||||
|
|
|
@ -225,7 +225,7 @@ module Google
|
||||||
result = @client.execute(params)
|
result = @client.execute(params)
|
||||||
return Google::APIClient::Service::Result.new(request, result)
|
return Google::APIClient::Service::Result.new(request, result)
|
||||||
elsif request.instance_of? Google::APIClient::Service::BatchRequest
|
elsif request.instance_of? Google::APIClient::Service::BatchRequest
|
||||||
@client.execute(request.base_batch)
|
@client.execute(request.base_batch, {:connection => @connection})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -493,6 +493,33 @@ RSpec.describe Google::APIClient::Service::Result do
|
||||||
end
|
end
|
||||||
|
|
||||||
RSpec.describe Google::APIClient::Service::BatchRequest do
|
RSpec.describe Google::APIClient::Service::BatchRequest do
|
||||||
|
|
||||||
|
include ConnectionHelpers
|
||||||
|
|
||||||
|
context 'with a service connection' do
|
||||||
|
before do
|
||||||
|
@conn = stub_connection do |stub|
|
||||||
|
stub.post('/batch') do |env|
|
||||||
|
[500, {'Content-Type' => 'application/json'}, '{}']
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@discovery = Google::APIClient::Service.new('discovery', 'v1',
|
||||||
|
{:application_name => APPLICATION_NAME, :authorization => nil,
|
||||||
|
:cache_store => nil, :connection => @conn})
|
||||||
|
@calls = [
|
||||||
|
@discovery.apis.get_rest(:api => 'plus', :version => 'v1'),
|
||||||
|
@discovery.apis.get_rest(:api => 'discovery', :version => 'v1')
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should use the service connection' do
|
||||||
|
batch = @discovery.batch(@calls) do
|
||||||
|
end
|
||||||
|
batch.execute
|
||||||
|
@conn.verify
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe 'with the discovery API' do
|
describe 'with the discovery API' do
|
||||||
before do
|
before do
|
||||||
@discovery = Google::APIClient::Service.new('discovery', 'v1',
|
@discovery = Google::APIClient::Service.new('discovery', 'v1',
|
||||||
|
@ -585,7 +612,7 @@ RSpec.describe Google::APIClient::Service::BatchRequest do
|
||||||
batch.execute
|
batch.execute
|
||||||
expect(call1_returned).to eq(true)
|
expect(call1_returned).to eq(true)
|
||||||
expect(call2_returned).to eq(true)
|
expect(call2_returned).to eq(true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
Loading…
Reference in New Issue