kerryb-right_aws 1.7.6 → 1.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +78 -1
 - data/Manifest.txt +3 -1
 - data/README.txt +28 -8
 - data/Rakefile +23 -7
 - data/lib/acf/right_acf_interface.rb +379 -0
 - data/lib/awsbase/right_awsbase.rb +150 -12
 - data/lib/ec2/right_ec2.rb +595 -77
 - data/lib/right_aws.rb +3 -3
 - data/lib/s3/right_s3_interface.rb +3 -3
 - data/lib/sdb/active_sdb.rb +267 -32
 - data/lib/sdb/right_sdb_interface.rb +272 -48
 - data/lib/sqs/right_sqs.rb +8 -0
 - data/lib/sqs/right_sqs_gen2.rb +8 -0
 - data/lib/sqs/right_sqs_gen2_interface.rb +17 -22
 - data/lib/sqs/right_sqs_interface.rb +7 -13
 - data/test/acf/test_helper.rb +2 -0
 - data/test/acf/test_right_acf.rb +146 -0
 - data/test/ec2/test_right_ec2.rb +32 -0
 - data/test/s3/test_right_s3.rb +41 -10
 - data/test/sdb/test_active_sdb.rb +59 -9
 - data/test/sdb/test_helper.rb +1 -0
 - data/test/sdb/test_right_sdb.rb +106 -6
 - data/test/ts_right_aws.rb +1 -0
 - metadata +30 -21
 - data/lib/awsbase/file_fix.rb +0 -33
 
| 
         @@ -33,11 +33,14 @@ module RightAws 
     | 
|
| 
       33 
33 
     | 
    
         
             
                DEFAULT_PORT      = 443
         
     | 
| 
       34 
34 
     | 
    
         
             
                DEFAULT_PROTOCOL  = 'https'
         
     | 
| 
       35 
35 
     | 
    
         
             
                API_VERSION       = '2007-11-07'
         
     | 
| 
      
 36 
     | 
    
         
            +
                DEFAULT_NIL_REPRESENTATION = 'nil'
         
     | 
| 
       36 
37 
     | 
    
         | 
| 
       37 
38 
     | 
    
         
             
                @@bench = AwsBenchmarkingBlock.new
         
     | 
| 
       38 
39 
     | 
    
         
             
                def self.bench_xml; @@bench.xml;     end
         
     | 
| 
       39 
40 
     | 
    
         
             
                def self.bench_sdb; @@bench.service; end
         
     | 
| 
       40 
41 
     | 
    
         | 
| 
      
 42 
     | 
    
         
            +
                attr_reader :last_query_expression
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
       41 
44 
     | 
    
         
             
                # Creates new RightSdb instance.
         
     | 
| 
       42 
45 
     | 
    
         
             
                #
         
     | 
| 
       43 
46 
     | 
    
         
             
                # Params:
         
     | 
| 
         @@ -46,7 +49,8 @@ module RightAws 
     | 
|
| 
       46 
49 
     | 
    
         
             
                #      :protocol     => 'https'              # Amazon service protocol: 'http' or 'https'(default)
         
     | 
| 
       47 
50 
     | 
    
         
             
                #      :signature_version => '0'             # The signature version : '0' or '1'(default)
         
     | 
| 
       48 
51 
     | 
    
         
             
                #      :multi_thread => true|false           # Multi-threaded (connection per each thread): true or false(default)
         
     | 
| 
       49 
     | 
    
         
            -
                #      :logger       => Logger Object 
     | 
| 
      
 52 
     | 
    
         
            +
                #      :logger       => Logger Object        # Logger instance: logs to STDOUT if omitted 
         
     | 
| 
      
 53 
     | 
    
         
            +
                #      :nil_representation => 'mynil'}       # interpret Ruby nil as this string value; i.e. use this string in SDB to represent Ruby nils (default is the string 'nil')
         
     | 
| 
       50 
54 
     | 
    
         
             
                #      
         
     | 
| 
       51 
55 
     | 
    
         
             
                # Example:
         
     | 
| 
       52 
56 
     | 
    
         
             
                # 
         
     | 
| 
         @@ -55,6 +59,8 @@ module RightAws 
     | 
|
| 
       55 
59 
     | 
    
         
             
                # see: http://docs.amazonwebservices.com/AmazonSimpleDB/2007-11-07/DeveloperGuide/
         
     | 
| 
       56 
60 
     | 
    
         
             
                #
         
     | 
| 
       57 
61 
     | 
    
         
             
                def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={})
         
     | 
| 
      
 62 
     | 
    
         
            +
                  @nil_rep = params[:nil_representation] ? params[:nil_representation] : DEFAULT_NIL_REPRESENTATION
         
     | 
| 
      
 63 
     | 
    
         
            +
                  params.delete(:nil_representation)
         
     | 
| 
       58 
64 
     | 
    
         
             
                  init({ :name             => 'SDB', 
         
     | 
| 
       59 
65 
     | 
    
         
             
                         :default_host     => ENV['SDB_URL'] ? URI.parse(ENV['SDB_URL']).host   : DEFAULT_HOST, 
         
     | 
| 
       60 
66 
     | 
    
         
             
                         :default_port     => ENV['SDB_URL'] ? URI.parse(ENV['SDB_URL']).port   : DEFAULT_PORT, 
         
     | 
| 
         @@ -69,38 +75,35 @@ module RightAws 
     | 
|
| 
       69 
75 
     | 
    
         
             
                #-----------------------------------------------------------------
         
     | 
| 
       70 
76 
     | 
    
         
             
                def generate_request(action, params={}) #:nodoc:
         
     | 
| 
       71 
77 
     | 
    
         
             
                  # remove empty params from request
         
     | 
| 
       72 
     | 
    
         
            -
                  params.delete_if {|key,value| value. 
     | 
| 
       73 
     | 
    
         
            -
                  params_string  = params.to_a.collect{|key,val| key + "=#{CGI::escape(val.to_s)}" }.join("&")
         
     | 
| 
      
 78 
     | 
    
         
            +
                  params.delete_if {|key,value| value.nil? }
         
     | 
| 
      
 79 
     | 
    
         
            +
                  #params_string  = params.to_a.collect{|key,val| key + "=#{CGI::escape(val.to_s)}" }.join("&")
         
     | 
| 
       74 
80 
     | 
    
         
             
                  # prepare service data
         
     | 
| 
       75 
     | 
    
         
            -
                   
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
                                  " 
     | 
| 
       78 
     | 
    
         
            -
                                  " 
     | 
| 
       79 
     | 
    
         
            -
                                  "SignatureVersion"  => signature_version }
         
     | 
| 
      
 81 
     | 
    
         
            +
                  service = '/'
         
     | 
| 
      
 82 
     | 
    
         
            +
                  service_hash = {"Action"         => action,
         
     | 
| 
      
 83 
     | 
    
         
            +
                                  "AWSAccessKeyId" => @aws_access_key_id,
         
     | 
| 
      
 84 
     | 
    
         
            +
                                  "Version"        => API_VERSION }
         
     | 
| 
       80 
85 
     | 
    
         
             
                  service_hash.update(params)
         
     | 
| 
       81 
     | 
    
         
            -
                   
     | 
| 
       82 
     | 
    
         
            -
                  string_to_sign = case signature_version
         
     | 
| 
       83 
     | 
    
         
            -
                                   when '0' : service_hash["Action"] + service_hash["Timestamp"]
         
     | 
| 
       84 
     | 
    
         
            -
                                   when '1' : service_hash.sort{|a,b| (a[0].to_s.downcase)<=>(b[0].to_s.downcase)}.to_s
         
     | 
| 
       85 
     | 
    
         
            -
                                   end
         
     | 
| 
       86 
     | 
    
         
            -
                  service_hash.update('Signature' =>  AwsUtils::sign(@aws_secret_access_key, string_to_sign))
         
     | 
| 
       87 
     | 
    
         
            -
                  service_string = service_hash.to_a.collect{|key,val| key + "=#{CGI::escape(val.to_s)}" }.join("&")
         
     | 
| 
      
 86 
     | 
    
         
            +
                  service_params = signed_service_params(@aws_secret_access_key, service_hash, :get, @params[:server], service)
         
     | 
| 
       88 
87 
     | 
    
         
             
                  #
         
     | 
| 
       89 
88 
     | 
    
         
             
                  # use POST method if the length of the query string is too large
         
     | 
| 
       90 
89 
     | 
    
         
             
                  # see http://docs.amazonwebservices.com/AmazonSimpleDB/2007-11-07/DeveloperGuide/MakingRESTRequests.html
         
     | 
| 
       91 
     | 
    
         
            -
                  if  
     | 
| 
       92 
     | 
    
         
            -
                     
     | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
      
 90 
     | 
    
         
            +
                  if service_params.size > 2000
         
     | 
| 
      
 91 
     | 
    
         
            +
                    if signature_version == '2'
         
     | 
| 
      
 92 
     | 
    
         
            +
                      # resign the request because HTTP verb is included into signature
         
     | 
| 
      
 93 
     | 
    
         
            +
                      service_params = signed_service_params(@aws_secret_access_key, service_hash, :post, @params[:server], service)
         
     | 
| 
      
 94 
     | 
    
         
            +
                    end
         
     | 
| 
      
 95 
     | 
    
         
            +
                    request      = Net::HTTP::Post.new(service)
         
     | 
| 
      
 96 
     | 
    
         
            +
                    request.body = service_params
         
     | 
| 
      
 97 
     | 
    
         
            +
                    request['Content-Type'] = 'application/x-www-form-urlencoded'
         
     | 
| 
       94 
98 
     | 
    
         
             
                  else
         
     | 
| 
       95 
     | 
    
         
            -
                     
     | 
| 
       96 
     | 
    
         
            -
                    request       = Net::HTTP::Get.new("/?#{service_string}#{params_string}")
         
     | 
| 
      
 99 
     | 
    
         
            +
                    request = Net::HTTP::Get.new("#{service}?#{service_params}")
         
     | 
| 
       97 
100 
     | 
    
         
             
                  end
         
     | 
| 
       98 
101 
     | 
    
         
             
                  # prepare output hash
         
     | 
| 
       99 
102 
     | 
    
         
             
                  { :request  => request, 
         
     | 
| 
       100 
103 
     | 
    
         
             
                    :server   => @params[:server],
         
     | 
| 
       101 
104 
     | 
    
         
             
                    :port     => @params[:port],
         
     | 
| 
       102 
105 
     | 
    
         
             
                    :protocol => @params[:protocol],
         
     | 
| 
       103 
     | 
    
         
            -
                    :proxy 
     | 
| 
      
 106 
     | 
    
         
            +
                    :proxy    => @params[:proxy] }
         
     | 
| 
       104 
107 
     | 
    
         
             
                end
         
     | 
| 
       105 
108 
     | 
    
         | 
| 
       106 
109 
     | 
    
         
             
                # Sends request to Amazon and parses the response
         
     | 
| 
         @@ -117,18 +120,20 @@ module RightAws 
     | 
|
| 
       117 
120 
     | 
    
         
             
                  result = {}
         
     | 
| 
       118 
121 
     | 
    
         
             
                  if attributes
         
     | 
| 
       119 
122 
     | 
    
         
             
                    idx = 0
         
     | 
| 
      
 123 
     | 
    
         
            +
                    skip_values = attributes.is_a?(Array)
         
     | 
| 
       120 
124 
     | 
    
         
             
                    attributes.each do |attribute, values|
         
     | 
| 
       121 
125 
     | 
    
         
             
                      # set replacement attribute
         
     | 
| 
       122 
126 
     | 
    
         
             
                      result["Attribute.#{idx}.Replace"] = 'true' if replace
         
     | 
| 
       123 
127 
     | 
    
         
             
                      # pack Name/Value
         
     | 
| 
       124 
     | 
    
         
            -
                      unless values. 
     | 
| 
       125 
     | 
    
         
            -
                        values. 
     | 
| 
      
 128 
     | 
    
         
            +
                      unless values.nil?
         
     | 
| 
      
 129 
     | 
    
         
            +
                        Array(values).each do |value|
         
     | 
| 
       126 
130 
     | 
    
         
             
                          result["Attribute.#{idx}.Name"]  = attribute
         
     | 
| 
       127 
     | 
    
         
            -
                          result["Attribute.#{idx}.Value"] = value 
         
     | 
| 
      
 131 
     | 
    
         
            +
                          result["Attribute.#{idx}.Value"] = ruby_to_sdb(value) unless skip_values
         
     | 
| 
       128 
132 
     | 
    
         
             
                          idx += 1
         
     | 
| 
       129 
133 
     | 
    
         
             
                        end
         
     | 
| 
       130 
134 
     | 
    
         
             
                      else
         
     | 
| 
       131 
135 
     | 
    
         
             
                        result["Attribute.#{idx}.Name"] = attribute
         
     | 
| 
      
 136 
     | 
    
         
            +
                        result["Attribute.#{idx}.Value"] = ruby_to_sdb(nil) unless skip_values
         
     | 
| 
       132 
137 
     | 
    
         
             
                        idx += 1
         
     | 
| 
       133 
138 
     | 
    
         
             
                      end
         
     | 
| 
       134 
139 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -145,22 +150,55 @@ module RightAws 
     | 
|
| 
       145 
150 
     | 
    
         
             
                  %Q{'#{value.to_s.gsub(/(['\\])/){ "\\#{$1}" }}'} if value
         
     | 
| 
       146 
151 
     | 
    
         
             
                end
         
     | 
| 
       147 
152 
     | 
    
         | 
| 
      
 153 
     | 
    
         
            +
                # Convert a Ruby language value to a SDB value by replacing Ruby nil with the user's chosen string representation of nil.
         
     | 
| 
      
 154 
     | 
    
         
            +
                # Non-nil values are unaffected by this filter.
         
     | 
| 
      
 155 
     | 
    
         
            +
                def ruby_to_sdb(value)
         
     | 
| 
      
 156 
     | 
    
         
            +
                  value.nil? ? @nil_rep : value
         
     | 
| 
      
 157 
     | 
    
         
            +
                end
         
     | 
| 
      
 158 
     | 
    
         
            +
                
         
     | 
| 
      
 159 
     | 
    
         
            +
                # Convert a SDB value to a Ruby language value by replacing the user's chosen string representation of nil with Ruby nil.
         
     | 
| 
      
 160 
     | 
    
         
            +
                # Values are unaffected by this filter unless they match the nil representation exactly.
         
     | 
| 
      
 161 
     | 
    
         
            +
                def sdb_to_ruby(value)
         
     | 
| 
      
 162 
     | 
    
         
            +
                  value.eql?(@nil_rep) ? nil : value
         
     | 
| 
      
 163 
     | 
    
         
            +
                end
         
     | 
| 
      
 164 
     | 
    
         
            +
             
     | 
| 
      
 165 
     | 
    
         
            +
                # Convert select and query_with_attributes responses to a Ruby language values by replacing the user's chosen string representation of nil with Ruby nil.
         
     | 
| 
      
 166 
     | 
    
         
            +
                # (This method affects on a passed response value)
         
     | 
| 
      
 167 
     | 
    
         
            +
                def select_response_to_ruby(response) #:nodoc:
         
     | 
| 
      
 168 
     | 
    
         
            +
                  response[:items].each_with_index do |item, idx|
         
     | 
| 
      
 169 
     | 
    
         
            +
                    item.each do |key, attributes|
         
     | 
| 
      
 170 
     | 
    
         
            +
                      attributes.each do |name, values|
         
     | 
| 
      
 171 
     | 
    
         
            +
                        values.collect! { |value| sdb_to_ruby(value) }
         
     | 
| 
      
 172 
     | 
    
         
            +
                      end
         
     | 
| 
      
 173 
     | 
    
         
            +
                    end
         
     | 
| 
      
 174 
     | 
    
         
            +
                  end
         
     | 
| 
      
 175 
     | 
    
         
            +
                  response
         
     | 
| 
      
 176 
     | 
    
         
            +
                end
         
     | 
| 
      
 177 
     | 
    
         
            +
             
     | 
| 
       148 
178 
     | 
    
         
             
                # Create query expression from an array.
         
     | 
| 
       149 
179 
     | 
    
         
             
                # (similar to ActiveRecord::Base#find using :conditions => ['query', param1, .., paramN])
         
     | 
| 
       150 
180 
     | 
    
         
             
                #
         
     | 
| 
       151 
181 
     | 
    
         
             
                def query_expression_from_array(params) #:nodoc:
         
     | 
| 
       152 
     | 
    
         
            -
                   
     | 
| 
       153 
     | 
    
         
            -
             
     | 
| 
       154 
     | 
    
         
            -
             
     | 
| 
       155 
     | 
    
         
            -
             
     | 
| 
       156 
     | 
    
         
            -
             
     | 
| 
       157 
     | 
    
         
            -
             
     | 
| 
       158 
     | 
    
         
            -
             
     | 
| 
       159 
     | 
    
         
            -
                      end
         
     | 
| 
      
 182 
     | 
    
         
            +
                  return '' if params.blank?
         
     | 
| 
      
 183 
     | 
    
         
            +
                  query = params.shift.to_s
         
     | 
| 
      
 184 
     | 
    
         
            +
                  query.gsub(/(\\)?(\?)/) do
         
     | 
| 
      
 185 
     | 
    
         
            +
                    if $1 # if escaped '\?' is found - replace it by '?' without backslash
         
     | 
| 
      
 186 
     | 
    
         
            +
                      "?"
         
     | 
| 
      
 187 
     | 
    
         
            +
                    else  # well, if no backslash precedes '?' then replace it by next param from the list
         
     | 
| 
      
 188 
     | 
    
         
            +
                      escape(params.shift)
         
     | 
| 
       160 
189 
     | 
    
         
             
                    end
         
     | 
| 
       161 
190 
     | 
    
         
             
                  end
         
     | 
| 
       162 
191 
     | 
    
         
             
                end
         
     | 
| 
       163 
     | 
    
         
            -
             
     | 
| 
      
 192 
     | 
    
         
            +
             
     | 
| 
      
 193 
     | 
    
         
            +
                def query_expression_from_hash(hash)
         
     | 
| 
      
 194 
     | 
    
         
            +
                  return '' if hash.blank?
         
     | 
| 
      
 195 
     | 
    
         
            +
                  expression = []
         
     | 
| 
      
 196 
     | 
    
         
            +
                  hash.each do |key, value|
         
     | 
| 
      
 197 
     | 
    
         
            +
                    expression << "#{key}=#{escape(value)}"
         
     | 
| 
      
 198 
     | 
    
         
            +
                  end
         
     | 
| 
      
 199 
     | 
    
         
            +
                  expression.join(' AND ')
         
     | 
| 
      
 200 
     | 
    
         
            +
                end
         
     | 
| 
      
 201 
     | 
    
         
            +
             
     | 
| 
       164 
202 
     | 
    
         
             
                # Retrieve a list of SDB domains from Amazon.
         
     | 
| 
       165 
203 
     | 
    
         
             
                # 
         
     | 
| 
       166 
204 
     | 
    
         
             
                # Returns a hash:
         
     | 
| 
         @@ -325,7 +363,11 @@ module RightAws 
     | 
|
| 
       325 
363 
     | 
    
         
             
                  link = generate_request("GetAttributes", 'DomainName'    => domain_name,
         
     | 
| 
       326 
364 
     | 
    
         
             
                                                           'ItemName'      => item_name,
         
     | 
| 
       327 
365 
     | 
    
         
             
                                                           'AttributeName' => attribute_name )
         
     | 
| 
       328 
     | 
    
         
            -
                  request_info(link, QSdbGetAttributesParser.new)
         
     | 
| 
      
 366 
     | 
    
         
            +
                  res = request_info(link, QSdbGetAttributesParser.new)
         
     | 
| 
      
 367 
     | 
    
         
            +
                  res[:attributes].each_value do |values|
         
     | 
| 
      
 368 
     | 
    
         
            +
                    values.collect! { |e| sdb_to_ruby(e) }
         
     | 
| 
      
 369 
     | 
    
         
            +
                  end
         
     | 
| 
      
 370 
     | 
    
         
            +
                  res
         
     | 
| 
       329 
371 
     | 
    
         
             
                rescue Exception
         
     | 
| 
       330 
372 
     | 
    
         
             
                  on_exception
         
     | 
| 
       331 
373 
     | 
    
         
             
                end
         
     | 
| 
         @@ -386,10 +428,15 @@ module RightAws 
     | 
|
| 
       386 
428 
     | 
    
         
             
                #   query = [ "['cat'=?] union ['dog'=?]", "clew", "Jon's boot" ]
         
     | 
| 
       387 
429 
     | 
    
         
             
                #   sdb.query('family', query)
         
     | 
| 
       388 
430 
     | 
    
         
             
                #
         
     | 
| 
      
 431 
     | 
    
         
            +
                #   query = [ "['cat'=?] union ['dog'=?] sort 'cat' desc", "clew", "Jon's boot" ]
         
     | 
| 
      
 432 
     | 
    
         
            +
                #   sdb.query('family', query)
         
     | 
| 
      
 433 
     | 
    
         
            +
                #
         
     | 
| 
       389 
434 
     | 
    
         
             
                # see: http://docs.amazonwebservices.com/AmazonSimpleDB/2007-11-07/DeveloperGuide/SDB_API_Query.html
         
     | 
| 
      
 435 
     | 
    
         
            +
                #      http://docs.amazonwebservices.com/AmazonSimpleDB/2007-11-07/DeveloperGuide/index.html?SortingData.html
         
     | 
| 
       390 
436 
     | 
    
         
             
                #
         
     | 
| 
       391 
437 
     | 
    
         
             
                def query(domain_name, query_expression = nil, max_number_of_items = nil, next_token = nil)
         
     | 
| 
       392 
438 
     | 
    
         
             
                  query_expression = query_expression_from_array(query_expression) if query_expression.is_a?(Array)
         
     | 
| 
      
 439 
     | 
    
         
            +
                  @last_query_expression = query_expression
         
     | 
| 
       393 
440 
     | 
    
         
             
                  #
         
     | 
| 
       394 
441 
     | 
    
         
             
                  request_params = { 'DomainName'       => domain_name,
         
     | 
| 
       395 
442 
     | 
    
         
             
                                     'QueryExpression'  => query_expression,
         
     | 
| 
         @@ -412,6 +459,137 @@ module RightAws 
     | 
|
| 
       412 
459 
     | 
    
         
             
                  on_exception
         
     | 
| 
       413 
460 
     | 
    
         
             
                end
         
     | 
| 
       414 
461 
     | 
    
         | 
| 
      
 462 
     | 
    
         
            +
                # Perform a query and fetch specified attributes.
         
     | 
| 
      
 463 
     | 
    
         
            +
                # If attributes are not specified then fetches the whole list of attributes.
         
     | 
| 
      
 464 
     | 
    
         
            +
                #
         
     | 
| 
      
 465 
     | 
    
         
            +
                #
         
     | 
| 
      
 466 
     | 
    
         
            +
                # Returns a hash:
         
     | 
| 
      
 467 
     | 
    
         
            +
                #   { :box_usage  => string,
         
     | 
| 
      
 468 
     | 
    
         
            +
                #     :request_id => string,
         
     | 
| 
      
 469 
     | 
    
         
            +
                #     :next_token => string,
         
     | 
| 
      
 470 
     | 
    
         
            +
                #     :items      => [ { ItemName1 => { attribute1 => value1, ...  attributeM => valueM } },
         
     | 
| 
      
 471 
     | 
    
         
            +
                #                      { ItemName2 => {...}}, ... ]
         
     | 
| 
      
 472 
     | 
    
         
            +
                #
         
     | 
| 
      
 473 
     | 
    
         
            +
                # Example:
         
     | 
| 
      
 474 
     | 
    
         
            +
                #
         
     | 
| 
      
 475 
     | 
    
         
            +
                #   sdb.query_with_attributes(domain, ['hobby', 'country'], "['gender'='female'] intersection ['name' starts-with ''] sort 'name'") #=>
         
     | 
| 
      
 476 
     | 
    
         
            +
                #     { :request_id => "06057228-70d0-4487-89fb-fd9c028580d3",
         
     | 
| 
      
 477 
     | 
    
         
            +
                #       :items =>
         
     | 
| 
      
 478 
     | 
    
         
            +
                #         [ { "035f1ba8-dbd8-11dd-80bd-001bfc466dd7"=>
         
     | 
| 
      
 479 
     | 
    
         
            +
                #             { "hobby"   => ["cooking", "flowers", "cats"],
         
     | 
| 
      
 480 
     | 
    
         
            +
                #               "country" => ["Russia"]}},
         
     | 
| 
      
 481 
     | 
    
         
            +
                #           { "0327614a-dbd8-11dd-80bd-001bfc466dd7"=>
         
     | 
| 
      
 482 
     | 
    
         
            +
                #             { "hobby"   => ["patchwork", "bundle jumping"],
         
     | 
| 
      
 483 
     | 
    
         
            +
                #               "country" => ["USA"]}}, ... ],
         
     | 
| 
      
 484 
     | 
    
         
            +
                #        :box_usage=>"0.0000504786"}
         
     | 
| 
      
 485 
     | 
    
         
            +
                #
         
     | 
| 
      
 486 
     | 
    
         
            +
                #   sdb.query_with_attributes(domain, [], "['gender'='female'] intersection ['name' starts-with ''] sort 'name'") #=>
         
     | 
| 
      
 487 
     | 
    
         
            +
                #     { :request_id => "75bb19db-a529-4f69-b86f-5e3800f79a45",
         
     | 
| 
      
 488 
     | 
    
         
            +
                #       :items =>
         
     | 
| 
      
 489 
     | 
    
         
            +
                #       [ { "035f1ba8-dbd8-11dd-80bd-001bfc466dd7"=>
         
     | 
| 
      
 490 
     | 
    
         
            +
                #           { "hobby"   => ["cooking", "flowers", "cats"],
         
     | 
| 
      
 491 
     | 
    
         
            +
                #             "name"    => ["Mary"],
         
     | 
| 
      
 492 
     | 
    
         
            +
                #             "country" => ["Russia"],
         
     | 
| 
      
 493 
     | 
    
         
            +
                #             "gender"  => ["female"],
         
     | 
| 
      
 494 
     | 
    
         
            +
                #             "id"      => ["035f1ba8-dbd8-11dd-80bd-001bfc466dd7"]}},
         
     | 
| 
      
 495 
     | 
    
         
            +
                #         { "0327614a-dbd8-11dd-80bd-001bfc466dd7"=>
         
     | 
| 
      
 496 
     | 
    
         
            +
                #           { "hobby"   => ["patchwork", "bundle jumping"],
         
     | 
| 
      
 497 
     | 
    
         
            +
                #             "name"    => ["Mary"],
         
     | 
| 
      
 498 
     | 
    
         
            +
                #             "country" => ["USA"],
         
     | 
| 
      
 499 
     | 
    
         
            +
                #             "gender"  => ["female"],
         
     | 
| 
      
 500 
     | 
    
         
            +
                #             "id"      => ["0327614a-dbd8-11dd-80bd-001bfc466dd7"]}}, ... ],
         
     | 
| 
      
 501 
     | 
    
         
            +
                #      :box_usage=>"0.0000506668"}
         
     | 
| 
      
 502 
     | 
    
         
            +
                #
         
     | 
| 
      
 503 
     | 
    
         
            +
                # see: http://docs.amazonwebservices.com/AmazonSimpleDB/2007-11-07/DeveloperGuide/index.html?SDB_API_QueryWithAttributes.html
         
     | 
| 
      
 504 
     | 
    
         
            +
                #
         
     | 
| 
      
 505 
     | 
    
         
            +
                def query_with_attributes(domain_name, attributes=[], query_expression = nil, max_number_of_items = nil, next_token = nil)
         
     | 
| 
      
 506 
     | 
    
         
            +
                  attributes = attributes.to_a
         
     | 
| 
      
 507 
     | 
    
         
            +
                  query_expression = query_expression_from_array(query_expression) if query_expression.is_a?(Array)
         
     | 
| 
      
 508 
     | 
    
         
            +
                  @last_query_expression = query_expression
         
     | 
| 
      
 509 
     | 
    
         
            +
                  #
         
     | 
| 
      
 510 
     | 
    
         
            +
                  request_params = { 'DomainName'       => domain_name,
         
     | 
| 
      
 511 
     | 
    
         
            +
                                     'QueryExpression'  => query_expression,
         
     | 
| 
      
 512 
     | 
    
         
            +
                                     'MaxNumberOfItems' => max_number_of_items,
         
     | 
| 
      
 513 
     | 
    
         
            +
                                     'NextToken'        => next_token }
         
     | 
| 
      
 514 
     | 
    
         
            +
                  attributes.each_with_index do |attribute, idx|
         
     | 
| 
      
 515 
     | 
    
         
            +
                    request_params["AttributeName.#{idx+1}"] = attribute
         
     | 
| 
      
 516 
     | 
    
         
            +
                  end
         
     | 
| 
      
 517 
     | 
    
         
            +
                  link   = generate_request("QueryWithAttributes", request_params)
         
     | 
| 
      
 518 
     | 
    
         
            +
                  result = select_response_to_ruby(request_info( link, QSdbQueryWithAttributesParser.new ))
         
     | 
| 
      
 519 
     | 
    
         
            +
                  # return result if no block given
         
     | 
| 
      
 520 
     | 
    
         
            +
                  return result unless block_given?
         
     | 
| 
      
 521 
     | 
    
         
            +
                  # loop if block if given
         
     | 
| 
      
 522 
     | 
    
         
            +
                  begin
         
     | 
| 
      
 523 
     | 
    
         
            +
                    # the block must return true if it wanna continue
         
     | 
| 
      
 524 
     | 
    
         
            +
                    break unless yield(result) && result[:next_token]
         
     | 
| 
      
 525 
     | 
    
         
            +
                    # make new request
         
     | 
| 
      
 526 
     | 
    
         
            +
                    request_params['NextToken'] = result[:next_token]
         
     | 
| 
      
 527 
     | 
    
         
            +
                    link   = generate_request("QueryWithAttributes", request_params)
         
     | 
| 
      
 528 
     | 
    
         
            +
                    result = select_response_to_ruby(request_info( link, QSdbQueryWithAttributesParser.new ))
         
     | 
| 
      
 529 
     | 
    
         
            +
                  end while true
         
     | 
| 
      
 530 
     | 
    
         
            +
                rescue Exception
         
     | 
| 
      
 531 
     | 
    
         
            +
                  on_exception
         
     | 
| 
      
 532 
     | 
    
         
            +
                end
         
     | 
| 
      
 533 
     | 
    
         
            +
             
     | 
| 
      
 534 
     | 
    
         
            +
                # Perform SQL-like select and fetch attributes.
         
     | 
| 
      
 535 
     | 
    
         
            +
                # Attribute values must be quoted with a single or double quote. If a quote appears within the attribute value, it must be escaped with the same quote symbol as shown in the following example.
         
     | 
| 
      
 536 
     | 
    
         
            +
                # (Use array to pass select_expression params to avoid manual escaping).
         
     | 
| 
      
 537 
     | 
    
         
            +
                #
         
     | 
| 
      
 538 
     | 
    
         
            +
                #  sdb.select(["select * from my_domain where gender=?", 'female']) #=>
         
     | 
| 
      
 539 
     | 
    
         
            +
                #    {:request_id =>"8241b843-0fb9-4d66-9100-effae12249ec",
         
     | 
| 
      
 540 
     | 
    
         
            +
                #     :items =>
         
     | 
| 
      
 541 
     | 
    
         
            +
                #      [ { "035f1ba8-dbd8-11dd-80bd-001bfc466dd7"=>
         
     | 
| 
      
 542 
     | 
    
         
            +
                #          {"hobby"   => ["cooking", "flowers", "cats"],
         
     | 
| 
      
 543 
     | 
    
         
            +
                #           "name"    => ["Mary"],
         
     | 
| 
      
 544 
     | 
    
         
            +
                #           "country" => ["Russia"],
         
     | 
| 
      
 545 
     | 
    
         
            +
                #           "gender"  => ["female"],
         
     | 
| 
      
 546 
     | 
    
         
            +
                #           "id"      => ["035f1ba8-dbd8-11dd-80bd-001bfc466dd7"]}},
         
     | 
| 
      
 547 
     | 
    
         
            +
                #        { "0327614a-dbd8-11dd-80bd-001bfc466dd7"=>
         
     | 
| 
      
 548 
     | 
    
         
            +
                #          {"hobby"   => ["patchwork", "bundle jumping"],
         
     | 
| 
      
 549 
     | 
    
         
            +
                #           "name"    => ["Mary"],
         
     | 
| 
      
 550 
     | 
    
         
            +
                #           "country" => ["USA"],
         
     | 
| 
      
 551 
     | 
    
         
            +
                #           "gender"  => ["female"],
         
     | 
| 
      
 552 
     | 
    
         
            +
                #           "id"      => ["0327614a-dbd8-11dd-80bd-001bfc466dd7"]}}, ... ]
         
     | 
| 
      
 553 
     | 
    
         
            +
                #     :box_usage =>"0.0000506197"}
         
     | 
| 
      
 554 
     | 
    
         
            +
                #
         
     | 
| 
      
 555 
     | 
    
         
            +
                #   sdb.select('select country, name from my_domain') #=>
         
     | 
| 
      
 556 
     | 
    
         
            +
                #    {:request_id=>"b1600198-c317-413f-a8dc-4e7f864a940a",
         
     | 
| 
      
 557 
     | 
    
         
            +
                #     :items=>
         
     | 
| 
      
 558 
     | 
    
         
            +
                #      [ { "035f1ba8-dbd8-11dd-80bd-001bfc466dd7"=> {"name"=>["Mary"],     "country"=>["Russia"]} },
         
     | 
| 
      
 559 
     | 
    
         
            +
                #        { "376d2e00-75b0-11dd-9557-001bfc466dd7"=> {"name"=>["Putin"],    "country"=>["Russia"]} },
         
     | 
| 
      
 560 
     | 
    
         
            +
                #        { "0327614a-dbd8-11dd-80bd-001bfc466dd7"=> {"name"=>["Mary"],     "country"=>["USA"]}    },
         
     | 
| 
      
 561 
     | 
    
         
            +
                #        { "372ebbd4-75b0-11dd-9557-001bfc466dd7"=> {"name"=>["Bush"],     "country"=>["USA"]}    },
         
     | 
| 
      
 562 
     | 
    
         
            +
                #        { "37a4e552-75b0-11dd-9557-001bfc466dd7"=> {"name"=>["Medvedev"], "country"=>["Russia"]} },
         
     | 
| 
      
 563 
     | 
    
         
            +
                #        { "38278dfe-75b0-11dd-9557-001bfc466dd7"=> {"name"=>["Mary"],     "country"=>["Russia"]} },
         
     | 
| 
      
 564 
     | 
    
         
            +
                #        { "37df6c36-75b0-11dd-9557-001bfc466dd7"=> {"name"=>["Mary"],     "country"=>["USA"]}    } ],
         
     | 
| 
      
 565 
     | 
    
         
            +
                #     :box_usage=>"0.0000777663"}
         
     | 
| 
      
 566 
     | 
    
         
            +
                #
         
     | 
| 
      
 567 
     | 
    
         
            +
                # see: http://docs.amazonwebservices.com/AmazonSimpleDB/2007-11-07/DeveloperGuide/index.html?SDB_API_Select.html
         
     | 
| 
      
 568 
     | 
    
         
            +
                #      http://docs.amazonwebservices.com/AmazonSimpleDB/2007-11-07/DeveloperGuide/index.html?UsingSelect.html
         
     | 
| 
      
 569 
     | 
    
         
            +
                #      http://docs.amazonwebservices.com/AmazonSimpleDB/2007-11-07/DeveloperGuide/index.html?SDBLimits.html
         
     | 
| 
      
 570 
     | 
    
         
            +
                #
         
     | 
| 
      
 571 
     | 
    
         
            +
                def select(select_expression, next_token = nil)
         
     | 
| 
      
 572 
     | 
    
         
            +
                  select_expression      = query_expression_from_array(select_expression) if select_expression.is_a?(Array)
         
     | 
| 
      
 573 
     | 
    
         
            +
                  @last_query_expression = select_expression
         
     | 
| 
      
 574 
     | 
    
         
            +
                  #
         
     | 
| 
      
 575 
     | 
    
         
            +
                  request_params = { 'SelectExpression' => select_expression,
         
     | 
| 
      
 576 
     | 
    
         
            +
                                     'NextToken'        => next_token }
         
     | 
| 
      
 577 
     | 
    
         
            +
                  link   = generate_request("Select", request_params)
         
     | 
| 
      
 578 
     | 
    
         
            +
                  result = select_response_to_ruby(request_info( link, QSdbSelectParser.new ))
         
     | 
| 
      
 579 
     | 
    
         
            +
                  return result unless block_given?
         
     | 
| 
      
 580 
     | 
    
         
            +
                  # loop if block if given
         
     | 
| 
      
 581 
     | 
    
         
            +
                  begin
         
     | 
| 
      
 582 
     | 
    
         
            +
                    # the block must return true if it wanna continue
         
     | 
| 
      
 583 
     | 
    
         
            +
                    break unless yield(result) && result[:next_token]
         
     | 
| 
      
 584 
     | 
    
         
            +
                    # make new request
         
     | 
| 
      
 585 
     | 
    
         
            +
                    request_params['NextToken'] = result[:next_token]
         
     | 
| 
      
 586 
     | 
    
         
            +
                    link   = generate_request("Select", request_params)
         
     | 
| 
      
 587 
     | 
    
         
            +
                    result = select_response_to_ruby(request_info( link, QSdbSelectParser.new ))
         
     | 
| 
      
 588 
     | 
    
         
            +
                  end while true
         
     | 
| 
      
 589 
     | 
    
         
            +
                rescue Exception
         
     | 
| 
      
 590 
     | 
    
         
            +
                  on_exception
         
     | 
| 
      
 591 
     | 
    
         
            +
                end
         
     | 
| 
      
 592 
     | 
    
         
            +
             
     | 
| 
       415 
593 
     | 
    
         
             
                #-----------------------------------------------------------------
         
     | 
| 
       416 
594 
     | 
    
         
             
                #      PARSERS:
         
     | 
| 
       417 
595 
     | 
    
         
             
                #-----------------------------------------------------------------
         
     | 
| 
         @@ -421,10 +599,10 @@ module RightAws 
     | 
|
| 
       421 
599 
     | 
    
         
             
                  end
         
     | 
| 
       422 
600 
     | 
    
         
             
                  def tagend(name)
         
     | 
| 
       423 
601 
     | 
    
         
             
                    case name
         
     | 
| 
       424 
     | 
    
         
            -
                    when 'NextToken'   
     | 
| 
       425 
     | 
    
         
            -
                    when 'DomainName'  
     | 
| 
       426 
     | 
    
         
            -
                    when 'BoxUsage'    
     | 
| 
       427 
     | 
    
         
            -
                    when 'RequestId'   
     | 
| 
      
 602 
     | 
    
         
            +
                    when 'NextToken'  then @result[:next_token] =  @text
         
     | 
| 
      
 603 
     | 
    
         
            +
                    when 'DomainName' then @result[:domains]    << @text
         
     | 
| 
      
 604 
     | 
    
         
            +
                    when 'BoxUsage'   then @result[:box_usage]  =  @text
         
     | 
| 
      
 605 
     | 
    
         
            +
                    when 'RequestId'  then @result[:request_id] =  @text
         
     | 
| 
       428 
606 
     | 
    
         
             
                    end
         
     | 
| 
       429 
607 
     | 
    
         
             
                  end
         
     | 
| 
       430 
608 
     | 
    
         
             
                end
         
     | 
| 
         @@ -435,8 +613,8 @@ module RightAws 
     | 
|
| 
       435 
613 
     | 
    
         
             
                  end
         
     | 
| 
       436 
614 
     | 
    
         
             
                  def tagend(name)
         
     | 
| 
       437 
615 
     | 
    
         
             
                    case name
         
     | 
| 
       438 
     | 
    
         
            -
                    when 'BoxUsage' 
     | 
| 
       439 
     | 
    
         
            -
                    when 'RequestId' 
     | 
| 
      
 616 
     | 
    
         
            +
                    when 'BoxUsage'  then @result[:box_usage]  =  @text
         
     | 
| 
      
 617 
     | 
    
         
            +
                    when 'RequestId' then @result[:request_id] =  @text
         
     | 
| 
       440 
618 
     | 
    
         
             
                    end
         
     | 
| 
       441 
619 
     | 
    
         
             
                  end
         
     | 
| 
       442 
620 
     | 
    
         
             
                end
         
     | 
| 
         @@ -448,10 +626,10 @@ module RightAws 
     | 
|
| 
       448 
626 
     | 
    
         
             
                  end
         
     | 
| 
       449 
627 
     | 
    
         
             
                  def tagend(name)
         
     | 
| 
       450 
628 
     | 
    
         
             
                    case name
         
     | 
| 
       451 
     | 
    
         
            -
                    when 'Name' 
     | 
| 
       452 
     | 
    
         
            -
                    when 'Value' 
     | 
| 
       453 
     | 
    
         
            -
                    when 'BoxUsage' 
     | 
| 
       454 
     | 
    
         
            -
                    when 'RequestId' 
     | 
| 
      
 629 
     | 
    
         
            +
                    when 'Name'      then @last_attribute_name = @text
         
     | 
| 
      
 630 
     | 
    
         
            +
                    when 'Value'     then (@result[:attributes][@last_attribute_name] ||= []) << @text
         
     | 
| 
      
 631 
     | 
    
         
            +
                    when 'BoxUsage'  then @result[:box_usage]  =  @text
         
     | 
| 
      
 632 
     | 
    
         
            +
                    when 'RequestId' then @result[:request_id] =  @text
         
     | 
| 
       455 
633 
     | 
    
         
             
                    end
         
     | 
| 
       456 
634 
     | 
    
         
             
                  end
         
     | 
| 
       457 
635 
     | 
    
         
             
                end
         
     | 
| 
         @@ -462,10 +640,56 @@ module RightAws 
     | 
|
| 
       462 
640 
     | 
    
         
             
                  end
         
     | 
| 
       463 
641 
     | 
    
         
             
                  def tagend(name)
         
     | 
| 
       464 
642 
     | 
    
         
             
                    case name
         
     | 
| 
       465 
     | 
    
         
            -
                    when 'ItemName' 
     | 
| 
       466 
     | 
    
         
            -
                    when 'BoxUsage' 
     | 
| 
       467 
     | 
    
         
            -
                    when 'RequestId' 
     | 
| 
       468 
     | 
    
         
            -
                    when 'NextToken' 
     | 
| 
      
 643 
     | 
    
         
            +
                    when 'ItemName'  then @result[:items]      << @text
         
     | 
| 
      
 644 
     | 
    
         
            +
                    when 'BoxUsage'  then @result[:box_usage]  =  @text
         
     | 
| 
      
 645 
     | 
    
         
            +
                    when 'RequestId' then @result[:request_id] =  @text
         
     | 
| 
      
 646 
     | 
    
         
            +
                    when 'NextToken' then @result[:next_token] =  @text
         
     | 
| 
      
 647 
     | 
    
         
            +
                    end
         
     | 
| 
      
 648 
     | 
    
         
            +
                  end
         
     | 
| 
      
 649 
     | 
    
         
            +
                end
         
     | 
| 
      
 650 
     | 
    
         
            +
             
     | 
| 
      
 651 
     | 
    
         
            +
                class QSdbQueryWithAttributesParser < RightAWSParser #:nodoc:
         
     | 
| 
      
 652 
     | 
    
         
            +
                  def reset
         
     | 
| 
      
 653 
     | 
    
         
            +
                    @result = { :items => [] }
         
     | 
| 
      
 654 
     | 
    
         
            +
                  end
         
     | 
| 
      
 655 
     | 
    
         
            +
                  def tagend(name)
         
     | 
| 
      
 656 
     | 
    
         
            +
                    case name
         
     | 
| 
      
 657 
     | 
    
         
            +
                    when 'Name'
         
     | 
| 
      
 658 
     | 
    
         
            +
                      case @xmlpath
         
     | 
| 
      
 659 
     | 
    
         
            +
                      when 'QueryWithAttributesResponse/QueryWithAttributesResult/Item'
         
     | 
| 
      
 660 
     | 
    
         
            +
                        @item = @text
         
     | 
| 
      
 661 
     | 
    
         
            +
                        @result[:items] << { @item => {} }
         
     | 
| 
      
 662 
     | 
    
         
            +
                      when 'QueryWithAttributesResponse/QueryWithAttributesResult/Item/Attribute'
         
     | 
| 
      
 663 
     | 
    
         
            +
                        @attribute = @text
         
     | 
| 
      
 664 
     | 
    
         
            +
                        @result[:items].last[@item][@attribute] ||= []
         
     | 
| 
      
 665 
     | 
    
         
            +
                      end
         
     | 
| 
      
 666 
     | 
    
         
            +
                    when 'RequestId' then @result[:request_id] = @text
         
     | 
| 
      
 667 
     | 
    
         
            +
                    when 'BoxUsage'  then @result[:box_usage]  = @text
         
     | 
| 
      
 668 
     | 
    
         
            +
                    when 'NextToken' then @result[:next_token] = @text
         
     | 
| 
      
 669 
     | 
    
         
            +
                    when 'Value'     then @result[:items].last[@item][@attribute] << @text
         
     | 
| 
      
 670 
     | 
    
         
            +
                    end
         
     | 
| 
      
 671 
     | 
    
         
            +
                  end
         
     | 
| 
      
 672 
     | 
    
         
            +
                end
         
     | 
| 
      
 673 
     | 
    
         
            +
             
     | 
| 
      
 674 
     | 
    
         
            +
                class QSdbSelectParser < RightAWSParser #:nodoc:
         
     | 
| 
      
 675 
     | 
    
         
            +
                  def reset
         
     | 
| 
      
 676 
     | 
    
         
            +
                    @result = { :items => [] }
         
     | 
| 
      
 677 
     | 
    
         
            +
                  end
         
     | 
| 
      
 678 
     | 
    
         
            +
                  def tagend(name)
         
     | 
| 
      
 679 
     | 
    
         
            +
                    case name
         
     | 
| 
      
 680 
     | 
    
         
            +
                    when 'Name'
         
     | 
| 
      
 681 
     | 
    
         
            +
                      case @xmlpath
         
     | 
| 
      
 682 
     | 
    
         
            +
                      when 'SelectResponse/SelectResult/Item'
         
     | 
| 
      
 683 
     | 
    
         
            +
                        @item = @text
         
     | 
| 
      
 684 
     | 
    
         
            +
                        @result[:items] << { @item => {} }
         
     | 
| 
      
 685 
     | 
    
         
            +
                      when 'SelectResponse/SelectResult/Item/Attribute'
         
     | 
| 
      
 686 
     | 
    
         
            +
                        @attribute = @text
         
     | 
| 
      
 687 
     | 
    
         
            +
                        @result[:items].last[@item][@attribute] ||= []
         
     | 
| 
      
 688 
     | 
    
         
            +
                      end
         
     | 
| 
      
 689 
     | 
    
         
            +
                    when 'RequestId' then @result[:request_id] = @text
         
     | 
| 
      
 690 
     | 
    
         
            +
                    when 'BoxUsage'  then @result[:box_usage]  = @text
         
     | 
| 
      
 691 
     | 
    
         
            +
                    when 'NextToken' then @result[:next_token] = @text
         
     | 
| 
      
 692 
     | 
    
         
            +
                    when 'Value'     then @result[:items].last[@item][@attribute] << @text
         
     | 
| 
       469 
693 
     | 
    
         
             
                    end
         
     | 
| 
       470 
694 
     | 
    
         
             
                  end
         
     | 
| 
       471 
695 
     | 
    
         
             
                end
         
     | 
    
        data/lib/sqs/right_sqs.rb
    CHANGED
    
    | 
         @@ -54,6 +54,14 @@ module RightAws 
     | 
|
| 
       54 
54 
     | 
    
         
             
                #   ...
         
     | 
| 
       55 
55 
     | 
    
         
             
                #  grantee2 = queue.grantees('another_cool_guy@email.address')
         
     | 
| 
       56 
56 
     | 
    
         
             
                #  grantee2.revoke('SENDMESSAGE')
         
     | 
| 
      
 57 
     | 
    
         
            +
                #       
         
     | 
| 
      
 58 
     | 
    
         
            +
                # Params is a hash:
         
     | 
| 
      
 59 
     | 
    
         
            +
                #
         
     | 
| 
      
 60 
     | 
    
         
            +
                #    {:server       => 'queue.amazonaws.com' # Amazon service host: 'queue.amazonaws.com' (default)
         
     | 
| 
      
 61 
     | 
    
         
            +
                #     :port         => 443                   # Amazon service port: 80 or 443 (default)
         
     | 
| 
      
 62 
     | 
    
         
            +
                #     :multi_thread => true|false            # Multi-threaded (connection per each thread): true or false (default)
         
     | 
| 
      
 63 
     | 
    
         
            +
                #     :signature_version => '0'              # The signature version : '0' or '1'(default)
         
     | 
| 
      
 64 
     | 
    
         
            +
                #     :logger       => Logger Object}        # Logger instance: logs to STDOUT if omitted }
         
     | 
| 
       57 
65 
     | 
    
         
             
                #
         
     | 
| 
       58 
66 
     | 
    
         
             
              class Sqs
         
     | 
| 
       59 
67 
     | 
    
         
             
                attr_reader :interface
         
     | 
    
        data/lib/sqs/right_sqs_gen2.rb
    CHANGED
    
    | 
         @@ -55,6 +55,14 @@ module RightAws 
     | 
|
| 
       55 
55 
     | 
    
         
             
                #   ...
         
     | 
| 
       56 
56 
     | 
    
         
             
                #
         
     | 
| 
       57 
57 
     | 
    
         
             
                # NB: Second-generation SQS has eliminated the entire access grant mechanism present in Gen 1.
         
     | 
| 
      
 58 
     | 
    
         
            +
                #
         
     | 
| 
      
 59 
     | 
    
         
            +
                # Params is a hash:
         
     | 
| 
      
 60 
     | 
    
         
            +
                #
         
     | 
| 
      
 61 
     | 
    
         
            +
                #    {:server       => 'queue.amazonaws.com' # Amazon service host: 'queue.amazonaws.com' (default)
         
     | 
| 
      
 62 
     | 
    
         
            +
                #     :port         => 443                   # Amazon service port: 80 or 443 (default)
         
     | 
| 
      
 63 
     | 
    
         
            +
                #     :multi_thread => true|false            # Multi-threaded (connection per each thread): true or false (default)
         
     | 
| 
      
 64 
     | 
    
         
            +
                #     :signature_version => '0'              # The signature version : '0' or '1'(default)
         
     | 
| 
      
 65 
     | 
    
         
            +
                #     :logger       => Logger Object}        # Logger instance: logs to STDOUT if omitted }
         
     | 
| 
       58 
66 
     | 
    
         
             
              class SqsGen2
         
     | 
| 
       59 
67 
     | 
    
         
             
                attr_reader :interface
         
     | 
| 
       60 
68 
     | 
    
         | 
| 
         @@ -38,7 +38,6 @@ module RightAws 
     | 
|
| 
       38 
38 
     | 
    
         
             
              class SqsGen2Interface < RightAwsBase
         
     | 
| 
       39 
39 
     | 
    
         
             
                include RightAwsBaseInterface
         
     | 
| 
       40 
40 
     | 
    
         | 
| 
       41 
     | 
    
         
            -
                SIGNATURE_VERSION = "1"
         
     | 
| 
       42 
41 
     | 
    
         
             
                API_VERSION       = "2008-01-01"
         
     | 
| 
       43 
42 
     | 
    
         
             
                DEFAULT_HOST      = "queue.amazonaws.com"
         
     | 
| 
       44 
43 
     | 
    
         
             
                DEFAULT_PORT      = 443
         
     | 
| 
         @@ -99,48 +98,44 @@ module RightAws 
     | 
|
| 
       99 
98 
     | 
    
         
             
                  # fields required in all requests, and then the headers passed in as
         
     | 
| 
       100 
99 
     | 
    
         
             
                  # params.  We sort the header fields alphabetically and then generate the
         
     | 
| 
       101 
100 
     | 
    
         
             
                  # signature before URL escaping the resulting query and sending it.
         
     | 
| 
       102 
     | 
    
         
            -
                   
     | 
| 
      
 101 
     | 
    
         
            +
                  service = param[:queue_url] ? URI(param[:queue_url]).path : '/'
         
     | 
| 
       103 
102 
     | 
    
         
             
                  param.each{ |key, value| param.delete(key) if (value.nil? || key.is_a?(Symbol)) }
         
     | 
| 
       104 
     | 
    
         
            -
                   
     | 
| 
      
 103 
     | 
    
         
            +
                  service_hash = { "Action"           => action,
         
     | 
| 
       105 
104 
     | 
    
         
             
                                   "Expires"          => (Time.now + REQUEST_TTL).utc.strftime("%Y-%m-%dT%H:%M:%SZ"),
         
     | 
| 
       106 
105 
     | 
    
         
             
                                   "AWSAccessKeyId"   => @aws_access_key_id,
         
     | 
| 
       107 
     | 
    
         
            -
                                   "Version"          => API_VERSION 
     | 
| 
       108 
     | 
    
         
            -
             
     | 
| 
       109 
     | 
    
         
            -
                   
     | 
| 
       110 
     | 
    
         
            -
                   
     | 
| 
       111 
     | 
    
         
            -
                  request_hash['Signature'] = AwsUtils::sign(@aws_secret_access_key, request_data)
         
     | 
| 
       112 
     | 
    
         
            -
                  request_params = request_hash.to_a.collect{|key,val| key.to_s + "=" + val.to_s }.join("&")
         
     | 
| 
       113 
     | 
    
         
            -
                  request        = Net::HTTP::Get.new(AwsUtils.URLencode("#{queue_uri}?#{request_params}"))
         
     | 
| 
      
 106 
     | 
    
         
            +
                                   "Version"          => API_VERSION }
         
     | 
| 
      
 107 
     | 
    
         
            +
                  service_hash.update(param)
         
     | 
| 
      
 108 
     | 
    
         
            +
                  service_params = signed_service_params(@aws_secret_access_key, service_hash, :get, @params[:server], service)
         
     | 
| 
      
 109 
     | 
    
         
            +
                  request        = Net::HTTP::Get.new("#{AwsUtils.URLencode(service)}?#{service_params}")
         
     | 
| 
       114 
110 
     | 
    
         
             
                    # prepare output hash
         
     | 
| 
       115 
111 
     | 
    
         
             
                  { :request  => request, 
         
     | 
| 
       116 
112 
     | 
    
         
             
                    :server   => @params[:server],
         
     | 
| 
       117 
113 
     | 
    
         
             
                    :port     => @params[:port],
         
     | 
| 
       118 
114 
     | 
    
         
             
                    :protocol => @params[:protocol],
         
     | 
| 
       119 
     | 
    
         
            -
                    :proxy 
     | 
| 
      
 115 
     | 
    
         
            +
                    :proxy    => @params[:proxy] }
         
     | 
| 
       120 
116 
     | 
    
         
             
                end
         
     | 
| 
       121 
117 
     | 
    
         | 
| 
       122 
118 
     | 
    
         
             
                def generate_post_request(action, param={})  # :nodoc:
         
     | 
| 
       123 
     | 
    
         
            -
                   
     | 
| 
      
 119 
     | 
    
         
            +
                  service = param[:queue_url] ? URI(param[:queue_url]).path : '/'
         
     | 
| 
       124 
120 
     | 
    
         
             
                  message   = param[:message]                # extract message body if nesessary
         
     | 
| 
       125 
121 
     | 
    
         
             
                  param.each{ |key, value| param.delete(key) if (value.nil? || key.is_a?(Symbol)) }
         
     | 
| 
       126 
     | 
    
         
            -
                   
     | 
| 
      
 122 
     | 
    
         
            +
                  service_hash = { "Action"           => action,
         
     | 
| 
       127 
123 
     | 
    
         
             
                                   "Expires"          => (Time.now + REQUEST_TTL).utc.strftime("%Y-%m-%dT%H:%M:%SZ"),
         
     | 
| 
       128 
124 
     | 
    
         
             
                                   "AWSAccessKeyId"   => @aws_access_key_id,
         
     | 
| 
       129 
125 
     | 
    
         
             
                                   "MessageBody"      => message,
         
     | 
| 
       130 
     | 
    
         
            -
                                   "Version"          => API_VERSION 
     | 
| 
       131 
     | 
    
         
            -
             
     | 
| 
       132 
     | 
    
         
            -
                   
     | 
| 
       133 
     | 
    
         
            -
                   
     | 
| 
       134 
     | 
    
         
            -
                   
     | 
| 
       135 
     | 
    
         
            -
                  request_body = request_hash.to_a.collect{|key,val| CGI.escape(key.to_s) + "=" + CGI.escape(val.to_s) }.join("&")
         
     | 
| 
       136 
     | 
    
         
            -
                  request        = Net::HTTP::Post.new(AwsUtils.URLencode(queue_uri))
         
     | 
| 
      
 126 
     | 
    
         
            +
                                   "Version"          => API_VERSION }
         
     | 
| 
      
 127 
     | 
    
         
            +
                  service_hash.update(param)
         
     | 
| 
      
 128 
     | 
    
         
            +
                  #
         
     | 
| 
      
 129 
     | 
    
         
            +
                  service_params = signed_service_params(@aws_secret_access_key, service_hash, :post, @params[:server], service)
         
     | 
| 
      
 130 
     | 
    
         
            +
                  request        = Net::HTTP::Post.new(AwsUtils::URLencode(service))
         
     | 
| 
       137 
131 
     | 
    
         
             
                  request['Content-Type'] = 'application/x-www-form-urlencoded' 
         
     | 
| 
       138 
     | 
    
         
            -
                  request.body =  
     | 
| 
      
 132 
     | 
    
         
            +
                  request.body = service_params
         
     | 
| 
       139 
133 
     | 
    
         
             
                    # prepare output hash
         
     | 
| 
       140 
134 
     | 
    
         
             
                  { :request  => request, 
         
     | 
| 
       141 
135 
     | 
    
         
             
                    :server   => @params[:server],
         
     | 
| 
       142 
136 
     | 
    
         
             
                    :port     => @params[:port],
         
     | 
| 
       143 
     | 
    
         
            -
                    :protocol => @params[:protocol] 
     | 
| 
      
 137 
     | 
    
         
            +
                    :protocol => @params[:protocol],
         
     | 
| 
      
 138 
     | 
    
         
            +
                    :proxy    => @params[:proxy] }
         
     | 
| 
       144 
139 
     | 
    
         
             
                end
         
     | 
| 
       145 
140 
     | 
    
         | 
| 
       146 
141 
     | 
    
         | 
| 
         @@ -78,30 +78,23 @@ module RightAws 
     | 
|
| 
       78 
78 
     | 
    
         
             
                def generate_request(action, params={})  # :nodoc:
         
     | 
| 
       79 
79 
     | 
    
         
             
                    # Sometimes we need to use queue uri (delete queue etc)
         
     | 
| 
       80 
80 
     | 
    
         
             
                    # In that case we will use Symbol key: 'param[:queue_url]'
         
     | 
| 
       81 
     | 
    
         
            -
                   
     | 
| 
      
 81 
     | 
    
         
            +
                  service = params[:queue_url] ? URI(params[:queue_url]).path : '/'
         
     | 
| 
       82 
82 
     | 
    
         
             
                    # remove unset(=optional) and symbolyc keys
         
     | 
| 
       83 
83 
     | 
    
         
             
                  params.each{ |key, value| params.delete(key) if (value.nil? || key.is_a?(Symbol)) }
         
     | 
| 
       84 
84 
     | 
    
         
             
                    # prepare output hash
         
     | 
| 
       85 
85 
     | 
    
         
             
                  service_hash = { "Action"           => action,
         
     | 
| 
       86 
86 
     | 
    
         
             
                                   "Expires"          => (Time.now + REQUEST_TTL).utc.strftime("%Y-%m-%dT%H:%M:%SZ"),
         
     | 
| 
       87 
87 
     | 
    
         
             
                                   "AWSAccessKeyId"   => @aws_access_key_id,
         
     | 
| 
       88 
     | 
    
         
            -
                                   "Version"          => API_VERSION 
     | 
| 
       89 
     | 
    
         
            -
                                   "SignatureVersion" => signature_version }
         
     | 
| 
      
 88 
     | 
    
         
            +
                                   "Version"          => API_VERSION }
         
     | 
| 
       90 
89 
     | 
    
         
             
                  service_hash.update(params)
         
     | 
| 
       91 
     | 
    
         
            -
                   
     | 
| 
       92 
     | 
    
         
            -
                   
     | 
| 
       93 
     | 
    
         
            -
                                   when '0' : service_hash["Action"] + service_hash["Expires"]
         
     | 
| 
       94 
     | 
    
         
            -
                                   when '1' : service_hash.sort{|a,b| (a[0].to_s.downcase)<=>(b[0].to_s.downcase)}.to_s
         
     | 
| 
       95 
     | 
    
         
            -
                                   end
         
     | 
| 
       96 
     | 
    
         
            -
                  service_hash['Signature'] = AwsUtils::sign(@aws_secret_access_key, string_to_sign)
         
     | 
| 
       97 
     | 
    
         
            -
                  request_params = service_hash.to_a.collect{|key,val| key.to_s + "=" + CGI::escape(val.to_s) }.join("&")
         
     | 
| 
       98 
     | 
    
         
            -
                  request        = Net::HTTP::Get.new("#{queue_uri}?#{request_params}")
         
     | 
| 
      
 90 
     | 
    
         
            +
                  service_params = signed_service_params(@aws_secret_access_key, service_hash, :get, @params[:server], service)
         
     | 
| 
      
 91 
     | 
    
         
            +
                  request        = Net::HTTP::Get.new("#{AwsUtils::URLencode(service)}?#{service_params}")
         
     | 
| 
       99 
92 
     | 
    
         
             
                    # prepare output hash
         
     | 
| 
       100 
93 
     | 
    
         
             
                  { :request  => request, 
         
     | 
| 
       101 
94 
     | 
    
         
             
                    :server   => @params[:server],
         
     | 
| 
       102 
95 
     | 
    
         
             
                    :port     => @params[:port],
         
     | 
| 
       103 
96 
     | 
    
         
             
                    :protocol => @params[:protocol],
         
     | 
| 
       104 
     | 
    
         
            -
                    :proxy 
     | 
| 
      
 97 
     | 
    
         
            +
                    :proxy    => @params[:proxy] }
         
     | 
| 
       105 
98 
     | 
    
         
             
                end
         
     | 
| 
       106 
99 
     | 
    
         | 
| 
       107 
100 
     | 
    
         
             
                  # Generates a request hash for the REST API
         
     | 
| 
         @@ -129,7 +122,8 @@ module RightAws 
     | 
|
| 
       129 
122 
     | 
    
         
             
                  { :request  => request, 
         
     | 
| 
       130 
123 
     | 
    
         
             
                    :server   => @params[:server],
         
     | 
| 
       131 
124 
     | 
    
         
             
                    :port     => @params[:port],
         
     | 
| 
       132 
     | 
    
         
            -
                    :protocol => @params[:protocol] 
     | 
| 
      
 125 
     | 
    
         
            +
                    :protocol => @params[:protocol],
         
     | 
| 
      
 126 
     | 
    
         
            +
                    :proxy    => @params[:proxy] }
         
     | 
| 
       133 
127 
     | 
    
         
             
                end
         
     | 
| 
       134 
128 
     | 
    
         | 
| 
       135 
129 
     | 
    
         |