Class | Amazon::AWS::MultipleOperation |
In: |
lib/amazon/aws.rb
|
Parent: | Operation |
This class can be used to encapsulate multiple operations in a single operation for greater efficiency.
This allows you to take multiple Operation objects and encapsulate them to form a single object, which can then be used to send a single request to AWS. This allows for greater efficiency, reducing the number of requests sent to AWS.
AWS currently imposes a limit of two operations when encapsulating operations in a multiple operation. Note, however, that one or both of these operations may be a batched operation. Combining two batched operations in this way makes it possible to send as many as four simple operations to AWS in a single MultipleOperation request.
operations is an array of objects subclassed from Operation, such as ItemSearch, ItemLookup, etc.
Please note the following implementation details:
In fact, if you create a MultipleOperation encapsulating objects of the same class, Ruby/AWS will actually apply simple batch syntax to your request, so it amounts to the same as using Operation#batch.
Example:
is = ItemSearch.new( 'Books', { 'Title' => 'Ruby' } ) il = ItemLookup.new( 'ASIN', { 'ItemId' => 'B0013DZAYO', 'MerchantId' => 'Amazon' } ) is.response_group = ResponseGroup.new( :Large ) il.response_group = ResponseGroup.new( :Small ) mo = MultipleOperation.new( is, il )
# File lib/amazon/aws.rb, line 814 def initialize(*operations) # Start with an empty parameter hash. # super( {} ) # Start off with the first operation and duplicate the original's # parameters to avoid accidental in-place modification. # operations.flatten! @params = operations.shift.params.freeze.dup # Add subsequent operations' parameter hashes, protecting them # against accidental in-place modification. # operations.each do |op| op.params.freeze.each do |op_kind, op_arr| @params[op_kind].concat( op_arr ) end end end