pubnub 4.0.9 → 4.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


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

Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/.pubnub.yml +49 -3
  3. data/CHANGELOG.md +10 -0
  4. data/Gemfile.lock +2 -2
  5. data/VERSION +1 -1
  6. data/fixtures/vcr_cassettes/examples/status_request_message_count_exceeded.yml +1484 -0
  7. data/fixtures/vcr_cassettes/lib/super_admin/cg.yml +47 -0
  8. data/fixtures/vcr_cassettes/lib/super_admin/here_now.yml +47 -0
  9. data/fixtures/vcr_cassettes/lib/super_admin/history.yml +46 -0
  10. data/fixtures/vcr_cassettes/lib/super_admin/leave.yml +46 -0
  11. data/fixtures/vcr_cassettes/lib/super_admin/presence.yml +79 -0
  12. data/fixtures/vcr_cassettes/lib/super_admin/publish.yml +40 -0
  13. data/fixtures/vcr_cassettes/lib/super_admin/state.yml +47 -0
  14. data/fixtures/vcr_cassettes/lib/super_admin/subscribe.yml +77 -0
  15. data/fixtures/vcr_cassettes/lib/super_admin/time.yml +40 -0
  16. data/fixtures/vcr_cassettes/lib/super_admin/where_now.yml +47 -0
  17. data/lib/pubnub/client.rb +4 -0
  18. data/lib/pubnub/configuration.rb +2 -1
  19. data/lib/pubnub/constants.rb +2 -0
  20. data/lib/pubnub/event.rb +78 -20
  21. data/lib/pubnub/events/audit.rb +4 -0
  22. data/lib/pubnub/events/channel_registration.rb +3 -36
  23. data/lib/pubnub/events/grant.rb +4 -0
  24. data/lib/pubnub/events/heartbeat.rb +5 -38
  25. data/lib/pubnub/events/here_now.rb +5 -38
  26. data/lib/pubnub/events/history.rb +5 -38
  27. data/lib/pubnub/events/leave.rb +4 -39
  28. data/lib/pubnub/events/presence.rb +6 -0
  29. data/lib/pubnub/events/publish.rb +12 -45
  30. data/lib/pubnub/events/revoke.rb +4 -0
  31. data/lib/pubnub/events/set_state.rb +5 -33
  32. data/lib/pubnub/events/state.rb +5 -38
  33. data/lib/pubnub/events/subscribe.rb +6 -0
  34. data/lib/pubnub/events/time.rb +4 -37
  35. data/lib/pubnub/events/where_now.rb +4 -37
  36. data/lib/pubnub/formatter.rb +7 -5
  37. data/lib/pubnub/pam.rb +0 -18
  38. data/lib/pubnub/single_event.rb +0 -4
  39. data/lib/pubnub/subscribe_event.rb +3 -1
  40. data/lib/pubnub/subscribe_event/callbacks.rb +11 -0
  41. data/lib/pubnub/subscriber.rb +31 -0
  42. data/lib/pubnub/version.rb +1 -1
  43. data/spec/examples/channel_registration_examples_spec.rb +0 -1
  44. data/spec/examples/heartbeat_examples_spec.rb +0 -1
  45. data/spec/examples/here_now_examples_spec.rb +0 -1
  46. data/spec/examples/history_examples_spec.rb +0 -1
  47. data/spec/examples/leave_examples_spec.rb +0 -1
  48. data/spec/examples/presence_examples_spec.rb +0 -1
  49. data/spec/examples/publish_examples_spec.rb +0 -865
  50. data/spec/examples/revoke_examples_spec.rb +3888 -3888
  51. data/spec/examples/set_state_examples_spec.rb +0 -1
  52. data/spec/examples/state_examples_spec.rb +0 -1
  53. data/spec/examples/status_request_message_count_exceeded_spec.rb +41 -0
  54. data/spec/examples/subscribe_examples_spec.rb +0 -445
  55. data/spec/examples/time_examples_spec.rb +0 -1
  56. data/spec/examples/where_now_examples_spec.rb +0 -1
  57. data/spec/lib/events/channel_registration_spec.rb +0 -1
  58. data/spec/lib/events/heartbeat_spec.rb +0 -1
  59. data/spec/lib/events/here_now_spec.rb +0 -1
  60. data/spec/lib/events/history_spec.rb +0 -1
  61. data/spec/lib/events/leave_spec.rb +0 -1
  62. data/spec/lib/events/presence_spec.rb +0 -4
  63. data/spec/lib/events/publish_spec.rb +0 -3
  64. data/spec/lib/events/state_spec.rb +0 -1
  65. data/spec/lib/events/subscribe_spec.rb +0 -7
  66. data/spec/lib/events/time_spec.rb +0 -1
  67. data/spec/lib/events/timeout_handling_spec.rb +30 -0
  68. data/spec/lib/events/where_now_spec.rb +0 -1
  69. data/spec/lib/super_admin_spec.rb +166 -0
  70. data/spec/spec_helper.rb +5 -3
  71. metadata +33 -16
@@ -12,6 +12,10 @@ module Pubnub
12
12
 
13
13
  private
14
14
 
15
+ def current_operation
16
+ Pubnub::Constants::OPERATION_HISTORY
17
+ end
18
+
15
19
  def timetoken(message)
16
20
  message['timetoken'] if @include_token
17
21
  end
@@ -41,7 +45,7 @@ module Pubnub
41
45
  ].join('/')
42
46
  end
43
47
 
44
- def parameters
48
+ def parameters(*_args)
45
49
  params = super
46
50
  params.merge!(start: @start) if @start
47
51
  params.merge!(end: @end) if @end
@@ -51,18 +55,6 @@ module Pubnub
51
55
  params
52
56
  end
53
57
 
54
- def format_envelopes(response, request)
55
- parsed_response, error = Formatter.parse_json(response.body)
56
-
57
- error = response if parsed_response && response.code.to_i != 200
58
-
59
- if error
60
- error_envelope(parsed_response, error, request: uri, response: response)
61
- else
62
- valid_envelope(parsed_response, request: request, response: response)
63
- end
64
- end
65
-
66
58
  def valid_envelope(parsed_response, req_res_objects)
67
59
  messages = parsed_response[0]
68
60
 
@@ -110,30 +102,5 @@ module Pubnub
110
102
  }
111
103
  )
112
104
  end
113
-
114
- def error_envelope(_parsed_response, error, req_res_objects)
115
- Pubnub::ErrorEnvelope.new(
116
- event: @event,
117
- event_options: @given_options,
118
- timetoken: nil,
119
- status: {
120
- code: req_res_objects[:response].code,
121
- operation: Pubnub::Constants::OPERATION_HEARTBEAT,
122
- client_request: req_res_objects[:request],
123
- server_response: req_res_objects[:response],
124
- data: nil,
125
- category: (error ? Pubnub::Constants::STATUS_NON_JSON_RESPONSE : Pubnub::Constants::STATUS_ERROR),
126
- error: true,
127
- auto_retried: false,
128
-
129
- current_timetoken: nil,
130
- last_timetoken: nil,
131
- subscribed_channels: nil,
132
- subscribed_channel_groups: nil,
133
-
134
- config: get_config
135
- }
136
- )
137
- end
138
105
  end
139
106
  end
@@ -18,6 +18,10 @@ module Pubnub
18
18
 
19
19
  private
20
20
 
21
+ def current_operation
22
+ Pubnub::Constants::OPERATION_PRESENCE_LEAVE
23
+ end
24
+
21
25
  def path
22
26
  '/' + [
23
27
  'v2',
@@ -30,20 +34,6 @@ module Pubnub
30
34
  ].join('/')
31
35
  end
32
36
 
33
- def format_envelopes(response, request)
34
- parsed_response, error = Formatter.parse_json(response.body)
35
-
36
- error = response if parsed_response && response.code.to_i != 200
37
-
38
- envelopes = if error
39
- error_envelope(parsed_response, error, request: request, response: response)
40
- else
41
- valid_envelope(parsed_response, request: request, response: response)
42
- end
43
-
44
- envelopes
45
- end
46
-
47
37
  def valid_envelope(parsed_response, req_res_objects)
48
38
  Pubnub::Envelope.new(
49
39
  event: @event,
@@ -68,30 +58,5 @@ module Pubnub
68
58
  }
69
59
  )
70
60
  end
71
-
72
- def error_envelope(_parsed_response, error, req_res_objects)
73
- Pubnub::ErrorEnvelope.new(
74
- event: @event,
75
- event_options: @given_options,
76
- timetoken: nil,
77
- status: {
78
- code: req_res_objects[:response].code,
79
- operation: Pubnub::Constants::OPERATION_HEARTBEAT,
80
- client_request: req_res_objects[:request],
81
- server_response: req_res_objects[:response],
82
- data: nil,
83
- category: (error ? Pubnub::Constants::STATUS_NON_JSON_RESPONSE : Pubnub::Constants::STATUS_ERROR),
84
- error: true,
85
- auto_retried: false,
86
-
87
- current_timetoken: nil,
88
- last_timetoken: nil,
89
- subscribed_channels: nil,
90
- subscribed_channel_groups: nil,
91
-
92
- config: get_config
93
- }
94
- )
95
- end
96
61
  end
97
62
  end
@@ -15,5 +15,11 @@ module Pubnub
15
15
  @channel = Formatter.format_channel(@channel || @channels)
16
16
  @channel = @channel.map { |c| c + '-pnpres' }
17
17
  end
18
+
19
+ private
20
+
21
+ def current_operation
22
+ Pubnub::Constants::OPERATION_PRESENCE
23
+ end
18
24
  end
19
25
  end
@@ -10,7 +10,9 @@ module Pubnub
10
10
  def initialize(options, app)
11
11
  @event = :publish
12
12
  super
13
- @sequence_number = nil
13
+ @sequence_number = sequence_number!
14
+ @origination_time_token = @app.generate_ortt
15
+
14
16
  @store = case @store
15
17
  when false
16
18
  0
@@ -33,15 +35,17 @@ module Pubnub
33
35
  finalize_event(envelopes)
34
36
  envelopes
35
37
  ensure
36
- # sender.terminate if @http_sync
37
38
  terminate unless @stay_alive
38
39
  end
39
40
 
40
41
  private
41
42
 
42
- def parameters
43
- @sequence_number = sequence_number!
44
- @origination_time_token = @app.generate_ortt
43
+ def current_operation
44
+ Pubnub::Constants::OPERATION_PUBLISH
45
+ end
46
+
47
+ def parameters(*_args)
48
+ params = super
45
49
 
46
50
  empty_if_blank = {
47
51
  store: @store,
@@ -51,12 +55,12 @@ module Pubnub
51
55
  replication = @replicate == false ? { norep: true } : {}
52
56
 
53
57
  empty_if_blank.delete_if { |_k, v| v.blank? }
54
- params = {}
58
+
55
59
  params = params.merge(empty_if_blank)
56
60
  params = params.merge(replication)
57
61
  params = params.merge(seqn: @sequence_number,
58
- ortt: Formatter.encode({ t: @origination_time_token }.to_json))
59
- super.merge(params)
62
+ ortt: { t: @origination_time_token })
63
+ params
60
64
  end
61
65
 
62
66
  def path
@@ -91,18 +95,6 @@ module Pubnub
91
95
  nil
92
96
  end
93
97
 
94
- def format_envelopes(response, request)
95
- parsed_response, error = Formatter.parse_json(response.body)
96
-
97
- error = response if parsed_response && response.code.to_i != 200
98
-
99
- if error
100
- error_envelope(parsed_response, error, request: request, response: response)
101
- else
102
- valid_envelope(parsed_response, request: request, response: response)
103
- end
104
- end
105
-
106
98
  def valid_envelope(_parsed_response, req_res_objects)
107
99
  Pubnub::Envelope.new(
108
100
  event: @event,
@@ -127,30 +119,5 @@ module Pubnub
127
119
  }
128
120
  )
129
121
  end
130
-
131
- def error_envelope(_parsed_response, error, req_res_objects)
132
- Pubnub::ErrorEnvelope.new(
133
- event: @event,
134
- event_options: @given_options,
135
- timetoken: nil,
136
- status: {
137
- code: req_res_objects[:response].code,
138
- operation: Pubnub::Constants::OPERATION_PUBLISH,
139
- client_request: req_res_objects[:request],
140
- server_response: req_res_objects[:response],
141
- data: nil,
142
- category: (error ? Pubnub::Constants::STATUS_NON_JSON_RESPONSE : Pubnub::Constants::STATUS_ERROR),
143
- error: true,
144
- auto_retried: false,
145
-
146
- current_timetoken: nil,
147
- last_timetoken: nil,
148
- subscribed_channels: nil,
149
- subscribed_channel_groups: nil,
150
-
151
- config: get_config
152
- }
153
- )
154
- end
155
122
  end
156
123
  end
@@ -13,6 +13,10 @@ module Pubnub
13
13
 
14
14
  private
15
15
 
16
+ def current_operation
17
+ Pubnub::Constants::OPERATION_REVOKE
18
+ end
19
+
16
20
  def parameters(signature = false)
17
21
  write = [0, '0', false].include?(@write) ? 1 : 0
18
22
  read = [0, '0', false].include?(@read) ? 1 : 0
@@ -13,7 +13,11 @@ module Pubnub
13
13
 
14
14
  private
15
15
 
16
- def parameters
16
+ def current_operation
17
+ Pubnub::Constants::OPERATION_SET_STATE
18
+ end
19
+
20
+ def parameters(*_args)
17
21
  parameters = super
18
22
  parameters.merge!(state: encode_parameter(@state))
19
23
  parameters.merge!('channel-group' => format_channel_group(@group).join(',')) unless @group.blank?
@@ -34,18 +38,6 @@ module Pubnub
34
38
  ].join('/')
35
39
  end
36
40
 
37
- def format_envelopes(response, request)
38
- parsed_response, error = Formatter.parse_json(response.body)
39
-
40
- error = response if parsed_response && response.code.to_i != 200
41
-
42
- if error
43
- error_envelope(parsed_response, error, request: request, response: response)
44
- else
45
- valid_envelope(parsed_response, request: request, response: response)
46
- end
47
- end
48
-
49
41
  def valid_envelope(_parsed_response, req_res_objects)
50
42
  Pubnub::Envelope.new(
51
43
  event: @event,
@@ -70,25 +62,5 @@ module Pubnub
70
62
  }
71
63
  )
72
64
  end
73
-
74
- def error_envelope(_parsed_response, error, req_res_objects)
75
- Pubnub::ErrorEnvelope.new(
76
- event: @event,
77
- event_options: @given_options,
78
- timetoken: nil,
79
- status: {
80
- code: req_res_objects[:response].code,
81
- operation: Pubnub::Constants::OPERATION_SET_STATE,
82
- client_request: req_res_objects[:request],
83
- server_response: req_res_objects[:response],
84
- data: nil,
85
- category: (error ? Pubnub::Constants::STATUS_NON_JSON_RESPONSE : Pubnub::Constants::STATUS_ERROR),
86
- error: true,
87
- auto_retried: false,
88
-
89
- config: get_config
90
- }
91
- )
92
- end
93
65
  end
94
66
  end
@@ -14,7 +14,11 @@ module Pubnub
14
14
 
15
15
  private
16
16
 
17
- def parameters
17
+ def current_operation
18
+ Pubnub::Constants::OPERATION_GET_STATE
19
+ end
20
+
21
+ def parameters(*_args)
18
22
  parameters = super
19
23
  parameters.merge!(
20
24
  'channel-group' => @group.join(',')
@@ -35,18 +39,6 @@ module Pubnub
35
39
  ].join('/')
36
40
  end
37
41
 
38
- def format_envelopes(response, request)
39
- parsed_response, error = Formatter.parse_json(response.body)
40
-
41
- error = response if parsed_response && response.code.to_i != 200
42
-
43
- if error
44
- error_envelope(parsed_response, error, request: request, response: response)
45
- else
46
- valid_envelope(parsed_response, request: request, response: response)
47
- end
48
- end
49
-
50
42
  def valid_envelope(parsed_response, req_res_objects)
51
43
  Pubnub::Envelope.new(
52
44
  event: @event,
@@ -82,30 +74,5 @@ module Pubnub
82
74
  }
83
75
  )
84
76
  end
85
-
86
- def error_envelope(_parsed_response, error, req_res_objects)
87
- Pubnub::ErrorEnvelope.new(
88
- event: @event,
89
- event_options: @given_options,
90
- timetoken: nil,
91
- status: {
92
- code: req_res_objects[:response].code,
93
- operation: Pubnub::Constants::OPERATION_HEARTBEAT,
94
- client_request: req_res_objects[:request],
95
- server_response: req_res_objects[:response],
96
- data: nil,
97
- category: (error ? Pubnub::Constants::STATUS_NON_JSON_RESPONSE : Pubnub::Constants::STATUS_ERROR),
98
- error: true,
99
- auto_retried: false,
100
-
101
- current_timetoken: nil,
102
- last_timetoken: nil,
103
- subscribed_channels: nil,
104
- subscribed_channel_groups: nil,
105
-
106
- config: get_config
107
- }
108
- )
109
- end
110
77
  end
111
78
  end
@@ -15,5 +15,11 @@ module Pubnub
15
15
  def clear_state
16
16
  @state = nil
17
17
  end
18
+
19
+ private
20
+
21
+ def current_operation
22
+ Pubnub::Constants::OPERATION_SUBSCRIBE
23
+ end
18
24
  end
19
25
  end
@@ -12,6 +12,10 @@ module Pubnub
12
12
 
13
13
  private
14
14
 
15
+ def current_operation
16
+ Pubnub::Constants::OPERATION_TIME
17
+ end
18
+
15
19
  def path
16
20
  '/time/0'
17
21
  end
@@ -22,18 +26,6 @@ module Pubnub
22
26
  nil
23
27
  end
24
28
 
25
- def format_envelopes(response, request)
26
- parsed_response, error = Formatter.parse_json(response.body)
27
-
28
- error = response if parsed_response && response.code.to_i != 200
29
-
30
- if error
31
- error_envelope(parsed_response, error, request: request, response: response)
32
- else
33
- valid_envelope(parsed_response, request: request, response: response)
34
- end
35
- end
36
-
37
29
  def valid_envelope(parsed_response, req_res_objects)
38
30
  Pubnub::Envelope.new(
39
31
  event: @event,
@@ -64,30 +56,5 @@ module Pubnub
64
56
  }
65
57
  )
66
58
  end
67
-
68
- def error_envelope(_parsed_response, error, req_res_objects)
69
- Pubnub::ErrorEnvelope.new(
70
- event: @event,
71
- event_options: @given_options,
72
- timetoken: nil,
73
- status: {
74
- code: req_res_objects[:response].code,
75
- operation: Pubnub::Constants::OPERATION_HEARTBEAT,
76
- client_request: req_res_objects[:request],
77
- server_response: req_res_objects[:response],
78
- data: nil,
79
- category: (error ? Pubnub::Constants::STATUS_NON_JSON_RESPONSE : Pubnub::Constants::STATUS_ERROR),
80
- error: true,
81
- auto_retried: false,
82
-
83
- current_timetoken: nil,
84
- last_timetoken: nil,
85
- subscribed_channels: nil,
86
- subscribed_channel_groups: nil,
87
-
88
- config: get_config
89
- }
90
- )
91
- end
92
59
  end
93
60
  end