Merge branch 'master' of https://github.com/sqrrrl/google-api-ruby-client into sqrrrl-master
This commit is contained in:
commit
48916bfce7
|
@ -164,10 +164,10 @@ module Google
|
||||||
batch_command.options = request_options.merge(options)
|
batch_command.options = request_options.merge(options)
|
||||||
apply_command_defaults(batch_command)
|
apply_command_defaults(batch_command)
|
||||||
begin
|
begin
|
||||||
Thread.current[:google_api_batch] = batch_command
|
start_batch(batch_command)
|
||||||
yield self
|
yield self
|
||||||
ensure
|
ensure
|
||||||
Thread.current[:google_api_batch] = nil
|
end_batch
|
||||||
end
|
end
|
||||||
batch_command.execute(client)
|
batch_command.execute(client)
|
||||||
end
|
end
|
||||||
|
@ -196,10 +196,10 @@ module Google
|
||||||
batch_command.options = request_options.merge(options)
|
batch_command.options = request_options.merge(options)
|
||||||
apply_command_defaults(batch_command)
|
apply_command_defaults(batch_command)
|
||||||
begin
|
begin
|
||||||
Thread.current[:google_api_batch] = batch_command
|
start_batch(batch_command)
|
||||||
yield self
|
yield self
|
||||||
ensure
|
ensure
|
||||||
Thread.current[:google_api_batch] = nil
|
end_batch
|
||||||
end
|
end
|
||||||
batch_command.execute(client)
|
batch_command.execute(client)
|
||||||
end
|
end
|
||||||
|
@ -347,6 +347,7 @@ module Google
|
||||||
def execute_or_queue_command(command, &callback)
|
def execute_or_queue_command(command, &callback)
|
||||||
batch_command = current_batch
|
batch_command = current_batch
|
||||||
if batch_command
|
if batch_command
|
||||||
|
fail "Can not combine services in a batch" if Thread.current[:google_api_batch_service] != self
|
||||||
batch_command.add(command, &callback)
|
batch_command.add(command, &callback)
|
||||||
nil
|
nil
|
||||||
else
|
else
|
||||||
|
@ -374,6 +375,20 @@ module Google
|
||||||
!current_batch.nil?
|
!current_batch.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Start a new thread-local batch context
|
||||||
|
# @param [Google::Apis::Core::BatchCommand] cmd
|
||||||
|
def start_batch(cmd)
|
||||||
|
fail "Batch already in progress" if batch?
|
||||||
|
Thread.current[:google_api_batch] = cmd
|
||||||
|
Thread.current[:google_api_batch_service] = self
|
||||||
|
end
|
||||||
|
|
||||||
|
# Clear thread-local batch context
|
||||||
|
def end_batch
|
||||||
|
Thread.current[:google_api_batch] = nil
|
||||||
|
Thread.current[:google_api_batch_service] = nil
|
||||||
|
end
|
||||||
|
|
||||||
# Create a new HTTP client
|
# Create a new HTTP client
|
||||||
# @return [HTTPClient]
|
# @return [HTTPClient]
|
||||||
def new_client
|
def new_client
|
||||||
|
|
|
@ -42,6 +42,7 @@ module Google
|
||||||
<% end -%>
|
<% end -%>
|
||||||
def initialize
|
def initialize
|
||||||
super('<%= api.root_url %>', '<%= api.service_path %>')
|
super('<%= api.root_url %>', '<%= api.service_path %>')
|
||||||
|
@batch_path = '<%= api.batch_path %>'
|
||||||
end
|
end
|
||||||
<% for api_method in api.all_methods -%>
|
<% for api_method in api.all_methods -%>
|
||||||
<%= indent(include('method', :api_method => api_method, :api => api), 8) -%>
|
<%= indent(include('method', :api_method => api_method, :api => api), 8) -%>
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
"basePath": "/test/",
|
"basePath": "/test/",
|
||||||
"rootUrl": "https://www.googleapis.com/",
|
"rootUrl": "https://www.googleapis.com/",
|
||||||
"servicePath": "test/v1/",
|
"servicePath": "test/v1/",
|
||||||
|
"batchPath": "batch/test/v1",
|
||||||
"rpcPath": "/rpc",
|
"rpcPath": "/rpc",
|
||||||
"auth": {
|
"auth": {
|
||||||
"oauth2": {
|
"oauth2": {
|
||||||
|
|
|
@ -196,6 +196,20 @@ EOF
|
||||||
end
|
end
|
||||||
end.to raise_error(Google::Apis::ClientError)
|
end.to raise_error(Google::Apis::ClientError)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should prevent mixing services in batch' do
|
||||||
|
expect do |b|
|
||||||
|
service.batch do |service|
|
||||||
|
command = service.send(:make_simple_command, :get, 'zoo/animals', {})
|
||||||
|
service.send(:execute_or_queue_command, command, &b)
|
||||||
|
|
||||||
|
service2 = service.dup
|
||||||
|
command2 = service.send(:make_simple_command, :get, 'zoo/animals', {})
|
||||||
|
service2.send(:execute_or_queue_command, command2, &b)
|
||||||
|
end
|
||||||
|
end.to raise_error
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with batch uploads' do
|
context 'with batch uploads' do
|
||||||
|
|
|
@ -30,6 +30,7 @@ RSpec.describe Google::Apis::Generator do
|
||||||
puts generator.dump_api_names
|
puts generator.dump_api_names
|
||||||
tempdir = Dir.mktmpdir
|
tempdir = Dir.mktmpdir
|
||||||
generated_files.each do |key, content|
|
generated_files.each do |key, content|
|
||||||
|
puts content
|
||||||
path = File.join(tempdir, key)
|
path = File.join(tempdir, key)
|
||||||
FileUtils.mkdir_p(File.dirname(path))
|
FileUtils.mkdir_p(File.dirname(path))
|
||||||
File.open(path, 'w') do |f|
|
File.open(path, 'w') do |f|
|
||||||
|
@ -47,6 +48,10 @@ RSpec.describe Google::Apis::Generator do
|
||||||
expect(service.root_url.to_s).to eql('https://www.googleapis.com/')
|
expect(service.root_url.to_s).to eql('https://www.googleapis.com/')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should set the batch path' do
|
||||||
|
expect(service.batch_path).to eql('batch/test/v1')
|
||||||
|
end
|
||||||
|
|
||||||
it 'should define global methods from discovery' do
|
it 'should define global methods from discovery' do
|
||||||
expect(service.method(:query)).to_not be_nil
|
expect(service.method(:query)).to_not be_nil
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue