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
Constant Summary collapse
- OPERATIONS =
These are the types of AWS operation currently implemented by Ruby/AWS.
%w[ ItemSearch ]
Instance Attribute Summary collapse
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#params ⇒ Object
Returns the value of attribute params.
-
#response_group ⇒ Object
Returns the value of attribute response_group.
Instance Method Summary collapse
-
#batch(*operations) ⇒ Object
Group together operations of the same class in a batch request.
-
#initialize(parameters) ⇒ Operation
constructor
A new instance of Operation.
-
#query_parameters ⇒ Object
Return a hash of operation parameters and values, possibly converted to batch syntax, suitable for encoding in a query.
-
#response_group_orig= ⇒ Object
Sets the attribute response_group Make sure we can still get to the old @response_group= writer method.
Constructor Details
#initialize(parameters) ⇒ Operation
Returns a new instance of Operation.
611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 |
# File 'lib/amazon/aws.rb', line 611 def initialize(parameters) op_kind = self.class.to_s.sub( /^.*::/, '' ) raise "Bad operation: #{op_kind}" unless OPERATIONS.include?( op_kind ) if ResponseGroup::DEFAULT.key?( op_kind ) response_group = ResponseGroup.new( ResponseGroup::DEFAULT[op_kind] ) else response_group = nil end if op_kind =~ /^Cart/ @params = parameters else @params = Hash.new { |hash, key| hash[key] = [] } @response_group = Hash.new { |hash, key| hash[key] = [] } unless op_kind == 'MultipleOperation' @params[op_kind] = [ parameters ] @response_group[op_kind] = [ response_group ] end end @kind = op_kind end |
Instance Attribute Details
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
608 609 610 |
# File 'lib/amazon/aws.rb', line 608 def kind @kind end |
#params ⇒ Object
Returns the value of attribute params.
609 610 611 |
# File 'lib/amazon/aws.rb', line 609 def params @params end |
#response_group ⇒ Object
Returns the value of attribute response_group.
609 610 611 |
# File 'lib/amazon/aws.rb', line 609 def response_group @response_group 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 of different classes, use a MultipleOperation instead.
Example:
is = ItemSearch.new( 'Books', { 'Title' => 'ruby programming' } )
is2 = ItemSearch.new( 'Music', { 'Artist' => 'stranglers' } )
is.response_group = ResponseGroup.new( :Small )
is2.response_group = ResponseGroup.new( :Tracks )
is.batch( is2 )
Please see MultipleOperation.new for implementation details that also apply to batched operations.
674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 |
# File 'lib/amazon/aws.rb', line 674 def batch(*operations) operations.flatten.each do |op| unless self.class == op.class raise BatchError, "You can't batch operations of different classes. Use class MultipleOperation." end # Add the operation's single element array containing the parameter # hash to the array. # @params[op.kind].concat( op.params[op.kind] ) # Add the operation's response group array to the array. # @response_group[op.kind].concat( op.response_group[op.kind] ) end end |
#query_parameters ⇒ Object
Return a hash of operation parameters and values, possibly converted to batch syntax, suitable for encoding in a query.
698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 |
# File 'lib/amazon/aws.rb', line 698 def query_parameters # :nodoc: query = {} @params.each do |op_kind, ops| # If we have only one type of operation and only one operation of # that type, return that one in non-batched syntax. # if @params.size == 1 && @params[op_kind].size == 1 return { 'Operation' => op_kind, 'ResponseGroup' => @response_group[op_kind][0] }. merge( @params[op_kind][0] ) end # Otherwise, use batch syntax. # ops.each_with_index do |op, op_index| # Make sure we use a response group of some kind. # shared = '%s.%d.ResponseGroup' % [ op_kind, op_index + 1 ] query[shared] = op['ResponseGroup'] || ResponseGroup::DEFAULT[op_kind] # Add all of the parameters to the query hash. # op.each do |k, v| shared = '%s.%d.%s' % [ op_kind, op_index + 1, k ] query[shared] = v end end end # Add the operation list. # { 'Operation' => @params.keys.join( ',' ) }.merge( query ) end |
#response_group_orig= ⇒ Object
Sets the attribute response_group Make sure we can still get to the old @response_group= writer method.
642 643 644 |
# File 'lib/amazon/aws.rb', line 642 def response_group=(value) @response_group = value end |