pubnub 3.5.14 → 3.6.7

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 (108) hide show
  1. checksums.yaml +4 -4
  2. data/3.5_to_3.6_upgrade_notes.md +148 -0
  3. data/{CHANGELOG → CHANGELOG.txt} +15 -0
  4. data/Gemfile.lock +5 -4
  5. data/LICENSE.txt +28 -0
  6. data/README.md +164 -19
  7. data/Rakefile +1 -6
  8. data/examples/demo_console.rb +370 -329
  9. data/fixtures/vcr_cassettes/grant-multiple-channels-presence-multi-1.yml +44 -0
  10. data/fixtures/vcr_cassettes/grant-multiple-channels-presence-multi-2.yml +44 -0
  11. data/fixtures/vcr_cassettes/grant-multiple-channels-presence-multi-3.yml +44 -0
  12. data/fixtures/vcr_cassettes/grant-multiple-channels-presence-multi-4.yml +44 -0
  13. data/fixtures/vcr_cassettes/grant-multiple-channels-presence.yml +44 -0
  14. data/fixtures/vcr_cassettes/heartbeated-subscribe.yml +1 -1
  15. data/fixtures/vcr_cassettes/here_now-nonssl-block-valid-200-async.yml +1 -1
  16. data/fixtures/vcr_cassettes/here_now-nonssl-block-valid-200-sync.yml +1 -1
  17. data/fixtures/vcr_cassettes/here_now-nonssl-block-valid-non-200-async.yml +1 -1
  18. data/fixtures/vcr_cassettes/here_now-nonssl-block-valid-non-200-sync.yml +1 -1
  19. data/fixtures/vcr_cassettes/here_now-nonssl-parameter-valid-200-async.yml +1 -1
  20. data/fixtures/vcr_cassettes/here_now-nonssl-parameter-valid-200-sync.yml +1 -1
  21. data/fixtures/vcr_cassettes/here_now-nonssl-parameter-valid-non-200-async.yml +1 -1
  22. data/fixtures/vcr_cassettes/here_now-nonssl-parameter-valid-non-200-sync.yml +1 -1
  23. data/fixtures/vcr_cassettes/here_now-ssl-block-valid-200-async.yml +1 -1
  24. data/fixtures/vcr_cassettes/here_now-ssl-block-valid-200-sync.yml +1 -1
  25. data/fixtures/vcr_cassettes/here_now-ssl-block-valid-non-200-async.yml +1 -1
  26. data/fixtures/vcr_cassettes/here_now-ssl-block-valid-non-200-sync.yml +1 -1
  27. data/fixtures/vcr_cassettes/here_now-ssl-parameter-valid-200-async.yml +1 -1
  28. data/fixtures/vcr_cassettes/here_now-ssl-parameter-valid-200-sync.yml +1 -1
  29. data/fixtures/vcr_cassettes/here_now-ssl-parameter-valid-non-200-async.yml +1 -1
  30. data/fixtures/vcr_cassettes/here_now-ssl-parameter-valid-non-200-sync.yml +1 -1
  31. data/fixtures/vcr_cassettes/leave-nonssl-block-valid-200-async.yml +1 -1
  32. data/fixtures/vcr_cassettes/leave-nonssl-block-valid-200-sync.yml +1 -1
  33. data/fixtures/vcr_cassettes/leave-nonssl-block-valid-non-200-async.yml +1 -1
  34. data/fixtures/vcr_cassettes/leave-nonssl-block-valid-non-200-sync.yml +1 -1
  35. data/fixtures/vcr_cassettes/leave-nonssl-parameter-valid-200-async.yml +1 -1
  36. data/fixtures/vcr_cassettes/leave-nonssl-parameter-valid-200-sync.yml +1 -1
  37. data/fixtures/vcr_cassettes/leave-nonssl-parameter-valid-non-200-async.yml +1 -1
  38. data/fixtures/vcr_cassettes/leave-nonssl-parameter-valid-non-200-sync.yml +1 -1
  39. data/fixtures/vcr_cassettes/leave-ssl-block-valid-200-async.yml +1 -1
  40. data/fixtures/vcr_cassettes/leave-ssl-block-valid-200-sync.yml +1 -1
  41. data/fixtures/vcr_cassettes/leave-ssl-block-valid-non-200-async.yml +1 -1
  42. data/fixtures/vcr_cassettes/leave-ssl-block-valid-non-200-sync.yml +1 -1
  43. data/fixtures/vcr_cassettes/leave-ssl-parameter-valid-200-async.yml +1 -1
  44. data/fixtures/vcr_cassettes/leave-ssl-parameter-valid-200-sync.yml +1 -1
  45. data/fixtures/vcr_cassettes/leave-ssl-parameter-valid-non-200-async.yml +1 -1
  46. data/fixtures/vcr_cassettes/leave-ssl-parameter-valid-non-200-sync.yml +1 -1
  47. data/fixtures/vcr_cassettes/state-async-set-state-via-subbedclient-2.yml +140 -0
  48. data/fixtures/vcr_cassettes/state-async-set-state-via-subbedclient.yml +131 -0
  49. data/fixtures/vcr_cassettes/state-async-set-state-via-subscribe.yml +90 -0
  50. data/fixtures/vcr_cassettes/state-set-state-via-client-2.yml +140 -0
  51. data/fixtures/vcr_cassettes/state-set-state-via-client.yml +90 -0
  52. data/fixtures/vcr_cassettes/state-set-state-via-subscribe.yml +90 -0
  53. data/fixtures/vcr_cassettes/where_now-ssl-block-invalid-200-async.yml +49 -0
  54. data/fixtures/vcr_cassettes/where_now-ssl-block-invalid-200-sync.yml +49 -0
  55. data/fixtures/vcr_cassettes/where_now-ssl-block-invalid-non-200-async.yml +49 -0
  56. data/fixtures/vcr_cassettes/where_now-ssl-block-invalid-non-200-sync.yml +49 -0
  57. data/fixtures/vcr_cassettes/where_now-ssl-block-valid-200-async.yml +49 -0
  58. data/fixtures/vcr_cassettes/where_now-ssl-block-valid-200-sync.yml +49 -0
  59. data/fixtures/vcr_cassettes/where_now-ssl-block-valid-non-200-async.yml +49 -0
  60. data/fixtures/vcr_cassettes/where_now-ssl-block-valid-non-200-sync.yml +49 -0
  61. data/fixtures/vcr_cassettes/where_now-ssl-parameter-invalid-200-async.yml +49 -0
  62. data/fixtures/vcr_cassettes/where_now-ssl-parameter-invalid-200-sync.yml +49 -0
  63. data/fixtures/vcr_cassettes/where_now-ssl-parameter-invalid-non-200-async.yml +49 -0
  64. data/fixtures/vcr_cassettes/where_now-ssl-parameter-invalid-non-200-sync.yml +49 -0
  65. data/fixtures/vcr_cassettes/where_now-ssl-parameter-valid-200-async.yml +49 -0
  66. data/fixtures/vcr_cassettes/where_now-ssl-parameter-valid-200-sync.yml +49 -0
  67. data/fixtures/vcr_cassettes/where_now-ssl-parameter-valid-non-200-async.yml +49 -0
  68. data/fixtures/vcr_cassettes/where_now-ssl-parameter-valid-non-200-sync.yml +49 -0
  69. data/lib/pubnub.rb +1 -2
  70. data/lib/pubnub/client.rb +97 -21
  71. data/lib/pubnub/configuration.rb +1 -1
  72. data/lib/pubnub/envelope.rb +3 -2
  73. data/lib/pubnub/event.rb +9 -5
  74. data/lib/pubnub/events/audit.rb +1 -1
  75. data/lib/pubnub/events/grant.rb +1 -1
  76. data/lib/pubnub/events/heartbeat.rb +7 -3
  77. data/lib/pubnub/events/here_now.rb +7 -4
  78. data/lib/pubnub/events/history.rb +1 -1
  79. data/lib/pubnub/events/leave.rb +10 -4
  80. data/lib/pubnub/events/presence.rb +1 -1
  81. data/lib/pubnub/events/publish.rb +6 -2
  82. data/lib/pubnub/events/revoke.rb +1 -1
  83. data/lib/pubnub/events/set_state.rb +77 -0
  84. data/lib/pubnub/events/state.rb +63 -0
  85. data/lib/pubnub/events/subscribe.rb +7 -0
  86. data/lib/pubnub/events/where_now.rb +55 -0
  87. data/lib/pubnub/pam.rb +10 -16
  88. data/lib/pubnub/version.rb +2 -2
  89. data/pubnub.gemspec +21 -19
  90. data/spec/lib/channel_presence_concat_pam_spec.rb +94 -0
  91. data/spec/lib/client_spec.rb +3 -4
  92. data/spec/lib/heartbeat_spec.rb +16 -16
  93. data/spec/lib/integration/global_here_now_dpc_spec.rb +10 -10
  94. data/spec/lib/integration/global_here_now_spec.rb +8 -8
  95. data/spec/lib/integration/here_now_dpc_spec.rb +24 -24
  96. data/spec/lib/integration/here_now_spec.rb +24 -24
  97. data/spec/lib/integration/leave_dpc_spec.rb +24 -25
  98. data/spec/lib/integration/leave_spec.rb +24 -24
  99. data/spec/lib/integration/publish_spec.rb +5 -0
  100. data/spec/lib/integration/state_spec.rb +84 -0
  101. data/spec/lib/integration/where_now_spec.rb +312 -0
  102. metadata +108 -26
  103. data/LICENSE +0 -27
  104. data/VERSION +0 -1
  105. data/examples/demo_console_new.rb +0 -286
  106. data/fixtures/vcr_cassettes/heartbeat-non200.yml +0 -667
  107. data/spec/tools/pam-test-generator.rb +0 -367
  108. data/spec/tools/test-generator.rb +0 -310
@@ -0,0 +1,49 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://pubsub.pubnub.com/v2/presence/sub-key/demo/uuid/demo_uuid?auth=demoish_authkey&pnsdk=PubNub-Ruby/3.5.3&uuid=rubytests
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
+ - Mon, 28 Apr 2014 11:22:29 GMT
27
+ Content-Type:
28
+ - application/json
29
+ Content-Length:
30
+ - '84'
31
+ Connection:
32
+ - keep-alive
33
+ Access-Control-Allow-Origin:
34
+ - "*"
35
+ Access-Control-Allow-Methods:
36
+ - GET
37
+ Accept-Ranges:
38
+ - bytes
39
+ Age:
40
+ - '0'
41
+ Server:
42
+ - Pubnub Presence
43
+ body:
44
+ encoding: UTF-8
45
+ string: '{"status": 200, "message": "OK", "payload": {"channels": []}, "service":
46
+ "Presence"}'
47
+ http_version:
48
+ recorded_at: Mon, 28 Apr 2014 11:22:28 GMT
49
+ recorded_with: VCR 2.9.0
@@ -0,0 +1,49 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://pubsub.pubnub.com/v2/presence/sub-key/demo/uuid/demo_uuid?auth=demoish_authkey&pnsdk=PubNub-Ruby/3.5.3&uuid=rubytests
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
+ - Mon, 28 Apr 2014 11:22:29 GMT
27
+ Content-Type:
28
+ - application/json
29
+ Content-Length:
30
+ - '84'
31
+ Connection:
32
+ - keep-alive
33
+ Access-Control-Allow-Origin:
34
+ - "*"
35
+ Access-Control-Allow-Methods:
36
+ - GET
37
+ Accept-Ranges:
38
+ - bytes
39
+ Age:
40
+ - '0'
41
+ Server:
42
+ - Pubnub Presence
43
+ body:
44
+ encoding: UTF-8
45
+ string: '{"status": 200, "message": "OK", "payload": {"channels": []}, "service":
46
+ "Presence"}'
47
+ http_version:
48
+ recorded_at: Mon, 28 Apr 2014 11:22:28 GMT
49
+ recorded_with: VCR 2.9.0
@@ -0,0 +1,49 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://pubsub.pubnub.com/v2/presence/sub-key/demo/uuid/demo_uuid?auth=demoish_authkey&pnsdk=PubNub-Ruby/3.5.3&uuid=rubytests
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: 500
23
+ message: OK
24
+ headers:
25
+ Date:
26
+ - Mon, 28 Apr 2014 11:22:29 GMT
27
+ Content-Type:
28
+ - application/json
29
+ Content-Length:
30
+ - '84'
31
+ Connection:
32
+ - keep-alive
33
+ Access-Control-Allow-Origin:
34
+ - "*"
35
+ Access-Control-Allow-Methods:
36
+ - GET
37
+ Accept-Ranges:
38
+ - bytes
39
+ Age:
40
+ - '0'
41
+ Server:
42
+ - Pubnub Presence
43
+ body:
44
+ encoding: UTF-8
45
+ string: '{"status": 200, "message": "OK", "payload": {"channels": []}, "service":
46
+ "Presence"}'
47
+ http_version:
48
+ recorded_at: Mon, 28 Apr 2014 11:22:28 GMT
49
+ recorded_with: VCR 2.9.0
@@ -0,0 +1,49 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://pubsub.pubnub.com/v2/presence/sub-key/demo/uuid/demo_uuid?auth=demoish_authkey&pnsdk=PubNub-Ruby/3.5.3&uuid=rubytests
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: 500
23
+ message: OK
24
+ headers:
25
+ Date:
26
+ - Mon, 28 Apr 2014 11:22:29 GMT
27
+ Content-Type:
28
+ - application/json
29
+ Content-Length:
30
+ - '84'
31
+ Connection:
32
+ - keep-alive
33
+ Access-Control-Allow-Origin:
34
+ - "*"
35
+ Access-Control-Allow-Methods:
36
+ - GET
37
+ Accept-Ranges:
38
+ - bytes
39
+ Age:
40
+ - '0'
41
+ Server:
42
+ - Pubnub Presence
43
+ body:
44
+ encoding: UTF-8
45
+ string: '{"status": 200, "message": "OK", "payload": {"channels": []}, "service":
46
+ "Presence"}'
47
+ http_version:
48
+ recorded_at: Mon, 28 Apr 2014 11:22:28 GMT
49
+ recorded_with: VCR 2.9.0
data/lib/pubnub.rb CHANGED
@@ -6,7 +6,7 @@
6
6
  ## http://www.pubnub.com/
7
7
 
8
8
  ## -----------------------------------
9
- ## PubNub 3.5.1 Real-time Push Cloud API
9
+ ## PubNub Real-time Push Cloud API
10
10
  ## -----------------------------------
11
11
 
12
12
  require 'json'
@@ -18,7 +18,6 @@ require 'net/http/persistent'
18
18
  require 'logger'
19
19
 
20
20
  require 'pubnub/version'
21
-
22
21
  require 'pubnub/client'
23
22
 
24
23
 
data/lib/pubnub/client.rb CHANGED
@@ -16,7 +16,7 @@ module Pubnub
16
16
  attr_reader :env
17
17
  attr_accessor :single_event_connections_pool, :subscribe_event_connections_pool, :uuid, :async_events
18
18
 
19
- EVENTS = %w(publish subscribe presence leave history here_now audit grant revoke time heartbeat)
19
+ EVENTS = %w(publish subscribe presence leave history here_now audit grant revoke time heartbeat where_now state set_state)
20
20
  VERSION = Pubnub::VERSION
21
21
 
22
22
  EVENTS.each do |event_name|
@@ -35,11 +35,56 @@ module Pubnub
35
35
 
36
36
  def initialize(options)
37
37
  validate!(options)
38
- setup_app(options)
39
- # From this moment we have to use @env in that method instead of options
38
+ setup_app(options) # After that we have to use @env in that method instead of options
40
39
  create_connections_pools(@env)
41
40
  create_subscriptions_pools(@env)
42
- start_event_machine(@env)
41
+ # start_event_machine(@env)
42
+ end
43
+
44
+ def paged_history(options = {}, &block)
45
+ channel = options[:channel]
46
+ page = options[:page] || 1
47
+ limit = options[:limit] || 100
48
+ callback = options[:callback] || block
49
+ sync = options[:http_sync] ? true : false
50
+ start_tt = options[:start] || nil
51
+ end_tt = options[:end] || nil
52
+
53
+ current_start_tt = start_tt
54
+
55
+ if sync
56
+
57
+ puts "page = #{page}"
58
+ envelopes = nil
59
+ page.times do
60
+ envelopes = self.history(:channel => channel, :http_sync => true, :count => limit, :start => current_start_tt, :end => end_tt)
61
+ current_start_tt = envelopes.last.history_start.to_i - 1
62
+ end
63
+
64
+ envelopes.each do |envelope|
65
+ callback.call envelope
66
+ end if callback
67
+
68
+
69
+ else
70
+ EM.defer do
71
+ until msgs.size <= page * entries
72
+ msgs.merge!(self.history(:channel => channel, :http_sync => true, :start => start_tt, :end => end_tt, :limit => entries))
73
+ end
74
+
75
+ msgs.reverse[0..entries].each do |envelope|
76
+ callback.call envelope
77
+ end
78
+
79
+ end
80
+ end
81
+
82
+ envelopes
83
+
84
+ end
85
+
86
+ def state_for(origin = DEFAULT_ORIGIN)
87
+ @env[:state][origin]
43
88
  end
44
89
 
45
90
  def shutdown(stop_em = false)
@@ -63,6 +108,27 @@ module Pubnub
63
108
  $logger.info('Pubnub'){'Bye!'}
64
109
  end
65
110
 
111
+ def stop_async
112
+ $logger.debug('Pubnub'){'Pubnub::Client#stop_async | fired'}
113
+ @env[:subscribe_railgun].cancel unless @env[:subscribe_railgun].blank?
114
+ @env[:respirator].cancel unless @env[:respirator].blank?
115
+ @env[:subscribe_railgun].cancel unless @env[:subscribe_railgun].blank?
116
+
117
+ @env[:subscribe_railgun] = nil
118
+ @env[:respirator] = nil
119
+ @env[:subscribe_railgun] = nil
120
+
121
+ EM.stop
122
+
123
+ $logger.debug('Pubnub'){'Pubnub::Client#stop_async | timers killed'}
124
+ end
125
+
126
+ def restore_async
127
+ start_event_machine
128
+ start_subscribe unless @env[:subscriptions].blank?
129
+ start_railgun
130
+ end
131
+
66
132
  def start_respirator
67
133
  $logger.debug('Pubnub'){'Pubnub::Client#start_respirator | fired'}
68
134
  if @env[:heartbeat]
@@ -99,29 +165,38 @@ module Pubnub
99
165
  end
100
166
  end
101
167
 
102
- @env[:wait_for_response] = Hash.new unless @wait_for_response
103
- @env[:subscribe_railgun] = EM.add_periodic_timer(PERIODIC_TIMER_INTERVAL) do
104
- begin
105
- @env[:subscriptions].each do |origin, subscribe|
106
- unless @env[:wait_for_response][origin]
107
- @env[:wait_for_response][origin] = true
168
+ if @env[:subscribe_railgun] && @subscribe_deffered_thread
169
+ $logger.debug('Pubnub'){'Pubnub::Client#start_subscribe | Aborting previous request'}
170
+ @subscribe_deffered_thread.kill
171
+ Thread.pass until @subscribe_deffered_thread.status == false
172
+ end
108
173
 
109
- $logger.debug('Pubnub'){'Async subscription running'}
110
- $logger.debug('Pubnub'){"origin: #{origin}"}
111
- $logger.debug('Pubnub'){"timetoken: #{@env[:timetoken]}"}
174
+ @env[:wait_for_response] = Hash.new unless @wait_for_response
175
+ unless @env[:subscribe_railgun]
176
+ @env[:subscribe_railgun] = EM.add_periodic_timer(PERIODIC_TIMER_INTERVAL) do
177
+ begin
178
+ @env[:subscriptions].each do |origin, subscribe|
179
+ unless @env[:wait_for_response][origin]
180
+ @env[:wait_for_response][origin] = true
181
+
182
+ $logger.debug('Pubnub'){'Async subscription running'}
183
+ $logger.debug('Pubnub'){"origin: #{origin}"}
184
+ $logger.debug('Pubnub'){"timetoken: #{@env[:timetoken]}"}
185
+
186
+ EM.defer do
187
+ @subscribe_deffered_thread = Thread.current
188
+ subscribe.start_event(self) if subscribe
189
+ # @env[:wait_for_response][origin] = false # moved to Event
190
+ end
112
191
 
113
- EM.defer do
114
- subscribe.start_event(self) if subscribe
115
- # @env[:wait_for_response][origin] = false # moved to Event
116
192
  end
117
-
118
193
  end
194
+ rescue => e
195
+ $logger.error('Pubnub'){e}
196
+ $logger.error('Pubnub'){e.backtrace}
119
197
  end
120
- rescue => e
121
- $logger.error('Pubnub'){e}
122
- $logger.error('Pubnub'){e.backtrace}
123
198
  end
124
- end unless @env[:subscribe_railgun]
199
+ end
125
200
  end
126
201
 
127
202
  def subscription_running?
@@ -172,6 +247,7 @@ module Pubnub
172
247
  alias_method :cipher_key=, :set_cipher_key
173
248
 
174
249
  def start_railgun
250
+ start_event_machine(@env)
175
251
  if @env[:railgun]
176
252
  $logger.debug('Pubnub'){'Pubnub::Client#start_railgun | Railgun already initialized'}
177
253
  else
@@ -1,7 +1,7 @@
1
1
  module Pubnub
2
2
  module Configuration
3
3
  DEFAULT_ERROR_CALLBACK = lambda { |err| puts err.inspect }
4
- DEFAULT_CONNECT_CALLBACK = lambda { |msg| puts msg.inspect }
4
+ DEFAULT_CONNECT_CALLBACK = lambda { |msg| msg.inspect }
5
5
  DEFAULT_SSL = false
6
6
  DEFAULT_CONNECTION_PORT = 80
7
7
  DEFAULT_NON_SUBSCRIBE_TIMEOUT = 310
@@ -13,11 +13,12 @@ module Pubnub
13
13
  :object,
14
14
  :payload,
15
15
  :response,
16
+ :parsed_response,
16
17
  :response_message,
17
18
  :service,
18
19
  :status,
19
20
  :timetoken,
20
- :timetoken_update,
21
+ :timetoken_update
21
22
  ]
22
23
 
23
24
  INSTANCE_VARIABLES.each do |var_name|
@@ -42,4 +43,4 @@ module Pubnub
42
43
  end
43
44
 
44
45
  end
45
- end
46
+ end
data/lib/pubnub/event.rb CHANGED
@@ -103,6 +103,7 @@ module Pubnub
103
103
 
104
104
  $logger.debug('Pubnub'){'Event#handle_response'}
105
105
  envelopes = format_envelopes(response, app, error)
106
+ $logger.debug('Pubnub'){"Response: #{response.body}"} if (response && response.body)
106
107
  update_app_timetoken(envelopes, app)
107
108
  fire_callbacks(envelopes,app)
108
109
  @finished = true
@@ -118,7 +119,7 @@ module Pubnub
118
119
  unless envelopes.blank?
119
120
  $logger.debug('Pubnub'){'Firing callbacks'}
120
121
  envelopes.each do |envelope|
121
- @callback.call(envelope) if !envelope.error && @callback && !envelope.timetoken_update
122
+ @callback.call(envelope) if envelope && !envelope.error && @callback && !envelope.timetoken_update
122
123
  #if envelope.timetoken_update || envelope.timetoken.to_i > app.env[:timetoken].to_i
123
124
  # update_timetoken(app, envelope.timetoken)
124
125
  #end
@@ -261,9 +262,8 @@ module Pubnub
261
262
  def new_connection(app)
262
263
  unless app.disabled_persistent_connection?
263
264
  connection = Net::HTTP::Persistent.new "pubnub_ruby_client_v#{Pubnub::VERSION}"
264
- connection.idle_timeout = app.env[:subscribe_timeout]
265
- connection.read_timeout = app.env[:subscribe_timeout]
266
- @connect_callback.call "New connection to #{@origin}"
265
+ connection.idle_timeout = app.env[:timeout]
266
+ connection.read_timeout = app.env[:timeout]
267
267
  connection.proxy_from_env
268
268
  connection
269
269
  end
@@ -369,9 +369,14 @@ module Pubnub
369
369
  def parameters(app)
370
370
  parameters = super(app)
371
371
  parameters.merge!({:heartbeat => app.env[:heartbeat]}) if app.env[:heartbeat]
372
+ parameters.merge!({:state => encode_state(app.env[:state][@origin])}) if app.env[:state] && app.env[:state][@origin]
372
373
  parameters
373
374
  end
374
375
 
376
+ def encode_state(state)
377
+ URI.encode_www_form_component(state.to_json).gsub('+', '%20')
378
+ end
379
+
375
380
  def update_app_timetoken(envelopes, app)
376
381
  $logger.debug('Pubnub'){'Event#update_app_timetoken'}
377
382
  envelopes.each do |envelope|
@@ -524,7 +529,6 @@ module Pubnub
524
529
  connection.proxy_from_env
525
530
  connection
526
531
  end
527
-
528
532
  end
529
533
  end
530
534
  end