diff --git a/lib/google/api_client/batch.rb b/lib/google/api_client/batch.rb index 1082516ad..f7b1e096b 100644 --- a/lib/google/api_client/batch.rb +++ b/lib/google/api_client/batch.rb @@ -139,14 +139,17 @@ module Google # the HTTP response. def process_http_response(response) content_type = find_header('Content-Type', response.headers) - boundary = /.*boundary=(.+)/.match(content_type)[1] - parts = response.body.split(/--#{Regexp.escape(boundary)}/) - parts = parts[1...-1] - parts.each do |part| - call_response = deserialize_call_response(part) - _, call, callback = @calls.assoc(call_response.call_id) - result = Google::APIClient::Result.new(call, call_response) - callback.call(result) if callback + m = /.*boundary=(.+)/.match(content_type) + if m + boundary = m[1] + parts = response.body.split(/--#{Regexp.escape(boundary)}/) + parts = parts[1...-1] + parts.each do |part| + call_response = deserialize_call_response(part) + _, call, callback = @calls.assoc(call_response.call_id) + result = Google::APIClient::Result.new(call, call_response) + callback.call(result) if callback + end end Google::APIClient::Result.new(self, response) end diff --git a/lib/google/api_client/service.rb b/lib/google/api_client/service.rb index 685c61780..28f2605d9 100755 --- a/lib/google/api_client/service.rb +++ b/lib/google/api_client/service.rb @@ -225,7 +225,7 @@ module Google result = @client.execute(params) return Google::APIClient::Service::Result.new(request, result) elsif request.instance_of? Google::APIClient::Service::BatchRequest - @client.execute(request.base_batch) + @client.execute(request.base_batch, {:connection => @connection}) end end end diff --git a/spec/google/api_client/service_spec.rb b/spec/google/api_client/service_spec.rb index e5184372c..a6f6925e5 100644 --- a/spec/google/api_client/service_spec.rb +++ b/spec/google/api_client/service_spec.rb @@ -493,6 +493,33 @@ RSpec.describe Google::APIClient::Service::Result do end 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 before do @discovery = Google::APIClient::Service.new('discovery', 'v1', @@ -585,7 +612,7 @@ RSpec.describe Google::APIClient::Service::BatchRequest do batch.execute expect(call1_returned).to eq(true) expect(call2_returned).to eq(true) - end + end end end end \ No newline at end of file