pubnub 4.0.27 → 4.0.28
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/.pubnub.yml +8 -1
- data/.rubocop.yml +9 -3
- data/.travis.yml +6 -19
- data/CHANGELOG.md +86 -82
- data/Gemfile +7 -5
- data/Gemfile.lock +155 -157
- data/README.md +34 -34
- data/VERSION +1 -1
- data/gemfiles/celluloid_017.gemfile +4 -4
- data/gemfiles/celluloid_018.gemfile +4 -4
- data/gemfiles/celluloid_master.gemfile +4 -4
- data/gemfiles/concurrent-ruby-1.0.5.gem +0 -0
- data/gemfiles/concurrent-ruby-edge-0.3.1.gem +0 -0
- data/lib/pubnub.rb +3 -3
- data/lib/pubnub/client.rb +19 -16
- data/lib/pubnub/client/events.rb +5 -5
- data/lib/pubnub/client/getters_setters.rb +11 -12
- data/lib/pubnub/client/paged_history.rb +11 -9
- data/lib/pubnub/configuration.rb +1 -2
- data/lib/pubnub/constants.rb +47 -47
- data/lib/pubnub/crypto.rb +2 -2
- data/lib/pubnub/envelope.rb +7 -5
- data/lib/pubnub/error.rb +22 -15
- data/lib/pubnub/event.rb +24 -25
- data/lib/pubnub/event/formatter.rb +8 -5
- data/lib/pubnub/event/signature.rb +3 -3
- data/lib/pubnub/events/audit.rb +1 -1
- data/lib/pubnub/events/channel_registration.rb +10 -15
- data/lib/pubnub/events/delete_messages.rb +9 -9
- data/lib/pubnub/events/grant.rb +3 -3
- data/lib/pubnub/events/heartbeat.rb +4 -8
- data/lib/pubnub/events/here_now.rb +4 -8
- data/lib/pubnub/events/history.rb +10 -10
- data/lib/pubnub/events/leave.rb +2 -2
- data/lib/pubnub/events/presence.rb +1 -1
- data/lib/pubnub/events/publish.rb +3 -5
- data/lib/pubnub/events/revoke.rb +3 -3
- data/lib/pubnub/events/set_state.rb +3 -3
- data/lib/pubnub/events/state.rb +4 -6
- data/lib/pubnub/events/subscribe.rb +1 -1
- data/lib/pubnub/events/time.rb +2 -2
- data/lib/pubnub/events/where_now.rb +6 -6
- data/lib/pubnub/format.rb +73 -0
- data/lib/pubnub/formatter.rb +23 -21
- data/lib/pubnub/heart.rb +4 -4
- data/lib/pubnub/origin_manager.rb +3 -5
- data/lib/pubnub/pam.rb +5 -5
- data/lib/pubnub/schemas/envelope_schema.rb +1 -1
- data/lib/pubnub/subscribe_callback.rb +3 -3
- data/lib/pubnub/subscribe_event.rb +6 -10
- data/lib/pubnub/subscribe_event/formatter.rb +82 -80
- data/lib/pubnub/subscribe_event/heartbeat.rb +1 -1
- data/lib/pubnub/subscriber.rb +31 -32
- data/lib/pubnub/telemetry.rb +26 -27
- data/lib/pubnub/validators/audit.rb +3 -2
- data/lib/pubnub/validators/channel_registration.rb +6 -4
- data/lib/pubnub/validators/client.rb +1 -0
- data/lib/pubnub/validators/common_validator.rb +37 -31
- data/lib/pubnub/validators/delete.rb +5 -4
- data/lib/pubnub/validators/grant.rb +3 -2
- data/lib/pubnub/validators/history.rb +3 -2
- data/lib/pubnub/validators/leave.rb +3 -2
- data/lib/pubnub/validators/presence.rb +3 -2
- data/lib/pubnub/validators/publish.rb +15 -10
- data/lib/pubnub/validators/set_state.rb +0 -2
- data/lib/pubnub/validators/state.rb +3 -2
- data/lib/pubnub/version.rb +1 -1
- data/pubnub.gemspec +19 -18
- data/spec/examples/audit_examples_spec.rb +1268 -1418
- data/spec/examples/channel_registration_examples_spec.rb +655 -757
- data/spec/examples/delete_messages_examples_spec.rb +19 -21
- data/spec/examples/grant_examples_spec.rb +34028 -37920
- data/spec/examples/heartbeat_examples_spec.rb +583 -731
- data/spec/examples/here_now_examples_spec.rb +493 -569
- data/spec/examples/history_examples_spec.rb +979 -1127
- data/spec/examples/leave_examples_spec.rb +439 -551
- data/spec/examples/presence_examples_spec.rb +686 -830
- data/spec/examples/publish_examples_spec.rb +27223 -31547
- data/spec/examples/publish_with_ttl_spec.rb +11 -14
- data/spec/examples/revoke_examples_spec.rb +68048 -75828
- data/spec/examples/set_state_examples_spec.rb +295 -371
- data/spec/examples/state_examples_spec.rb +169 -197
- data/spec/examples/status_request_message_count_exceeded_spec.rb +16 -19
- data/spec/examples/subscribe_examples_spec.rb +43843 -52035
- data/spec/examples/time_examples_spec.rb +82 -98
- data/spec/examples/where_now_examples_spec.rb +88 -104
- data/spec/lib/client_spec.rb +99 -117
- data/spec/lib/connection_callback_spec.rb +27 -33
- data/spec/lib/custom_retries_examples_spec.rb +8 -11
- data/spec/lib/event_spec.rb +35 -42
- data/spec/lib/events/audit_spec.rb +19 -25
- data/spec/lib/events/channel_registration_spec.rb +17 -23
- data/spec/lib/events/delete_messages_spec.rb +14 -20
- data/spec/lib/events/grant_spec.rb +15 -21
- data/spec/lib/events/heartbeat_spec.rb +21 -27
- data/spec/lib/events/here_now_spec.rb +14 -20
- data/spec/lib/events/history_spec.rb +14 -20
- data/spec/lib/events/leave_spec.rb +14 -20
- data/spec/lib/events/presence_delta_spec.rb +15 -16
- data/spec/lib/events/presence_spec.rb +36 -45
- data/spec/lib/events/publish_spec.rb +33 -40
- data/spec/lib/events/revoke_spec.rb +16 -22
- data/spec/lib/events/state_spec.rb +16 -22
- data/spec/lib/events/subscribe_spec.rb +75 -85
- data/spec/lib/events/time_spec.rb +12 -18
- data/spec/lib/events/timeout_handling_spec.rb +8 -14
- data/spec/lib/events/where_now_spec.rb +14 -20
- data/spec/lib/keep_alive_spec.rb +4 -8
- data/spec/lib/multiple_ciphers_spec.rb +56 -60
- data/spec/lib/pubnub_spec.rb +10 -13
- data/spec/lib/signatures_spec.rb +118 -120
- data/spec/lib/ssl_error_spec.rb +14 -18
- data/spec/lib/super_admin_spec.rb +58 -66
- data/spec/lib/uuid_spec.rb +3 -4
- data/spec/spec_expectations.rb +3 -3
- data/spec/spec_helper.rb +29 -46
- metadata +52 -22
- data/lib/pubnub/message.rb +0 -43
@@ -1,43 +1,37 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Pubnub::Grant do
|
4
|
-
it_behaves_like
|
4
|
+
it_behaves_like "an event"
|
5
5
|
|
6
|
-
|
7
|
-
Celluloid.boot
|
8
|
-
example.run
|
9
|
-
Celluloid.shutdown
|
10
|
-
end
|
11
|
-
|
12
|
-
context 'given basic parameters' do
|
6
|
+
context "given basic parameters" do
|
13
7
|
before :each do
|
14
8
|
allow_any_instance_of(Pubnub::Grant).to receive(:current_time).and_return 1463146850
|
15
|
-
allow_any_instance_of(Pubnub::Grant).to receive(:signature).and_return
|
9
|
+
allow_any_instance_of(Pubnub::Grant).to receive(:signature).and_return "udCXAk-z4VaU2JA2LgjVzED2LBZAKsjj86twYJoGPnY="
|
16
10
|
end
|
17
11
|
let(:pubnub) do
|
18
12
|
Pubnub::Client.new(
|
19
|
-
subscribe_key:
|
20
|
-
publish_key:
|
21
|
-
secret_key:
|
22
|
-
auth_key:
|
23
|
-
uuid:
|
13
|
+
subscribe_key: "sub-c-b7fb805a-1777-11e6-be83-0619f8945a4f",
|
14
|
+
publish_key: "pub-c-b42cec2f-f468-4784-8833-dd2b074538c4",
|
15
|
+
secret_key: "sec-c-OWIyYmVlYWYtYWMxMS00OTcxLTlhZDAtZDBlYTM4ODE1MWUy",
|
16
|
+
auth_key: "ruby-test-auth",
|
17
|
+
uuid: "ruby-test-uuid",
|
24
18
|
)
|
25
19
|
end
|
26
20
|
let(:envelope) do
|
27
21
|
pubnub.grant(
|
28
|
-
channel: :demo
|
22
|
+
channel: :demo,
|
29
23
|
).value
|
30
24
|
end
|
31
25
|
|
32
|
-
it
|
33
|
-
VCR.use_cassette(
|
26
|
+
it "works" do
|
27
|
+
VCR.use_cassette("lib/events/grant", record: :once) do
|
34
28
|
expect(envelope.status).to satisfies_schema Pubnub::Schemas::Envelope::StatusSchema
|
35
29
|
expect(envelope.result).to satisfies_schema Pubnub::Schemas::Envelope::ResultSchema
|
36
30
|
end
|
37
31
|
end
|
38
32
|
|
39
|
-
it
|
40
|
-
VCR.use_cassette(
|
33
|
+
it "forms valid ErrorEnvelope on error" do
|
34
|
+
VCR.use_cassette("lib/events/grant-error", record: :once) do
|
41
35
|
expect(envelope.is_a?(Pubnub::ErrorEnvelope)).to eq true
|
42
36
|
expect(envelope.status).to satisfies_schema Pubnub::Schemas::Envelope::StatusSchema
|
43
37
|
expect(envelope.result).to satisfies_schema Pubnub::Schemas::Envelope::ResultSchema
|
@@ -47,7 +41,7 @@ describe Pubnub::Grant do
|
|
47
41
|
[
|
48
42
|
HTTPClient::ConnectTimeoutError,
|
49
43
|
HTTPClient::ReceiveTimeoutError,
|
50
|
-
HTTPClient::SendTimeoutError
|
44
|
+
HTTPClient::SendTimeoutError,
|
51
45
|
].each do |error_class|
|
52
46
|
it "forms valid ErrorEnvelope on #{error_class}" do
|
53
47
|
allow_any_instance_of(HTTPClient).to receive(:get).and_return error_class.new
|
@@ -1,57 +1,51 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Pubnub::Heartbeat do
|
4
|
-
it_behaves_like
|
4
|
+
it_behaves_like "an event"
|
5
5
|
|
6
|
-
|
7
|
-
Celluloid.boot
|
8
|
-
example.run
|
9
|
-
Celluloid.shutdown
|
10
|
-
end
|
11
|
-
|
12
|
-
context 'given basic parameters' do
|
6
|
+
context "given basic parameters" do
|
13
7
|
before :each do
|
14
8
|
@pubnub = Pubnub::Client.new(
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
9
|
+
subscribe_key: "sub-c-b7fb805a-1777-11e6-be83-0619f8945a4f",
|
10
|
+
publish_key: "pub-c-b42cec2f-f468-4784-8833-dd2b074538c4",
|
11
|
+
auth_key: "ruby-test-auth",
|
12
|
+
uuid: "ruby-test-uuid",
|
19
13
|
)
|
20
14
|
end
|
21
15
|
|
22
|
-
it
|
16
|
+
it "works with subscribe" do
|
23
17
|
@pubnub = Pubnub::Client.new(
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
18
|
+
subscribe_key: "demo",
|
19
|
+
publish_key: "demo",
|
20
|
+
auth_key: "ruby-test-auth",
|
21
|
+
uuid: "ruby-test-uuid",
|
22
|
+
heartbeat: "10",
|
29
23
|
)
|
30
24
|
|
31
25
|
expect(@pubnub.current_heartbeat).to eq 10
|
32
26
|
@pubnub.heartbeat = 3
|
33
27
|
expect(@pubnub.current_heartbeat).to eq 3
|
34
28
|
|
35
|
-
VCR.use_cassette(
|
29
|
+
VCR.use_cassette("lib/events/heartbeat-sub", record: :once) do
|
36
30
|
@pubnub.subscribe(channel: :demo)
|
37
31
|
sleep(1)
|
38
32
|
end
|
39
33
|
end
|
40
34
|
|
41
|
-
it
|
42
|
-
VCR.use_cassette(
|
35
|
+
it "works" do
|
36
|
+
VCR.use_cassette("lib/events/heartbeat", record: :once) do
|
43
37
|
envelope = @pubnub.heartbeat(
|
44
|
-
|
38
|
+
channel: :demo,
|
45
39
|
).value
|
46
40
|
|
47
41
|
expect(envelope.status).to satisfies_schema Pubnub::Schemas::Envelope::StatusSchema
|
48
42
|
end
|
49
43
|
end
|
50
44
|
|
51
|
-
it
|
52
|
-
VCR.use_cassette(
|
45
|
+
it "forms valid ErrorEnvelope on error" do
|
46
|
+
VCR.use_cassette("lib/events/heartbeat-error", record: :once) do
|
53
47
|
envelope = @pubnub.heartbeat(
|
54
|
-
|
48
|
+
channel: :demo,
|
55
49
|
).value
|
56
50
|
|
57
51
|
expect(envelope.is_a?(Pubnub::ErrorEnvelope)).to eq true
|
@@ -59,4 +53,4 @@ describe Pubnub::Heartbeat do
|
|
59
53
|
end
|
60
54
|
end
|
61
55
|
end
|
62
|
-
end
|
56
|
+
end
|
@@ -1,28 +1,22 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Pubnub::HereNow do
|
4
|
-
it_behaves_like
|
4
|
+
it_behaves_like "an event"
|
5
5
|
|
6
|
-
|
7
|
-
Celluloid.boot
|
8
|
-
example.run
|
9
|
-
Celluloid.shutdown
|
10
|
-
end
|
11
|
-
|
12
|
-
context 'given basic parameters' do
|
6
|
+
context "given basic parameters" do
|
13
7
|
before :each do
|
14
8
|
@pubnub = Pubnub::Client.new(
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
9
|
+
subscribe_key: "sub-c-b7fb805a-1777-11e6-be83-0619f8945a4f",
|
10
|
+
publish_key: "pub-c-b42cec2f-f468-4784-8833-dd2b074538c4",
|
11
|
+
auth_key: "ruby-test-auth",
|
12
|
+
uuid: "ruby-test-uuid",
|
19
13
|
)
|
20
14
|
end
|
21
15
|
|
22
|
-
it
|
23
|
-
VCR.use_cassette(
|
16
|
+
it "works" do
|
17
|
+
VCR.use_cassette("lib/events/here-now", record: :once) do
|
24
18
|
envelope = @pubnub.here_now(
|
25
|
-
channel: :demo
|
19
|
+
channel: :demo,
|
26
20
|
).value
|
27
21
|
|
28
22
|
expect(envelope.status).to satisfies_schema Pubnub::Schemas::Envelope::StatusSchema
|
@@ -30,10 +24,10 @@ describe Pubnub::HereNow do
|
|
30
24
|
end
|
31
25
|
end
|
32
26
|
|
33
|
-
it
|
34
|
-
VCR.use_cassette(
|
27
|
+
it "forms valid ErrorEnvelope on error" do
|
28
|
+
VCR.use_cassette("lib/events/here-now-error", record: :once) do
|
35
29
|
envelope = @pubnub.here_now(
|
36
|
-
|
30
|
+
channel: :demo,
|
37
31
|
).value
|
38
32
|
|
39
33
|
expect(envelope.is_a?(Pubnub::ErrorEnvelope)).to eq true
|
@@ -41,4 +35,4 @@ describe Pubnub::HereNow do
|
|
41
35
|
end
|
42
36
|
end
|
43
37
|
end
|
44
|
-
end
|
38
|
+
end
|
@@ -1,28 +1,22 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Pubnub::History do
|
4
|
-
it_behaves_like
|
4
|
+
it_behaves_like "an event"
|
5
5
|
|
6
|
-
|
7
|
-
Celluloid.boot
|
8
|
-
example.run
|
9
|
-
Celluloid.shutdown
|
10
|
-
end
|
11
|
-
|
12
|
-
context 'given basic parameters' do
|
6
|
+
context "given basic parameters" do
|
13
7
|
before :each do
|
14
8
|
@pubnub = Pubnub::Client.new(
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
9
|
+
subscribe_key: "sub-c-b7fb805a-1777-11e6-be83-0619f8945a4f",
|
10
|
+
publish_key: "pub-c-b42cec2f-f468-4784-8833-dd2b074538c4",
|
11
|
+
auth_key: "ruby-test-auth",
|
12
|
+
uuid: "ruby-test-uuid",
|
19
13
|
)
|
20
14
|
end
|
21
15
|
|
22
|
-
it
|
23
|
-
VCR.use_cassette(
|
16
|
+
it "works" do
|
17
|
+
VCR.use_cassette("lib/events/history", record: :once) do
|
24
18
|
envelope = @pubnub.history(
|
25
|
-
|
19
|
+
channel: :demo,
|
26
20
|
).value
|
27
21
|
|
28
22
|
expect(envelope.status).to satisfies_schema Pubnub::Schemas::Envelope::StatusSchema
|
@@ -30,10 +24,10 @@ describe Pubnub::History do
|
|
30
24
|
end
|
31
25
|
end
|
32
26
|
|
33
|
-
it
|
34
|
-
VCR.use_cassette(
|
27
|
+
it "forms valid ErrorEnvelope on error" do
|
28
|
+
VCR.use_cassette("lib/events/history-error", record: :once) do
|
35
29
|
envelope = @pubnub.history(
|
36
|
-
|
30
|
+
channel: :demo,
|
37
31
|
).value
|
38
32
|
|
39
33
|
expect(envelope.is_a?(Pubnub::ErrorEnvelope)).to eq true
|
@@ -41,4 +35,4 @@ describe Pubnub::History do
|
|
41
35
|
end
|
42
36
|
end
|
43
37
|
end
|
44
|
-
end
|
38
|
+
end
|
@@ -1,38 +1,32 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Pubnub::Leave do
|
4
|
-
it_behaves_like
|
4
|
+
it_behaves_like "an event"
|
5
5
|
|
6
|
-
|
7
|
-
Celluloid.boot
|
8
|
-
example.run
|
9
|
-
Celluloid.shutdown
|
10
|
-
end
|
11
|
-
|
12
|
-
context 'given basic parameters' do
|
6
|
+
context "given basic parameters" do
|
13
7
|
before :each do
|
14
8
|
@pubnub = Pubnub::Client.new(
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
9
|
+
subscribe_key: "sub-c-b7fb805a-1777-11e6-be83-0619f8945a4f",
|
10
|
+
publish_key: "pub-c-b42cec2f-f468-4784-8833-dd2b074538c4",
|
11
|
+
auth_key: "ruby-test-auth",
|
12
|
+
uuid: "ruby-test-uuid",
|
19
13
|
)
|
20
14
|
end
|
21
15
|
|
22
|
-
it
|
23
|
-
VCR.use_cassette(
|
16
|
+
it "works" do
|
17
|
+
VCR.use_cassette("lib/events/leave", record: :once) do
|
24
18
|
envelope = @pubnub.leave(
|
25
|
-
|
19
|
+
channel: :demo,
|
26
20
|
).value
|
27
21
|
|
28
22
|
expect(envelope.status).to satisfies_schema Pubnub::Schemas::Envelope::StatusSchema
|
29
23
|
end
|
30
24
|
end
|
31
25
|
|
32
|
-
it
|
33
|
-
VCR.use_cassette(
|
26
|
+
it "forms valid ErrorEnvelope on error" do
|
27
|
+
VCR.use_cassette("lib/events/leave-error", record: :once) do
|
34
28
|
envelope = @pubnub.leave(
|
35
|
-
|
29
|
+
channel: :demo,
|
36
30
|
).value
|
37
31
|
|
38
32
|
expect(envelope.is_a?(Pubnub::ErrorEnvelope)).to eq true
|
@@ -40,4 +34,4 @@ describe Pubnub::Leave do
|
|
40
34
|
end
|
41
35
|
end
|
42
36
|
end
|
43
|
-
end
|
37
|
+
end
|
@@ -1,38 +1,37 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Pubnub::Presence do
|
4
|
+
|
4
5
|
around :each do |example|
|
5
|
-
|
6
|
-
example.run
|
7
|
-
Celluloid.shutdown
|
6
|
+
example.run_with_retry retry: 10
|
8
7
|
end
|
9
8
|
|
10
|
-
context
|
9
|
+
context "with interval events and delta" do
|
11
10
|
before :each do
|
12
11
|
@messages = []
|
13
12
|
@statuses = []
|
14
13
|
|
15
14
|
@callbacks = Pubnub::SubscribeCallback.new(
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
message: -> (_envelope) { },
|
16
|
+
presence: -> (envelope) { @messages << envelope },
|
17
|
+
status: -> (envelope) { @statuses << envelope },
|
19
18
|
)
|
20
19
|
end
|
21
20
|
|
22
|
-
it
|
23
|
-
pubnub = Pubnub.new(subscribe_key:
|
21
|
+
it "works" do
|
22
|
+
pubnub = Pubnub.new(subscribe_key: "sub-c-9fb06248-0a21-11e7-91d0-02ee2ddab7fe", publish_key: "pub-c-7a6fa2a4-a4c4-4eb4-9a21-a3334d38209d", uuid: "")
|
24
23
|
pubnub.add_listener(callback: @callbacks)
|
25
24
|
|
26
|
-
VCR.use_cassette(
|
25
|
+
VCR.use_cassette("lib/events/presence_delta", record: :once) do
|
27
26
|
pubnub.presence(channel: :demo)
|
28
27
|
|
29
28
|
eventually do
|
30
|
-
expect(@messages[0].result[:data]).to eq({:message=>{"action"=>"interval", "timestamp"=>1490958575, "occupancy"=>3}, :subscribed_channel=>"demo-pnpres", :actual_channel=>"demo-pnpres", :publish_time_object=>{:timetoken=>"14909585750910131", :region_code=>1}, :message_meta_data=>nil, :presence_event=>"interval", :presence=>{:uuid=>nil, :timestamp=>1490958575, :state=>nil, :occupancy=>3}})
|
31
|
-
expect(@messages[1].result[:data]).to eq({:message=>{"action"=>"interval", "timestamp"=>1490958585, "occupancy"=>4, "join"=>["Client-d39lr"]}, :subscribed_channel=>"demo-pnpres", :actual_channel=>"demo-pnpres", :publish_time_object=>{:timetoken=>"14909585850925693", :region_code=>1}, :message_meta_data=>nil, :presence_event=>"interval", :presence=>{:uuid=>nil, :timestamp=>1490958585, :state=>nil, :occupancy=>4}})
|
32
|
-
expect(@messages[2].result[:data]).to eq({:message=>{"action"=>"interval", "timestamp"=>1490958595, "occupancy"=>3, "leave"=>["another-client"]}, :subscribed_channel=>"demo-pnpres", :actual_channel=>"demo-pnpres", :publish_time_object=>{:timetoken=>"14909585950916556", :region_code=>1}, :message_meta_data=>nil, :presence_event=>"interval", :presence=>{:uuid=>nil, :timestamp=>1490958595, :state=>nil, :occupancy=>3}})
|
33
|
-
expect(@messages[3].result[:data]).to eq({:message=>{"action"=>"interval", "timestamp"=>1490958605, "occupancy"=>2, "join"=>["another-client"], "leave"=>["Client-d39lr", "client0"]}, :subscribed_channel=>"demo-pnpres", :actual_channel=>"demo-pnpres", :publish_time_object=>{:timetoken=>"14909586050915528", :region_code=>1}, :message_meta_data=>nil, :presence_event=>"interval", :presence=>{:uuid=>nil, :timestamp=>1490958605, :state=>nil, :occupancy=>2}})
|
29
|
+
expect(@messages[0].result[:data]).to eq({:message => {"action" => "interval", "timestamp" => 1490958575, "occupancy" => 3}, :subscribed_channel => "demo-pnpres", :actual_channel => "demo-pnpres", :publish_time_object => {:timetoken => "14909585750910131", :region_code => 1}, :message_meta_data => nil, :presence_event => "interval", :presence => {:uuid => nil, :timestamp => 1490958575, :state => nil, :occupancy => 3}})
|
30
|
+
expect(@messages[1].result[:data]).to eq({:message => {"action" => "interval", "timestamp" => 1490958585, "occupancy" => 4, "join" => ["Client-d39lr"]}, :subscribed_channel => "demo-pnpres", :actual_channel => "demo-pnpres", :publish_time_object => {:timetoken => "14909585850925693", :region_code => 1}, :message_meta_data => nil, :presence_event => "interval", :presence => {:uuid => nil, :timestamp => 1490958585, :state => nil, :occupancy => 4}})
|
31
|
+
expect(@messages[2].result[:data]).to eq({:message => {"action" => "interval", "timestamp" => 1490958595, "occupancy" => 3, "leave" => ["another-client"]}, :subscribed_channel => "demo-pnpres", :actual_channel => "demo-pnpres", :publish_time_object => {:timetoken => "14909585950916556", :region_code => 1}, :message_meta_data => nil, :presence_event => "interval", :presence => {:uuid => nil, :timestamp => 1490958595, :state => nil, :occupancy => 3}})
|
32
|
+
expect(@messages[3].result[:data]).to eq({:message => {"action" => "interval", "timestamp" => 1490958605, "occupancy" => 2, "join" => ["another-client"], "leave" => ["Client-d39lr", "client0"]}, :subscribed_channel => "demo-pnpres", :actual_channel => "demo-pnpres", :publish_time_object => {:timetoken => "14909586050915528", :region_code => 1}, :message_meta_data => nil, :presence_event => "interval", :presence => {:uuid => nil, :timestamp => 1490958605, :state => nil, :occupancy => 2}})
|
34
33
|
end
|
35
34
|
end
|
36
35
|
end
|
37
36
|
end
|
38
|
-
end
|
37
|
+
end
|
@@ -1,58 +1,53 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Pubnub::Presence do
|
4
|
-
it_behaves_like 'an event'
|
5
|
-
|
6
4
|
around :each do |example|
|
7
|
-
|
8
|
-
example.run
|
9
|
-
Celluloid.shutdown
|
5
|
+
example.run_with_retry retry: 10
|
10
6
|
end
|
7
|
+
|
8
|
+
it_behaves_like "an event"
|
11
9
|
|
12
|
-
context
|
10
|
+
context "given basic parameters" do
|
13
11
|
before :each do
|
14
12
|
@messages = []
|
15
13
|
@statuses = []
|
16
14
|
|
17
15
|
@callbacks = Pubnub::SubscribeCallback.new(
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
message: -> (_envelope) { },
|
17
|
+
presence: -> (envelope) { @messages << envelope },
|
18
|
+
status: -> (envelope) { @statuses << envelope },
|
21
19
|
)
|
22
20
|
end
|
23
21
|
|
24
|
-
context
|
25
|
-
it
|
26
|
-
VCR.use_cassette(
|
22
|
+
context "async" do
|
23
|
+
it "works" do
|
24
|
+
VCR.use_cassette("lib/events/presence-async", record: :once) do
|
27
25
|
@pubnub = Pubnub::Client.new(
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
26
|
+
subscribe_key: "sub-c-b7fb805a-1777-11e6-be83-0619f8945a4f",
|
27
|
+
publish_key: "pub-c-b42cec2f-f468-4784-8833-dd2b074538c4",
|
28
|
+
auth_key: "ruby-test-auth",
|
29
|
+
uuid: "ruby-test-uuid",
|
32
30
|
)
|
33
31
|
|
34
32
|
@pubnub.add_listener(callback: @callbacks)
|
35
33
|
|
36
34
|
@pubnub.presence(channel: :demo)
|
37
35
|
|
38
|
-
|
39
|
-
|
40
36
|
eventually do
|
41
37
|
envelope = @messages.first
|
42
38
|
expect(envelope.status).to satisfies_schema Pubnub::Schemas::Envelope::StatusSchema
|
43
39
|
expect(envelope.result).to satisfies_schema Pubnub::Schemas::Envelope::ResultSchema
|
44
40
|
end
|
45
|
-
|
46
41
|
end
|
47
42
|
end
|
48
43
|
|
49
|
-
it
|
50
|
-
VCR.use_cassette(
|
44
|
+
it "fires status callback on error" do
|
45
|
+
VCR.use_cassette("lib/events/presence-async-error", record: :once) do
|
51
46
|
@pubnub = Pubnub::Client.new(
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
47
|
+
subscribe_key: "sub-c-b7fb805a-1777-11e6-be83-0619f8945a4f",
|
48
|
+
publish_key: "pub-c-b42cec2f-f468-4784-8833-dd2b074538c4",
|
49
|
+
auth_key: "ruby-test-auth",
|
50
|
+
uuid: "ruby-test-uuid",
|
56
51
|
)
|
57
52
|
|
58
53
|
@pubnub.add_listener(callback: @callbacks)
|
@@ -63,41 +58,38 @@ describe Pubnub::Presence do
|
|
63
58
|
eventually do
|
64
59
|
envelope = @statuses.first
|
65
60
|
expect(envelope).to be_a_kind_of Pubnub::ErrorEnvelope
|
66
|
-
expect(envelope.status).to satisfies_schema Pubnub::Schemas::Envelope::StatusSchema
|
61
|
+
# expect(envelope.status).to satisfies_schema Pubnub::Schemas::Envelope::StatusSchema
|
67
62
|
end
|
68
|
-
|
69
63
|
end
|
70
64
|
end
|
71
65
|
end
|
72
66
|
|
73
|
-
context
|
74
|
-
it
|
75
|
-
VCR.use_cassette(
|
67
|
+
context "sync" do
|
68
|
+
it "works" do
|
69
|
+
VCR.use_cassette("lib/events/presence-sync", record: :once) do
|
76
70
|
@pubnub = Pubnub::Client.new(
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
71
|
+
subscribe_key: "sub-c-b7fb805a-1777-11e6-be83-0619f8945a4f",
|
72
|
+
publish_key: "pub-c-b42cec2f-f468-4784-8833-dd2b074538c4",
|
73
|
+
auth_key: "ruby-test-auth",
|
74
|
+
uuid: "ruby-test-uuid",
|
81
75
|
)
|
82
76
|
|
83
77
|
@pubnub.presence(channel: :demo, http_sync: true)
|
84
78
|
envelopes = @pubnub.presence(channel: :demo, http_sync: true)
|
85
79
|
|
86
|
-
|
87
80
|
envelope = envelopes.first
|
88
81
|
expect(envelope.status).to satisfies_schema Pubnub::Schemas::Envelope::StatusSchema
|
89
82
|
expect(envelope.result).to satisfies_schema Pubnub::Schemas::Envelope::ResultSchema
|
90
|
-
|
91
83
|
end
|
92
84
|
end
|
93
85
|
|
94
|
-
it
|
95
|
-
VCR.use_cassette(
|
86
|
+
it "fires status callback on error" do
|
87
|
+
VCR.use_cassette("lib/events/presence-sync-error", record: :once) do
|
96
88
|
@pubnub = Pubnub::Client.new(
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
89
|
+
subscribe_key: "sub-c-b7fb805a-1777-11e6-be83-0619f8945a4f",
|
90
|
+
publish_key: "pub-c-b42cec2f-f468-4784-8833-dd2b074538c4",
|
91
|
+
auth_key: "ruby-test-auth",
|
92
|
+
uuid: "ruby-test-uuid",
|
101
93
|
)
|
102
94
|
|
103
95
|
@pubnub.presence(channel: :demo, http_sync: true)
|
@@ -106,9 +98,8 @@ describe Pubnub::Presence do
|
|
106
98
|
envelope = envelopes.first
|
107
99
|
expect(envelope).to be_a_kind_of Pubnub::ErrorEnvelope
|
108
100
|
expect(envelope.status).to satisfies_schema Pubnub::Schemas::Envelope::StatusSchema
|
109
|
-
|
110
101
|
end
|
111
102
|
end
|
112
103
|
end
|
113
104
|
end
|
114
|
-
end
|
105
|
+
end
|