Class: Amazon::AWS::Operation
- Inherits:
-
Object
- Object
- Amazon::AWS::Operation
- Defined in:
- lib/amazon/aws.rb
Overview
This is the base class of all AWS operations.
Direct Known Subclasses
BrowseNodeLookup, CustomerContentLookup, CustomerContentSearch, Help, ItemLookup, ItemSearch, ListLookup, ListSearch, MultipleOperation, SellerListingSearch, SellerLookup, ShoppingCart::CartClear, ShoppingCart::CartCreate, ShoppingCart::CartGet, SimilarityLookup, TagLookup, TransactionLookup, VehiclePartLookup, VehiclePartSearch, VehicleSearch
Constant Summary collapse
- OPERATIONS =
These are the types of AWS operation currently implemented by Ruby/AWS.
%w[ BrowseNodeLookup CustomerContentLookup CustomerContentSearch Help ItemLookup ItemSearch ListLookup ListSearch SellerListingLookup SellerListingSearch SellerLookup SimilarityLookup TagLookup TransactionLookup VehiclePartLookup VehiclePartSearch VehicleSearch CartAdd CartClear CartCreate CartGet CartModify ]
Instance Attribute Summary collapse
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#params ⇒ Object
Returns the value of attribute params.
Instance Method Summary collapse
-
#batch(*operations) ⇒ Object
Group together operations of the same class in a batch request.
-
#batch_parameters(params, *b_params) ⇒ Object
Convert parameters to batch format, e.g.
-
#initialize(parameters) ⇒ Operation
constructor
A new instance of Operation.
Constructor Details
#initialize(parameters) ⇒ Operation
Returns a new instance of Operation.
579 580 581 582 583 584 585 586 587 588 589 |
# File 'lib/amazon/aws.rb', line 579 def initialize(parameters) op_kind = self.class.to_s.sub( /^.*::/, '' ) unless OPERATIONS.include?( op_kind ) || op_kind == 'MultipleOperation' raise "Bad operation: #{op_kind}" end #raise 'Too many parameters' if parameters.size > 10 @kind = op_kind @params = { 'Operation' => op_kind }.merge( parameters ) end |
Instance Attribute Details
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
576 577 578 |
# File 'lib/amazon/aws.rb', line 576 def kind @kind end |
#params ⇒ Object
Returns the value of attribute params.
577 578 579 |
# File 'lib/amazon/aws.rb', line 577 def params @params end |
Instance Method Details
#batch(*operations) ⇒ Object
Group together operations of the same class in a batch request. operations should be either an operation of the same class as self or an array of such operations.
If you need to batch operations from different classes, use a MultipleOperation instead.
Example:
is = ItemSearch.new( 'Books', { 'Title' => 'ruby programming' } )
is2 = ItemSearch.new( 'Music', { 'Artist' => 'stranglers' } )
is.batch( is2 )
Please see MultipleOperation.new for details of a couple of restrictions that also apply to batched operations.
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 |
# File 'lib/amazon/aws.rb', line 608 def batch(*operations) # Remove the Operation parameter to avoid batch syntax being applied. # We'll readd it at the end. # op_type = @params.delete( 'Operation' ) operations.flatten.each do |op| unless self.class == op.class raise BatchError, "You can't batch different classes of operation. Use class MultipleOperation." end # Remove the Operation parameter. # op.params.delete( 'Operation' ) # Apply batch syntax. # @params = batch_parameters( @params, op.params ) end # Reinstate the Operation parameter. # @params.merge!( { 'Operation' => op_type } ) end |
#batch_parameters(params, *b_params) ⇒ Object
Convert parameters to batch format, e.g. ItemSearch.1.Title.
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 |
# File 'lib/amazon/aws.rb', line 638 def batch_parameters(params, *b_params) # :nodoc: @index ||= 1 unless b_params.empty? op_str = self.class.to_s.sub( /^.+::/, '' ) # Fudge the operation string if we're dealing with a shopping cart. # op_str = 'Item' if op_str =~ /^Cart/ all_parameters = [ params ].concat( b_params ) params = {} all_parameters.each_with_index do |hash, index| # Don't batch an already batched hash. # if ! hash.empty? && hash.to_a[0][0] =~ /^.+\..+\..+$/ params = hash next end hash.each do |tag, val| shared_param = '%s.%d.%s' % [ op_str, @index + index, tag ] params[shared_param] = val end end @index += b_params.size end params end |