Class: Amazon::AWS::MultipleOperation
- Defined in:
- lib/amazon/aws.rb
Overview
This class can be used to merge multiple operations into a single operation for greater efficiency.
Constant Summary
Constants inherited from Operation
Instance Attribute Summary
Attributes inherited from Operation
#kind, #params, #response_group
Instance Method Summary collapse
-
#initialize(operation1, operation2) ⇒ MultipleOperation
constructor
This allows you to take two Operation objects and combine them to form a single object, which can then be used to perform a single request to AWS.
Methods inherited from Operation
Constructor Details
#initialize(operation1, operation2) ⇒ MultipleOperation
This allows you to take two Operation objects and combine them to form a single object, which can then be used to perform 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.
operation1 and operation2 are both objects from a subclass of Operation, such as ItemSearch, ItemLookup, etc.
Please note the following implementation details:
-
If you use the response_group parameter of Search::Request#search to pass the list of response groups, it will apply to both operations.
If you want to use a different response group set for each operation, you should assign the relevant groups to the @response_group attribute of each Operation object. You must do this before you instantiate the MultipleOperation.
-
One or both operations may have multiple results pages available, but only the first page is returned. If you need the subsequent pages, perform the operations separately, not as part of a multiple operation.
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 )
As you can see, the operations that are combined as a MultipleOperation do not have to belong to the same class. In the above example, we compose a multiple operation consisting of an ItemSearch and an ItemLookup.
If you want to batch operations belonging to the same class, Operation#batch provides an alternative.
824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 |
# File 'lib/amazon/aws.rb', line 824 def initialize(operation1, operation2) op_kind = [ operation1.kind, operation2.kind ].join( ',' ) # Duplicate Operation objects and remove their Operation parameter. # op1 = operation1.dup op1.params.delete( 'Operation' ) op2 = operation2.dup op2.params.delete( 'Operation' ) if op1.class == op2.class # If both operations are of the same type, we combine the parameters # of both. # b_params = op1.batch_parameters( op1.params, op2.params ) else # We have to convert the parameters to batch format. # bp1 = op1.batch_parameters( op1.params, {} ) bp2 = op2.batch_parameters( op2.params, {} ) b_params = bp1.merge( bp2 ) end params = { 'Operation' => op_kind }.merge( b_params ) super( params ) @response_group = ResponseGroup.new( [] ) @response_group.params.delete( 'ResponseGroup' ) @response_group.params = op1.batch_response_groups( op2 ) end |