Class: Amazon::AWS::MultipleOperation

Inherits:
Operation
  • Object
show all
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

Operation::OPERATIONS

Instance Attribute Summary

Attributes inherited from Operation

#kind, #params

Instance Method Summary collapse

Methods inherited from Operation

#batch, #batch_parameters

Constructor Details

#initialize(operation1, operation2) ⇒ MultipleOperation

This will allow 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 combined operations in a multiple operation.

operation1 and operation2 are both objects from a subclass of Operation, such as ItemSearch, ItemLookup, etc.

There are currently a few restrictions in the Ruby/AWS implementation of multiple operations:

  • ResponseGroup objects used when calling AWS::Search::Request#search apply to both operations. You cannot use a different ResponseGroup with each operation.

  • 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 MultipleOperation.

Example:

is = ItemSearch.new( 'Books', { 'Title' => 'Ruby' } )
il = ItemLookup.new( 'ASIN', { 'ItemId' => 'B0013DZAYO',

‘MerchantId’ => ‘Amazon’ } )

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.



752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
# File 'lib/amazon/aws.rb', line 752

def initialize(operation1, operation2)

	# Safeguard against changing original Operation objects in place. This
	# is to protect me, not for user code.
	#
	operation1.freeze
	operation2.freeze

	op_kind = '%s,%s' % [ operation1.kind, operation2.kind ]

	# Duplicate Operation objects and remove their Operation parameter.
	# 
	op1 = operation1.dup
	op1.params = op1.params.dup
	op1.params.delete( 'Operation' )

	op2 = operation2.dup
	op2.params = op2.params.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 )

end