iron_mq 3.1.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ce00af7c17301f12971aae72083ba984718c11be
4
+ data.tar.gz: 42965aeda2d296af77c3125a663132c7beb0a450
5
+ SHA512:
6
+ metadata.gz: 0f40c8007eba47c0982c091e9857b79ff2be1c112416a0094196601e3744be3516680a9f67f9c2f8ebb543d09a84418e20f5e12d1960c424d612a5413fcb0028
7
+ data.tar.gz: 162e8e411c13837561c0c8bc1e3a5bd874ccd5df8110e1ae0b832994df27560217192d3d1c8c2fc03fb295f23ca2ba344646e73bd77ebb86ea4e6c014f55d8f9
data/Gemfile.lock CHANGED
@@ -1,32 +1,33 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- iron_mq (3.1.0)
4
+ iron_mq (4.0.0)
5
5
  iron_core (>= 0.5.1)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
10
  beanstalk-client (1.1.1)
11
- concur (1.0.2)
12
- ethon (0.5.7)
11
+ concur (2.0.0)
12
+ ethon (0.5.9)
13
13
  ffi (~> 1.2.0)
14
14
  mime-types (~> 1.18)
15
15
  ffi (1.2.1)
16
16
  iron_core (0.5.1)
17
17
  rest (>= 2.2.0)
18
- mime-types (1.19)
19
- minitest (4.4.0)
18
+ mime-types (1.21)
19
+ minitest (4.6.2)
20
20
  net-http-persistent (2.8)
21
+ quicky (0.4.0)
21
22
  rake (10.0.3)
22
23
  rest (2.2.0)
23
24
  net-http-persistent
24
25
  rest-client (>= 0.3.0)
25
26
  rest-client (1.6.7)
26
27
  mime-types (>= 1.16)
27
- test-unit (2.5.3)
28
- typhoeus (0.5.4)
29
- ethon (~> 0.5.7)
28
+ test-unit (2.5.4)
29
+ typhoeus (0.6.1)
30
+ ethon (~> 0.5.9)
30
31
  uber_config (1.0.5)
31
32
 
32
33
  PLATFORMS
@@ -38,6 +39,7 @@ DEPENDENCIES
38
39
  iron_mq!
39
40
  minitest
40
41
  net-http-persistent
42
+ quicky
41
43
  rake
42
44
  test-unit
43
45
  typhoeus (>= 0.5.4)
data/README.md CHANGED
@@ -6,113 +6,338 @@ much as possible so if you see an option in the API docs, you can use it in the
6
6
 
7
7
  http://dev.iron.io/mq/reference/api/
8
8
 
9
- Getting Started
10
- ==============
9
+ #Getting Started
11
10
 
12
11
  1\. Install the gem:
13
12
 
14
- gem install iron_mq
13
+ ```ruby
14
+ gem install iron_mq
15
+ ```
15
16
 
16
- 2\. Setup your Iron.io credentials: http://dev.iron.io/articles/configuration/
17
+ 2\. Setup your Iron.io credentials: http://dev.iron.io/mq/reference/configuration/
17
18
 
18
19
  3\. Create an IronMQ client object:
19
20
 
20
- @ironmq = IronMQ::Client.new()
21
+ ```ruby
22
+ ironmq = IronMQ::Client.new
23
+ ```
21
24
 
22
25
  Or pass in credentials:
23
26
 
24
- @ironmq = IronMQ::Client.new(token: MY_TOKEN, project_id: MY_PROJECT_ID)
25
-
27
+ ```ruby
28
+ ironmq = IronMQ::Client.new(:token => "MY_TOKEN", :project_id => "MY_PROJECT_ID")
29
+ ```
26
30
 
27
- The Basics
28
- =========
31
+ #The Basics
29
32
 
30
- **Get a Queue object**
33
+ ###Get a Queue Object
31
34
 
32
35
  You can have as many queues as you want, each with their own unique set of messages.
33
36
 
34
- @queue = @ironmq.queue("my_queue")
35
-
36
- Now you can use it:
37
+ ```ruby
38
+ queue = ironmq.queue("my_queue")
39
+ ```
37
40
 
38
- ### Post a message on the queue:
41
+ Now you can use it.
39
42
 
40
- @queue.post("hello world!")
43
+ ### Post a Message on a Queue
41
44
 
42
- Post a message with options:
45
+ Messages are placed on the queue in a FIFO arrangement.
46
+ If a queue does not exist, it will be created upon the first posting of a message.
43
47
 
44
- @queue.post("hello world!", delay: 3600)
48
+ ```ruby
49
+ queue.post("hello world!")
50
+ ```
45
51
 
46
- ### Get a message off the queue:
52
+ ### Retrieve Queue Information
47
53
 
48
- msg = @queue.get()
49
- puts msg.body
54
+ ```ruby
55
+ queue.info # => {"id"=>"5127bf043264140e863e2283", "name"=>"my_queue", ...}
56
+ queue.id # => "5127bf043264140e863e2283"
57
+ ```
50
58
 
51
- Get a message with options:
59
+ ### Get a Message off a Queue
52
60
 
53
- msg = @queue.get(timeout: 300)
61
+ ```ruby
62
+ msg = queue.get
63
+ msg.body # => "hello world!"
64
+ ```
54
65
 
55
- When you pop/get a message from the queue, it will NOT be deleted. It will eventually go back onto the queue after
56
- a timeout if you don't delete it (default timeout is 60 seconds).
66
+ When you pop/get a message from the queue, it is no longer on the queue but it still exists within the system.
67
+ You have to explicitly delete the message or else it will go back onto the queue after the `timeout`.
68
+ The default `timeout` is 60 seconds. Minimal `timeout` is 30 seconds.
57
69
 
58
- ### Delete a message from the queue:
70
+ ### Delete a Message from a Queue
59
71
 
60
- msg.delete # or @queue.delete(msg.id)
72
+ ```ruby
73
+ msg.delete
74
+ # or
75
+ queue.delete(msg.id)
76
+ ```
61
77
 
62
78
  Be sure to delete a message from the queue when you're done with it.
63
79
 
64
- ### Poll for messages:
65
80
 
66
- @queue.poll do |msg|
67
- puts msg.body
68
- end
81
+ #Client
82
+
83
+ `IronMQ::Client` is based on `IronCore::Client` and provides easy access to the queues and messages.
84
+
85
+ ```ruby
86
+ ironmq = IronMQ::Client.new(:token => "MY_TOKEN", :project_id => "MY_PROJECT_ID")
87
+ ```
88
+
89
+ ### List Queues
90
+
91
+ ```ruby
92
+ all_queues = ironmq.queues.list # => [#<IronMQ::Queue:...>, ...]
93
+ # or
94
+ all_queues = ironmq.queues.all # => [#<IronMQ::Queue:...>, ...]
95
+ ```
96
+
97
+ **Optional parameters:**
98
+
99
+ * `page`: The 0-based page to view. The default is 0.
100
+ * `per_page`: The number of queues to return per page. The default is 30, the maximum is 100.
101
+
102
+ ```ruby
103
+ queues = ironmq.queues.all(:page => 1, :per_page => 10)
104
+ ```
105
+
106
+ ### Get Queue by Name
107
+
108
+ ```ruby
109
+ queue = ironmq.queue "my_queue" # => #<IronMQ::Queue:...>
110
+ ```
111
+
112
+ **Note:** if queue with desired name does not exist it returns fake queue.
113
+ Queue will be created automatically on post of first message or queue configuration update.
114
+
115
+ #Queues
116
+
117
+ ### Retrieve Queue Information
118
+
119
+ ```ruby
120
+ info = queue.info # => {"id"=>"5127bf043264140e863e2283", "name"=>"my_queue", ...}
121
+ ```
122
+
123
+ Shortcuts for `queue.info[key]`:
124
+
125
+ ```ruby
126
+ id = queue.id # => "5127bf043264140e863e2283"
127
+ # Does queue exists on server? Alias for `queue.id.nil?`
128
+ is_new = queue.new? # => false
129
+
130
+ size = queue.size # => 7
131
+ name = queue.name # => "my_queue"
132
+ overall_messages = queue.total_messages # => 13
133
+ subscribers = queue.subscribers # => [{"url" => "http://..."}, ...]
134
+
135
+ push_type = queue.push_type # => "multicast"
136
+ # Does queue Push Queue? Alias for `queue.push_type.nil?`
137
+ is_push_queue = queue.push_queue? # => true
138
+ ```
139
+
140
+ **Warning:** to be sure configuration information is up-to-date
141
+ client library call IronMQ API each time you request for any parameter except `queue.name`.
142
+ In this case you may prefer to use `queue.info` to have `Hash` with all available info parameters.
143
+
144
+ ### Delete a Message Queue
145
+
146
+ ```ruby
147
+ response = queue.delete_queue # => #<IronMQ::ResponseBase:...>
148
+ ```
149
+
150
+ ### Post Messages to a Queue
151
+
152
+ **Single message:**
153
+
154
+ ```ruby
155
+ response = queue.post("something helpful") # => #<IronMQ::ResponseBase:...>
156
+ # or
157
+ response = queue.post("with parameteres", :timeout => 300) # => #<IronMQ::ResponseBase:...>
158
+
159
+ message_id = response.id # => "5847899158098068288"
160
+ status_message = response.msg # => "Messages put on queue."
161
+ http_code = response.code # => 200
162
+ ```
163
+
164
+ **Multiple messages:**
165
+ ```ruby
166
+ # [{:body => VALUE}, ...] format is required
167
+ messages = [{:body => "first"}, {:body => "second"}]
168
+
169
+ response = queue.post(messages) # => {"ids" => ["5847899158098068288", ...], "msg" => "Messages put on queue."}
170
+ # or
171
+ response = queue.post(messages, :timeout => 300) # => {"ids" => ["5847899158098068288", ...], "msg" => "Messages put on queue."}
172
+ ```
173
+
174
+ **Optional parameters:**
175
+
176
+ * `timeout`: After timeout (in seconds), item will be placed back onto queue.
177
+ You must delete the message from the queue to ensure it does not go back onto the queue.
178
+ Default is 60 seconds. Minimum is 30 seconds. Maximum is 86,400 seconds (24 hours).
179
+
180
+ * `delay`: The item will not be available on the queue until this many seconds have passed.
181
+ Default is 0 seconds. Maximum is 604,800 seconds (7 days).
182
+
183
+ * `expires_in`: How long in seconds to keep the item on the queue before it is deleted.
184
+ Default is 604,800 seconds (7 days). Maximum is 2,592,000 seconds (30 days).
185
+
186
+ ### Get Messages from a Queue
187
+
188
+ ```ruby
189
+ message = queue.get # => #<IronMQ::Message:...>
190
+
191
+ # or N messages
192
+ messages = queue.get(:n => 7) # => [#<IronMQ::Message:...>, ...]
193
+
194
+ # or message by ID
195
+ message = queue.get "5127bf043264140e863e2283" # => #<IronMQ::Message:...>
196
+ ```
197
+
198
+ **Optional parameters:**
199
+
200
+ * `n`: The maximum number of messages to get. Default is 1. Maximum is 100.
201
+
202
+ * `timeout`: timeout: After timeout (in seconds), item will be placed back onto queue.
203
+ You must delete the message from the queue to ensure it does not go back onto the queue.
204
+ If not set, value from POST is used. Default is 60 seconds. Minimum is 30 seconds.
205
+ Maximum is 86,400 seconds (24 hours).
206
+
207
+ When `n` parameter is specified and greater than 1 method returns `Array` of `Queue`s.
208
+ Otherwise, `Queue` object would be returned.
209
+
210
+ ### Touch a Message on a Queue
211
+
212
+ Touching a reserved message extends its timeout by the duration specified when the message was created, which is 60 seconds by default.
213
+
214
+ ```ruby
215
+ message = queue.get # => #<IronMQ::Message:...>
216
+
217
+ message.touch # => #<IronMQ::ResponseBase:...>
218
+ ```
219
+
220
+ ### Release Message
221
+
222
+ ```ruby
223
+ message = queue.get => #<IronMQ::Message:...>
224
+
225
+ response = message.release # => #<IronMQ::ResponseBase:...>
226
+ # or
227
+ response = message.release(:delay => 42) # => #<IronMQ::ResponseBase:...>
228
+ ```
229
+
230
+ **Optional parameters:**
231
+
232
+ * `delay`: The item will not be available on the queue until this many seconds have passed.
233
+ Default is 0 seconds. Maximum is 604,800 seconds (7 days).
234
+
235
+ ### Delete a Message from a Queue
236
+
237
+ ```ruby
238
+ message = queue.get # => #<IronMQ::Queue:...>
239
+
240
+ message.delete # => #<IronMQ::ResponseBase:...>
241
+ # or
242
+ queue.delete_message(message.id) # => #<IronMQ::ResponseBase:...>
243
+ ```
244
+
245
+ ### Peek Messages from a Queue
246
+
247
+ Peeking at a queue returns the next messages on the queue, but it does not reserve them.
248
+
249
+ ```ruby
250
+ message = queue.peek # => #<IronMQ::Message:...>
251
+ # or multiple messages
252
+ messages = queue.peek(:n => 13) # => [#<IronMQ::Message:...>, ...]
253
+ ```
254
+
255
+ **Optional parameters:**
256
+
257
+ * `n`: The maximum number of messages to peek. Default is 1. Maximum is 100.
258
+
259
+ ### Poll for Messages
260
+
261
+ ```ruby
262
+ queue.poll { |msg| puts msg.body }
263
+ ```
69
264
 
70
265
  Polling will automatically delete the message at the end of the block.
71
266
 
72
- Queue Information
73
- =================
267
+ ### Clear a Queue
74
268
 
75
- queue = @client.queue("my_queue")
76
- puts "size: #{queue.size}"
269
+ ```ruby
270
+ queue.clear # => #<IronMQ::ResponseBase:...>
271
+ ```
77
272
 
273
+ #Push Queues
78
274
 
79
- Push Queues
80
- ===========
275
+ IronMQ push queues allow you to setup a queue that will push to an endpoint, rather than having to poll the endpoint.
276
+ [Here's the announcement for an overview](http://blog.iron.io/2013/01/ironmq-push-queues-reliable-message.html).
81
277
 
82
- IronMQ push queues allow you to setup a queue that will push to an endpoint, rather than having to poll the endpoint.
278
+ ### Update a Message Queue
83
279
 
84
- LINK TO BLOG POST
280
+ ```ruby
281
+ queue_info = queue.update(options) # => {"id"=>"5127bf043264140e863e2283", "name"=>"my_queue", ...}
282
+ ```
85
283
 
86
- ### Set subscribers on a queue:
284
+ **The following parameters are all related to Push Queues:**
87
285
 
88
- Subscribers can be any http endpoint. push_type is one of:
286
+ * `subscribers`: An array of subscriber hashes containing a “url” field.
287
+ This set of subscribers will replace the existing subscribers.
288
+ To add or remove subscribers, see the add subscribers endpoint or the remove subscribers endpoint.
289
+ See below for example json.
290
+ * `push_type`: Either `multicast` to push to all subscribers or `unicast` to push to one and only one subscriber. Default is `multicast`.
291
+ * `retries`: How many times to retry on failure. Default is 3.
292
+ * `retries_delay`: Delay between each retry in seconds. Default is 60.
89
293
 
90
- - multicast - will push to all endpoints/subscribers
91
- - unicast - will push to one and only one endpoint/subscriber
294
+ ### Set Subscribers on a Queue
92
295
 
296
+ Subscribers can be any HTTP endpoint. `push_type` is one of:
297
+
298
+ * `multicast`: will push to all endpoints/subscribers
299
+ * `unicast`: will push to one and only one endpoint/subscriber
93
300
 
94
301
  ```ruby
95
- subscribers = []
96
- subscribers << {url: "http://rest-test.iron.io/code/200?store=key1"}
97
- subscribers << {url: "http://rest-test.iron.io/code/200?store=key2"}
98
- res = @queue.update_queue(:subscribers => subscribers,
99
- :push_type => t)
302
+ ptype = :multicast
303
+ subscribers = [
304
+ {url: "http://rest-test.iron.io/code/200?store=key1"}
305
+ {url: "http://rest-test.iron.io/code/200?store=key2"}
306
+ ]
307
+
308
+ queue.update(:subscribers => subscribers, :push_type => ptype)
100
309
  ```
101
310
 
102
- ### Add/remove subscribers on a queue
311
+ ### Add/Remove Subscribers on a Queue
103
312
 
104
313
  ```ruby
105
- @queue.add_subscriber({url: "http://nowhere.com"})
106
- # Or to remove a subscriber:
107
- @queue.remove_subscriber({url: "http://nowhere.com"})
314
+ queue.add_subscriber({url: "http://nowhere.com"})
315
+
316
+ queue.remove_subscriber({url: "http://nowhere.com"})
108
317
  ```
109
318
 
110
- ### Get message push status
319
+ ### Get Message Push Status
111
320
 
112
321
  After pushing a message:
113
322
 
114
323
  ```ruby
115
- queue.messages.get(m.id).subscribers
324
+ subscribers = queue.get(msg.id).subscribers # => [#<IronMQ::Subscriber:...>, ...]
325
+ # old syntax, still supported
326
+ subscribers = queue.messages.get(msg.id).subscribers # => [#<IronMQ::Subscriber:...>, ...]
327
+
328
+ subscribers.each { |ss| puts "#{ss.id}: #{(ss.code == 200) ? 'Success' : 'Fail'}" }
116
329
  ```
117
330
 
118
331
  Returns an array of subscribers with status.
332
+
333
+ ### Delete Message Push Status
334
+
335
+ ```ruby
336
+ subscribers = queue.get(msg.id).subscribers # => [#<IronMQ::Subscriber:...>, ...]
337
+
338
+ subscribers.each { |ss| ss.delete }
339
+ ```
340
+
341
+
342
+ -------------
343
+ © 2011 - 2013 Iron.io Inc. All Rights Reserved.
data/iron_mq.gemspec CHANGED
@@ -1,8 +1,8 @@
1
1
  require File.expand_path('../lib/iron_mq/version', __FILE__)
2
2
 
3
3
  Gem::Specification.new do |gem|
4
- gem.authors = ["Travis Reeder"]
5
- gem.email = ["travis@iron.io"]
4
+ gem.authors = ["Yury Yantsevich", "Travis Reeder"]
5
+ gem.email = ["yury@iron.io", "travis@iron.io"]
6
6
  gem.description = "Ruby client for IronMQ by www.iron.io"
7
7
  gem.summary = "Ruby client for IronMQ by www.iron.io"
8
8
  gem.homepage = "https://github.com/iron-io/iron_mq_ruby"
@@ -26,6 +26,7 @@ Gem::Specification.new do |gem|
26
26
  gem.add_development_dependency "typhoeus", ">= 0.5.4"
27
27
  gem.add_development_dependency "concur"
28
28
  gem.add_development_dependency "net-http-persistent"
29
+ gem.add_development_dependency "quicky"
29
30
 
30
31
  end
31
32
 
@@ -16,11 +16,10 @@ module IronMQ
16
16
  :host => IronMQ::Client::AWS_US_EAST_HOST,
17
17
  :port => 443,
18
18
  :api_version => 1,
19
- :user_agent => 'iron_mq_ruby-' + IronMQ::VERSION + ' (iron_core_ruby-' + IronCore.version + ')',
20
- :queue_name => 'default'
19
+ :user_agent => 'iron_mq_ruby-' + 'very_new' + ' (iron_core_ruby-' + IronCore.version + ')'
21
20
  }
22
21
 
23
- super('iron', 'mq', options, default_options, [:project_id, :token, :api_version, :queue_name])
22
+ super('iron', 'mq', options, default_options, [:project_id, :token, :api_version])
24
23
 
25
24
  IronCore::Logger.error 'IronMQ', "Token is not set", IronCore::Error if @token.nil?
26
25
 
@@ -35,19 +34,43 @@ module IronMQ
35
34
  end
36
35
 
37
36
  def base_url
38
- super + @api_version.to_s + '/'
37
+ @base_url = "#{super}#{@api_version}/projects/#{@project_id}/queues"
39
38
  end
40
39
 
41
- def queue(name)
42
- return Queue.new(self, {"name" => name})
40
+ def queues_list(options = {})
41
+ response = parse_response(get('', options)) # GET base_url
42
+ # returns list of evaluated queues
43
+ response.each_with_object([]) { |q_info, ret| ret << Queue.new(self, q_info["name"]) }
43
44
  end
44
45
 
45
- def messages
46
- return Messages.new(self)
46
+ alias_method :list, :queues_list
47
+ alias_method :all, :queues_list
48
+
49
+ def queues_get(name)
50
+ Queue.new(self, name)
47
51
  end
48
52
 
53
+ alias_method :queue, :queues_get
54
+
55
+ # Backward compatibility for
56
+ # client.queues.get(:name => "my_queue")
57
+ # client.queues.get("name" => "my_queue")
58
+ def get(*args)
59
+ if args.size == 1 && args[0].is_a?(Hash)
60
+ queue_name = (args[0][:name] || args[0]["name"]).to_s
61
+ queue_name.empty? ? super : queues_get(queue_name)
62
+ else
63
+ super
64
+ end
65
+ end
66
+
67
+ # Backward compatibility, adds possibility to call
68
+ # client.queues.all
69
+ # client.queues.list
70
+ # client.queues.queue(name)
49
71
  def queues
50
- return Queues.new(self)
72
+ self
51
73
  end
52
74
  end
75
+
53
76
  end
@@ -1,128 +1,45 @@
1
1
  require 'cgi'
2
2
 
3
3
  module IronMQ
4
- class Messages
5
4
 
6
- attr_reader :client, :queue
5
+ class Message < ResponseBase
6
+ attr_reader :queue
7
7
 
8
- def initialize(client, queue=nil)
9
- @client = client
8
+ def initialize(queue, data)
10
9
  @queue = queue
10
+ super(data, 200)
11
11
  end
12
12
 
13
-
14
- def path(options={})
15
- options[:queue_name] ||= ((@queue ? @queue.name : nil) || @client.queue_name)
16
- options[:project_id] = @client.project_id
17
- Messages.path(options)
13
+ def touch
14
+ call_api_and_parse_response(:post, "/touch")
18
15
  end
19
16
 
20
- def self.path(options)
21
- path = "#{Queues.path(options)}/messages"
22
- if options[:msg_id]
23
- path << "/#{options[:msg_id]}"
24
- end
25
- path
17
+ def release(options = {})
18
+ call_api_and_parse_response(:post, "/release", options)
26
19
  end
27
20
 
28
- # options:
29
- # :queue_name => can specify an alternative queue name
30
- # :timeout => amount of time before message goes back on the queue
31
- def get(options={})
32
- if options.is_a?(String)
33
- # assume it's an id
34
- puts 'get_by_id'
35
- return Message.new(self, {'id'=>options}, options)
36
- #r = @client.get(path(:msg_id=>options))
37
- #p r
38
- #return r
39
- end
40
- res = @client.parse_response(@client.get(path(options), options))
41
- ret = []
42
- res["messages"].each do |m|
43
- ret << Message.new(self, m, options)
44
- end
45
- if options[:n] || options['n']
46
- return ret
47
- else
48
- if ret.size > 0
49
- return ret[0]
50
- else
51
- return nil
52
- end
53
- end
54
- end
21
+ # `options` was kept for backward compatibility
22
+ def subscribers(options = {})
23
+ response = call_api_and_parse_response(:get, "/subscribers", {}, false)
55
24
 
56
- # options:
57
- # :queue_name => can specify an alternative queue name
58
- # :delay => time to wait before message will be available on the queue
59
- # :timeout => The time in seconds to wait after message is taken off the queue, before it is put back on. Delete before :timeout to ensure it does not go back on the queue.
60
- # :expires_in => After this time, message will be automatically removed from the queue.
61
- def post(payload, options={})
62
- batch = false
63
- if payload.is_a?(Array)
64
- batch = true
65
- msgs = payload
66
- else
67
- options[:body] = payload
68
- msgs = []
69
- msgs << options
70
- end
71
- to_send = {}
72
- to_send[:messages] = msgs
73
- res = @client.parse_response(@client.post(path(options), to_send))
74
- if batch
75
- return res
76
- else
77
- return ResponseBase.new({"id"=>res["ids"][0], "msg"=>res["msg"]})
25
+ response['subscribers'].each_with_object([]) do |subscriber, ret|
26
+ ret << Subscriber.new(subscriber, self, options)
78
27
  end
79
28
  end
80
29
 
81
- def delete(message_id, options={})
82
- path2 = "#{self.path(options)}/#{message_id}"
83
- res = @client.parse_response(@client.delete(path2))
84
- return ResponseBase.new(res)
85
- end
86
-
87
- def release(message_id, options={})
88
- path2 = "#{self.path(options)}/#{message_id}/release"
89
- res = @client.parse_response(@client.post(path2, options))
90
- return ResponseBase.new(res)
91
- end
92
-
93
- end
94
-
95
- class Message < ResponseBase
96
- attr_reader :messages
97
-
98
- def initialize(messages, res, options={})
99
- super(res)
100
- @messages = messages
101
- @options = options
102
- end
103
-
104
- def body
105
- raw["body"]
106
- end
107
-
108
30
  def delete
109
- @messages.delete(self.id, @options)
31
+ call_api_and_parse_response(:delete)
110
32
  end
111
33
 
112
- def release(options={})
113
- options2 = options || {}
114
- options2 = options.merge(@options) if @options
115
- @messages.release(self.id, options2)
34
+ def call_api_and_parse_response(meth, ext_path = "", options = {}, instantiate = true)
35
+ @queue.call_api_and_parse_response(meth, "#{path(ext_path)}", options, instantiate)
116
36
  end
117
37
 
118
- def subscribers(options={})
119
- res = @messages.client.get(@messages.path(options.merge(:msg_id => id)) + "/subscribers", options)
120
- res = @messages.client.parse_response(res)
121
- ret = []
122
- res['subscribers'].each do |m|
123
- ret << Subscriber.new(m, self, options)
124
- end
125
- ret
38
+ private
39
+
40
+ def path(ext_path)
41
+ "/messages/#{id}#{ext_path}"
126
42
  end
127
43
  end
44
+
128
45
  end