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.
- checksums.yaml +4 -4
- data/CHANGELOG.txt +3 -0
- data/Gemfile.lock +1 -1
- data/README.md +144 -10
- data/examples/demo_console.rb +61 -23
- data/fixtures/vcr_cassettes/cg/add-c-as-array.yml +51 -0
- data/fixtures/vcr_cassettes/cg/add-c-as-csv.yml +51 -0
- data/fixtures/vcr_cassettes/cg/add-c-as-string.yml +51 -0
- data/fixtures/vcr_cassettes/cg/add-c-as-symbol.yml +51 -0
- data/fixtures/vcr_cassettes/cg/audit-cg.yml +44 -0
- data/fixtures/vcr_cassettes/cg/audit-ns.yml +44 -0
- data/fixtures/vcr_cassettes/cg/grant-cg.yml +44 -0
- data/fixtures/vcr_cassettes/cg/grant-ns.yml +44 -0
- data/fixtures/vcr_cassettes/cg/here_now-cg.yml +51 -0
- data/fixtures/vcr_cassettes/cg/leave-cg-c.yml +132 -0
- data/fixtures/vcr_cassettes/cg/leave-cg.yml +133 -0
- data/fixtures/vcr_cassettes/cg/list-all-c-in-in-ns-cg.yml +50 -0
- data/fixtures/vcr_cassettes/cg/list-all-c-in-non-ns-cg.yml +51 -0
- data/fixtures/vcr_cassettes/cg/list-all-cg-in-ns.yml +51 -0
- data/fixtures/vcr_cassettes/cg/list-all-namespaces.yml +50 -0
- data/fixtures/vcr_cassettes/cg/list-all-non-namespaced-cg.yml +49 -0
- data/fixtures/vcr_cassettes/cg/remove-c-as-array.yml +51 -0
- data/fixtures/vcr_cassettes/cg/remove-c-as-csv.yml +51 -0
- data/fixtures/vcr_cassettes/cg/remove-c-as-string.yml +51 -0
- data/fixtures/vcr_cassettes/cg/remove-c-as-symbol.yml +51 -0
- data/fixtures/vcr_cassettes/cg/remove-cg-from-ns-csv.yml +51 -0
- data/fixtures/vcr_cassettes/cg/remove-ns-csv.yml +51 -0
- data/fixtures/vcr_cassettes/cg/subscribe-cg-and-channel.yml +85 -0
- data/fixtures/vcr_cassettes/cg/subscribe-cg-only.yml +85 -0
- data/lib/pubnub/client.rb +6 -2
- data/lib/pubnub/envelope.rb +1 -0
- data/lib/pubnub/event.rb +105 -20
- data/lib/pubnub/events/audit.rb +13 -0
- data/lib/pubnub/events/channel_registration.rb +132 -0
- data/lib/pubnub/events/grant.rb +17 -7
- data/lib/pubnub/events/heartbeat.rb +29 -3
- data/lib/pubnub/events/here_now.rb +21 -7
- data/lib/pubnub/events/leave.rb +27 -3
- data/lib/pubnub/events/presence.rb +4 -3
- data/lib/pubnub/events/set_state.rb +16 -3
- data/lib/pubnub/events/state.rb +15 -9
- data/lib/pubnub/events/subscribe.rb +17 -3
- data/lib/pubnub/formatter.rb +31 -7
- data/lib/pubnub/pam.rb +4 -3
- data/lib/pubnub/version.rb +1 -1
- data/spec/lib/integration/channel_groups_spec.rb +120 -0
- data/spec/lib/integration/channel_registration_spec.rb +317 -0
- data/spec/spec_helper.rb +0 -1
- metadata +31 -2
data/lib/pubnub/events/state.rb
CHANGED
@@ -16,12 +16,18 @@ module Pubnub
|
|
16
16
|
super
|
17
17
|
|
18
18
|
# check channel/channels
|
19
|
-
raise ArgumentError.new(:object => self, :message => 'State requires :channel argument') unless @channel
|
20
|
-
raise ArgumentError.new(:object => self, :message => 'Invalid channel format! Should be type of: String or Symbol') unless @channel.is_a?(String) or @channel.is_a?(Symbol)
|
19
|
+
# raise ArgumentError.new(:object => self, :message => 'State requires :channel argument') unless @channel
|
20
|
+
# raise ArgumentError.new(:object => self, :message => 'Invalid channel format! Should be type of: String or Symbol') unless @channel.is_a?(String) or @channel.is_a?(Symbol)
|
21
21
|
end
|
22
22
|
|
23
23
|
private
|
24
24
|
|
25
|
+
def parameters(app)
|
26
|
+
parameters = super(app)
|
27
|
+
parameters.merge!({ 'channel-group' => format_channel_group(@channel_group).join(',') }) unless @channel_group.blank?
|
28
|
+
parameters
|
29
|
+
end
|
30
|
+
|
25
31
|
def path(app)
|
26
32
|
'/' + [
|
27
33
|
'v2',
|
@@ -29,7 +35,7 @@ module Pubnub
|
|
29
35
|
'sub_key',
|
30
36
|
@subscribe_key,
|
31
37
|
'channel',
|
32
|
-
@channel,
|
38
|
+
channels_for_url(@channel),
|
33
39
|
'uuid',
|
34
40
|
@uuid_looking_for
|
35
41
|
].join('/')
|
@@ -43,12 +49,12 @@ module Pubnub
|
|
43
49
|
envelopes << Envelope.new(
|
44
50
|
{
|
45
51
|
:parsed_response => parsed_response,
|
46
|
-
:channel
|
47
|
-
:payload
|
48
|
-
:service
|
49
|
-
:message
|
50
|
-
:uuid
|
51
|
-
:status
|
52
|
+
:channel => (parsed_response['channel'] if parsed_response),
|
53
|
+
:payload => (parsed_response['payload'] if parsed_response),
|
54
|
+
:service => (parsed_response['service'] if parsed_response),
|
55
|
+
:message => (parsed_response['message'] if parsed_response),
|
56
|
+
:uuid => (parsed_response['uuid'] if parsed_response),
|
57
|
+
:status => (parsed_response['status'] if parsed_response)
|
52
58
|
},
|
53
59
|
app
|
54
60
|
)
|
@@ -23,11 +23,20 @@ module Pubnub
|
|
23
23
|
def validate!
|
24
24
|
super
|
25
25
|
# Check channels
|
26
|
-
raise ArgumentError.new(:object => self, :message => 'Subscribe requires :channel or :
|
26
|
+
raise ArgumentError.new(:object => self, :message => 'Subscribe requires :channel, :channels or :group argument') if @channel.blank? && @channel_group.blank?
|
27
27
|
|
28
28
|
# Check callback
|
29
29
|
raise ArgumentError.new(:object => self, :message => 'Callback parameter is required while using async subscribe') if !@http_sync && @callback.blank?
|
30
30
|
|
31
|
+
# Channel group
|
32
|
+
if @channel_group.class == Array
|
33
|
+
@channel_group.each do |cg|
|
34
|
+
# raise ArgumentError.new(:object => self, :message => ':group argument has to be in format "ns:cg", "ns:" or ":cg"') if cg.count(':') != 1
|
35
|
+
end
|
36
|
+
elsif !@channel_group.blank?
|
37
|
+
number_of_groups = @channel_group.to_s.split(',').size # In case it will be given as csv
|
38
|
+
# raise ArgumentError.new(:object => self, :message => ':group argument has to be in format "ns:cg", "ns:" or ":cg"') if @channel_group.to_s.count(':') != number_of_groups
|
39
|
+
end
|
31
40
|
end
|
32
41
|
|
33
42
|
private
|
@@ -35,7 +44,12 @@ module Pubnub
|
|
35
44
|
def add_state(state, app)
|
36
45
|
app.env[:state] = {} unless app.env[:state]
|
37
46
|
app.env[:state][@origin] = {} unless app.env[:state][@origin]
|
38
|
-
|
47
|
+
@channel.each do |channel|
|
48
|
+
app.env[:state][@origin][channel] = state
|
49
|
+
end
|
50
|
+
@channel_group.each do |channel_group|
|
51
|
+
app.env[:state][@origin][channel_group] = state
|
52
|
+
end
|
39
53
|
end
|
40
54
|
end
|
41
|
-
end
|
55
|
+
end
|
data/lib/pubnub/formatter.rb
CHANGED
@@ -3,18 +3,36 @@ module Pubnub
|
|
3
3
|
# Formats channels as array of channels as strings
|
4
4
|
def format_channels(channels, should_encode = true)
|
5
5
|
channel_array = case channels.class.to_s
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
6
|
+
when 'String'
|
7
|
+
channels.split(',')
|
8
|
+
when 'Array'
|
9
|
+
channels.map { |channel| channel.to_s }
|
10
|
+
when 'NilClass'
|
11
|
+
[]
|
12
|
+
else
|
13
|
+
[channels.to_s]
|
14
|
+
end
|
13
15
|
|
14
16
|
channel_array = channel_array.map { |channel| encode_channel(channel) } if should_encode
|
15
17
|
channel_array
|
16
18
|
end
|
17
19
|
|
20
|
+
def format_channel_group(channel_group, should_encode = true)
|
21
|
+
channel_group_array = case channel_group.class.to_s
|
22
|
+
when 'String'
|
23
|
+
channel_group.split(',')
|
24
|
+
when 'Array'
|
25
|
+
channel_group.map { |channel| channel.to_s }
|
26
|
+
when 'NilClass'
|
27
|
+
[]
|
28
|
+
else
|
29
|
+
[channel_group.to_s]
|
30
|
+
end
|
31
|
+
|
32
|
+
channel_group_array = channel_group_array.map { |channel| encode_channel(channel) } if should_encode
|
33
|
+
channel_group_array
|
34
|
+
end
|
35
|
+
|
18
36
|
def encode_channel(channel)
|
19
37
|
URI.encode_www_form_component(channel).gsub('+', '%20')
|
20
38
|
end
|
@@ -42,5 +60,11 @@ module Pubnub
|
|
42
60
|
params
|
43
61
|
end
|
44
62
|
|
63
|
+
def channels_for_url(channels)
|
64
|
+
channel = channels.join(',')
|
65
|
+
channel = ',' if channel.empty?
|
66
|
+
channel
|
67
|
+
end
|
68
|
+
|
45
69
|
end
|
46
70
|
end
|
data/lib/pubnub/pam.rb
CHANGED
@@ -16,9 +16,10 @@ module Pubnub
|
|
16
16
|
|
17
17
|
def parameters(app, signature = false)
|
18
18
|
params = super(app)
|
19
|
-
params.merge!({ :timestamp
|
20
|
-
params.merge!({
|
21
|
-
params.merge!({ :
|
19
|
+
params.merge!({ :timestamp => @timestamp })
|
20
|
+
params.merge!({ 'channel-group' => @channel_group.join(',') }) unless @channel_group.blank?
|
21
|
+
params.merge!({ :channel => @channel.join(',') }) unless @channel.first.blank?
|
22
|
+
params.merge!({ :signature => signature(app) }) unless signature
|
22
23
|
params
|
23
24
|
end
|
24
25
|
|
data/lib/pubnub/version.rb
CHANGED
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'channel groups specific events' do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
EM.stop if EM.reactor_running?
|
7
|
+
while EM.reactor_running? do end
|
8
|
+
sleep(0.1)
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:callback) { lambda { |envelope| @envelopes = [envelope] } }
|
12
|
+
|
13
|
+
context '#subscribe' do
|
14
|
+
|
15
|
+
before :each do
|
16
|
+
@pubnub_client = Pubnub.new(subscribe_key: 'demo', publish_key: 'demo')
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'allows us to subscribe to cg and channel' do
|
20
|
+
VCR.use_cassette('cg/subscribe-cg-and-channel', :record => :once) do
|
21
|
+
@pubnub_client.subscribe(channel: :bot, group: 'foo:foo', callback: callback)
|
22
|
+
eventually do
|
23
|
+
expect(@envelopes.first.message).to eq '*****.......... 3520 - 2014-11-05 03:49:35'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'allows us to subscribe to cg only' do
|
29
|
+
VCR.use_cassette('cg/subscribe-cg-only', :record => :once) do
|
30
|
+
@pubnub_client.subscribe(group: 'foo:foo', callback: callback)
|
31
|
+
eventually do
|
32
|
+
expect(@envelopes.first.message).to eq '*****.......... 4495 - 2014-11-05 04:08:46'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context '#leave' do
|
39
|
+
before :each do
|
40
|
+
@pubnub_client = Pubnub.new(subscribe_key: 'demo', publish_key: 'demo')
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'leaves cg' do
|
44
|
+
VCR.use_cassette('cg/leave-cg', :record => :once) do
|
45
|
+
@pubnub_client.subscribe(channel: :bot, group: 'foo:foo', callback: callback)
|
46
|
+
sleep(1)
|
47
|
+
@pubnub_client.leave(channel: :bot, group: 'foo:foo', callback: callback)
|
48
|
+
sleep(1)
|
49
|
+
expect(@pubnub_client.env[:subscriptions].empty?).to eq true
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'leaves cg and channel' do
|
54
|
+
VCR.use_cassette('cg/leave-cg-c', :record => :once) do
|
55
|
+
@pubnub_client.subscribe(group: 'foo:foo', callback: callback)
|
56
|
+
sleep(1)
|
57
|
+
@pubnub_client.leave(group: 'foo:foo', callback: callback)
|
58
|
+
sleep(1)
|
59
|
+
expect(@pubnub_client.env[:subscriptions].empty?).to eq true
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context '#here_now' do
|
65
|
+
before :each do
|
66
|
+
@pubnub_client = Pubnub.new(subscribe_key: 'demo', publish_key: 'demo')
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'can check cg' do
|
70
|
+
VCR.use_cassette('cg/here_now-cg', :record => :once) do
|
71
|
+
envelopes = @pubnub_client.here_now(group: 'foo:', http_sync: true)
|
72
|
+
expect(envelopes.first.message).to eq 'OK'
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'PAM' do
|
79
|
+
|
80
|
+
before :each do
|
81
|
+
@pubnub_client = Pubnub.new(:subscribe_key => 'sub-c-53c3d30a-4135-11e3-9970-02ee2ddab7fe', :publish_key => 'pub-c-15d6fd3c-05de-4abc-8eba-6595a441959d', :secret_key => 'sec-c-ZWYwMGJiZTYtMTQwMC00NDQ5LWI0NmEtMzZiM2M5NThlOTJh')
|
82
|
+
Pubnub::Grant.any_instance.stub(:current_time).and_return 1234567890
|
83
|
+
Pubnub::Grant.any_instance.stub(:signature).and_return 'sig'
|
84
|
+
Pubnub::Audit.any_instance.stub(:current_time).and_return 1234567890
|
85
|
+
Pubnub::Audit.any_instance.stub(:signature).and_return 'sig'
|
86
|
+
end
|
87
|
+
|
88
|
+
context '#grant' do
|
89
|
+
it 'grants all permissions on cg' do
|
90
|
+
VCR.use_cassette('cg/grant-cg', :record => :once) do
|
91
|
+
envelopes = @pubnub_client.grant(group: 'foo:foo', http_sync: true)
|
92
|
+
expect(envelopes.first.message).to eq 'Success'
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'grants all permissions on ns' do
|
97
|
+
VCR.use_cassette('cg/grant-ns', :record => :once) do
|
98
|
+
envelopes = @pubnub_client.grant(group: 'foo:', http_sync: true)
|
99
|
+
expect(envelopes.first.message).to eq 'Success'
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context '#audit' do
|
105
|
+
it 'audits permissions on cg' do
|
106
|
+
VCR.use_cassette('cg/audit-cg', :record => :once) do
|
107
|
+
envelopes = @pubnub_client.audit(group: 'foo:foo', http_sync: true)
|
108
|
+
expect(envelopes.first.message).to eq 'Success'
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'audits permissions on ns' do
|
113
|
+
VCR.use_cassette('cg/audit-ns', :record => :once) do
|
114
|
+
envelopes = @pubnub_client.audit(group: 'foo:', http_sync: true)
|
115
|
+
expect(envelopes.first.message).to eq 'Success'
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,317 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '#channel_registration' do
|
4
|
+
|
5
|
+
let(:pubnub_client) { Pubnub.new(subscribe_key: 'demo', publish_key: 'demo') }
|
6
|
+
let(:callback) { lambda { |envelope| @envelopes = [envelope] } }
|
7
|
+
|
8
|
+
context 'sync' do
|
9
|
+
it 'lists all namespaces' do
|
10
|
+
VCR.use_cassette('cg/list-all-namespaces', :record => :once) do
|
11
|
+
envelopes = pubnub_client.channel_registration(action: :list_namespaces, http_sync: true)
|
12
|
+
expect(envelopes.first.status).to eq 200
|
13
|
+
expect(envelopes.first.payload['namespaces']).to eq %w(foo namespace_test)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'lists all non-namespaced channel groups' do
|
18
|
+
VCR.use_cassette('cg/list-all-non-namespaced-cg', :record => :once) do
|
19
|
+
envelopes = pubnub_client.channel_registration(action: :list_groups, http_sync: true)
|
20
|
+
expect(envelopes.first.status).to eq 200
|
21
|
+
expect(envelopes.first.payload['namespace']).to eq ''
|
22
|
+
expect(envelopes.first.payload['groups']).to eq %w(cg dk1)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'lists all cg in namespace' do
|
27
|
+
VCR.use_cassette('cg/list-all-cg-in-ns', :record => :once) do
|
28
|
+
envelopes = pubnub_client.channel_registration(action: :get, group: 'foo:', http_sync: true)
|
29
|
+
expect(envelopes.first.status).to eq 200
|
30
|
+
expect(envelopes.first.payload['namespace']).to eq 'foo'
|
31
|
+
expect(envelopes.first.payload['groups']).to eq %w(foo new_group)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'lists all channels in namespaced cg' do
|
36
|
+
VCR.use_cassette('cg/list-all-c-in-in-ns-cg', :record => :once) do
|
37
|
+
envelopes = pubnub_client.channel_registration(action: :get, group: 'foo:foo', http_sync: true)
|
38
|
+
expect(envelopes.first.status).to eq 200
|
39
|
+
expect(envelopes.first.payload['group']).to eq 'foo'
|
40
|
+
expect(envelopes.first.payload['channels']).to eq %w(aaa bbb)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'lists all channels in non-namespaced cg' do
|
45
|
+
VCR.use_cassette('cg/list-all-c-in-non-ns-cg', :record => :once) do
|
46
|
+
envelopes = pubnub_client.channel_registration(action: :get, group: ':cg', http_sync: true)
|
47
|
+
expect(envelopes.first.status).to eq 200
|
48
|
+
expect(envelopes.first.payload['group']).to eq 'cg'
|
49
|
+
expect(envelopes.first.payload['channels']).to eq %w(ping_3 x z)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'adding channel to cg' do
|
54
|
+
it 'adds channel to cg if given channel symbol' do
|
55
|
+
VCR.use_cassette('cg/add-c-as-symbol', :record => :once) do
|
56
|
+
envelopes = pubnub_client.channel_registration(action: :add, group: 'foo:foo', channel: :one, http_sync: true)
|
57
|
+
expect(envelopes.first.status).to eq 200
|
58
|
+
expect(envelopes.first.message).to eq 'OK'
|
59
|
+
expect(envelopes.first.error).to eq false
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'adds channel to cg if given channel array' do
|
64
|
+
VCR.use_cassette('cg/add-c-as-array', :record => :once) do
|
65
|
+
envelopes = pubnub_client.channel_registration(action: :add, group: 'foo:foo', channel: %w(one two), http_sync: true)
|
66
|
+
expect(envelopes.first.status).to eq 200
|
67
|
+
expect(envelopes.first.message).to eq 'OK'
|
68
|
+
expect(envelopes.first.error).to eq false
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'adds channel to cg if given channel string' do
|
73
|
+
VCR.use_cassette('cg/add-c-as-string', :record => :once) do
|
74
|
+
envelopes = pubnub_client.channel_registration(action: :add, group: 'foo:foo', channel: 'one', http_sync: true)
|
75
|
+
expect(envelopes.first.status).to eq 200
|
76
|
+
expect(envelopes.first.message).to eq 'OK'
|
77
|
+
expect(envelopes.first.error).to eq false
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'adds channel to cg if given channel csv' do
|
82
|
+
VCR.use_cassette('cg/add-c-as-csv', :record => :once) do
|
83
|
+
envelopes = pubnub_client.channel_registration(action: :add, group: 'foo:foo', channel: 'one,two', http_sync: true)
|
84
|
+
expect(envelopes.first.status).to eq 200
|
85
|
+
expect(envelopes.first.message).to eq 'OK'
|
86
|
+
expect(envelopes.first.error).to eq false
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context 'removing channel from cg' do
|
92
|
+
it 'removes channel from cg if given channel symbol' do
|
93
|
+
VCR.use_cassette('cg/remove-c-as-symbol', :record => :once) do
|
94
|
+
envelopes = pubnub_client.channel_registration(action: :remove, group: 'foo:foo', channel: :one, http_sync: true)
|
95
|
+
expect(envelopes.first.status).to eq 200
|
96
|
+
expect(envelopes.first.message).to eq 'OK'
|
97
|
+
expect(envelopes.first.error).to eq false
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'removes channel from cg if given channel array' do
|
102
|
+
VCR.use_cassette('cg/remove-c-as-array', :record => :once) do
|
103
|
+
envelopes = pubnub_client.channel_registration(action: :remove, group: 'foo:foo', channel: %w(one two), http_sync: true)
|
104
|
+
expect(envelopes.first.status).to eq 200
|
105
|
+
expect(envelopes.first.message).to eq 'OK'
|
106
|
+
expect(envelopes.first.error).to eq false
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'removes channel from cg if given channel string' do
|
111
|
+
VCR.use_cassette('cg/remove-c-as-string', :record => :once) do
|
112
|
+
envelopes = pubnub_client.channel_registration(action: :remove, group: 'foo:foo', channel: 'one', http_sync: true)
|
113
|
+
expect(envelopes.first.status).to eq 200
|
114
|
+
expect(envelopes.first.message).to eq 'OK'
|
115
|
+
expect(envelopes.first.error).to eq false
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'removes channel from cg if given channel csv' do
|
120
|
+
VCR.use_cassette('cg/remove-c-as-csv', :record => :once) do
|
121
|
+
envelopes = pubnub_client.channel_registration(action: :remove, group: 'foo:foo', channel: 'one,two', http_sync: true)
|
122
|
+
expect(envelopes.first.status).to eq 200
|
123
|
+
expect(envelopes.first.message).to eq 'OK'
|
124
|
+
expect(envelopes.first.error).to eq false
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'removes cg from ns' do
|
129
|
+
VCR.use_cassette('cg/remove-cg-from-ns-csv', :record => :once) do
|
130
|
+
envelopes = pubnub_client.channel_registration(action: :remove, group: 'foo:foo', http_sync: true)
|
131
|
+
expect(envelopes.first.status).to eq 200
|
132
|
+
expect(envelopes.first.message).to eq 'OK'
|
133
|
+
expect(envelopes.first.error).to eq false
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'removes ns' do
|
138
|
+
VCR.use_cassette('cg/remove-ns-csv', :record => :once) do
|
139
|
+
envelopes = pubnub_client.channel_registration(action: :remove, group: 'foo:', http_sync: true)
|
140
|
+
expect(envelopes.first.status).to eq 200
|
141
|
+
expect(envelopes.first.message).to eq 'OK'
|
142
|
+
expect(envelopes.first.error).to eq false
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
context 'async' do
|
149
|
+
it 'lists all namespaces' do
|
150
|
+
VCR.use_cassette('cg/list-all-namespaces', :record => :once) do
|
151
|
+
pubnub_client.channel_registration(action: :list_namespaces, http_sync: false, callback: callback)
|
152
|
+
eventually do
|
153
|
+
expect(@envelopes.first.status).to eq 200
|
154
|
+
expect(@envelopes.first.payload['namespaces']).to eq %w(foo namespace_test)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'lists all non-namespaced channel groups' do
|
160
|
+
VCR.use_cassette('cg/list-all-non-namespaced-cg', :record => :once) do
|
161
|
+
pubnub_client.channel_registration(action: :list_groups, http_sync: false, callback: callback)
|
162
|
+
eventually do
|
163
|
+
expect(@envelopes.first.status).to eq 200
|
164
|
+
expect(@envelopes.first.payload['namespace']).to eq ''
|
165
|
+
expect(@envelopes.first.payload['groups']).to eq %w(cg dk1)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'lists all cg in namespace' do
|
171
|
+
VCR.use_cassette('cg/list-all-cg-in-ns', :record => :once) do
|
172
|
+
pubnub_client.channel_registration(action: :get, group: 'foo:', http_sync: false, callback: callback)
|
173
|
+
eventually do
|
174
|
+
expect(@envelopes.first.status).to eq 200
|
175
|
+
expect(@envelopes.first.payload['namespace']).to eq 'foo'
|
176
|
+
expect(@envelopes.first.payload['groups']).to eq %w(foo new_group)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
it 'lists all channels in namespaced cg' do
|
182
|
+
VCR.use_cassette('cg/list-all-c-in-in-ns-cg', :record => :once) do
|
183
|
+
pubnub_client.channel_registration(action: :get, group: 'foo:foo', http_sync: false, callback: callback)
|
184
|
+
eventually do
|
185
|
+
expect(@envelopes.first.status).to eq 200
|
186
|
+
expect(@envelopes.first.payload['group']).to eq 'foo'
|
187
|
+
expect(@envelopes.first.payload['channels']).to eq %w(aaa bbb)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'lists all channels in non-namespaced cg' do
|
193
|
+
VCR.use_cassette('cg/list-all-c-in-non-ns-cg', :record => :once) do
|
194
|
+
pubnub_client.channel_registration(action: :get, group: ':cg', http_sync: false, callback: callback)
|
195
|
+
eventually do
|
196
|
+
expect(@envelopes.first.status).to eq 200
|
197
|
+
expect(@envelopes.first.payload['group']).to eq 'cg'
|
198
|
+
expect(@envelopes.first.payload['channels']).to eq %w(ping_3 x z)
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
context 'adding channel to cg' do
|
204
|
+
it 'adds channel to cg if given channel symbol' do
|
205
|
+
VCR.use_cassette('cg/add-c-as-symbol', :record => :once) do
|
206
|
+
pubnub_client.channel_registration(action: :add, group: 'foo:foo', channel: :one, http_sync: false, callback: callback)
|
207
|
+
eventually do
|
208
|
+
expect(@envelopes.first.status).to eq 200
|
209
|
+
expect(@envelopes.first.message).to eq 'OK'
|
210
|
+
expect(@envelopes.first.error).to eq false
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
it 'adds channel to cg if given channel array' do
|
216
|
+
VCR.use_cassette('cg/add-c-as-array', :record => :once) do
|
217
|
+
pubnub_client.channel_registration(action: :add, group: 'foo:foo', channel: %w(one two), http_sync: false, callback: callback)
|
218
|
+
eventually do
|
219
|
+
expect(@envelopes.first.status).to eq 200
|
220
|
+
expect(@envelopes.first.message).to eq 'OK'
|
221
|
+
expect(@envelopes.first.error).to eq false
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
it 'adds channel to cg if given channel string' do
|
227
|
+
VCR.use_cassette('cg/add-c-as-string', :record => :once) do
|
228
|
+
pubnub_client.channel_registration(action: :add, group: 'foo:foo', channel: 'one', http_sync: false, callback: callback)
|
229
|
+
eventually do
|
230
|
+
expect(@envelopes.first.status).to eq 200
|
231
|
+
expect(@envelopes.first.message).to eq 'OK'
|
232
|
+
expect(@envelopes.first.error).to eq false
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
it 'adds channel to cg if given channel csv' do
|
238
|
+
VCR.use_cassette('cg/add-c-as-csv', :record => :once) do
|
239
|
+
pubnub_client.channel_registration(action: :add, group: 'foo:foo', channel: 'one,two', http_sync: false, callback: callback)
|
240
|
+
eventually do
|
241
|
+
expect(@envelopes.first.status).to eq 200
|
242
|
+
expect(@envelopes.first.message).to eq 'OK'
|
243
|
+
expect(@envelopes.first.error).to eq false
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
context 'removing channel from cg' do
|
250
|
+
it 'removes channel from cg if given channel symbol' do
|
251
|
+
VCR.use_cassette('cg/remove-c-as-symbol', :record => :once) do
|
252
|
+
pubnub_client.channel_registration(action: :remove, group: 'foo:foo', channel: :one, http_sync: false, callback: callback)
|
253
|
+
eventually do
|
254
|
+
expect(@envelopes.first.status).to eq 200
|
255
|
+
expect(@envelopes.first.message).to eq 'OK'
|
256
|
+
expect(@envelopes.first.error).to eq false
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
it 'removes channel from cg if given channel array' do
|
262
|
+
VCR.use_cassette('cg/remove-c-as-array', :record => :once) do
|
263
|
+
pubnub_client.channel_registration(action: :remove, group: 'foo:foo', channel: %w(one two), http_sync: false, callback: callback)
|
264
|
+
eventually do
|
265
|
+
expect(@envelopes.first.status).to eq 200
|
266
|
+
expect(@envelopes.first.message).to eq 'OK'
|
267
|
+
expect(@envelopes.first.error).to eq false
|
268
|
+
end
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
it 'removes channel from cg if given channel string' do
|
273
|
+
VCR.use_cassette('cg/remove-c-as-string', :record => :once) do
|
274
|
+
pubnub_client.channel_registration(action: :remove, group: 'foo:foo', channel: 'one', http_sync: false, callback: callback)
|
275
|
+
eventually do
|
276
|
+
expect(@envelopes.first.status).to eq 200
|
277
|
+
expect(@envelopes.first.message).to eq 'OK'
|
278
|
+
expect(@envelopes.first.error).to eq false
|
279
|
+
end
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
it 'removes channel from cg if given channel csv' do
|
284
|
+
VCR.use_cassette('cg/remove-c-as-csv', :record => :once) do
|
285
|
+
pubnub_client.channel_registration(action: :remove, group: 'foo:foo', channel: 'one,two', http_sync: false, callback: callback)
|
286
|
+
eventually do
|
287
|
+
expect(@envelopes.first.status).to eq 200
|
288
|
+
expect(@envelopes.first.message).to eq 'OK'
|
289
|
+
expect(@envelopes.first.error).to eq false
|
290
|
+
end
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
it 'removes cg from ns' do
|
295
|
+
VCR.use_cassette('cg/remove-cg-from-ns-csv', :record => :once) do
|
296
|
+
pubnub_client.channel_registration(action: :remove, group: 'foo:foo', http_sync: false, callback: callback)
|
297
|
+
eventually do
|
298
|
+
expect(@envelopes.first.status).to eq 200
|
299
|
+
expect(@envelopes.first.message).to eq 'OK'
|
300
|
+
expect(@envelopes.first.error).to eq false
|
301
|
+
end
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
it 'removes ns' do
|
306
|
+
VCR.use_cassette('cg/remove-ns-csv', :record => :once) do
|
307
|
+
pubnub_client.channel_registration(action: :remove, group: 'foo:', http_sync: false, callback: callback)
|
308
|
+
eventually do
|
309
|
+
expect(@envelopes.first.status).to eq 200
|
310
|
+
expect(@envelopes.first.message).to eq 'OK'
|
311
|
+
expect(@envelopes.first.error).to eq false
|
312
|
+
end
|
313
|
+
end
|
314
|
+
end
|
315
|
+
end
|
316
|
+
end
|
317
|
+
end
|