iron_mq 4.0.0 → 4.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ce00af7c17301f12971aae72083ba984718c11be
4
- data.tar.gz: 42965aeda2d296af77c3125a663132c7beb0a450
3
+ metadata.gz: ae70cddc4f116d5a8d516a5eed1cd722f221df59
4
+ data.tar.gz: ba911a0556103b6fa9c4b5407b59fd6966b92661
5
5
  SHA512:
6
- metadata.gz: 0f40c8007eba47c0982c091e9857b79ff2be1c112416a0094196601e3744be3516680a9f67f9c2f8ebb543d09a84418e20f5e12d1960c424d612a5413fcb0028
7
- data.tar.gz: 162e8e411c13837561c0c8bc1e3a5bd874ccd5df8110e1ae0b832994df27560217192d3d1c8c2fc03fb295f23ca2ba344646e73bd77ebb86ea4e6c014f55d8f9
6
+ metadata.gz: 8e07437588ae4af6e20c4816d23db5a88aed43e39311c329a3871751c96147628bf984044d333f270c5b55a8e67af17922fc7bf5694550198cae89fd5f3fea19
7
+ data.tar.gz: c4a9adda56a141bcad44756ae830310503410019725aa5590d1b36f9aa9449b21ed0ed03db725ad83e8842ba3360c5e6d1d9de3d96aa2b883f150a4335765c7a
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- iron_mq (4.0.0)
4
+ iron_mq (4.0.1)
5
5
  iron_core (>= 0.5.1)
6
6
 
7
7
  GEM
@@ -13,7 +13,7 @@ GEM
13
13
  ffi (~> 1.2.0)
14
14
  mime-types (~> 1.18)
15
15
  ffi (1.2.1)
16
- iron_core (0.5.1)
16
+ iron_core (0.5.2)
17
17
  rest (>= 2.2.0)
18
18
  mime-types (1.21)
19
19
  minitest (4.6.2)
data/README.md CHANGED
@@ -4,9 +4,8 @@ IronMQ Ruby Client
4
4
  The [full API documentation is here](http://dev.iron.io/mq/reference/api/) and this client tries to stick to the API as
5
5
  much as possible so if you see an option in the API docs, you can use it in the methods below.
6
6
 
7
- http://dev.iron.io/mq/reference/api/
8
7
 
9
- #Getting Started
8
+ ## Getting Started
10
9
 
11
10
  1\. Install the gem:
12
11
 
@@ -14,7 +13,7 @@ http://dev.iron.io/mq/reference/api/
14
13
  gem install iron_mq
15
14
  ```
16
15
 
17
- 2\. Setup your Iron.io credentials: http://dev.iron.io/mq/reference/configuration/
16
+ 2\. [Setup your Iron.io credentials](http://dev.iron.io/mq/reference/configuration/)
18
17
 
19
18
  3\. Create an IronMQ client object:
20
19
 
@@ -28,9 +27,18 @@ Or pass in credentials:
28
27
  ironmq = IronMQ::Client.new(:token => "MY_TOKEN", :project_id => "MY_PROJECT_ID")
29
28
  ```
30
29
 
31
- #The Basics
32
30
 
33
- ###Get a Queue Object
31
+ ## The Basics
32
+
33
+ ### Get Queues List
34
+
35
+ ```ruby
36
+ list_queues = ironmq.queues # => [#<IronMQ::Queue:...>, ...]
37
+ ```
38
+
39
+ --
40
+
41
+ ### Get a Queue Object
34
42
 
35
43
  You can have as many queues as you want, each with their own unique set of messages.
36
44
 
@@ -40,6 +48,8 @@ queue = ironmq.queue("my_queue")
40
48
 
41
49
  Now you can use it.
42
50
 
51
+ --
52
+
43
53
  ### Post a Message on a Queue
44
54
 
45
55
  Messages are placed on the queue in a FIFO arrangement.
@@ -49,6 +59,8 @@ If a queue does not exist, it will be created upon the first posting of a messag
49
59
  queue.post("hello world!")
50
60
  ```
51
61
 
62
+ --
63
+
52
64
  ### Retrieve Queue Information
53
65
 
54
66
  ```ruby
@@ -56,6 +68,8 @@ queue.info # => {"id"=>"5127bf043264140e863e2283", "name"=>"my_queue", ...}
56
68
  queue.id # => "5127bf043264140e863e2283"
57
69
  ```
58
70
 
71
+ --
72
+
59
73
  ### Get a Message off a Queue
60
74
 
61
75
  ```ruby
@@ -67,6 +81,8 @@ When you pop/get a message from the queue, it is no longer on the queue but it s
67
81
  You have to explicitly delete the message or else it will go back onto the queue after the `timeout`.
68
82
  The default `timeout` is 60 seconds. Minimal `timeout` is 30 seconds.
69
83
 
84
+ --
85
+
70
86
  ### Delete a Message from a Queue
71
87
 
72
88
  ```ruby
@@ -77,10 +93,12 @@ queue.delete(msg.id)
77
93
 
78
94
  Be sure to delete a message from the queue when you're done with it.
79
95
 
96
+ --
97
+
80
98
 
81
- #Client
99
+ ## Client
82
100
 
83
- `IronMQ::Client` is based on `IronCore::Client` and provides easy access to the queues and messages.
101
+ `IronMQ::Client` is based on `IronCore::Client` and provides easy access to the queues.
84
102
 
85
103
  ```ruby
86
104
  ironmq = IronMQ::Client.new(:token => "MY_TOKEN", :project_id => "MY_PROJECT_ID")
@@ -103,6 +121,8 @@ all_queues = ironmq.queues.all # => [#<IronMQ::Queue:...>, ...]
103
121
  queues = ironmq.queues.all(:page => 1, :per_page => 10)
104
122
  ```
105
123
 
124
+ --
125
+
106
126
  ### Get Queue by Name
107
127
 
108
128
  ```ruby
@@ -112,7 +132,9 @@ queue = ironmq.queue "my_queue" # => #<IronMQ::Queue:...>
112
132
  **Note:** if queue with desired name does not exist it returns fake queue.
113
133
  Queue will be created automatically on post of first message or queue configuration update.
114
134
 
115
- #Queues
135
+ --
136
+
137
+ ## Queues
116
138
 
117
139
  ### Retrieve Queue Information
118
140
 
@@ -141,12 +163,16 @@ is_push_queue = queue.push_queue? # => true
141
163
  client library call IronMQ API each time you request for any parameter except `queue.name`.
142
164
  In this case you may prefer to use `queue.info` to have `Hash` with all available info parameters.
143
165
 
166
+ --
167
+
144
168
  ### Delete a Message Queue
145
169
 
146
170
  ```ruby
147
171
  response = queue.delete_queue # => #<IronMQ::ResponseBase:...>
148
172
  ```
149
173
 
174
+ --
175
+
150
176
  ### Post Messages to a Queue
151
177
 
152
178
  **Single message:**
@@ -183,6 +209,8 @@ Default is 0 seconds. Maximum is 604,800 seconds (7 days).
183
209
  * `expires_in`: How long in seconds to keep the item on the queue before it is deleted.
184
210
  Default is 604,800 seconds (7 days). Maximum is 2,592,000 seconds (30 days).
185
211
 
212
+ --
213
+
186
214
  ### Get Messages from a Queue
187
215
 
188
216
  ```ruby
@@ -199,7 +227,7 @@ message = queue.get "5127bf043264140e863e2283" # => #<IronMQ::Message:...>
199
227
 
200
228
  * `n`: The maximum number of messages to get. Default is 1. Maximum is 100.
201
229
 
202
- * `timeout`: timeout: After timeout (in seconds), item will be placed back onto queue.
230
+ * `timeout`: After timeout (in seconds), item will be placed back onto queue.
203
231
  You must delete the message from the queue to ensure it does not go back onto the queue.
204
232
  If not set, value from POST is used. Default is 60 seconds. Minimum is 30 seconds.
205
233
  Maximum is 86,400 seconds (24 hours).
@@ -207,6 +235,8 @@ Maximum is 86,400 seconds (24 hours).
207
235
  When `n` parameter is specified and greater than 1 method returns `Array` of `Queue`s.
208
236
  Otherwise, `Queue` object would be returned.
209
237
 
238
+ --
239
+
210
240
  ### Touch a Message on a Queue
211
241
 
212
242
  Touching a reserved message extends its timeout by the duration specified when the message was created, which is 60 seconds by default.
@@ -217,10 +247,12 @@ message = queue.get # => #<IronMQ::Message:...>
217
247
  message.touch # => #<IronMQ::ResponseBase:...>
218
248
  ```
219
249
 
250
+ --
251
+
220
252
  ### Release Message
221
253
 
222
254
  ```ruby
223
- message = queue.get => #<IronMQ::Message:...>
255
+ message = queue.get # => #<IronMQ::Message:...>
224
256
 
225
257
  response = message.release # => #<IronMQ::ResponseBase:...>
226
258
  # or
@@ -232,16 +264,18 @@ response = message.release(:delay => 42) # => #<IronMQ::ResponseBase:...>
232
264
  * `delay`: The item will not be available on the queue until this many seconds have passed.
233
265
  Default is 0 seconds. Maximum is 604,800 seconds (7 days).
234
266
 
267
+ --
268
+
235
269
  ### Delete a Message from a Queue
236
270
 
237
271
  ```ruby
238
272
  message = queue.get # => #<IronMQ::Queue:...>
239
273
 
240
274
  message.delete # => #<IronMQ::ResponseBase:...>
241
- # or
242
- queue.delete_message(message.id) # => #<IronMQ::ResponseBase:...>
243
275
  ```
244
276
 
277
+ --
278
+
245
279
  ### Peek Messages from a Queue
246
280
 
247
281
  Peeking at a queue returns the next messages on the queue, but it does not reserve them.
@@ -256,6 +290,8 @@ messages = queue.peek(:n => 13) # => [#<IronMQ::Message:...>, ...]
256
290
 
257
291
  * `n`: The maximum number of messages to peek. Default is 1. Maximum is 100.
258
292
 
293
+ --
294
+
259
295
  ### Poll for Messages
260
296
 
261
297
  ```ruby
@@ -264,13 +300,18 @@ queue.poll { |msg| puts msg.body }
264
300
 
265
301
  Polling will automatically delete the message at the end of the block.
266
302
 
303
+ --
304
+
267
305
  ### Clear a Queue
268
306
 
269
307
  ```ruby
270
308
  queue.clear # => #<IronMQ::ResponseBase:...>
271
309
  ```
272
310
 
273
- #Push Queues
311
+ --
312
+
313
+
314
+ ## Push Queues
274
315
 
275
316
  IronMQ push queues allow you to setup a queue that will push to an endpoint, rather than having to poll the endpoint.
276
317
  [Here's the announcement for an overview](http://blog.iron.io/2013/01/ironmq-push-queues-reliable-message.html).
@@ -291,6 +332,8 @@ See below for example json.
291
332
  * `retries`: How many times to retry on failure. Default is 3.
292
333
  * `retries_delay`: Delay between each retry in seconds. Default is 60.
293
334
 
335
+ --
336
+
294
337
  ### Set Subscribers on a Queue
295
338
 
296
339
  Subscribers can be any HTTP endpoint. `push_type` is one of:
@@ -301,43 +344,90 @@ Subscribers can be any HTTP endpoint. `push_type` is one of:
301
344
  ```ruby
302
345
  ptype = :multicast
303
346
  subscribers = [
304
- {url: "http://rest-test.iron.io/code/200?store=key1"}
305
- {url: "http://rest-test.iron.io/code/200?store=key2"}
347
+ {:url => "http://rest-test.iron.io/code/200?store=key1"}
348
+ {:url => "http://rest-test.iron.io/code/200?store=key2"}
306
349
  ]
307
350
 
308
351
  queue.update(:subscribers => subscribers, :push_type => ptype)
309
352
  ```
310
353
 
354
+ --
355
+
311
356
  ### Add/Remove Subscribers on a Queue
312
357
 
313
358
  ```ruby
314
- queue.add_subscriber({url: "http://nowhere.com"})
359
+ queue.add_subscriber({:url => "http://nowhere.com"})
360
+
361
+ queue.add_subscribers([
362
+ {:url => 'http://first.endpoint.xx/process'},
363
+ {:url => 'http://second.endpoint.xx/process'}
364
+ ])
365
+
315
366
 
316
367
  queue.remove_subscriber({url: "http://nowhere.com"})
368
+
369
+ queue.remove_subscribers([
370
+ {:url => 'http://first.endpoint.xx/process'},
371
+ {:url => 'http://second.endpoint.xx/process'}
372
+ ])
317
373
  ```
318
374
 
375
+ --
376
+
377
+ ### Post and instantiate
378
+
379
+ Sometimes you may want to post message to the Push Queue and instantiate `Message`
380
+ instead getting it by ID returned in API response. To do this just set `:instantiate`
381
+ to `true`.
382
+
383
+ ```ruby
384
+ message = queue.post('push me!', :instantiate => true) # => #<IronMQ::Message:...>
385
+
386
+ msgs = queue([{:body => 'push'}, {:body => 'me'}], :instantiate => true) # => [#<IronMQ::Message:...>, ...]
387
+ ```
388
+
389
+ This creates fake `Message` objects. They contain only IDs.
390
+
391
+ --
392
+
319
393
  ### Get Message Push Status
320
394
 
321
395
  After pushing a message:
322
396
 
323
397
  ```ruby
324
398
  subscribers = queue.get(msg.id).subscribers # => [#<IronMQ::Subscriber:...>, ...]
325
- # old syntax, still supported
326
- subscribers = queue.messages.get(msg.id).subscribers # => [#<IronMQ::Subscriber:...>, ...]
327
399
 
328
400
  subscribers.each { |ss| puts "#{ss.id}: #{(ss.code == 200) ? 'Success' : 'Fail'}" }
329
401
  ```
330
402
 
331
403
  Returns an array of subscribers with status.
332
404
 
333
- ### Delete Message Push Status
405
+ **Note:** getting a message by ID is only for usable for Push Queues.
406
+ This creates fake `IronMQ::Message` instance on which you call for subscribers' push statuses.
407
+
408
+ --
409
+
410
+ ### Acknowledge / Delete Message Push Status
334
411
 
335
412
  ```ruby
336
413
  subscribers = queue.get(msg.id).subscribers # => [#<IronMQ::Subscriber:...>, ...]
337
414
 
338
- subscribers.each { |ss| ss.delete }
415
+ subscribers.each do |ss|
416
+ ss.delete
417
+ # ss.acknowledge # This is `delete` alias
418
+ end
339
419
  ```
340
420
 
421
+ --
422
+
423
+
424
+ ## Further Links
425
+
426
+ * [IronMQ Overview](http://dev.iron.io/mq/)
427
+ * [IronMQ REST/HTTP API](http://dev.iron.io/mq/reference/api/)
428
+ * [Push Queues](http://dev.iron.io/mq/reference/push_queues/)
429
+ * [Other Client Libraries](http://dev.iron.io/mq/libraries/)
430
+ * [Live Chat, Support & Fun](http://get.iron.io/chat)
341
431
 
342
432
  -------------
343
433
  © 2011 - 2013 Iron.io Inc. All Rights Reserved.
@@ -1,5 +1,5 @@
1
- require 'iron_mq/response'
2
- require 'iron_mq/queues'
3
- require 'iron_mq/messages'
4
- require 'iron_mq/client'
5
- require 'iron_mq/version'
1
+ require File.expand_path('iron_mq/response', File.dirname(__FILE__))
2
+ require File.expand_path('iron_mq/queues', File.dirname(__FILE__))
3
+ require File.expand_path('iron_mq/messages', File.dirname(__FILE__))
4
+ require File.expand_path('iron_mq/client', File.dirname(__FILE__))
5
+ require File.expand_path('iron_mq/version', File.dirname(__FILE__))
@@ -1,7 +1,6 @@
1
1
  require 'yaml'
2
2
 
3
3
  require 'iron_core'
4
- require 'iron_mq/queues'
5
4
 
6
5
  module IronMQ
7
6
 
@@ -28,7 +28,15 @@ module IronMQ
28
28
  end
29
29
 
30
30
  def delete
31
- call_api_and_parse_response(:delete)
31
+ begin
32
+ call_api_and_parse_response(:delete)
33
+ rescue Rest::HttpError => ex
34
+ if ex.code == 404
35
+ Rest.logger.info("Delete got 404, safe to ignore.")
36
+ else
37
+ raise ex
38
+ end
39
+ end
32
40
  end
33
41
 
34
42
  def call_api_and_parse_response(meth, ext_path = "", options = {}, instantiate = true)
@@ -1,5 +1,4 @@
1
1
  require 'cgi'
2
- require 'iron_mq/subscribers'
3
2
 
4
3
  module IronMQ
5
4
 
@@ -13,7 +12,7 @@ module IronMQ
13
12
  end
14
13
 
15
14
  def info
16
- info = raw
15
+ info = raw
17
16
  begin
18
17
  # Do not instantiate response
19
18
  info = call_api_and_parse_response(:get, '', {}, false)
@@ -90,6 +89,9 @@ module IronMQ
90
89
  def post_messages(payload, options = {})
91
90
  batch = false
92
91
 
92
+ instantiate = [options.delete(:instantiate),
93
+ options.delete('instantiate')].compact.first
94
+
93
95
  msgs = if payload.is_a?(Array)
94
96
  batch = true
95
97
  # FIXME: This maybe better to process Array of Objects the same way as for single message.
@@ -109,15 +111,22 @@ module IronMQ
109
111
  # Do not instantiate response
110
112
  res = call_api_and_parse_response(:post, "/messages", {:messages => msgs}, false)
111
113
 
112
- if batch
113
- # FIXME: Return Array of ResponsBase instead, it seems more clear than raw response
114
- #
115
- # res["ids"].each_with_object([]) do |id, responses|
116
- # responses << ResponseBase.new({"id" => id, "msg" => res["msg"]})
117
- # end
118
- ResponseBase.new(res) # Backward capable
114
+ if instantiate
115
+ n = batch ? 2 : 1
116
+ msg_ids = res["ids"].map { |id| {'id' => id} }
117
+
118
+ process_messages(msg_ids, {:n => n})
119
119
  else
120
- ResponseBase.new({"id" => res["ids"][0], "msg" => res["msg"]})
120
+ if batch
121
+ # FIXME: Return Array of ResponsBase instead, it seems more clear than raw response
122
+ #
123
+ # res["ids"].each_with_object([]) do |id, responses|
124
+ # responses << ResponseBase.new({"id" => id, "msg" => res["msg"]})
125
+ # end
126
+ ResponseBase.new(res) # Backward capable
127
+ else
128
+ ResponseBase.new({"id" => res["ids"][0], "msg" => res["msg"]})
129
+ end
121
130
  end
122
131
  end
123
132
 
@@ -15,6 +15,8 @@ module IronMQ
15
15
  @message.call_api_and_parse_response(:delete, path)
16
16
  end
17
17
 
18
+ alias_method :acknowledge, :delete
19
+
18
20
  private
19
21
 
20
22
  def path
@@ -1,4 +1,4 @@
1
1
  module IronMQ
2
- VERSION = "4.0.0"
2
+ VERSION = "4.0.1"
3
3
  end
4
4
 
@@ -11,7 +11,7 @@ unless Hash.instance_methods.include?(:default_proc=)
11
11
  end
12
12
 
13
13
  begin
14
- require File.join(File.dirname(__FILE__), '../lib/iron_mq')
14
+ require File.expand_path('../lib/iron_mq', File.dirname(__FILE__))
15
15
  rescue Exception => ex
16
16
  puts "Could NOT load current iron_mq: " + ex.message
17
17
  raise ex
@@ -19,7 +19,7 @@ class BeanstalkTests < TestBase
19
19
  end
20
20
 
21
21
  def test_basics
22
- omit_if @skip # bypass this test if rackspace
22
+ return if @skip # bypass this test if rackspace
23
23
  puts 'test_basics3'
24
24
 
25
25
  queue_name = "beanstalk_test"
@@ -60,7 +60,7 @@ class BeanstalkTests < TestBase
60
60
  end
61
61
 
62
62
  def clear_tube(tube)
63
- omit_if @skip # bypass this test if rackspace
63
+ return if @skip # bypass this test if rackspace
64
64
  watched = @beanstalk.list_tubes_watched(true)
65
65
  puts 'watched: ' + watched.inspect
66
66
  @beanstalk.watch(tube)
@@ -75,7 +75,7 @@ class BeanstalkTests < TestBase
75
75
  end
76
76
 
77
77
  def test_basics2
78
- omit_if @skip # bypass this test if rackspace
78
+ return if @skip # bypass this test if rackspace
79
79
  puts 'test_basics'
80
80
  msg = "hello #{Time.now}"
81
81
  @beanstalk.put(msg)
@@ -110,7 +110,7 @@ class BeanstalkTests < TestBase
110
110
  end
111
111
 
112
112
  def test_timeout
113
- omit_if @skip # bypass this test if rackspace
113
+ return if @skip # bypass this test if rackspace
114
114
  puts 'test_timeout'
115
115
  msg = "timeout message #{Time.now}"
116
116
  # timeout of 10 seconds
@@ -137,7 +137,7 @@ class BeanstalkTests < TestBase
137
137
  end
138
138
 
139
139
  def test_delay
140
- omit_if @skip # bypass this test if rackspace
140
+ return if @skip # bypass this test if rackspace
141
141
  puts 'test_delay'
142
142
  msg = "delayed message #{Time.now}"
143
143
  # delay of 2 seconds
@@ -160,12 +160,12 @@ class BeanstalkTests < TestBase
160
160
  end
161
161
 
162
162
  def tube_message(tube)
163
- omit_if @skip # bypass this test if rackspace
163
+ return if @skip # bypass this test if rackspace
164
164
  "hello #{tube}! #{Time.now}"
165
165
  end
166
166
 
167
167
  def reserve(timeout=nil)
168
- omit_if @skip # bypass this test if rackspace
168
+ return if @skip # bypass this test if rackspace
169
169
  begin
170
170
  job = @beanstalk.reserve(timeout)
171
171
  LOG.info 'got job: ' + job.inspect
@@ -177,7 +177,7 @@ class BeanstalkTests < TestBase
177
177
  end
178
178
 
179
179
  def test_tubes
180
- omit_if @skip # bypass this test if rackspace
180
+ return if @skip # bypass this test if rackspace
181
181
  clear_tube('youtube')
182
182
  tube1 = 'default'
183
183
  msg1 = tube_message(tube1)
@@ -5,7 +5,6 @@ require File.expand_path('test_base.rb', File.dirname(__FILE__))
5
5
  class IronMQTests < TestBase
6
6
  def setup
7
7
  super
8
- @skip = @host.include? 'rackspace'
9
8
  LOG.info "@host: #{@host}"
10
9
 
11
10
  queues = @client.queues.list
@@ -125,10 +124,12 @@ class IronMQTests < TestBase
125
124
  # p res
126
125
 
127
126
  res = @client.queues.list
127
+ assert res.size > 0, "project must contain at least one queue"
128
+
128
129
  res.each do |q|
129
- puts "#{q.name} and #{queue_name}";
130
+ # puts "#{q.name} and #{queue_name}"
130
131
  if q.name == queue_name
131
- assert_equal q.size, 1
132
+ assert_equal q.size, 1
132
133
  end
133
134
  end
134
135
 
@@ -613,8 +614,6 @@ class IronMQTests < TestBase
613
614
  end
614
615
 
615
616
  def test_webhooks
616
- omit_if @skip
617
- puts "skip webhooks: #{@skip}"
618
617
  qname ="webhook_queue"
619
618
  url = "#{@client.base_url}/#{qname}/messages/webhook?oauth=#{@client.token}"
620
619
  # p url
@@ -6,8 +6,6 @@ class TestPushQueues < TestBase
6
6
 
7
7
  def setup
8
8
  super
9
- @skip = @host.include? 'rackspace'
10
- return if @skip # bypass these tests if rackspace
11
9
  end
12
10
 
13
11
  def make_key(i, t, random=0)
@@ -16,7 +14,6 @@ class TestPushQueues < TestBase
16
14
 
17
15
 
18
16
  def test_queue_subscriptions
19
- omit_if @skip
20
17
  types = ["multicast", "unicast"]
21
18
  # to delete queues later (clear project)
22
19
  queue_names = []
@@ -153,7 +150,6 @@ class TestPushQueues < TestBase
153
150
 
154
151
 
155
152
  def test_failure
156
- omit_if @skip
157
153
  @rest = Rest::Client.new
158
154
  qname = "failure-queue"
159
155
 
@@ -214,11 +210,19 @@ class TestPushQueues < TestBase
214
210
  subscribers.each do |s|
215
211
  LOG.debug s
216
212
  if s["url"] == "http://rest-test.iron.io/code/503"
217
- do_retry = true unless 503 == s["status_code"]
218
- do_retry = true unless "error" == s["status"]
213
+ if "error" == s["status"]
214
+ assert_equal 0, s["retries_remaining"]
215
+ else
216
+ assert_equal 503, s["status_code"]
217
+ do_retry = true
218
+ end
219
219
  else
220
- do_retry = true unless 200 == s["status_code"]
221
- do_retry = true unless "deleted" == s["status"]
220
+ LOG.info "retries_remaining: #{s["retries_remaining"]}"
221
+ if ["deleted", "error"].include? s["status"] || 200 == s["status_code"]
222
+ assert_equal 0, s["retries_remaining"]
223
+ else
224
+ do_retry = true
225
+ end
222
226
  end
223
227
  end
224
228
  next if do_retry
@@ -233,7 +237,6 @@ class TestPushQueues < TestBase
233
237
 
234
238
 
235
239
  def test_202
236
- omit_if @skip
237
240
  types = ["multicast"]
238
241
  types.each do |t|
239
242
 
@@ -340,8 +343,37 @@ class TestPushQueues < TestBase
340
343
  end
341
344
 
342
345
 
343
- def test_202_failure
344
- omit_if @skip
346
+ def test_post_and_instantiate
347
+ queue = @client.queue('push_and_instantiate')
348
+
349
+ subscribers = [{:url => "http://rest-test.iron.io/code/200"},
350
+ {:url => "http://rest-test.iron.io/code/200"}]
351
+
352
+ res = queue.update_queue(:subscribers => subscribers,
353
+ :push_type => 'multicast')
354
+
355
+ expected_size = subscribers.size
356
+ got_size = queue.subscribers.size
357
+ assert_equal expected_size, got_size, "queue's subscribers list must contain #{expected_size} elements, but got #{got_size}"
358
+
359
+ msgs = queue.post([{:body => 'push'},
360
+ {:body => 'me'},
361
+ {:body => 'now'}], :instantiate => true)
362
+ msgs.each { |msg| assert_instance_of(IronMQ::Message, msg, "post(:instantiate => true) must instantiate messages") }
363
+
364
+ sleep 5
365
+
366
+ msgs.each do |msg|
367
+ subscr_arr = msg.subscribers
368
+ subscr_arr.each do |s|
369
+ assert_instance_of(IronMQ::Subscriber, s, "message must return `Subscriber`, but got `#{s.class}`")
370
+ rsp = s.delete
371
+ assert_equal 200, rsp.code, "API must response with HTTP 200 status, but returned HTTP #{rsp.code}"
372
+ end
373
+ end
374
+
375
+ resp = queue.delete_queue
376
+ assert_equal 200, resp.code, "API must response with HTTP 200 status, but returned HTTP #{resp.code}"
345
377
  end
346
378
 
347
379
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iron_mq
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yury Yantsevich
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-13 00:00:00.000000000 Z
12
+ date: 2013-03-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: iron_core