aws 1.11.9 → 1.11.36

Sign up to get free protection for your applications and to get access to all the features.
@@ -30,9 +30,10 @@ module RightAws
30
30
  include RightAwsBaseInterface
31
31
 
32
32
  DEFAULT_HOST = 'sdb.amazonaws.com'
33
- DEFAULT_PORT = 80
34
- DEFAULT_PROTOCOL = 'http'
35
- API_VERSION = '2007-11-07'
33
+ DEFAULT_PORT = 443
34
+ DEFAULT_PROTOCOL = 'https'
35
+ DEFAULT_SERVICE = '/'
36
+ API_VERSION = '2009-04-15'
36
37
  DEFAULT_NIL_REPRESENTATION = 'nil'
37
38
 
38
39
  @@bench = AwsBenchmarkingBlock.new
@@ -45,16 +46,22 @@ module RightAws
45
46
  #
46
47
  # Params:
47
48
  # { :server => 'sdb.amazonaws.com' # Amazon service host: 'sdb.amazonaws.com'(default)
48
- # :port => 443 # Amazon service port: 80 or 443(default)
49
- # :protocol => 'https' # Amazon service protocol: 'http' or 'https'(default)
50
- # :signature_version => '0' # The signature version : '0' or '1'(default)
51
- # :multi_thread => true|false # Multi-threaded (connection per each thread): true or false(default)
49
+ # :port => 443 # Amazon service port: 80(default) or 443
50
+ # :protocol => 'https' # Amazon service protocol: 'http'(default) or 'https'
51
+ # :signature_version => '2' # The signature version : '0', '1' or '2' (default)
52
+ # DEPRECATED :multi_thread => true|false # Multi-threaded (connection per each thread): true or false(default)
53
+ # :connection_mode => :default # options are :default (will use best known option, may change in the future)
54
+ # :per_request (opens and closes a connection on every request to SDB)
55
+ # :single - one connection shared across app (same as old multi_thread=>false)
56
+ # :per_thread - one connection per ruby thread (same as old multi_thread=>true)
57
+ # :pool (uses a connection pool with a maximum number of connections - NOT IMPLEMENTED YET)
52
58
  # :logger => Logger Object # Logger instance: logs to STDOUT if omitted
53
59
  # :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')
60
+ # :service => '/' # Set this to /mdb/request.mgwsi for usage with M/DB #
54
61
  #
55
62
  # Example:
56
63
  #
57
- # sdb = RightAws::SdbInterface.new('1E3GDYEOGFJPIT7XXXXXX','hgTHt68JY07JKUY08ftHYtERkjgtfERn57XXXXXX', {:multi_thread => true, :logger => Logger.new('/tmp/x.log')}) #=> #<RightSdb:0xa6b8c27c>
64
+ # sdb = RightAws::SdbInterface.new('1E3GDYEOGFJPIT7XXXXXX','hgTHt68JY07JKUY08ftHYtERkjgtfERn57XXXXXX', {:connection_mode => :per_request, :logger => Logger.new('/tmp/x.log')}) #=> #<RightSdb:0xa6b8c27c>
58
65
  #
59
66
  # see: http://docs.amazonwebservices.com/AmazonSimpleDB/2007-11-07/DeveloperGuide/
60
67
  #
@@ -64,7 +71,9 @@ module RightAws
64
71
  init({ :name => 'SDB',
65
72
  :default_host => ENV['SDB_URL'] ? URI.parse(ENV['SDB_URL']).host : DEFAULT_HOST,
66
73
  :default_port => ENV['SDB_URL'] ? URI.parse(ENV['SDB_URL']).port : DEFAULT_PORT,
67
- :default_protocol => ENV['SDB_URL'] ? URI.parse(ENV['SDB_URL']).scheme : DEFAULT_PROTOCOL },
74
+ :default_protocol => ENV['SDB_URL'] ? URI.parse(ENV['SDB_URL']).scheme : DEFAULT_PROTOCOL,
75
+ :default_service => ENV['SDB_URL'] ? URI.parse(ENV['SDB_URL']).path : DEFAULT_SERVICE },
76
+ # :service_endpoint => ENV['SDB_URL'] ? URI.parse(ENV['SDB_URL']).path : DEFAULT_ENDPOINT },
68
77
  aws_access_key_id || ENV['AWS_ACCESS_KEY_ID'],
69
78
  aws_secret_access_key || ENV['AWS_SECRET_ACCESS_KEY'],
70
79
  params)
@@ -78,12 +87,13 @@ module RightAws
78
87
  params.delete_if {|key,value| value.nil? }
79
88
  #params_string = params.to_a.collect{|key,val| key + "=#{CGI::escape(val.to_s)}" }.join("&")
80
89
  # prepare service data
81
- service = '/'
90
+ service = @params[:service]
91
+ # puts 'service=' + service.to_s
82
92
  service_hash = {"Action" => action,
83
93
  "AWSAccessKeyId" => @aws_access_key_id,
84
94
  "Version" => API_VERSION }
85
95
  service_hash.update(params)
86
- service_params = signed_service_params(@aws_secret_access_key, service_hash, :get, @params[:server], service)
96
+ service_params = signed_service_params(@aws_secret_access_key, service_hash, :get, @params[:server], @params[:service])
87
97
  #
88
98
  # use POST method if the length of the query string is too large
89
99
  # see http://docs.amazonwebservices.com/AmazonSimpleDB/2007-11-07/DeveloperGuide/MakingRESTRequests.html
@@ -201,12 +211,15 @@ module RightAws
201
211
  #
202
212
  def query_expression_from_array(params) #:nodoc:
203
213
  return '' if params.blank?
204
- query = params.shift.to_s
214
+ query = params[0].to_s
215
+ i = 1
205
216
  query.gsub(/(\\)?(\?)/) do
206
217
  if $1 # if escaped '\?' is found - replace it by '?' without backslash
207
218
  "?"
208
219
  else # well, if no backslash precedes '?' then replace it by next param from the list
209
- escape(params.shift)
220
+ ret = escape(params[i])
221
+ i+=1
222
+ ret
210
223
  end
211
224
  end
212
225
  end
@@ -265,6 +278,41 @@ module RightAws
265
278
  on_exception
266
279
  end
267
280
 
281
+ # Retrieve a list of SDB domains from Amazon.
282
+ #
283
+ # Returns a hash:
284
+ # { :domains => [domain1, ..., domainN],
285
+ # :next_token => string || nil,
286
+ # :box_usage => string,
287
+ # :request_id => string }
288
+ #
289
+ # Example:
290
+ #
291
+ # sdb = RightAws::SdbInterface.new
292
+ # sdb.list_domains #=> { :box_usage => "0.0000071759",
293
+ # :request_id => "976709f9-0111-2345-92cb-9ce90acd0982",
294
+ # :domains => ["toys", "dolls"]}
295
+ #
296
+ # If a block is given, this method yields to it. If the block returns true, list_domains will continue looping the request. If the block returns false,
297
+ # list_domains will end.
298
+ #
299
+ # sdb.list_domains(10) do |result| # list by 10 domains per iteration
300
+ # puts result.inspect
301
+ # true
302
+ # end
303
+ #
304
+ # see: http://docs.amazonwebservices.com/AmazonSimpleDB/2007-11-07/DeveloperGuide/SDB_API_ListDomains.html
305
+ #
306
+ def domain_metadata(domain_name)
307
+ link = generate_request("DomainMetadata", 'DomainName' => domain_name)
308
+ result = request_info(link, QSdbDomainMetadataParser.new)
309
+ return result
310
+ rescue Exception
311
+ on_exception
312
+ end
313
+
314
+
315
+
268
316
  # Create new SDB domain at Amazon.
269
317
  #
270
318
  # Returns a hash: { :box_usage, :request_id } on success or an exception on error.
@@ -646,22 +694,41 @@ module RightAws
646
694
  end
647
695
  def tagend(name)
648
696
  case name
649
- when 'NextToken' then @result[:next_token] = @text
650
- when 'DomainName' then @result[:domains] << @text
651
- when 'BoxUsage' then @result[:box_usage] = @text
652
- when 'RequestId' then @result[:request_id] = @text
697
+ when 'NextToken' then @result[:next_token] = @text
698
+ when 'DomainName' then @result[:domains] << @text
699
+ when 'BoxUsage' then @result[:box_usage] = @text
700
+ when 'RequestId' then @result[:request_id] = @text
653
701
  end
654
702
  end
655
703
  end
656
704
 
705
+ class QSdbDomainMetadataParser < RightAWSParser #:nodoc:
706
+ def reset
707
+ @result = {}
708
+ end
709
+ def tagend(name)
710
+ case name
711
+ when 'Timestamp' then @result[:timestamp] = @text
712
+ when 'ItemCount' then @result[:item_count] = @text.to_i
713
+ when 'AttributeValueCount' then @result[:attribute_value_count] = @text.to_i
714
+ when 'AttributeNameCount' then @result[:attribute_name_acount] = @text.to_i
715
+ when 'ItemNamesSizeBytes' then @result[:item_names_size_bytes] = @text.to_i
716
+ when 'AttributeValuesSizeBytes' then @result[:attributes_values_size_bytes] = @text.to_i
717
+ when 'AttributeNamesSizeBytes' then @result[:attributes_names_size_bytes] = @text.to_i
718
+
719
+ end
720
+ end
721
+ end
722
+
723
+
657
724
  class QSdbSimpleParser < RightAWSParser #:nodoc:
658
725
  def reset
659
726
  @result = {}
660
727
  end
661
728
  def tagend(name)
662
729
  case name
663
- when 'BoxUsage' then @result[:box_usage] = @text
664
- when 'RequestId' then @result[:request_id] = @text
730
+ when 'BoxUsage' then @result[:box_usage] = @text
731
+ when 'RequestId' then @result[:request_id] = @text
665
732
  end
666
733
  end
667
734
  end
@@ -673,10 +740,10 @@ module RightAws
673
740
  end
674
741
  def tagend(name)
675
742
  case name
676
- when 'Name' then @last_attribute_name = @text
677
- when 'Value' then (@result[:attributes][@last_attribute_name] ||= []) << @text
678
- when 'BoxUsage' then @result[:box_usage] = @text
679
- when 'RequestId' then @result[:request_id] = @text
743
+ when 'Name' then @last_attribute_name = @text
744
+ when 'Value' then (@result[:attributes][@last_attribute_name] ||= []) << @text
745
+ when 'BoxUsage' then @result[:box_usage] = @text
746
+ when 'RequestId' then @result[:request_id] = @text
680
747
  end
681
748
  end
682
749
  end
@@ -687,10 +754,10 @@ module RightAws
687
754
  end
688
755
  def tagend(name)
689
756
  case name
690
- when 'ItemName' then @result[:items] << @text
691
- when 'BoxUsage' then @result[:box_usage] = @text
692
- when 'RequestId' then @result[:request_id] = @text
693
- when 'NextToken' then @result[:next_token] = @text
757
+ when 'ItemName' then @result[:items] << @text
758
+ when 'BoxUsage' then @result[:box_usage] = @text
759
+ when 'RequestId' then @result[:request_id] = @text
760
+ when 'NextToken' then @result[:next_token] = @text
694
761
  end
695
762
  end
696
763
  end
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright (c) 2007-2008 RightScale Inc
2
+ # Copyright (c) 2008 RightScale Inc
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -24,13 +24,18 @@
24
24
  module RightAws
25
25
 
26
26
  #
27
- # = RightAws::Sqs -- RightScale's Amazon SQS interface
28
- # The RightAws::Sqs class provides a complete interface to Amazon's Simple
27
+ # RightAws::Sqs -- RightScale's Amazon SQS interface, API version
28
+ # 2008-01-01 and later.
29
+ # The RightAws::Sqs class provides a complete interface to the second generation of Amazon's Simple
29
30
  # Queue Service.
30
31
  # For explanations of the semantics
31
32
  # of each call, please refer to Amazon's documentation at
32
33
  # http://developer.amazonwebservices.com/connect/kbcategory.jspa?categoryID=31
33
34
  #
35
+ #
36
+ # RightAws::Sqs is built atop RightAws::SqsInterface, a lower-level
37
+ # procedural API that may be appropriate for certain programs.
38
+ #
34
39
  # Error handling: all operations raise an RightAws::AwsError in case
35
40
  # of problems. Note that transient errors are automatically retried.
36
41
  #
@@ -48,13 +53,9 @@ module RightAws
48
53
  # queue2.send_message('Ola-la!')
49
54
  # message2 = queue2.pop
50
55
  # ...
51
- # grantee1 = RightAws::Sqs::Grantee.create(queue2,'one_cool_guy@email.address')
52
- # grantee1.grant('FULLCONTROL')
53
- # grantee1.drop
54
- # ...
55
- # grantee2 = queue.grantees('another_cool_guy@email.address')
56
- # grantee2.revoke('SENDMESSAGE')
57
- #
56
+ #
57
+ # NB: Second-generation SQS has eliminated the entire access grant mechanism present in Gen 1.
58
+ #
58
59
  # Params is a hash:
59
60
  #
60
61
  # {:server => 'queue.amazonaws.com' # Amazon service host: 'queue.amazonaws.com' (default)
@@ -62,15 +63,14 @@ module RightAws
62
63
  # :multi_thread => true|false # Multi-threaded (connection per each thread): true or false (default)
63
64
  # :signature_version => '0' # The signature version : '0' or '1'(default)
64
65
  # :logger => Logger Object} # Logger instance: logs to STDOUT if omitted }
65
- #
66
66
  class Sqs
67
67
  attr_reader :interface
68
-
68
+
69
69
  def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={})
70
70
  @interface = SqsInterface.new(aws_access_key_id, aws_secret_access_key, params)
71
71
  end
72
-
73
- # Retrieves a list of queues.
72
+
73
+ # Retrieves a list of queues.
74
74
  # Returns an +array+ of +Queue+ instances.
75
75
  #
76
76
  # RightAws::Sqs.queues #=> array of queues
@@ -80,8 +80,8 @@ module RightAws
80
80
  Queue.new(self, url)
81
81
  end
82
82
  end
83
-
84
- # Returns Queue instance by queue name.
83
+
84
+ # Returns Queue instance by queue name.
85
85
  # If the queue does not exist at Amazon SQS and +create+ is true, the method creates it.
86
86
  #
87
87
  # RightAws::Sqs.queue('my_awesome_queue') #=> #<RightAws::Sqs::Queue:0xb7b626e4 ... >
@@ -91,12 +91,12 @@ module RightAws
91
91
  url = (create ? @interface.create_queue(queue_name, visibility) : nil) unless url
92
92
  url ? Queue.new(self, url) : nil
93
93
  end
94
-
95
-
94
+
95
+
96
96
  class Queue
97
97
  attr_reader :name, :url, :sqs
98
-
99
- # Returns Queue instance by queue name.
98
+
99
+ # Returns Queue instance by queue name.
100
100
  # If the queue does not exist at Amazon SQS and +create+ is true, the method creates it.
101
101
  #
102
102
  # RightAws::Sqs::Queue.create(sqs, 'my_awesome_queue') #=> #<RightAws::Sqs::Queue:0xb7b626e4 ... >
@@ -104,8 +104,8 @@ module RightAws
104
104
  def self.create(sqs, url_or_name, create=true, visibility=nil)
105
105
  sqs.queue(url_or_name, create, visibility)
106
106
  end
107
-
108
- # Creates new Queue instance.
107
+
108
+ # Creates new Queue instance.
109
109
  # Does not create a queue at Amazon.
110
110
  #
111
111
  # queue = RightAws::Sqs::Queue.new(sqs, 'my_awesome_queue')
@@ -115,7 +115,7 @@ module RightAws
115
115
  @url = @sqs.interface.queue_url_by_name(url_or_name)
116
116
  @name = @sqs.interface.queue_name_by_url(@url)
117
117
  end
118
-
118
+
119
119
  # Retrieves queue size.
120
120
  #
121
121
  # queue.size #=> 1
@@ -123,64 +123,62 @@ module RightAws
123
123
  def size
124
124
  @sqs.interface.get_queue_length(@url)
125
125
  end
126
-
127
- # Clears queue.
128
- # Deletes only the visible messages unless +force+ is +true+.
129
- #
130
- # queue.clear(true) #=> true
126
+
127
+ # Clears queue, deleting only the visible messages. Any message within its visibility
128
+ # timeout will not be deleted, and will re-appear in the queue in the
129
+ # future when the timeout expires.
131
130
  #
132
- # P.S. when <tt>force==true</tt> the queue deletes then creates again. This is
133
- # the quickest method to clear a big queue or a queue with 'locked' messages. All queue
134
- # attributes are restored. But there is no way to restore grantees' permissions to
135
- # this queue. If you have no grantees except 'root' then you have no problems.
136
- # Otherwise, it's better to use <tt>queue.clear(false)</tt>.
131
+ # To delete all messages in a queue and eliminate the chance of any
132
+ # messages re-appearing in the future, it's best to delete the queue and
133
+ # re-create it as a new queue. Note that doing this will take at least 60
134
+ # s since SQS does not allow re-creation of a queue within this interval.
137
135
  #
138
- # PS This function is no longer supported. Amazon has changed the SQS semantics to require at least 60 seconds between
139
- # queue deletion and creation. Hence this method will fail with an exception.
136
+ # queue.clear() #=> true
140
137
  #
141
- def clear(force=false)
142
- ## if force
143
- ## @sqs.interface.force_clear_queue(@url)
144
- ## else
138
+ def clear()
145
139
  @sqs.interface.clear_queue(@url)
146
- ## end
147
140
  end
148
-
149
- # Deletes queue.
150
- # Queue must be empty or +force+ must be set to +true+.
151
- # Returns +true+.
141
+
142
+ # Deletes queue. Any messages in the queue will be permanently lost.
143
+ # Returns +true+.
152
144
  #
153
- # queue.delete(true) #=> true
145
+ # NB: Use with caution; severe data loss is possible!
146
+ #
147
+ # queue.delete(true) #=> true
154
148
  #
155
149
  def delete(force=false)
156
- @sqs.interface.delete_queue(@url, force)
150
+ @sqs.interface.delete_queue(@url)
157
151
  end
158
152
 
159
- # Sends new message to queue.
153
+ # Sends new message to queue.
160
154
  # Returns new Message instance that has been sent to queue.
161
155
  def send_message(message)
162
156
  message = message.to_s
163
- msg = Message.new(self, @sqs.interface.send_message(@url, message), message)
157
+ res = @sqs.interface.send_message(@url, message)
158
+ msg = Message.new(self, res['MessageId'], nil, message)
159
+ msg.send_checksum = res['MD5OfMessageBody']
164
160
  msg.sent_at = Time.now
165
161
  msg
166
162
  end
167
163
  alias_method :push, :send_message
168
164
 
169
- # Retrieves several messages from queue.
170
- # Returns an array of Message instances.
165
+ # Retrieves several messages from queue.
166
+ # Returns an array of Message instances.
171
167
  #
172
168
  # queue.receive_messages(2,10) #=> array of messages
173
169
  #
174
170
  def receive_messages(number_of_messages=1, visibility=nil)
175
- list = @sqs.interface.receive_messages(@url, number_of_messages, visibility)
171
+ list = @sqs.interface.receive_message(@url, number_of_messages, visibility)
176
172
  list.map! do |entry|
177
- msg = Message.new(self, entry[:id], entry[:body], visibility)
178
- msg.received_at = Time.now
173
+ msg = Message.new(self, entry['MessageId'], entry['ReceiptHandle'],
174
+ entry['Body'], visibility)
175
+ msg.received_at = Time.now
176
+ msg.receive_checksum = entry['MD5OfBody']
179
177
  msg
180
178
  end
181
179
  end
182
-
183
- # Retrieves first accessible message from queue.
180
+
181
+ # Retrieves first accessible message from queue.
184
182
  # Returns Message instance or +nil+ it the queue is empty.
185
183
  #
186
184
  # queue.receive #=> #<RightAws::Sqs::Message:0xb7bf0884 ... >
@@ -190,52 +188,49 @@ module RightAws
190
188
  list.empty? ? nil : list[0]
191
189
  end
192
190
 
193
- # Peeks message body.
194
- #
195
- # queue.peek #=> #<RightAws::Sqs::Message:0xb7bf0884 ... >
196
- #
197
- def peek(message_id)
198
- entry = @sqs.interface.peek_message(@url, message_id)
199
- msg = Message.new(self, entry[:id], entry[:body])
200
- msg.received_at = Time.now
201
- msg
202
- end
203
-
204
- # Pops (and deletes) first accessible message from queue.
205
- # Returns Message instance or +nil+ it the queue is empty.
191
+ # Pops (and deletes) first accessible message from queue.
192
+ # Returns Message instance or +nil+ if the queue is empty.
206
193
  #
207
194
  # queue.pop #=> #<RightAws::Sqs::Message:0xb7bf0884 ... >
208
195
  #
209
196
  def pop
210
- msg = receive
211
- msg.delete if msg
197
+ list = @sqs.interface.pop_messages(@url, 1)
198
+ return nil if list.empty?
199
+ entry = list[0]
200
+ msg = Message.new(self, entry['MessageId'], entry['ReceiptHandle'],
201
+ entry['Body'], visibility)
202
+ msg.received_at = Time.now
203
+ msg.receive_checksum = entry['MD5OfBody']
212
204
  msg
213
205
  end
214
206
 
215
- # Retrieves +VisibilityTimeout+ value for the queue.
207
+ # Retrieves +VisibilityTimeout+ value for the queue.
216
208
  # Returns new timeout value.
217
209
  #
218
210
  # queue.visibility #=> 30
219
211
  #
220
212
  def visibility
221
- @sqs.interface.get_visibility_timeout(@url)
213
+ @sqs.interface.get_queue_attributes(@url, 'VisibilityTimeout')['VisibilityTimeout']
222
214
  end
223
-
224
- # Sets new +VisibilityTimeout+ for the queue.
225
- # Returns new timeout value.
215
+
216
+ # Sets new +VisibilityTimeout+ for the queue.
217
+ # Returns new timeout value.
226
218
  #
227
219
  # queue.visibility #=> 30
228
220
  # queue.visibility = 33
229
221
  # queue.visibility #=> 33
230
222
  #
231
223
  def visibility=(visibility_timeout)
232
- @sqs.interface.set_visibility_timeout(@url, visibility_timeout)
224
+ @sqs.interface.set_queue_attributes(@url, 'VisibilityTimeout', visibility_timeout)
233
225
  visibility_timeout
234
226
  end
235
-
236
- # Sets new queue attribute value.
237
- # Not all attributes may be changed: +ApproximateNumberOfMessages+ (for example) is a read only attribute.
238
- # Returns a value to be assigned to attribute.
227
+
228
+ # Sets new queue attribute value.
229
+ # Not all attributes may be changed: +ApproximateNumberOfMessages+ (for example) is a read only attribute.
230
+ # Returns a value to be assigned to attribute.
231
+ # Currently, 'VisibilityTimeout' is the only settable queue attribute.
232
+ # Attempting to set non-existent attributes generates an indignant
233
+ # exception.
239
234
  #
240
235
  # queue.set_attribute('VisibilityTimeout', '100') #=> '100'
241
236
  # queue.get_attribute('VisibilityTimeout') #=> '100'
@@ -244,145 +239,48 @@ module RightAws
244
239
  @sqs.interface.set_queue_attributes(@url, attribute, value)
245
240
  value
246
241
  end
247
-
248
- # Retrieves queue attributes.
249
- # At this moment Amazon supports +VisibilityTimeout+ and +ApproximateNumberOfMessages+ only.
242
+
243
+ # Retrieves queue attributes.
244
+ # At this moment Amazon supports +VisibilityTimeout+ and +ApproximateNumberOfMessages+ only.
250
245
  # If the name of attribute is set, returns its value. Otherwise, returns a hash of attributes.
251
246
  #
252
- # queue.get_attribute('VisibilityTimeout') #=> '100'
247
+ # queue.get_attribute('VisibilityTimeout') #=> {"VisibilityTimeout"=>"45"}
253
248
  #
254
249
  def get_attribute(attribute='All')
255
250
  attributes = @sqs.interface.get_queue_attributes(@url, attribute)
256
251
  attribute=='All' ? attributes : attributes[attribute]
257
252
  end
258
-
259
- # Retrieves a list of grantees.
260
- # Returns an +array+ of Grantee instances if the +grantee_email_address+ is unset.
261
- # Otherwise returns a Grantee instance that points to +grantee_email_address+ or +nil+.
262
- #
263
- # grantees = queue.grantees #=> [#<RightAws::Sqs::Grantee:0xb7bf0888 ... >, ...]
264
- # ...
265
- # grantee = queue.grantees('cool_guy@email.address') #=> nil | #<RightAws::Sqs::Grantee:0xb7bf0888 ... >
266
- #
267
- def grantees(grantee_email_address=nil, permission = nil)
268
- hash = @sqs.interface.list_grants(@url, grantee_email_address, permission)
269
- grantees = []
270
- hash.each do |key, value|
271
- grantees << Grantee.new(self, grantee_email_address, key, value[:name], value[:perms])
272
- end
273
- if grantee_email_address
274
- grantees.blank? ? nil : grantees.shift
275
- else
276
- grantees
277
- end
278
- end
279
253
  end
280
-
281
-
254
+
282
255
  class Message
283
- attr_reader :queue, :id, :body, :visibility
284
- attr_accessor :sent_at, :received_at
285
-
286
- def initialize(queue, id=nil, body=nil, visibility=nil)
256
+ attr_reader :queue, :id, :body, :visibility, :receipt_handle
257
+ attr_accessor :sent_at, :received_at, :send_checksum, :receive_checksum
258
+
259
+ def initialize(queue, id=nil, rh = nil, body=nil, visibility=nil)
287
260
  @queue = queue
288
261
  @id = id
262
+ @receipt_handle = rh
289
263
  @body = body
290
264
  @visibility = visibility
291
265
  @sent_at = nil
292
266
  @received_at = nil
267
+ @send_checksum = nil
268
+ @receive_checksum = nil
293
269
  end
294
-
270
+
295
271
  # Returns +Message+ instance body.
296
272
  def to_s
297
273
  @body
298
274
  end
299
-
300
- # Changes +VisibilityTimeout+ for current message.
301
- # Returns new +VisibilityTimeout+ value.
302
- def visibility=(visibility_timeout)
303
- @queue.sqs.interface.change_message_visibility(@queue.url, @id, visibility_timeout)
304
- @visibility = visibility_timeout
305
- end
306
-
307
- # Removes message from queue.
275
+
276
+ # Removes message from queue.
308
277
  # Returns +true+.
309
278
  def delete
310
- @queue.sqs.interface.delete_message(@queue.url, @id)
279
+ @queue.sqs.interface.delete_message(@queue.url, @receipt_handle) if @receipt_handle
311
280
  end
312
- end
313
281
 
314
-
315
- class Grantee
316
- attr_accessor :queue, :id, :name, :perms, :email
317
-
318
- # Creates new Grantee instance.
319
- # To create new grantee for queue use:
320
- #
321
- # grantee = Grantee.new(queue, grantee@email.address)
322
- # grantee.grant('FULLCONTROL')
323
- #
324
- def initialize(queue, email=nil, id=nil, name=nil, perms=[])
325
- @queue = queue
326
- @id = id
327
- @name = name
328
- @perms = perms
329
- @email = email
330
- retrieve unless id
331
- end
332
-
333
- # Retrieves security information for grantee identified by email.
334
- # Returns +nil+ if the named user has no privileges on this queue, or
335
- # +true+ if perms updated successfully.
336
- def retrieve # :nodoc:
337
- @id = nil
338
- @name = nil
339
- @perms = []
340
-
341
- hash = @queue.sqs.interface.list_grants(@queue.url, @email)
342
- return nil if hash.empty?
343
-
344
- grantee = hash.shift
345
- @id = grantee[0]
346
- @name = grantee[1][:name]
347
- @perms = grantee[1][:perms]
348
- true
349
- end
350
-
351
- # Adds permissions for grantee.
352
- # Permission: 'FULLCONTROL' | 'RECEIVEMESSAGE' | 'SENDMESSAGE'.
353
- # The caller must have set the email instance variable.
354
- def grant(permission=nil)
355
- raise "You can't grant permission without defining a grantee email address!" unless @email
356
- @queue.sqs.interface.add_grant(@queue.url, @email, permission)
357
- retrieve
358
- end
359
-
360
- # Revokes permissions for grantee.
361
- # Permission: 'FULLCONTROL' | 'RECEIVEMESSAGE' | 'SENDMESSAGE'.
362
- # Default value is 'FULLCONTROL'.
363
- # User must have +@email+ or +@id+ set.
364
- # Returns +true+.
365
- def revoke(permission='FULLCONTROL')
366
- @queue.sqs.interface.remove_grant(@queue.url, @email || @id, permission)
367
- unless @email # if email is unknown - just remove permission from local perms list...
368
- @perms.delete(permission)
369
- else # ... else retrieve updated information from Amazon
370
- retrieve
371
- end
372
- true
373
- end
374
-
375
- # Revokes all permissions for this grantee.
376
- # Returns +true+
377
- def drop
378
- @perms.each do |permission|
379
- @queue.sqs.interface.remove_grant(@queue.url, @email || @id, permission)
380
- end
381
- retrieve
382
- true
383
- end
384
-
385
282
  end
386
283
 
284
+
387
285
  end
388
286
  end