pubnub 4.0.1 → 4.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 91af15ac50959fdcb3f3de5522b9f3a7bfaaaa11
4
- data.tar.gz: a491ad0bb5a0ea410131ef4ff4641e2ab17dff3e
3
+ metadata.gz: 073b843850f0f7ef524956d1790888537dd85d1b
4
+ data.tar.gz: 78d98c67a1d37bdea2ebeca38a89483e6cff8c0b
5
5
  SHA512:
6
- metadata.gz: 41b4bfa1df127156b0009695a480d3968d77bdef94de15915cb5416618e67fc8c41651bf7b1f96954961a14a94b28458fb6171256bf48aeb29333abcaedc7758
7
- data.tar.gz: 9d7f32cfd9b4a0da467d8d57ce5894a18a96c90ef117aa8fbfb33fbcfc0983282787d59c3eb2716ce133a8767fedfcd0d8fb74c2707e3d7b16300c782288a6e2
6
+ metadata.gz: c89703845876a25e3c67d84313b9d0679905fd83cae885048c0d9c590693a1853fcac9ed3d408f71322a0164df36594f194d06819603f5ce07efb4fc48471229
7
+ data.tar.gz: 6b04ae9b1f799c28053170dfe39f9d097f2055a42b56f3c9535d904f7219d02fb369a29bcf148bd0bfadcae7be89a0ddd682b08c439564411402a03663fb193d
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ##### 4.0.2
2
+ * Added #subscribe_filter for client
3
+
1
4
  ##### 4.0.1
2
5
  * Updated dry-validation and EnvelopeSchema
3
6
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pubnub (4.0.1)
4
+ pubnub (4.0.2)
5
5
  celluloid (~> 0.17)
6
6
  dry-validation (~> 0.8)
7
7
  httpclient (~> 2.8)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.0.1
1
+ 4.0.3
@@ -0,0 +1,120 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://pubsub.pubnub.com/v2/subscribe/demo/demo/0?pnsdk=PubNub-Ruby/4.0.1&t=%7B%22r%22:0,%22t%22:0%7D&uuid=9c9bb363-c504-4bd5-a545-1e925a2bccf1
6
+ body:
7
+ encoding: UTF-8
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - HTTPClient/1.0 (2.8.0, ruby 2.1.10 (2016-04-01))
12
+ Accept:
13
+ - "*/*"
14
+ Date:
15
+ - Mon, 18 Jul 2016 12:39:39 GMT
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Date:
22
+ - Mon, 18 Jul 2016 12:39:39 GMT
23
+ Content-Type:
24
+ - text/javascript; charset="UTF-8"
25
+ Content-Length:
26
+ - '44'
27
+ Connection:
28
+ - keep-alive
29
+ Cache-Control:
30
+ - no-cache
31
+ Access-Control-Allow-Origin:
32
+ - "*"
33
+ Access-Control-Allow-Methods:
34
+ - GET
35
+ body:
36
+ encoding: UTF-8
37
+ string: '{"t":{"t":"14688455796837739","r":2},"m":[]}'
38
+ http_version:
39
+ recorded_at: Mon, 18 Jul 2016 12:39:39 GMT
40
+ - request:
41
+ method: get
42
+ uri: http://pubsub.pubnub.com/v2/subscribe/demo/demo/0?pnsdk=PubNub-Ruby/4.0.1&t=%7B%22r%22:2,%22t%22:0%7D&uuid=9c9bb363-c504-4bd5-a545-1e925a2bccf1
43
+ body:
44
+ encoding: UTF-8
45
+ string: ''
46
+ headers:
47
+ User-Agent:
48
+ - HTTPClient/1.0 (2.8.0, ruby 2.1.10 (2016-04-01))
49
+ Accept:
50
+ - "*/*"
51
+ Date:
52
+ - Mon, 18 Jul 2016 12:39:39 GMT
53
+ response:
54
+ status:
55
+ code: 200
56
+ message: OK
57
+ headers:
58
+ Date:
59
+ - Mon, 18 Jul 2016 12:39:39 GMT
60
+ Content-Type:
61
+ - text/javascript; charset="UTF-8"
62
+ Content-Length:
63
+ - '44'
64
+ Connection:
65
+ - keep-alive
66
+ Cache-Control:
67
+ - no-cache
68
+ Access-Control-Allow-Origin:
69
+ - "*"
70
+ Access-Control-Allow-Methods:
71
+ - GET
72
+ body:
73
+ encoding: UTF-8
74
+ string: '{"t":{"t":"14688455798262519","r":2},"m":[]}'
75
+ http_version:
76
+ recorded_at: Mon, 18 Jul 2016 12:39:40 GMT
77
+ - request:
78
+ method: get
79
+ uri: http://pubsub.pubnub.com/v2/presence/sub-key/demo/channel/demo/leave?pnsdk=PubNub-Ruby/4.0.1&uuid=9c9bb363-c504-4bd5-a545-1e925a2bccf1
80
+ body:
81
+ encoding: UTF-8
82
+ string: ''
83
+ headers:
84
+ User-Agent:
85
+ - HTTPClient/1.0 (2.8.0, ruby 2.1.10 (2016-04-01))
86
+ Accept:
87
+ - "*/*"
88
+ Date:
89
+ - Mon, 18 Jul 2016 12:39:39 GMT
90
+ response:
91
+ status:
92
+ code: 200
93
+ message: OK
94
+ headers:
95
+ Date:
96
+ - Mon, 18 Jul 2016 12:39:40 GMT
97
+ Content-Type:
98
+ - text/javascript; charset="UTF-8"
99
+ Content-Length:
100
+ - '74'
101
+ Connection:
102
+ - keep-alive
103
+ Access-Control-Allow-Origin:
104
+ - "*"
105
+ Access-Control-Allow-Methods:
106
+ - OPTIONS, GET, POST
107
+ Cache-Control:
108
+ - no-cache
109
+ Accept-Ranges:
110
+ - bytes
111
+ Age:
112
+ - '0'
113
+ Server:
114
+ - Pubnub Presence
115
+ body:
116
+ encoding: UTF-8
117
+ string: '{"status": 200, "action": "leave", "message": "OK", "service": "Presence"}'
118
+ http_version:
119
+ recorded_at: Mon, 18 Jul 2016 12:39:40 GMT
120
+ recorded_with: VCR 3.0.1
@@ -0,0 +1,40 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://pubsub.pubnub.com/v2/subscribe/demo/demo/0?pnsdk=PubNub-Ruby/4.0.1&t=%7B%22r%22:0,%22t%22:0%7D&uuid=0aab59cc-c81a-4787-b297-7476aab0c387
6
+ body:
7
+ encoding: UTF-8
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - HTTPClient/1.0 (2.8.0, ruby 2.1.10 (2016-04-01))
12
+ Accept:
13
+ - "*/*"
14
+ Date:
15
+ - Mon, 18 Jul 2016 12:39:49 GMT
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Date:
22
+ - Mon, 18 Jul 2016 12:39:49 GMT
23
+ Content-Type:
24
+ - text/javascript; charset="UTF-8"
25
+ Content-Length:
26
+ - '44'
27
+ Connection:
28
+ - keep-alive
29
+ Cache-Control:
30
+ - no-cache
31
+ Access-Control-Allow-Origin:
32
+ - "*"
33
+ Access-Control-Allow-Methods:
34
+ - GET
35
+ body:
36
+ encoding: UTF-8
37
+ string: '{"t":{"t":"14688455897110615","r":2},"m":[]}'
38
+ http_version:
39
+ recorded_at: Mon, 18 Jul 2016 12:39:50 GMT
40
+ recorded_with: VCR 3.0.1
@@ -0,0 +1,40 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://pubsub.pubnub.com/v2/subscribe/demo/demo/0?pnsdk=PubNub-Ruby/4.0.1&t=%7B%22r%22:0,%22t%22:0%7D&uuid=6ecf0edc-c865-4842-8721-daa7c558b588
6
+ body:
7
+ encoding: UTF-8
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - HTTPClient/1.0 (2.8.0, ruby 2.1.10 (2016-04-01))
12
+ Accept:
13
+ - "*/*"
14
+ Date:
15
+ - Mon, 18 Jul 2016 12:39:50 GMT
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Date:
22
+ - Mon, 18 Jul 2016 12:39:50 GMT
23
+ Content-Type:
24
+ - text/javascript; charset="UTF-8"
25
+ Content-Length:
26
+ - '44'
27
+ Connection:
28
+ - keep-alive
29
+ Cache-Control:
30
+ - no-cache
31
+ Access-Control-Allow-Origin:
32
+ - "*"
33
+ Access-Control-Allow-Methods:
34
+ - GET
35
+ body:
36
+ encoding: UTF-8
37
+ string: '{"t":{"t":"14688455903391979","r":2},"m":[]}'
38
+ http_version:
39
+ recorded_at: Mon, 18 Jul 2016 12:39:50 GMT
40
+ recorded_with: VCR 3.0.1
data/lib/pubnub/client.rb CHANGED
@@ -107,22 +107,6 @@ module Pubnub
107
107
  # <dt>callback</dt>
108
108
  # <dd><b>optional.</b> Default callback function for all events if not overwrote while firing event.</dd>
109
109
  #
110
- # <dt>error_callback</dt>
111
- # <dd><b>optional.</b> Default error callback.</dd>
112
- #
113
- # <dt>connect_callback</dt>
114
- # <dd><b>optional.</b> Callback that is called when connection with origin is established.
115
- # It should take string as parameter.</dd>
116
- #
117
- # <dt>disconnect_callback</dt>
118
- # <dd><b>optional.</b> Callback that is called when connection with origin is teared down
119
- # (it's called each time when reestablishing connection didn't work).
120
- # It should take string as parameter.</dd>
121
- #
122
- # <dt>reconnect_callback</dt>
123
- # <dd><b>optional.</b> Callback that is called when connection with origin is reestablished.
124
- # It should take string as parameter.</dd>
125
- #
126
110
  # <dt>ssl</dt>
127
111
  # <dd><b>optional.</b> Your connection will use ssl if set to true.</dd>
128
112
  #
@@ -412,6 +396,16 @@ module Pubnub
412
396
  (::Time.now.to_f * 10_000_000).to_i
413
397
  end
414
398
 
399
+ def subscribe_filter=(filter_expr)
400
+ @env[:subscribe_filter] = filter_expr
401
+ @subscriber.reset if subscribed?
402
+ filter_expr
403
+ end
404
+
405
+ def subscribe_filter
406
+ @env[:subscribe_filter]
407
+ end
408
+
415
409
  private
416
410
 
417
411
  def create_state_pools(event)
data/lib/pubnub/crypto.rb CHANGED
@@ -4,7 +4,7 @@ module Pubnub
4
4
  class Crypto
5
5
  def initialize(cipher_key)
6
6
  @alg = 'AES-256-CBC'
7
- sha256_key = Digest::SHA256.hexdigest(cipher_key)
7
+ sha256_key = Digest::SHA256.hexdigest(cipher_key.to_s)
8
8
  @key = sha256_key.slice(0, 32)
9
9
 
10
10
  @iv = '0123456789012345'
data/lib/pubnub/event.rb CHANGED
@@ -149,8 +149,9 @@ module Pubnub
149
149
  ::Time.now.to_i
150
150
  end
151
151
 
152
- def encode_parameter(parameter)
153
- URI.encode_www_form_component(parameter.to_json).gsub('+', '%20')
152
+ def encode_parameter(parameter, format_json = true)
153
+ parameter = format_json ? parameter.to_json : parameter
154
+ URI.encode_www_form_component(parameter).gsub('+', '%20')
154
155
  end
155
156
 
156
157
  def error_message(parsed_response)
@@ -53,7 +53,7 @@ module Pubnub
53
53
  timetoken: nil,
54
54
  status: {
55
55
  code: req_res_objects[:response].code,
56
- operation: Pubnub::Constants::OPERATION_PUBLISH,
56
+ operation: Pubnub::Constants::OPERATION_SET_STATE,
57
57
  client_request: req_res_objects[:request],
58
58
  server_response: req_res_objects[:response],
59
59
  data: nil,
@@ -78,7 +78,7 @@ module Pubnub
78
78
  timetoken: nil,
79
79
  status: {
80
80
  code: req_res_objects[:response].code,
81
- operation: Pubnub::Constants::OPERATION_HEARTBEAT,
81
+ operation: Pubnub::Constants::OPERATION_SET_STATE,
82
82
  client_request: req_res_objects[:request],
83
83
  server_response: req_res_objects[:response],
84
84
  data: nil,
@@ -129,9 +129,15 @@ module Pubnub
129
129
  params = super
130
130
  params = add_timetoken_to_params(params)
131
131
  params = add_group_to_params(params)
132
+ params = add_filter_to_params(params)
132
133
  add_state_to_params(params)
133
134
  end
134
135
 
136
+ def add_filter_to_params(params)
137
+ params.merge!('filter-expr' => encode_parameter("(#{@app.subscribe_filter})", false)) if @app.subscribe_filter
138
+ params
139
+ end
140
+
135
141
  def add_timetoken_to_params(params)
136
142
  params.merge!(t: encode_parameter(r: @app.region_code, t: @app.timetoken))
137
143
  params
@@ -1,4 +1,4 @@
1
1
  # Toplevel Pubnub module.
2
2
  module Pubnub
3
- VERSION = '4.0.1'
3
+ VERSION = '4.0.3'
4
4
  end
@@ -28,7 +28,7 @@ expect(envelope.is_a?(Pubnub::Envelope)).to eq true
28
28
  expect(envelope.error?).to eq false
29
29
 
30
30
  expect(envelope.status[:code]).to eq(200)
31
- expect(envelope.status[:operation]).to eq(:publish)
31
+ expect(envelope.status[:operation]).to eq(:set_state)
32
32
  expect(envelope.status[:category]).to eq(:ack)
33
33
  expect(envelope.status[:config]).to eq({:tls=>false, :uuid=>"ruby-test-uuid-client-one", :auth_key=>"ruby-test-auth-client-one", :origin=>"pubsub.pubnub.com"})
34
34
 
@@ -44,7 +44,7 @@ expect(envelope.is_a?(Pubnub::Envelope)).to eq true
44
44
  expect(envelope.error?).to eq false
45
45
 
46
46
  expect(envelope.status[:code]).to eq(200)
47
- expect(envelope.status[:operation]).to eq(:publish)
47
+ expect(envelope.status[:operation]).to eq(:set_state)
48
48
  expect(envelope.status[:category]).to eq(:ack)
49
49
  expect(envelope.status[:config]).to eq({:tls=>false, :uuid=>"ruby-test-uuid-client-one", :auth_key=>"ruby-test-auth-client-one", :origin=>"pubsub.pubnub.com"})
50
50
 
@@ -60,7 +60,7 @@ expect(envelope.is_a?(Pubnub::Envelope)).to eq true
60
60
  expect(envelope.error?).to eq false
61
61
 
62
62
  expect(envelope.status[:code]).to eq(200)
63
- expect(envelope.status[:operation]).to eq(:publish)
63
+ expect(envelope.status[:operation]).to eq(:set_state)
64
64
  expect(envelope.status[:category]).to eq(:ack)
65
65
  expect(envelope.status[:config]).to eq({:tls=>false, :uuid=>"ruby-test-uuid-client-one", :auth_key=>"ruby-test-auth-client-one", :origin=>"pubsub.pubnub.com"})
66
66
 
@@ -77,7 +77,7 @@ expect(envelope.is_a?(Pubnub::Envelope)).to eq true
77
77
  expect(envelope.error?).to eq false
78
78
 
79
79
  expect(envelope.status[:code]).to eq(200)
80
- expect(envelope.status[:operation]).to eq(:publish)
80
+ expect(envelope.status[:operation]).to eq(:set_state)
81
81
  expect(envelope.status[:category]).to eq(:ack)
82
82
  expect(envelope.status[:config]).to eq({:tls=>false, :uuid=>"ruby-test-uuid-client-one", :auth_key=>"ruby-test-auth-client-one", :origin=>"pubsub.pubnub.com"})
83
83
 
@@ -94,7 +94,7 @@ expect(envelope.is_a?(Pubnub::Envelope)).to eq true
94
94
  expect(envelope.error?).to eq false
95
95
 
96
96
  expect(envelope.status[:code]).to eq(200)
97
- expect(envelope.status[:operation]).to eq(:publish)
97
+ expect(envelope.status[:operation]).to eq(:set_state)
98
98
  expect(envelope.status[:category]).to eq(:ack)
99
99
  expect(envelope.status[:config]).to eq({:tls=>false, :uuid=>"ruby-test-uuid-client-one", :auth_key=>"ruby-test-auth-client-one", :origin=>"pubsub.pubnub.com"})
100
100
 
@@ -111,7 +111,7 @@ expect(envelope.is_a?(Pubnub::Envelope)).to eq true
111
111
  expect(envelope.error?).to eq false
112
112
 
113
113
  expect(envelope.status[:code]).to eq(200)
114
- expect(envelope.status[:operation]).to eq(:publish)
114
+ expect(envelope.status[:operation]).to eq(:set_state)
115
115
  expect(envelope.status[:category]).to eq(:ack)
116
116
  expect(envelope.status[:config]).to eq({:tls=>false, :uuid=>"ruby-test-uuid-client-one", :auth_key=>"ruby-test-auth-client-one", :origin=>"pubsub.pubnub.com"})
117
117
 
@@ -127,7 +127,7 @@ expect(envelope.is_a?(Pubnub::Envelope)).to eq true
127
127
  expect(envelope.error?).to eq false
128
128
 
129
129
  expect(envelope.status[:code]).to eq(200)
130
- expect(envelope.status[:operation]).to eq(:publish)
130
+ expect(envelope.status[:operation]).to eq(:set_state)
131
131
  expect(envelope.status[:category]).to eq(:ack)
132
132
  expect(envelope.status[:config]).to eq({:tls=>false, :uuid=>"ruby-test-uuid-client-one", :auth_key=>"ruby-test-auth-client-one", :origin=>"pubsub.pubnub.com"})
133
133
 
@@ -143,7 +143,7 @@ expect(envelope.is_a?(Pubnub::Envelope)).to eq true
143
143
  expect(envelope.error?).to eq false
144
144
 
145
145
  expect(envelope.status[:code]).to eq(200)
146
- expect(envelope.status[:operation]).to eq(:publish)
146
+ expect(envelope.status[:operation]).to eq(:set_state)
147
147
  expect(envelope.status[:category]).to eq(:ack)
148
148
  expect(envelope.status[:config]).to eq({:tls=>false, :uuid=>"ruby-test-uuid-client-one", :auth_key=>"ruby-test-auth-client-one", :origin=>"pubsub.pubnub.com"})
149
149
 
@@ -159,7 +159,7 @@ expect(envelope.is_a?(Pubnub::Envelope)).to eq true
159
159
  expect(envelope.error?).to eq false
160
160
 
161
161
  expect(envelope.status[:code]).to eq(200)
162
- expect(envelope.status[:operation]).to eq(:publish)
162
+ expect(envelope.status[:operation]).to eq(:set_state)
163
163
  expect(envelope.status[:category]).to eq(:ack)
164
164
  expect(envelope.status[:config]).to eq({:tls=>false, :uuid=>"ruby-test-uuid-client-one", :auth_key=>"ruby-test-auth-client-one", :origin=>"pubsub.pubnub.com"})
165
165
 
@@ -176,7 +176,7 @@ expect(envelope.is_a?(Pubnub::Envelope)).to eq true
176
176
  expect(envelope.error?).to eq false
177
177
 
178
178
  expect(envelope.status[:code]).to eq(200)
179
- expect(envelope.status[:operation]).to eq(:publish)
179
+ expect(envelope.status[:operation]).to eq(:set_state)
180
180
  expect(envelope.status[:category]).to eq(:ack)
181
181
  expect(envelope.status[:config]).to eq({:tls=>false, :uuid=>"ruby-test-uuid-client-one", :auth_key=>"ruby-test-auth-client-one", :origin=>"pubsub.pubnub.com"})
182
182
 
@@ -193,7 +193,7 @@ expect(envelope.is_a?(Pubnub::Envelope)).to eq true
193
193
  expect(envelope.error?).to eq false
194
194
 
195
195
  expect(envelope.status[:code]).to eq(200)
196
- expect(envelope.status[:operation]).to eq(:publish)
196
+ expect(envelope.status[:operation]).to eq(:set_state)
197
197
  expect(envelope.status[:category]).to eq(:ack)
198
198
  expect(envelope.status[:config]).to eq({:tls=>false, :uuid=>"ruby-test-uuid-client-one", :auth_key=>"ruby-test-auth-client-one", :origin=>"pubsub.pubnub.com"})
199
199
 
@@ -210,7 +210,7 @@ expect(envelope.is_a?(Pubnub::Envelope)).to eq true
210
210
  expect(envelope.error?).to eq false
211
211
 
212
212
  expect(envelope.status[:code]).to eq(200)
213
- expect(envelope.status[:operation]).to eq(:publish)
213
+ expect(envelope.status[:operation]).to eq(:set_state)
214
214
  expect(envelope.status[:category]).to eq(:ack)
215
215
  expect(envelope.status[:config]).to eq({:tls=>false, :uuid=>"ruby-test-uuid-client-one", :auth_key=>"ruby-test-auth-client-one", :origin=>"pubsub.pubnub.com"})
216
216
 
@@ -226,7 +226,7 @@ expect(envelope.is_a?(Pubnub::Envelope)).to eq true
226
226
  expect(envelope.error?).to eq false
227
227
 
228
228
  expect(envelope.status[:code]).to eq(200)
229
- expect(envelope.status[:operation]).to eq(:publish)
229
+ expect(envelope.status[:operation]).to eq(:set_state)
230
230
  expect(envelope.status[:category]).to eq(:ack)
231
231
  expect(envelope.status[:config]).to eq({:tls=>false, :uuid=>"ruby-test-uuid-client-one", :auth_key=>"ruby-test-auth-client-one", :origin=>"pubsub.pubnub.com"})
232
232
 
@@ -242,7 +242,7 @@ expect(envelope.is_a?(Pubnub::Envelope)).to eq true
242
242
  expect(envelope.error?).to eq false
243
243
 
244
244
  expect(envelope.status[:code]).to eq(200)
245
- expect(envelope.status[:operation]).to eq(:publish)
245
+ expect(envelope.status[:operation]).to eq(:set_state)
246
246
  expect(envelope.status[:category]).to eq(:ack)
247
247
  expect(envelope.status[:config]).to eq({:tls=>false, :uuid=>"ruby-test-uuid-client-one", :auth_key=>"ruby-test-auth-client-one", :origin=>"pubsub.pubnub.com"})
248
248
 
@@ -258,7 +258,7 @@ expect(envelope.is_a?(Pubnub::Envelope)).to eq true
258
258
  expect(envelope.error?).to eq false
259
259
 
260
260
  expect(envelope.status[:code]).to eq(200)
261
- expect(envelope.status[:operation]).to eq(:publish)
261
+ expect(envelope.status[:operation]).to eq(:set_state)
262
262
  expect(envelope.status[:category]).to eq(:ack)
263
263
  expect(envelope.status[:config]).to eq({:tls=>false, :uuid=>"ruby-test-uuid-client-one", :auth_key=>"ruby-test-auth-client-one", :origin=>"pubsub.pubnub.com"})
264
264
 
@@ -275,7 +275,7 @@ expect(envelope.is_a?(Pubnub::Envelope)).to eq true
275
275
  expect(envelope.error?).to eq false
276
276
 
277
277
  expect(envelope.status[:code]).to eq(200)
278
- expect(envelope.status[:operation]).to eq(:publish)
278
+ expect(envelope.status[:operation]).to eq(:set_state)
279
279
  expect(envelope.status[:category]).to eq(:ack)
280
280
  expect(envelope.status[:config]).to eq({:tls=>false, :uuid=>"ruby-test-uuid-client-one", :auth_key=>"ruby-test-auth-client-one", :origin=>"pubsub.pubnub.com"})
281
281
 
@@ -292,7 +292,7 @@ expect(envelope.is_a?(Pubnub::Envelope)).to eq true
292
292
  expect(envelope.error?).to eq false
293
293
 
294
294
  expect(envelope.status[:code]).to eq(200)
295
- expect(envelope.status[:operation]).to eq(:publish)
295
+ expect(envelope.status[:operation]).to eq(:set_state)
296
296
  expect(envelope.status[:category]).to eq(:ack)
297
297
  expect(envelope.status[:config]).to eq({:tls=>false, :uuid=>"ruby-test-uuid-client-one", :auth_key=>"ruby-test-auth-client-one", :origin=>"pubsub.pubnub.com"})
298
298
 
@@ -309,7 +309,7 @@ expect(envelope.is_a?(Pubnub::Envelope)).to eq true
309
309
  expect(envelope.error?).to eq false
310
310
 
311
311
  expect(envelope.status[:code]).to eq(200)
312
- expect(envelope.status[:operation]).to eq(:publish)
312
+ expect(envelope.status[:operation]).to eq(:set_state)
313
313
  expect(envelope.status[:category]).to eq(:ack)
314
314
  expect(envelope.status[:config]).to eq({:tls=>false, :uuid=>"ruby-test-uuid-client-one", :auth_key=>"ruby-test-auth-client-one", :origin=>"pubsub.pubnub.com"})
315
315
 
@@ -325,7 +325,7 @@ expect(envelope.is_a?(Pubnub::Envelope)).to eq true
325
325
  expect(envelope.error?).to eq false
326
326
 
327
327
  expect(envelope.status[:code]).to eq(200)
328
- expect(envelope.status[:operation]).to eq(:publish)
328
+ expect(envelope.status[:operation]).to eq(:set_state)
329
329
  expect(envelope.status[:category]).to eq(:ack)
330
330
  expect(envelope.status[:config]).to eq({:tls=>false, :uuid=>"ruby-test-uuid-client-one", :auth_key=>"ruby-test-auth-client-one", :origin=>"pubsub.pubnub.com"})
331
331
 
@@ -341,7 +341,7 @@ expect(envelope.is_a?(Pubnub::Envelope)).to eq true
341
341
  expect(envelope.error?).to eq false
342
342
 
343
343
  expect(envelope.status[:code]).to eq(200)
344
- expect(envelope.status[:operation]).to eq(:publish)
344
+ expect(envelope.status[:operation]).to eq(:set_state)
345
345
  expect(envelope.status[:category]).to eq(:ack)
346
346
  expect(envelope.status[:config]).to eq({:tls=>false, :uuid=>"ruby-test-uuid-client-one", :auth_key=>"ruby-test-auth-client-one", :origin=>"pubsub.pubnub.com"})
347
347
 
@@ -357,7 +357,7 @@ expect(envelope.is_a?(Pubnub::Envelope)).to eq true
357
357
  expect(envelope.error?).to eq false
358
358
 
359
359
  expect(envelope.status[:code]).to eq(200)
360
- expect(envelope.status[:operation]).to eq(:publish)
360
+ expect(envelope.status[:operation]).to eq(:set_state)
361
361
  expect(envelope.status[:category]).to eq(:ack)
362
362
  expect(envelope.status[:config]).to eq({:tls=>false, :uuid=>"ruby-test-uuid-client-one", :auth_key=>"ruby-test-auth-client-one", :origin=>"pubsub.pubnub.com"})
363
363
 
@@ -374,7 +374,7 @@ expect(envelope.is_a?(Pubnub::Envelope)).to eq true
374
374
  expect(envelope.error?).to eq false
375
375
 
376
376
  expect(envelope.status[:code]).to eq(200)
377
- expect(envelope.status[:operation]).to eq(:publish)
377
+ expect(envelope.status[:operation]).to eq(:set_state)
378
378
  expect(envelope.status[:category]).to eq(:ack)
379
379
  expect(envelope.status[:config]).to eq({:tls=>false, :uuid=>"ruby-test-uuid-client-one", :auth_key=>"ruby-test-auth-client-one", :origin=>"pubsub.pubnub.com"})
380
380
 
@@ -391,7 +391,7 @@ expect(envelope.is_a?(Pubnub::Envelope)).to eq true
391
391
  expect(envelope.error?).to eq false
392
392
 
393
393
  expect(envelope.status[:code]).to eq(200)
394
- expect(envelope.status[:operation]).to eq(:publish)
394
+ expect(envelope.status[:operation]).to eq(:set_state)
395
395
  expect(envelope.status[:category]).to eq(:ack)
396
396
  expect(envelope.status[:config]).to eq({:tls=>false, :uuid=>"ruby-test-uuid-client-one", :auth_key=>"ruby-test-auth-client-one", :origin=>"pubsub.pubnub.com"})
397
397
 
@@ -408,7 +408,7 @@ expect(envelope.is_a?(Pubnub::Envelope)).to eq true
408
408
  expect(envelope.error?).to eq false
409
409
 
410
410
  expect(envelope.status[:code]).to eq(200)
411
- expect(envelope.status[:operation]).to eq(:publish)
411
+ expect(envelope.status[:operation]).to eq(:set_state)
412
412
  expect(envelope.status[:category]).to eq(:ack)
413
413
  expect(envelope.status[:config]).to eq({:tls=>false, :uuid=>"ruby-test-uuid-client-one", :auth_key=>"ruby-test-auth-client-one", :origin=>"pubsub.pubnub.com"})
414
414
 
@@ -1,60 +1,70 @@
1
- # require 'spec_helper'
2
- #
3
- # describe 'Connect, disconnect and reconnect callbacks' do
4
- #
5
- # around :each do |example|
6
- # Celluloid.boot
7
- # example.run
8
- # Celluloid.shutdown
9
- # end
10
- #
11
- # before(:each) do
12
- # @connect_messages, @reconnect_messages, @disconnect_messages = [], [], []
13
- #
14
- # connect_callback = ->(msg) { @connect_messages << msg }
15
- # reconnect_callback = ->(msg) { @reconnect_messages << msg }
16
- # disconnect_callback = ->(msg) { @disconnect_messages << msg }
17
- #
18
- # @pubnub = Pubnub.new(
19
- # subscribe_key: :demo,
20
- # publish_key: :demo,
21
- # connect_callback: connect_callback,
22
- # disconnect_callback: disconnect_callback,
23
- # reconnect_callback: reconnect_callback,
24
- # reconnect_interval: 0
25
- # )
26
- # end
27
- #
28
- # it 'fire connect callback when connection is made' do
29
- # VCR.use_cassette('client/connection_callbacks_0', :record => :once) do
30
- # @pubnub.subscribe(channel: :demo, http_sync: true){ |_e| }
31
- # eventually do
32
- # expect(@connect_messages.size).to eq 1
33
- # end
34
- # end
35
- # end
36
- #
37
- # it 'fire disconnect callback when connection is lost' do
38
- #
39
- # Pubnub::SubscribeEvent.any_instance.stub(:request_dispatcher) { Pubnub::SubscribeEvent.any_instance.unstub(:request_dispatcher); raise 'error' }
40
- #
41
- # VCR.use_cassette('client/connection_callbacks_1', :record => :once) do
42
- # @pubnub.subscribe(channel: :demo, http_sync: true){ |_e| }
43
- # eventually do
44
- # expect(@disconnect_messages.size).to eq 1
45
- # end
46
- # end
47
- # end
48
- #
49
- # it 'fire reconnect callback when connection is reestablished' do
50
- # Pubnub::SubscribeEvent.any_instance.stub(:request_dispatcher) { Pubnub::SubscribeEvent.any_instance.unstub(:request_dispatcher); raise 'error' }
51
- #
52
- # VCR.use_cassette('client/connection_callbacks_2', :record => :once) do
53
- # @pubnub.subscribe(channel: :demo, http_sync: true){ |_e| }
54
- # eventually do
55
- # expect(@reconnect_messages.size).to eq 1
56
- # end
57
- # end
58
- # end
59
- #
60
- # end
1
+ require 'spec_helper'
2
+
3
+ describe 'Connect, disconnect and reconnect callbacks' do
4
+
5
+ around :each do |example|
6
+ Celluloid.boot
7
+ example.run
8
+ Celluloid.shutdown
9
+ end
10
+
11
+ before(:each) do
12
+ @connect_messages, @reconnect_messages, @disconnect_messages = [], [], []
13
+
14
+ callback = Pubnub::SubscribeCallback.new(
15
+ message: ->(_envelope) { },
16
+ presence: ->(_envelope) { },
17
+ status: lambda do |envelope|
18
+
19
+ if envelope.error?
20
+ @disconnect_messages << envelope
21
+ else
22
+ if envelope.status[:last_timetoken] == 0 && !@disconnect_messages.empty?
23
+ @reconnect_messages << envelope
24
+ elsif envelope.status[:last_timetoken] == 0 # Connected!
25
+ @connect_messages << envelope
26
+ @pubnub.leave(channel: :demo)
27
+ end
28
+ end
29
+ end
30
+ )
31
+
32
+ @pubnub = Pubnub.new(
33
+ subscribe_key: :demo,
34
+ publish_key: :demo,
35
+ reconnect_interval: 0
36
+ )
37
+
38
+ @pubnub.add_listener(callback: callback)
39
+ end
40
+
41
+ it 'fire connect callback when connection is made' do
42
+ VCR.use_cassette('client/connection_callbacks_0', :record => :once) do
43
+ @pubnub.subscribe(channel: :demo)
44
+ sleep 0.5
45
+ expect(@connect_messages.size).to be > 0
46
+ end
47
+ end
48
+
49
+ it 'fire status callback when connection is lost' do
50
+
51
+ Pubnub::SubscribeEvent.any_instance.stub(:request_dispatcher) { Pubnub::SubscribeEvent.any_instance.unstub(:request_dispatcher); raise 'error' }
52
+
53
+ VCR.use_cassette('client/connection_callbacks_1', :record => :once) do
54
+ @pubnub.subscribe(channel: :demo)
55
+ sleep 0.5
56
+ expect(@disconnect_messages.size).to be > 0
57
+ end
58
+ end
59
+
60
+ it 'fire reconnect callback when connection is reestablished' do
61
+ Pubnub::SubscribeEvent.any_instance.stub(:request_dispatcher) { Pubnub::SubscribeEvent.any_instance.unstub(:request_dispatcher); raise 'error' }
62
+
63
+ VCR.use_cassette('client/connection_callbacks_2', :record => :once) do
64
+ @pubnub.subscribe(channel: :demo)
65
+ sleep 0.5
66
+ expect(@reconnect_messages.size).to be > 0
67
+ end
68
+ end
69
+
70
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pubnub
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.1
4
+ version: 4.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - PubNub
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-12 00:00:00.000000000 Z
11
+ date: 2016-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: celluloid
@@ -101,6 +101,9 @@ files:
101
101
  - Rakefile
102
102
  - VERSION
103
103
  - docs.md
104
+ - fixtures/vcr_cassettes/client/connection_callbacks_0.yml
105
+ - fixtures/vcr_cassettes/client/connection_callbacks_1.yml
106
+ - fixtures/vcr_cassettes/client/connection_callbacks_2.yml
104
107
  - fixtures/vcr_cassettes/examples/audit/0.yml
105
108
  - fixtures/vcr_cassettes/examples/audit/1.yml
106
109
  - fixtures/vcr_cassettes/examples/audit/10.yml
@@ -10521,7 +10524,6 @@ files:
10521
10524
  - lib/pubnub/validators/time.rb
10522
10525
  - lib/pubnub/validators/where_now.rb
10523
10526
  - lib/pubnub/version.rb
10524
- - lib/pubnub/version.rb.orig
10525
10527
  - pubnub.gemspec
10526
10528
  - spec/examples/audit_examples_spec.rb
10527
10529
  - spec/examples/channel_registration_examples_spec.rb
@@ -10583,7 +10585,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
10583
10585
  version: '0'
10584
10586
  requirements: []
10585
10587
  rubyforge_project:
10586
- rubygems_version: 2.5.1
10588
+ rubygems_version: 2.2.5
10587
10589
  signing_key:
10588
10590
  specification_version: 4
10589
10591
  summary: PubNub Official Ruby gem.
@@ -1,8 +0,0 @@
1
- # Toplevel Pubnub module.
2
- module Pubnub
3
- <<<<<<< HEAD
4
- VERSION = '4.0.1'
5
- =======
6
- VERSION = '4.0.0'
7
- >>>>>>> master
8
- end