raws 0.0.10 → 0.0.11
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/LICENSE +1 -1
- data/README.rdoc +50 -29
- data/Rakefile +5 -5
- data/VERSION +1 -1
- data/lib/raws/http.rb +1 -0
- data/lib/raws/s3.rb +84 -52
- data/lib/raws/s3/acl.rb +144 -0
- data/lib/raws/s3/adapter.rb +44 -20
- data/lib/raws/s3/metadata.rb +9 -3
- data/lib/raws/s3/model.rb +76 -50
- data/lib/raws/s3/owner.rb +8 -0
- data/lib/raws/sdb.rb +61 -50
- data/lib/raws/sdb/adapter.rb +2 -4
- data/lib/raws/sdb/model.rb +53 -44
- data/lib/raws/sdb/select.rb +1 -1
- data/lib/raws/sqs.rb +155 -89
- data/lib/raws/sqs/adapter.rb +28 -27
- data/lib/raws/sqs/message.rb +39 -0
- data/lib/raws/sqs/model.rb +33 -0
- data/lib/raws/xml.rb +0 -2
- data/lib/raws/xml/nokogiri.rb +4 -1
- data/raws.gemspec +24 -19
- data/spec/raws/s3/acl_spec.rb +30 -0
- data/spec/raws/s3/model_spec.rb +2 -3
- data/spec/raws/s3_spec.rb +34 -36
- data/spec/raws/sdb/model_spec.rb +104 -9
- data/spec/raws/sdb_spec.rb +43 -52
- data/spec/raws/sqs_spec.rb +40 -35
- data/spec/raws_spec.rb +2 -0
- data/spec/spec_config.rb.example +8 -13
- metadata +13 -8
- data/spec/spec.opts +0 -1
data/lib/raws/sdb/adapter.rb
CHANGED
@@ -97,10 +97,8 @@ class RAWS::SDB::Adapter
|
|
97
97
|
connect('GET', URI, PARAMS.merge(params))
|
98
98
|
end
|
99
99
|
|
100
|
-
def list_domains(
|
101
|
-
params
|
102
|
-
params['NextToken'] = next_token if next_token
|
103
|
-
params['MaxNumberOfDomains'] = max_num if max_num
|
100
|
+
def list_domains(params={}, &block)
|
101
|
+
params.merge!('Action' => 'ListDomains')
|
104
102
|
|
105
103
|
connect('GET', URI, PARAMS.merge(params), :multiple => %w'DomainName')
|
106
104
|
end
|
data/lib/raws/sdb/model.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'forwardable'
|
1
2
|
require 'uuidtools'
|
2
3
|
|
3
4
|
module RAWS::SDB::Model
|
@@ -8,19 +9,30 @@ module RAWS::SDB::Model
|
|
8
9
|
end
|
9
10
|
|
10
11
|
def attr_filter(val)
|
11
|
-
@model.new(val.last, val.first)
|
12
|
+
@model.new(val.last, val.first, true)
|
12
13
|
end
|
13
14
|
end
|
14
15
|
|
15
16
|
module ClassMethods
|
16
|
-
|
17
|
+
extend Forwardable
|
18
|
+
def_delegators :domain,
|
19
|
+
:create_domain,
|
20
|
+
:delete_domain,
|
21
|
+
:domain_metadata,
|
22
|
+
:metadata,
|
23
|
+
:get_attributes,
|
24
|
+
:get,
|
25
|
+
:put_attributes,
|
26
|
+
:put,
|
27
|
+
:batch_put_attributes,
|
28
|
+
:batch_put,
|
29
|
+
:delete_attributes,
|
30
|
+
:delete
|
17
31
|
|
18
|
-
|
19
|
-
RAWS::SDB[domain_name].create_domain
|
20
|
-
end
|
32
|
+
attr_accessor :domain_name
|
21
33
|
|
22
|
-
def
|
23
|
-
RAWS::SDB[domain_name]
|
34
|
+
def domain
|
35
|
+
RAWS::SDB[domain_name]
|
24
36
|
end
|
25
37
|
|
26
38
|
def select(&block)
|
@@ -29,47 +41,33 @@ module RAWS::SDB::Model
|
|
29
41
|
alias :all :select
|
30
42
|
|
31
43
|
def find(id)
|
32
|
-
if attrs =
|
33
|
-
self.new(attrs, id)
|
44
|
+
if attrs = get_attributes(id)
|
45
|
+
self.new(attrs, id, true)
|
34
46
|
end
|
35
47
|
end
|
36
48
|
|
37
|
-
def
|
38
|
-
|
49
|
+
def create_id
|
50
|
+
[
|
51
|
+
UUIDTools::UUID.random_create.raw
|
52
|
+
].pack('m').sub(/==\n$/, '').tr('+/', '-_')
|
39
53
|
end
|
54
|
+
end
|
40
55
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
def #{name}
|
45
|
-
self['#{name}']
|
46
|
-
end
|
47
|
-
}
|
48
|
-
end
|
49
|
-
end
|
56
|
+
module InstanceMethods
|
57
|
+
attr_accessor :id
|
58
|
+
attr_reader :values
|
50
59
|
|
51
|
-
def
|
52
|
-
|
53
|
-
|
54
|
-
def #{name}=(val)
|
55
|
-
self['#{name}'] = val
|
56
|
-
end
|
57
|
-
}
|
58
|
-
end
|
60
|
+
def initialize(values={}, id=nil, exists=false)
|
61
|
+
@id, @values, @exists = id, values, exists
|
62
|
+
after_initialize
|
59
63
|
end
|
60
64
|
|
61
|
-
def
|
62
|
-
|
63
|
-
sdb_writer(*names)
|
65
|
+
def create_id
|
66
|
+
self.class.create_id
|
64
67
|
end
|
65
|
-
end
|
66
|
-
|
67
|
-
module InstanceMethods
|
68
|
-
attr_reader :id, :values
|
69
68
|
|
70
|
-
def
|
71
|
-
@
|
72
|
-
after_initialize
|
69
|
+
def exists?
|
70
|
+
@exists
|
73
71
|
end
|
74
72
|
|
75
73
|
def [](key)
|
@@ -80,22 +78,24 @@ module RAWS::SDB::Model
|
|
80
78
|
values[key] = val
|
81
79
|
end
|
82
80
|
|
83
|
-
def delete
|
81
|
+
def delete(attrs={})
|
84
82
|
before_delete
|
85
|
-
|
83
|
+
self.class.delete_attributes(id, attrs) if id
|
84
|
+
@exists = false
|
86
85
|
after_delete
|
87
86
|
end
|
88
87
|
|
89
88
|
def save
|
90
89
|
before_save
|
91
|
-
if
|
90
|
+
if exists?
|
92
91
|
before_update
|
93
|
-
|
92
|
+
self.class.put_attributes(id, values, *values.keys)
|
94
93
|
after_update
|
95
94
|
else
|
96
95
|
before_insert
|
97
|
-
@id
|
98
|
-
|
96
|
+
@id ||= create_id
|
97
|
+
self.class.put_attributes(id, values, *values.keys)
|
98
|
+
@exists = true
|
99
99
|
after_insert
|
100
100
|
end
|
101
101
|
after_save
|
@@ -110,6 +110,15 @@ module RAWS::SDB::Model
|
|
110
110
|
def after_update; end
|
111
111
|
def before_insert; end
|
112
112
|
def after_insert; end
|
113
|
+
|
114
|
+
def method_missing(_name, *args)
|
115
|
+
name = _name.to_s
|
116
|
+
if md = /(.+)=$/.match(name)
|
117
|
+
self[md[1]] = args.unshift
|
118
|
+
elsif values.key?(name)
|
119
|
+
self[name]
|
120
|
+
end
|
121
|
+
end
|
113
122
|
end
|
114
123
|
|
115
124
|
def self.included(mod)
|
data/lib/raws/sdb/select.rb
CHANGED
data/lib/raws/sqs.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
class RAWS::SQS
|
2
2
|
autoload :Adapter, 'raws/sqs/adapter'
|
3
|
+
autoload :Message, 'raws/sqs/message'
|
4
|
+
autoload :Model, 'raws/sqs/model'
|
3
5
|
|
4
6
|
class << self
|
5
7
|
include Enumerable
|
@@ -10,112 +12,140 @@ class RAWS::SQS
|
|
10
12
|
@http ||= RAWS.http
|
11
13
|
end
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
return url
|
15
|
+
# Returns the queue URL for the +queue_name_or_url+ if exists the queue.
|
16
|
+
def queue_url(queue_name_or_url)
|
17
|
+
if URI.parse(queue_name_or_url).scheme
|
18
|
+
queue_name_or_url
|
19
|
+
else
|
20
|
+
list_queues(queue_name_or_url).map do |sqs|
|
21
|
+
sqs.queue_url
|
22
|
+
end.each do |url|
|
23
|
+
return url if URI.parse(url).path.split('/').last == queue_name_or_url
|
22
24
|
end
|
23
|
-
end
|
25
|
+
end
|
24
26
|
end
|
25
27
|
|
26
|
-
|
27
|
-
|
28
|
+
# Creates a new queue and returns the instance of RAWS::SQS.
|
29
|
+
def create_queue(queue_name, default_visibility_timeout=nil)
|
30
|
+
self.new\
|
28
31
|
Adapter.create_queue(
|
29
32
|
queue_name,
|
30
|
-
|
33
|
+
default_visibility_timeout
|
31
34
|
)['CreateQueueResponse']['CreateQueueResult']['QueueUrl']
|
32
|
-
)
|
33
35
|
end
|
34
36
|
|
35
|
-
|
36
|
-
|
37
|
+
# Deletes the queue.
|
38
|
+
def delete_queue(queue_name_or_url)
|
39
|
+
Adapter.delete_queue queue_url(queue_name_or_url)
|
37
40
|
end
|
38
41
|
|
39
|
-
|
40
|
-
|
41
|
-
doc
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
42
|
+
# Returns an array of RAWS::SQS objects.
|
43
|
+
def list_queues(prefix=nil)
|
44
|
+
doc = Adapter.list_queues(prefix)\
|
45
|
+
['ListQueuesResponse']['ListQueuesResult']
|
46
|
+
if doc
|
47
|
+
doc['QueueUrl'].map do |val|
|
48
|
+
self.new(val)
|
49
|
+
end
|
50
|
+
else
|
51
|
+
[]
|
47
52
|
end
|
48
53
|
end
|
49
54
|
|
50
|
-
def each(&block)
|
51
|
-
|
55
|
+
def each(prefix=nil, &block)
|
56
|
+
list_queues(prefix).each(&block)
|
52
57
|
end
|
53
58
|
|
54
|
-
def
|
55
|
-
if
|
56
|
-
|
59
|
+
def queues(&block)
|
60
|
+
if block_given?
|
61
|
+
each(&block)
|
62
|
+
else
|
63
|
+
map
|
57
64
|
end
|
58
65
|
end
|
59
66
|
|
60
|
-
|
67
|
+
# Returns the instance of RAWS::SQS.
|
68
|
+
def [](queue_name_or_url)
|
69
|
+
self.new queue_url(queue_name_or_url)
|
70
|
+
end
|
71
|
+
|
72
|
+
# Returns the queue attributes.
|
73
|
+
#
|
74
|
+
# * +attrs+ -
|
75
|
+
# All,
|
76
|
+
# ApproximateNumberOfMessages,
|
77
|
+
# ApproximateNumberOfMessagesNotVisible,
|
78
|
+
# VisibilityTimeout,
|
79
|
+
# CreatedTimestamp,
|
80
|
+
# LastModifiedTimestamp,
|
81
|
+
# Policy
|
82
|
+
def get_queue_attributes(queue_name_or_url, *attrs)
|
61
83
|
Adapter.get_queue_attributes(
|
62
|
-
queue_url,
|
84
|
+
queue_url(queue_name_or_url),
|
63
85
|
*attrs
|
64
86
|
)['GetQueueAttributesResponse']['GetQueueAttributesResult']['Attribute']
|
65
87
|
end
|
66
88
|
|
67
|
-
|
68
|
-
|
89
|
+
# Sets the queue attributes.
|
90
|
+
#
|
91
|
+
# * +attrs+ - {_AttributeName_ => _AttributeValue_}
|
92
|
+
# * AttributeName - VisibilityTimeout, Policy
|
93
|
+
def set_queue_attributes(queue_name_or_url, attrs)
|
94
|
+
Adapter.set_queue_attributes queue_url(queue_name_or_url), attrs
|
69
95
|
end
|
70
96
|
|
71
|
-
|
72
|
-
|
97
|
+
# Sends a message to the queue.
|
98
|
+
def send_message(queue_name_or_url, msg)
|
99
|
+
Adapter.send_message queue_url(queue_name_or_url), msg
|
73
100
|
end
|
101
|
+
alias :send :send_message
|
74
102
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
103
|
+
# Receives one or more messages form the queue.
|
104
|
+
# Returns an array of message data.
|
105
|
+
def receive_message(queue_name_or_url, params={}, *attrs)
|
106
|
+
doc = Adapter.receive_message(
|
107
|
+
queue_url(queue_name_or_url),
|
108
|
+
params,
|
80
109
|
*attrs
|
81
|
-
)['ReceiveMessageResponse']['ReceiveMessageResult']
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
Adapter.remove_permission(queue_url, label)
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
class Message
|
102
|
-
attr_reader :queue
|
103
|
-
attr_reader :data
|
104
|
-
|
105
|
-
def initialize(queue, data)
|
106
|
-
@queue, @data = queue, data
|
110
|
+
)['ReceiveMessageResponse']['ReceiveMessageResult']
|
111
|
+
doc ? doc['Message'] : []
|
112
|
+
end
|
113
|
+
alias :receive :receive_message
|
114
|
+
|
115
|
+
# Changes the message visibility timeout.
|
116
|
+
def change_message_visibility(
|
117
|
+
queue_name_or_url,
|
118
|
+
receipt_handle,
|
119
|
+
visibility_timeout
|
120
|
+
)
|
121
|
+
Adapter.change_message_visibility(
|
122
|
+
queue_url(queue_name_or_url),
|
123
|
+
receipt_handle,
|
124
|
+
visibility_timeout
|
125
|
+
)
|
107
126
|
end
|
108
127
|
|
109
|
-
|
110
|
-
|
128
|
+
# Deletes the message.
|
129
|
+
def delete_message(queue_name, receipt_handle)
|
130
|
+
Adapter.delete_message queue_url(queue_name), receipt_handle
|
111
131
|
end
|
112
132
|
|
113
|
-
|
114
|
-
|
133
|
+
# Adds the permissions.
|
134
|
+
#
|
135
|
+
# * +permissions+ - {_AWSAccountId_ => [_ActionName_, ...], ...}
|
136
|
+
# * +ActionName+ - *,
|
137
|
+
# SendMessage,
|
138
|
+
# ReceiveMessage,
|
139
|
+
# DeleteMessage,
|
140
|
+
# ChangeMessageVisibility,
|
141
|
+
# GetQueueAttributes
|
142
|
+
def add_permission(queue_name, label, permissions)
|
143
|
+
Adapter.add_permission queue_url(queue_name), label, permissions
|
115
144
|
end
|
116
145
|
|
117
|
-
|
118
|
-
|
146
|
+
# Removes the permission.
|
147
|
+
def remove_permission(queue_name, label)
|
148
|
+
Adapter.remove_permission queue_url(queue_name), label
|
119
149
|
end
|
120
150
|
end
|
121
151
|
|
@@ -127,42 +157,78 @@ class RAWS::SQS
|
|
127
157
|
@queue_name = URI.parse(@queue_url).path.split('/').last
|
128
158
|
end
|
129
159
|
|
160
|
+
# Delete the queue.
|
130
161
|
def delete_queue
|
131
|
-
self.class.delete_queue
|
162
|
+
self.class.delete_queue queue_url
|
132
163
|
end
|
133
164
|
|
134
|
-
|
135
|
-
|
165
|
+
# Returns the queue attributes.
|
166
|
+
#
|
167
|
+
# * +attrs+ -
|
168
|
+
# All,
|
169
|
+
# ApproximateNumberOfMessages,
|
170
|
+
# ApproximateNumberOfMessagesNotVisible,
|
171
|
+
# VisibilityTimeout,
|
172
|
+
# CreatedTimestamp,
|
173
|
+
# LastModifiedTimestamp,
|
174
|
+
# Policy
|
175
|
+
def get_queue_attributes(*attrs)
|
176
|
+
self.class.get_queue_attributes queue_url, *attrs
|
136
177
|
end
|
137
178
|
|
138
|
-
|
139
|
-
|
179
|
+
# Sets the queue attributes.
|
180
|
+
#
|
181
|
+
# * +attrs+ - {_AttributeName_ => _AttributeValue_}
|
182
|
+
# * AttributeName - VisibilityTimeout, Policy
|
183
|
+
def set_queue_attributes(attrs)
|
184
|
+
self.class.set_queue_attributes queue_url, attrs
|
140
185
|
end
|
141
186
|
|
142
|
-
|
143
|
-
|
187
|
+
# Sends the message to the queue.
|
188
|
+
def send_message(msg)
|
189
|
+
self.class.send_message queue_url, msg
|
144
190
|
end
|
191
|
+
alias :send :send_message
|
145
192
|
|
146
|
-
|
147
|
-
|
148
|
-
|
193
|
+
# Receives the messages form the queue.
|
194
|
+
# Returns an array of RAWS::SQS::Message objects.
|
195
|
+
def receive_message(params={}, *attrs)
|
196
|
+
self.class.receive_message(queue_url, params, *attrs).map do |val|
|
197
|
+
Message.new self, val
|
149
198
|
end
|
150
199
|
end
|
151
|
-
|
152
|
-
|
153
|
-
|
200
|
+
alias :receive :receive_message
|
201
|
+
|
202
|
+
# Changes the message visivility timeout.
|
203
|
+
def change_message_visibility(receipt_handle, visibility_timeout)
|
204
|
+
self.class.change_message_visibility(
|
205
|
+
queue_url,
|
206
|
+
receipt_handle,
|
207
|
+
visibility_timeout
|
208
|
+
)
|
154
209
|
end
|
155
210
|
|
156
|
-
|
157
|
-
|
211
|
+
# Deletes the message.
|
212
|
+
def delete_message(receipt_handle)
|
213
|
+
self.class.delete_message queue_url, receipt_handle
|
158
214
|
end
|
159
215
|
|
216
|
+
# Adds the permissions.
|
217
|
+
#
|
218
|
+
# * +permissions+ - {_AWSAccountId_ => [_ActionName_, ...], ...}
|
219
|
+
# * +ActionName+ - *,
|
220
|
+
# SendMessage,
|
221
|
+
# ReceiveMessage,
|
222
|
+
# DeleteMessage,
|
223
|
+
# ChangeMessageVisibility,
|
224
|
+
# GetQueueAttributes
|
160
225
|
def add_permission(label, permission)
|
161
|
-
self.class.add_permission
|
226
|
+
self.class.add_permission queue_url, label, permission
|
162
227
|
end
|
163
228
|
|
229
|
+
# Removes the permission.
|
164
230
|
def remove_permission(label)
|
165
|
-
self.class.remove_permission
|
231
|
+
self.class.remove_permission queue_url, label
|
166
232
|
end
|
167
233
|
|
168
234
|
def <=>(a)
|