Class: Google::APIClient::Service::BatchRequest
- Inherits:
-
Object
- Object
- Google::APIClient::Service::BatchRequest
- Defined in:
- lib/google/api_client/service/batch.rb
Instance Attribute Summary collapse
-
#base_batch ⇒ Object
readonly
Returns the value of attribute base_batch.
Instance Method Summary collapse
-
#add(call, &block) {|Google::APIClient::Service::Result| ... } ⇒ Google::APIClient::Service::BatchRequest
Add a new call to the batch request.
-
#execute ⇒ Object
Executes the batch request.
-
#initialize(service, calls, &block) {|Google::APIClient::Service::Result| ... } ⇒ BatchRequest
constructor
Creates a new batch request.
Constructor Details
#initialize(service, calls, &block) {|Google::APIClient::Service::Result| ... } ⇒ BatchRequest
Creates a new batch request. This class shouldn’t be instantiated directly, but rather through Service.batch.
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/google/api_client/service/batch.rb', line 49 def initialize(service, calls, &block) @service = service @base_batch = Google::APIClient::BatchRequest.new @global_callback = block if block_given? if calls && calls.length > 0 calls.each do |call| add(call) end end end |
Instance Attribute Details
#base_batch ⇒ Object (readonly)
Returns the value of attribute base_batch.
104 105 106 |
# File 'lib/google/api_client/service/batch.rb', line 104 def base_batch @base_batch end |
Instance Method Details
#add(call, &block) {|Google::APIClient::Service::Result| ... } ⇒ Google::APIClient::Service::BatchRequest
Add a new call to the batch request.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/google/api_client/service/batch.rb', line 74 def add(call, &block) if !block_given? && @global_callback.nil? raise BatchError, 'Request needs a block' end callback = block || @global_callback base_call = { :api_method => call.method, :parameters => call.parameters } if call.respond_to? :body if call.body.respond_to? :to_hash base_call[:body_object] = call.body else base_call[:body] = call.body end end @base_batch.add(base_call) do |base_result| result = Google::APIClient::Service::BatchedCallResult.new( call, base_result) callback.call(result) end return self end |
#execute ⇒ Object
Executes the batch request.
100 101 102 |
# File 'lib/google/api_client/service/batch.rb', line 100 def execute @service.execute(self) end |