pubnub 3.6.10 → 3.7.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of pubnub might be problematic. Click here for more details.

Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.txt +3 -0
  3. data/Gemfile.lock +1 -1
  4. data/README.md +144 -10
  5. data/examples/demo_console.rb +61 -23
  6. data/fixtures/vcr_cassettes/cg/add-c-as-array.yml +51 -0
  7. data/fixtures/vcr_cassettes/cg/add-c-as-csv.yml +51 -0
  8. data/fixtures/vcr_cassettes/cg/add-c-as-string.yml +51 -0
  9. data/fixtures/vcr_cassettes/cg/add-c-as-symbol.yml +51 -0
  10. data/fixtures/vcr_cassettes/cg/audit-cg.yml +44 -0
  11. data/fixtures/vcr_cassettes/cg/audit-ns.yml +44 -0
  12. data/fixtures/vcr_cassettes/cg/grant-cg.yml +44 -0
  13. data/fixtures/vcr_cassettes/cg/grant-ns.yml +44 -0
  14. data/fixtures/vcr_cassettes/cg/here_now-cg.yml +51 -0
  15. data/fixtures/vcr_cassettes/cg/leave-cg-c.yml +132 -0
  16. data/fixtures/vcr_cassettes/cg/leave-cg.yml +133 -0
  17. data/fixtures/vcr_cassettes/cg/list-all-c-in-in-ns-cg.yml +50 -0
  18. data/fixtures/vcr_cassettes/cg/list-all-c-in-non-ns-cg.yml +51 -0
  19. data/fixtures/vcr_cassettes/cg/list-all-cg-in-ns.yml +51 -0
  20. data/fixtures/vcr_cassettes/cg/list-all-namespaces.yml +50 -0
  21. data/fixtures/vcr_cassettes/cg/list-all-non-namespaced-cg.yml +49 -0
  22. data/fixtures/vcr_cassettes/cg/remove-c-as-array.yml +51 -0
  23. data/fixtures/vcr_cassettes/cg/remove-c-as-csv.yml +51 -0
  24. data/fixtures/vcr_cassettes/cg/remove-c-as-string.yml +51 -0
  25. data/fixtures/vcr_cassettes/cg/remove-c-as-symbol.yml +51 -0
  26. data/fixtures/vcr_cassettes/cg/remove-cg-from-ns-csv.yml +51 -0
  27. data/fixtures/vcr_cassettes/cg/remove-ns-csv.yml +51 -0
  28. data/fixtures/vcr_cassettes/cg/subscribe-cg-and-channel.yml +85 -0
  29. data/fixtures/vcr_cassettes/cg/subscribe-cg-only.yml +85 -0
  30. data/lib/pubnub/client.rb +6 -2
  31. data/lib/pubnub/envelope.rb +1 -0
  32. data/lib/pubnub/event.rb +105 -20
  33. data/lib/pubnub/events/audit.rb +13 -0
  34. data/lib/pubnub/events/channel_registration.rb +132 -0
  35. data/lib/pubnub/events/grant.rb +17 -7
  36. data/lib/pubnub/events/heartbeat.rb +29 -3
  37. data/lib/pubnub/events/here_now.rb +21 -7
  38. data/lib/pubnub/events/leave.rb +27 -3
  39. data/lib/pubnub/events/presence.rb +4 -3
  40. data/lib/pubnub/events/set_state.rb +16 -3
  41. data/lib/pubnub/events/state.rb +15 -9
  42. data/lib/pubnub/events/subscribe.rb +17 -3
  43. data/lib/pubnub/formatter.rb +31 -7
  44. data/lib/pubnub/pam.rb +4 -3
  45. data/lib/pubnub/version.rb +1 -1
  46. data/spec/lib/integration/channel_groups_spec.rb +120 -0
  47. data/spec/lib/integration/channel_registration_spec.rb +317 -0
  48. data/spec/spec_helper.rb +0 -1
  49. metadata +31 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 72ab3a0cc365b65f7d43792c3b48090ca98c8a2f
4
- data.tar.gz: a4bfd82d2992245e27b3966f43d4d86c040435fa
3
+ metadata.gz: bfd5538b26675782f56350179deedd2806381507
4
+ data.tar.gz: afd697119dafc00c909f3e4ca3e69d83658af633
5
5
  SHA512:
6
- metadata.gz: 5fece7ee84335eea9608bb4a3a424f2eb96c6820f1f493b9d6430fa4a9b1e235d6e31f16906fec21b4e436d9357ec5179e9e51d8c6c4870bfb19ac0755fcad48
7
- data.tar.gz: bdc45b7d2bc1f4c4332fe6698270cbf7d4c0f306371592e707773374de39292516eade4711e45b8656c5b6be96f8f605975c7db6c8ee7d76b9915da73b9701f9
6
+ metadata.gz: 859506af0ab59f9d66e926a220bee8bb462accba1ec03d9dfbe8bc102694751171621754bd0489180b4a2b63a1888cc04083d86a21efd4838de8cad10258e4cc
7
+ data.tar.gz: 2d514980a3f04733bac4282ec8d114c47733f100129c0a21c38afbf9fa9def8a38bf5c9f1dea49d63a2f0a55d4f6ab1755aeaf2d4320a3915cca3b563ccffa10
@@ -1,3 +1,6 @@
1
+ 3.7.0 Release
2
+ . Added channel groups features
3
+
1
4
  3.6.10 Release
2
5
  . Envelope formatting fix
3
6
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pubnub (3.6.7)
4
+ pubnub (3.7.0beta0)
5
5
  eventmachine (~> 1.0)
6
6
  json (~> 1.8)
7
7
  net-http-persistent (~> 2.9)
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Please direct all Support Questions and Concerns to Support@PubNub.com
2
2
 
3
- ## PubNub Gem version 3.6.10
3
+ ## PubNub Gem version 3.7.0
4
4
 
5
5
  ##### YOU MUST HAVE A PUBNUB ACCOUNT TO USE THE API.
6
6
  ##### http://www.pubnub.com/account
@@ -17,17 +17,17 @@ We've made the response format compatible across all operations. This may break
17
17
  Examples of affected operations can be found [here](3.5_to_3.6_upgrade_notes.md).
18
18
 
19
19
  ### Upgrading from PubNub 3.3.x and Earlier
20
- PubNub 3.6.10 is NOT compatible with earlier than 3.4 versions of Pubnub Ruby Client.
20
+ PubNub 3.7.0 is NOT compatible with earlier than 3.4 versions of Pubnub Ruby Client.
21
21
 
22
22
  ### Upgrading from PubNub 3.4 and higher versions
23
- PubNub 3.6.10 is compatible with 3.4 version.
23
+ PubNub 3.7.0 is compatible with 3.4 version.
24
24
 
25
25
  ## Important Notice about Blocking vs Non-Blocking Calls
26
26
 
27
27
  #### Asynchronous vs Synchronous Requests
28
- Every operation is by default asyncronous. Asynchronous operations will not block your main thread and will be fired within a new thread.
28
+ Every operation is by default asynchronous. Asynchronous operations will not block your main thread and will be fired within a new thread.
29
29
 
30
- This can cause issues under certain situations, depending on your implementation. To work around this, you can force an operation to run syncronously (block) via the :http_sync option:
30
+ This can cause issues under certain situations, depending on your implementation. To work around this, you can force an operation to run synchronously (block) via the :http_sync option:
31
31
 
32
32
  ```ruby
33
33
  :http_sync => true
@@ -36,7 +36,7 @@ This can cause issues under certain situations, depending on your implementation
36
36
  Unless otherwise specified, this option is default implied false (all calls by default will be async).
37
37
 
38
38
  #### Message Handling: callback, block, return
39
- Results are provided via block, callback, and return, depending on how you structure the call. Callback will be fired for every message that will event get in response. Synchornous events will return array of envelopes (if you passed callback to sychronous event it will be called too!).
39
+ Results are provided via block, callback, and return, depending on how you structure the call. Callback will be fired for every message that will event get in response. Synchronous events will return array of envelopes (if you passed callback to sychronous event it will be called too!).
40
40
 
41
41
  ### Code Examples
42
42
 
@@ -55,7 +55,6 @@ my_logger = Logger.new(STDOUT)
55
55
  pubnub = Pubnub.new(
56
56
  :subscribe_key => 'demo',
57
57
  :publish_key => 'demo',
58
- :origin => origin,
59
58
  :error_callback => lambda { |msg|
60
59
  puts "Error callback says: #{msg.inspect}"
61
60
  },
@@ -207,7 +206,9 @@ pubnub.subscribe(
207
206
  ```
208
207
 
209
208
  #### Leave
210
- Unsubscribes from given channel and fires leave event. You need to be subscribed (only async counts) to channel that you want to leave
209
+ Unsubscribes from given channel (`:channel`) or channel group (`:group`) and
210
+ fires leave event. You need to be subscribed (only async counts) to channel that
211
+ You want to leave.
211
212
 
212
213
  ```ruby
213
214
  pubnub.subscribe(
@@ -262,8 +263,16 @@ pubnub.presence(
262
263
  )
263
264
  ```
264
265
 
266
+ ```ruby
267
+ pubnub.presence(
268
+ :group => 'foo:',
269
+ :callback => @my_callback
270
+ )
271
+ ```
272
+
265
273
  #### HereNow
266
- See who is "here now" in a channel at this very moment.
274
+ See who is "here now" in a channel (:channel) or channel group (:group) at this
275
+ very moment.
267
276
 
268
277
  ```ruby
269
278
  pubnub.here_now(
@@ -272,6 +281,13 @@ pubnub.here_now(
272
281
  )
273
282
  ```
274
283
 
284
+ ```ruby
285
+ pubnub.here_now(
286
+ :group => channel_group,
287
+ :callback => @my_callback
288
+ )
289
+ ```
290
+
275
291
  #### WhereNow
276
292
  See where is client with specific uuid
277
293
 
@@ -300,6 +316,95 @@ Get the current PubNub time. This is great to use as a "PubNub Ping"
300
316
  pubnub.time("callback" => @my_callback)
301
317
  ```
302
318
 
319
+ ### Channel Groups
320
+
321
+ Channel grouping is new feature introduced in Pubnub 3.7. It allows to group
322
+ channels into channel-groups and channel-groups into namespaces. For example you
323
+ can add `weather` and `sport` channel to `news` channel group, and `news` and
324
+ `local_ads` to `tv` namespace. Namespaces and channel groups are described as
325
+ `namespace:channel_group` e.g. `tv:news`. All channel-groups in namespace are
326
+ described as `namespace:` e.g. `tv:`. Non-namespaced channel groups are
327
+ described as `non-namespaced-channel-group` eg. `global_alerts`.
328
+
329
+ All channel groups specific operations can be issued with
330
+ `#channel_registration` method.
331
+
332
+ #### Getting info
333
+
334
+ ##### Getting all namespaces
335
+
336
+ ```ruby
337
+ # Response envelope will hold info as hash in payload attribute.
338
+ pubnub.channel_registration(action: :list_namespaces, http_sync: true)
339
+ ```
340
+
341
+ ##### Getting all non-namespaced channel groups
342
+
343
+ ```ruby
344
+ # Response envelope will hold info as hash in payload attribute.
345
+ pubnub.channel_registration(action: :list_groups, http_sync: true)
346
+ ```
347
+
348
+ ##### Getting all channel groups in given namespace
349
+
350
+ ```ruby
351
+ # Response envelope will hold info as hash in payload attribute.
352
+ pubnub.channel_registration(action: :get, group: 'foo:', http_sync: true)
353
+ ```
354
+
355
+ ##### Getting all channels in channel group
356
+
357
+ ```ruby
358
+ # Response envelope will hold info as hash in payload attribute.
359
+ pubnub.channel_registration(action: :get, group: 'foo:foo', http_sync: true)
360
+ ```
361
+
362
+ #### Adding
363
+
364
+ ##### Add channel to namespaced channel group
365
+
366
+ ```ruby
367
+ pubnub.channel_registration(action: :add, group: 'foo:new_group', channel: :bot, http_sync: true)
368
+ ```
369
+
370
+ ##### Add channel to non-namespaced channel group
371
+
372
+ ```ruby
373
+ pubnub.channel_registration(action: :add, group: 'new_group', channel: :bot, http_sync: true)
374
+ ```
375
+
376
+ #### Removing
377
+
378
+ ##### Remove namespace and all channel groups
379
+
380
+ ```ruby
381
+ pubnub.channel_registration(action: :remove, group: 'foo:', http_sync: true)
382
+ ```
383
+
384
+ ##### Remove namespaced channel group
385
+
386
+ ```ruby
387
+ pubnub.channel_registration(action: :remove, group: 'foo:cg', http_sync: true)
388
+ ```
389
+
390
+ ##### Remove non-namespaced channel group
391
+
392
+ ```ruby
393
+ pubnub.channel_registration(action: :remove, group: 'cg', http_sync: true)
394
+ ```
395
+
396
+ ##### Remove channel from namespaced channel group
397
+
398
+ ```ruby
399
+ pubnub.channel_registration(action: :remove, group: 'foo:cg', channel: :to_remove, http_sync: true)
400
+ ```
401
+
402
+ ##### Remove channel from non-namespaced channel group
403
+
404
+ ```ruby
405
+ pubnub.channel_registration(action: :remove, group: 'cg', channel: :to_remove, http_sync: true)
406
+ ```
407
+
303
408
  ### PAM
304
409
 
305
410
  Developers can grant/revoke/audit fine-grained permissions for their real-time apps and data at various levels.
@@ -325,6 +430,15 @@ end
325
430
  pubnub.grant(:presence => :demo, :channel => :demo) do |envelope|
326
431
  puts envelope.message
327
432
  end
433
+
434
+ # For channel groups, all above work.
435
+ # But channel groups additionally have :manage option.
436
+
437
+ # Will grant :r, :w and :m permissions to foo:foo
438
+ pubnub.grant(:group => 'foo:foo') do |envelope|
439
+ puts envelope.message
440
+ end
441
+
328
442
  ```
329
443
 
330
444
  ##### Audit
@@ -428,10 +542,23 @@ pubnub.subscribe(
428
542
  ) do |envelope|
429
543
  puts envelope.message['attacker']
430
544
  puts envelope.message['defender']
431
- puts envelope.message['demage']
545
+ puts envelope.message['damage']
432
546
  end
433
547
  ```
434
548
 
549
+ ###### Channel groups
550
+ You can subscribe to channel group same way as You're subscribing to channels.
551
+
552
+ ```ruby
553
+ pubnub.subscribe(group: 'foo:foo', channel: :ping_3, callback: callback)
554
+ ```
555
+
556
+ Response envelopes will hold channel and channel_group values. So, if You want
557
+ to subscribe to channel group and your callback need to know where are envelopes
558
+ from, You can check it using `envelope.channel_group`. Of course You can
559
+ subscribe to channel group and plain channel at once.
560
+
561
+
435
562
  ##### History
436
563
  History returns :count messages from given channel.
437
564
  ```ruby
@@ -565,6 +692,9 @@ pubnub.subscribe(:channel => 'my_channel', :state => {:my_channel => {:key => :v
565
692
  # Using event #set_state
566
693
  pubnub.set_state(:state => {:key => :value}, :channel => :my_channel, :http_sync => true)
567
694
 
695
+ # or with channel groups
696
+ pubnub.set_state(:state => {:key => :value}, :group => 'foo:foo', :http_sync => true)
697
+
568
698
  ```
569
699
 
570
700
  #### Getting state
@@ -573,6 +703,10 @@ pubnub.set_state(:state => {:key => :value}, :channel => :my_channel, :http_sync
573
703
  pubnub.state(:uuid => 'uuid_client_that_i_am_searching_for', :http_sync => true)
574
704
  ```
575
705
 
706
+ #### State and channel groups
707
+ State works fine with channel groups too! Just pass the `:group` key when
708
+ setting or do it while subscribing.
709
+
576
710
  ### Other
577
711
 
578
712
  Advanced usage examples can be found also in the examples directory.
@@ -35,10 +35,11 @@ class DemoConsole
35
35
  :'8' => :WhereNow,
36
36
  :'9' => :State,
37
37
  :'10' => :Heartbeat,
38
- :'11' => :Time,
39
- :'12' => :Audit,
40
- :'13' => :Grant,
41
- :'14' => :Revoke,
38
+ :'11' => :ChannelRegistration,
39
+ :'12' => :Time,
40
+ :'13' => :Audit,
41
+ :'14' => :Grant,
42
+ :'15' => :Revoke,
42
43
  :A => :set_uuid,
43
44
  :B => :set_auth_key,
44
45
  :C => :show_state,
@@ -174,10 +175,11 @@ class DemoConsole
174
175
  puts '8. WhereNow'
175
176
  puts '9. State'
176
177
  puts '10. Heartbeat'
177
- puts '11. Time'
178
- puts '12. Audit' if @secret_key
179
- puts '13. Grant' if @secret_key
180
- puts '14. Revoke' if @secret_key
178
+ puts '11. ChannelRegistration'
179
+ puts '12. Time'
180
+ puts '13. Audit' if @secret_key
181
+ puts '14. Grant' if @secret_key
182
+ puts '15. Revoke' if @secret_key
181
183
  puts "\nPubnub::Client interaction:".green
182
184
  puts 'A. Set UUID'
183
185
  puts 'B. Set auth_key'
@@ -195,13 +197,13 @@ class DemoConsole
195
197
  options = ask_about(:sync, :message, :channel)
196
198
  @pubnub.publish(options)
197
199
  when :Subscribe
198
- options = ask_about(:sync, :channel)
200
+ options = ask_about(:sync, :channel, :group)
199
201
  @pubnub.subscribe(options)
200
202
  when :Presence
201
- options = ask_about(:sync, :channel)
203
+ options = ask_about(:sync, :channel, :group)
202
204
  @pubnub.presence(options)
203
205
  when :Leave
204
- options = ask_about(:sync, :channel)
206
+ options = ask_about(:sync, :channel, :group)
205
207
  @pubnub.leave(options)
206
208
  when :History
207
209
  options = ask_about(:sync, :channel, :reverse, :history_start, :history_end, :count)
@@ -210,7 +212,7 @@ class DemoConsole
210
212
  options = ask_about(:sync, :channel, :reverse, :history_start, :history_end, :limit, :page)
211
213
  @pubnub.paged_history(options)
212
214
  when :HereNow
213
- options = ask_about(:sync, :optional_channel)
215
+ options = ask_about(:sync, :optional_channel, :group)
214
216
  @pubnub.here_now(options)
215
217
  when :WhereNow
216
218
  options = ask_about(:sync, :uuid)
@@ -221,17 +223,20 @@ class DemoConsole
221
223
  when :Heartbeat
222
224
  options = ask_about(:sync, :heartbeat, :channel)
223
225
  @pubnub.heartbeat(options)
226
+ when :ChannelRegistration
227
+ options = ask_about(:sync, :action, :group, :channel)
228
+ @pubnub.channel_registration(options)
224
229
  when :Time
225
230
  options = ask_about(:sync)
226
231
  @pubnub.time(options)
227
232
  when :Audit
228
- options = ask_about(:sync, :channel, :subscribe_key)
233
+ options = ask_about(:sync, :channel, :group, :auth_key)
229
234
  @pubnub.audit(options)
230
235
  when :Grant
231
- options = ask_about(:sync, :channel, :subscribe_key, :read, :write)
236
+ options = ask_about(:sync, :channel, :group, :auth_key, :read, :write, :manage)
232
237
  @pubnub.grant(options)
233
238
  when :Revoke
234
- options = ask_about(:sync, :channel, :subscribe_key, :read, :write)
239
+ options = ask_about(:sync, :channel, :group, :auth_key, :read, :write, :manage)
235
240
  @pubnub.revoke(options)
236
241
  when :set_uuid
237
242
  print 'Your new uuid: '
@@ -266,6 +271,31 @@ class DemoConsole
266
271
  print 'Should event be async? '
267
272
  options[:http_sync] = !acceptance
268
273
 
274
+ when :action
275
+ while options[:action].blank?
276
+ puts 'Specify action:'
277
+ puts '1. :list_namespaces'
278
+ puts '2. :list_groups'
279
+ puts '3. :get'
280
+ puts '4. :add'
281
+ puts '5. :remove'
282
+ puts 'Action: '
283
+ case gets.chomp!.to_i
284
+ when 1
285
+ options[:action] = :list_namespaces
286
+ when 2
287
+ options[:action] = :list_groups
288
+ when 3
289
+ options[:action] = :get
290
+ when 4
291
+ options[:action] = :add
292
+ when 5
293
+ options[:action] = :remove
294
+ else
295
+ options[:action] = nil
296
+ end
297
+ end
298
+
269
299
  when :message
270
300
  while options[:message].blank?
271
301
  puts 'Write below message to publish:'
@@ -273,10 +303,12 @@ class DemoConsole
273
303
  end
274
304
 
275
305
  when :channel
276
- while options[:channel].blank?
277
- print 'Specify channel(s): '
278
- options[:channel] = gets.chomp!
279
- end
306
+ print 'Specify channel(s): '
307
+ options[:channel] = gets.chomp!
308
+
309
+ when :group
310
+ print 'Specify channel group(s): '
311
+ options[:group] = gets.chomp!
280
312
 
281
313
  when :optional_channel
282
314
  print 'Specify channel(s) or leave blank for all channels (global here now): '
@@ -329,10 +361,10 @@ class DemoConsole
329
361
  options[:heartbeat] = gets.chomp!
330
362
  end
331
363
 
332
- when :subscribe_key
333
- while options[:subscribe_key].blank?
334
- print 'Enter subscribe key: '
335
- options[:subscribe_key] = gets.chomp!
364
+ when :auth_key
365
+ while options[:auth_key].blank?
366
+ print 'Enter auth key: '
367
+ options[:auth_key] = gets.chomp!
336
368
  end
337
369
 
338
370
  when :read
@@ -347,6 +379,12 @@ class DemoConsole
347
379
  options[:write] = acceptance
348
380
  end
349
381
 
382
+ when :manage
383
+ while options[:manage].blank? && options[:manage] != false
384
+ print 'Manage? '
385
+ options[:manage] = acceptance
386
+ end
387
+
350
388
  when :limit
351
389
  while options[:limit].blank?
352
390
  print 'limit: '
@@ -0,0 +1,51 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://pubsub.pubnub.com/v1/channel-registration/sub-key/demo/namespace/foo/channel-group/foo?add=one,two&pnsdk=PubNub-Ruby/3.7.0beta0&uuid=045b8b3d-da8e-4c28-9bb7-10c00b404849
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ Connection:
17
+ - keep-alive
18
+ Keep-Alive:
19
+ - 30
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Date:
26
+ - Tue, 04 Nov 2014 13:42:22 GMT
27
+ Content-Type:
28
+ - text/javascript; charset="UTF-8"
29
+ Content-Length:
30
+ - '79'
31
+ Connection:
32
+ - keep-alive
33
+ Cache-Control:
34
+ - no-cache
35
+ Access-Control-Allow-Origin:
36
+ - "*"
37
+ Access-Control-Allow-Methods:
38
+ - GET
39
+ Accept-Ranges:
40
+ - bytes
41
+ Age:
42
+ - '0'
43
+ Server:
44
+ - Pubnub
45
+ body:
46
+ encoding: UTF-8
47
+ string: '{"status": 200, "message": "OK", "service": "channel-registry", "error":
48
+ false}'
49
+ http_version:
50
+ recorded_at: Tue, 04 Nov 2014 13:42:22 GMT
51
+ recorded_with: VCR 2.9.2