pubnub 4.0.23 → 4.0.25

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 (63) hide show
  1. checksums.yaml +4 -4
  2. data/.pubnub.yml +18 -1
  3. data/.travis.yml +23 -6
  4. data/CHANGELOG.md +7 -0
  5. data/Gemfile.lock +59 -50
  6. data/VERSION +1 -1
  7. data/fixtures/vcr_cassettes/examples/delete_messages_channel.yml +46 -0
  8. data/fixtures/vcr_cassettes/examples/delete_messages_channel_end.yml +46 -0
  9. data/fixtures/vcr_cassettes/examples/delete_messages_channel_start.yml +46 -0
  10. data/fixtures/vcr_cassettes/examples/delete_messages_channel_start_end.yml +46 -0
  11. data/fixtures/vcr_cassettes/lib/events/delete_messages-error.yml +46 -0
  12. data/fixtures/vcr_cassettes/lib/events/delete_messages.yml +46 -0
  13. data/gemfiles/celluloid_017.gemfile +25 -0
  14. data/gemfiles/celluloid_017.gemfile.lock +159 -0
  15. data/gemfiles/celluloid_018.gemfile +25 -0
  16. data/gemfiles/celluloid_018.gemfile.lock +159 -0
  17. data/gemfiles/celluloid_master.gemfile +25 -0
  18. data/gemfiles/celluloid_master.gemfile.lock +155 -0
  19. data/lib/pubnub.rb +3 -0
  20. data/lib/pubnub/client.rb +13 -1
  21. data/lib/pubnub/client/events.rb +1 -1
  22. data/lib/pubnub/constants.rb +1 -0
  23. data/lib/pubnub/event.rb +20 -5
  24. data/lib/pubnub/event/formatter.rb +1 -3
  25. data/lib/pubnub/events/channel_registration.rb +1 -0
  26. data/lib/pubnub/events/delete_messages.rb +63 -0
  27. data/lib/pubnub/events/heartbeat.rb +1 -0
  28. data/lib/pubnub/events/here_now.rb +1 -0
  29. data/lib/pubnub/events/history.rb +1 -0
  30. data/lib/pubnub/events/leave.rb +1 -0
  31. data/lib/pubnub/events/presence.rb +1 -0
  32. data/lib/pubnub/events/publish.rb +1 -0
  33. data/lib/pubnub/events/set_state.rb +1 -0
  34. data/lib/pubnub/events/state.rb +1 -0
  35. data/lib/pubnub/events/time.rb +1 -0
  36. data/lib/pubnub/events/where_now.rb +1 -0
  37. data/lib/pubnub/pam.rb +2 -1
  38. data/lib/pubnub/telemetry.rb +29 -0
  39. data/lib/pubnub/validators/delete.rb +24 -0
  40. data/lib/pubnub/version.rb +1 -1
  41. data/spec/examples/audit_examples_spec.rb +3 -1
  42. data/spec/examples/channel_registration_examples_spec.rb +3 -1
  43. data/spec/examples/delete_messages_examples_spec.rb +48 -0
  44. data/spec/examples/grant_examples_spec.rb +2 -2
  45. data/spec/examples/heartbeat_examples_spec.rb +2 -2
  46. data/spec/examples/here_now_examples_spec.rb +2 -2
  47. data/spec/examples/history_examples_spec.rb +2 -2
  48. data/spec/examples/leave_examples_spec.rb +2 -2
  49. data/spec/examples/presence_examples_spec.rb +2 -2
  50. data/spec/examples/publish_examples_spec.rb +2 -2
  51. data/spec/examples/publish_with_ttl_spec.rb +3 -2
  52. data/spec/examples/revoke_examples_spec.rb +2 -2
  53. data/spec/examples/set_state_examples_spec.rb +2 -2
  54. data/spec/examples/state_examples_spec.rb +2 -2
  55. data/spec/examples/subscribe_examples_spec.rb +2 -2
  56. data/spec/examples/time_examples_spec.rb +2 -2
  57. data/spec/examples/where_now_examples_spec.rb +2 -2
  58. data/spec/lib/events/delete_messages_spec.rb +43 -0
  59. data/spec/lib/events/grant_spec.rb +27 -28
  60. data/spec/lib/events/timeout_handling_spec.rb +20 -14
  61. data/spec/lib/pubnub_spec.rb +7 -1
  62. data/spec/spec_helper.rb +21 -0
  63. metadata +22 -3
@@ -0,0 +1,25 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '../'
4
+
5
+ gem 'celluloid', git: 'https://github.com/celluloid/celluloid.git'
6
+
7
+ # dry-validation depends on dry-types that is not compatible with ruby
8
+ # 2.1.0 from 0.11.0.
9
+ gem 'dry-validation', '>= 0.10', '< 0.11'
10
+
11
+ group :test do
12
+ gem 'rubocop'
13
+ gem 'simplecov', '>= 0.12', require: false
14
+ gem 'codacy-coverage', require: false
15
+ gem 'rspec'
16
+ gem 'rspec-wait'
17
+ gem 'vcr'
18
+ gem 'rr'
19
+ gem 'webmock'
20
+ end
21
+
22
+ group :development, :test do
23
+ gem 'pry'
24
+ gem 'awesome_print'
25
+ end
@@ -0,0 +1,155 @@
1
+ GIT
2
+ remote: https://github.com/celluloid/celluloid.git
3
+ revision: 727fa67545f663536ab5792fe08db0870b1a15fb
4
+ specs:
5
+ celluloid (0.18.0.pre)
6
+ celluloid-pool (~> 0.20)
7
+ celluloid-supervision (~> 0.20)
8
+ timers (~> 4)
9
+
10
+ PATH
11
+ remote: ..
12
+ specs:
13
+ pubnub (4.0.24)
14
+ celluloid (~> 0.17)
15
+ dry-validation (~> 0.10)
16
+ httpclient (~> 2.8, >= 2.8.3)
17
+ json (>= 1.8, < 3)
18
+
19
+ GEM
20
+ remote: https://rubygems.org/
21
+ specs:
22
+ addressable (2.5.2)
23
+ public_suffix (>= 2.0.2, < 4.0)
24
+ ast (2.3.0)
25
+ awesome_print (1.8.0)
26
+ celluloid-pool (0.20.5)
27
+ timers (>= 4.1.1)
28
+ celluloid-supervision (0.20.6)
29
+ timers (>= 4.1.1)
30
+ codacy-coverage (1.1.7)
31
+ simplecov
32
+ coderay (1.1.2)
33
+ concurrent-ruby (1.0.5)
34
+ concurrent-ruby (1.0.5-java)
35
+ crack (0.4.3)
36
+ safe_yaml (~> 1.0.0)
37
+ diff-lcs (1.3)
38
+ docile (1.1.5)
39
+ dry-configurable (0.7.0)
40
+ concurrent-ruby (~> 1.0)
41
+ dry-container (0.6.0)
42
+ concurrent-ruby (~> 1.0)
43
+ dry-configurable (~> 0.1, >= 0.1.3)
44
+ dry-core (0.3.3)
45
+ concurrent-ruby (~> 1.0)
46
+ dry-equalizer (0.2.0)
47
+ dry-logic (0.4.1)
48
+ dry-container (~> 0.2, >= 0.2.6)
49
+ dry-core (~> 0.2)
50
+ dry-equalizer (~> 0.2)
51
+ dry-types (0.11.1)
52
+ concurrent-ruby (~> 1.0)
53
+ dry-configurable (~> 0.1)
54
+ dry-container (~> 0.3)
55
+ dry-core (~> 0.2, >= 0.2.1)
56
+ dry-equalizer (~> 0.2)
57
+ dry-logic (~> 0.4, >= 0.4.0)
58
+ inflecto (~> 0.0.0, >= 0.0.2)
59
+ dry-validation (0.10.7)
60
+ concurrent-ruby (~> 1.0)
61
+ dry-configurable (~> 0.1, >= 0.1.3)
62
+ dry-core (~> 0.2, >= 0.2.1)
63
+ dry-equalizer (~> 0.2)
64
+ dry-logic (~> 0.4, >= 0.4.0)
65
+ dry-types (~> 0.9, >= 0.9.0)
66
+ ffi (1.9.18-java)
67
+ hashdiff (0.3.6)
68
+ hitimes (1.2.6)
69
+ hitimes (1.2.6-java)
70
+ httpclient (2.8.3)
71
+ inflecto (0.0.2)
72
+ json (2.1.0)
73
+ json (2.1.0-java)
74
+ method_source (0.8.2)
75
+ parallel (1.12.0)
76
+ parser (2.4.0.0)
77
+ ast (~> 2.2)
78
+ powerpack (0.1.1)
79
+ pry (0.10.4)
80
+ coderay (~> 1.1.0)
81
+ method_source (~> 0.8.1)
82
+ slop (~> 3.4)
83
+ pry (0.10.4-java)
84
+ coderay (~> 1.1.0)
85
+ method_source (~> 0.8.1)
86
+ slop (~> 3.4)
87
+ spoon (~> 0.0)
88
+ public_suffix (3.0.0)
89
+ rainbow (2.2.2)
90
+ rake
91
+ rake (12.1.0)
92
+ rr (1.2.1)
93
+ rspec (3.6.0)
94
+ rspec-core (~> 3.6.0)
95
+ rspec-expectations (~> 3.6.0)
96
+ rspec-mocks (~> 3.6.0)
97
+ rspec-core (3.6.0)
98
+ rspec-support (~> 3.6.0)
99
+ rspec-expectations (3.6.0)
100
+ diff-lcs (>= 1.2.0, < 2.0)
101
+ rspec-support (~> 3.6.0)
102
+ rspec-mocks (3.6.0)
103
+ diff-lcs (>= 1.2.0, < 2.0)
104
+ rspec-support (~> 3.6.0)
105
+ rspec-support (3.6.0)
106
+ rspec-wait (0.0.9)
107
+ rspec (>= 3, < 4)
108
+ rubocop (0.49.1)
109
+ parallel (~> 1.10)
110
+ parser (>= 2.3.3.1, < 3.0)
111
+ powerpack (~> 0.1)
112
+ rainbow (>= 1.99.1, < 3.0)
113
+ ruby-progressbar (~> 1.7)
114
+ unicode-display_width (~> 1.0, >= 1.0.1)
115
+ ruby-progressbar (1.8.1)
116
+ safe_yaml (1.0.4)
117
+ simplecov (0.15.1)
118
+ docile (~> 1.1.0)
119
+ json (>= 1.8, < 3)
120
+ simplecov-html (~> 0.10.0)
121
+ simplecov-html (0.10.2)
122
+ slop (3.6.0)
123
+ spoon (0.0.6)
124
+ ffi
125
+ timers (4.1.2)
126
+ hitimes
127
+ unicode-display_width (1.3.0)
128
+ vcr (3.0.3)
129
+ webmock (3.0.1)
130
+ addressable (>= 2.3.6)
131
+ crack (>= 0.3.2)
132
+ hashdiff
133
+
134
+ PLATFORMS
135
+ java
136
+ ruby
137
+
138
+ DEPENDENCIES
139
+ awesome_print
140
+ bundler (~> 1.7)
141
+ celluloid!
142
+ codacy-coverage
143
+ dry-validation (>= 0.10, < 0.11)
144
+ pry
145
+ pubnub!
146
+ rr
147
+ rspec
148
+ rspec-wait
149
+ rubocop
150
+ simplecov (>= 0.12)
151
+ vcr
152
+ webmock
153
+
154
+ BUNDLED WITH
155
+ 1.15.4
@@ -4,6 +4,9 @@ require 'zlib'
4
4
  require 'open-uri'
5
5
  require 'openssl'
6
6
  require 'celluloid/current'
7
+
8
+ Celluloid.boot
9
+
7
10
  require 'timers'
8
11
  require 'httpclient'
9
12
  require 'logger'
@@ -20,6 +20,7 @@ require 'pubnub/subscribe_event'
20
20
  require 'pubnub/pam'
21
21
  require 'pubnub/heart'
22
22
  require 'pubnub/subscriber'
23
+ require 'pubnub/telemetry'
23
24
 
24
25
  require 'pubnub/envelope'
25
26
  require 'pubnub/error_envelope'
@@ -46,6 +47,7 @@ require 'pubnub/validators/state'
46
47
  require 'pubnub/validators/subscribe'
47
48
  require 'pubnub/validators/time'
48
49
  require 'pubnub/validators/where_now'
50
+ require 'pubnub/validators/delete'
49
51
 
50
52
  require 'pubnub/events/audit'
51
53
  require 'pubnub/events/channel_registration'
@@ -62,6 +64,7 @@ require 'pubnub/events/state'
62
64
  require 'pubnub/events/subscribe'
63
65
  require 'pubnub/events/time'
64
66
  require 'pubnub/events/where_now'
67
+ require 'pubnub/events/delete_messages'
65
68
 
66
69
  # Toplevel Pubnub module.
67
70
  module Pubnub
@@ -73,7 +76,7 @@ module Pubnub
73
76
  include Helpers
74
77
  include GettersSetters
75
78
 
76
- attr_reader :env, :subscriber, :heart
79
+ attr_reader :env, :subscriber, :telemetry
77
80
 
78
81
  VERSION = Pubnub::VERSION
79
82
 
@@ -160,6 +163,7 @@ module Pubnub
160
163
  clean_env
161
164
  prepare_env
162
165
  validate! @env
166
+ @telemetry = Telemetry.new
163
167
  Pubnub.logger.debug('Pubnub::Client') do
164
168
  "Created new Pubnub::Client instance. Version: #{Pubnub::VERSION}"
165
169
  end
@@ -298,6 +302,14 @@ module Pubnub
298
302
  (::Time.now.to_f * 10_000_000).to_i
299
303
  end
300
304
 
305
+ def record_telemetry(telemetry_type, time_start, time_end)
306
+ @telemetry.record_request(telemetry_type, time_start, time_end)
307
+ end
308
+
309
+ def telemetry_for(event)
310
+ @telemetry.fetch_average(event)
311
+ end
312
+
301
313
  private
302
314
 
303
315
  def create_state_pools(event)
@@ -4,7 +4,7 @@ module Pubnub
4
4
  class Client
5
5
  # Module that holds generator for all events
6
6
  module Events
7
- EVENTS = %w(publish subscribe presence leave history here_now audit grant
7
+ EVENTS = %w(publish subscribe presence leave history here_now audit grant delete_messages
8
8
  revoke time heartbeat where_now set_state state channel_registration)
9
9
 
10
10
  EVENTS.each do |event_name|
@@ -57,6 +57,7 @@ module Pubnub
57
57
  OPERATION_AUDIT = :audit
58
58
  OPERATION_GRANT = :grant
59
59
  OPERATION_REVOKE = :revoke
60
+ OPERATION_DELETE = :delete
60
61
  OPERATION_LIST_ALL_CHANNEL_GROUPS = :list_all_channel_groups
61
62
  OPERATION_LIST_ALL_CHANNELS_IN_CHANNEL_GROUP = :list_all_channels_in_channel_group
62
63
 
@@ -49,23 +49,38 @@ module Pubnub
49
49
  sender = request_dispatcher
50
50
  Pubnub.logger.debug('Pubnub::Event') { '#send_request got sender' }
51
51
 
52
- if compressed_body.empty?
53
- sender.get(uri.to_s)
52
+ telemetry_time_start = ::Time.now.to_f
53
+ if @event == Pubnub::Constants::OPERATION_DELETE
54
+ response = sender.delete(uri.to_s)
55
+ elsif compressed_body.empty?
56
+ response = sender.get(uri.to_s)
54
57
  else
55
- sender.post(uri.to_s, body: compressed_body)
58
+ response = sender.post(uri.to_s, body: compressed_body)
56
59
  end
60
+
61
+ @app.record_telemetry(@telemetry_name, telemetry_time_start, ::Time.now.to_f)
62
+
63
+ return response
64
+
57
65
  rescue => error
58
66
  error
59
67
  end
60
68
 
61
- def uri
69
+ def uri(memo = true)
70
+ unless self.is_a? SubscribeEvent
71
+ return @uri = uri(false) if memo
72
+ return @uri if @uri
73
+ end
74
+
62
75
  sa_signature = super_admin_signature unless parameters.include?(:signature)
76
+ telemetry = @app.telemetry_for(@telemetry_name)
63
77
 
64
78
  uri = @ssl ? 'https://' : 'http://'
65
79
  uri += @origin
66
80
  uri += path
67
81
  uri += '?' + Formatter.params_hash_to_url_params(parameters)
68
82
  uri += "&signature=#{sa_signature}" if sa_signature
83
+ uri += "&#{@telemetry_name}=#{telemetry.round(3)}" if telemetry
69
84
  Pubnub.logger.debug('Pubnub::Event') { "Requested URI: #{uri}" }
70
85
  URI uri
71
86
  end
@@ -174,7 +189,7 @@ module Pubnub
174
189
  when JSON::ParserError
175
190
  error_category = Pubnub::Constants::STATUS_NON_JSON_RESPONSE
176
191
  code = req_res_objects[:response].code
177
- when HTTPClient::ReceiveTimeoutError
192
+ when HTTPClient::TimeoutError
178
193
  error_category = Pubnub::Constants::STATUS_TIMEOUT
179
194
  code = 408
180
195
  when OpenSSL::SSL::SSLError
@@ -5,9 +5,7 @@ module Pubnub
5
5
  # Module that holds formatters for events
6
6
  module EFormatter
7
7
  def format_envelopes(response, request)
8
- if response.is_a? HTTPClient::ReceiveTimeoutError
9
- return error_envelope(nil, response, request: request, response: response)
10
- elsif response.is_a? OpenSSL::SSL::SSLError
8
+ if response.kind_of?(HTTPClient::TimeoutError) || response.is_a?(OpenSSL::SSL::SSLError)
11
9
  return error_envelope(nil, response, request: request, response: response)
12
10
  else
13
11
  parsed_response, error = Formatter.parse_json(response.body)
@@ -7,6 +7,7 @@ module Pubnub
7
7
 
8
8
  def initialize(options, app)
9
9
  @event = :channel_registration
10
+ @telemetry_name = :l_cg
10
11
  super
11
12
  @action = @action.to_sym unless @action.nil?
12
13
  end
@@ -0,0 +1,63 @@
1
+ # Toplevel Pubnub module.
2
+ module Pubnub
3
+ # Holds delete functionality
4
+ class DeleteMessages < SingleEvent
5
+ include Celluloid
6
+ include Pubnub::Validator::Delete
7
+
8
+ def initialize(options, app)
9
+ @event = :delete
10
+ @telemetry_name = :l_hist
11
+ super
12
+ end
13
+
14
+ private
15
+
16
+ def current_operation
17
+ Pubnub::Constants::OPERATION_DELETE
18
+ end
19
+
20
+ def parameters(signature = false)
21
+ {
22
+ start: @start,
23
+ end: @end
24
+ }.select { |_, value| !value.blank? }.merge(super(signature))
25
+ end
26
+
27
+ def path
28
+ '/' + [
29
+ 'v3',
30
+ 'history',
31
+ 'sub-key',
32
+ @subscribe_key,
33
+ 'channel',
34
+ @channel
35
+ ].join('/')
36
+ end
37
+
38
+ def valid_envelope(parsed_response, req_res_objects)
39
+ Pubnub::Envelope.new(
40
+ event: @event,
41
+ event_options: @given_options,
42
+ timetoken: nil,
43
+ status: {
44
+ code: req_res_objects[:response].code,
45
+ operation: Pubnub::Constants::OPERATION_DELETE,
46
+ client_request: req_res_objects[:request],
47
+ server_response: req_res_objects[:response],
48
+ data: nil,
49
+ category: Pubnub::Constants::STATUS_ACK,
50
+ error: false,
51
+ auto_retried: false,
52
+
53
+ current_timetoken: nil,
54
+ last_timetoken: nil,
55
+ subscribed_channels: nil,
56
+ subscribed_channel_groups: nil,
57
+
58
+ config: get_config
59
+ }
60
+ )
61
+ end
62
+ end
63
+ end
@@ -7,6 +7,7 @@ module Pubnub
7
7
  include Pubnub::Formatter
8
8
 
9
9
  def initialize(options, app)
10
+ @telemetry_name = :l_pres
10
11
  @event = :heartbeat
11
12
  super
12
13
  end
@@ -7,6 +7,7 @@ module Pubnub
7
7
 
8
8
  def initialize(options, app)
9
9
  @event = :here_now
10
+ @telemetry_name = :l_pres
10
11
  super
11
12
  end
12
13
 
@@ -7,6 +7,7 @@ module Pubnub
7
7
 
8
8
  def initialize(options, app)
9
9
  @event = :history
10
+ @telemetry_name = :l_hist
10
11
  super
11
12
  end
12
13
 
@@ -7,6 +7,7 @@ module Pubnub
7
7
 
8
8
  def initialize(options, app)
9
9
  @event = :leave
10
+ @telemetry_name = :l_pub
10
11
  super
11
12
  end
12
13
 
@@ -8,6 +8,7 @@ module Pubnub
8
8
 
9
9
  def initialize(options, app)
10
10
  @event = :presence
11
+ @telemetry_name = :l_pres
11
12
  super
12
13
  end
13
14
 
@@ -9,6 +9,7 @@ module Pubnub
9
9
 
10
10
  def initialize(options, app)
11
11
  @event = :publish
12
+ @telemetry_name = :l_pub
12
13
  super
13
14
  @sequence_number = sequence_number!
14
15
  @origination_time_token = @app.generate_ortt