pubnub 4.0.28 → 4.1.0

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: 88b73fbc6592b489fa25a48028c0d6b80b4c0b70
4
- data.tar.gz: 4e9a790b61303e81badf79e9c02651138029e329
3
+ metadata.gz: c6bb57cb1493dd96f772d531a71cf21efd28d4c3
4
+ data.tar.gz: bb6308568e32afea2d41eb3ee5c811048ba5827b
5
5
  SHA512:
6
- metadata.gz: a43bcb6b9c28dc29523832cf90f03b4da53260a389c871de888958d405d6e1077a8b1c5af3db9103f546e4b4575b0d0037dcf1645283693abac470348705a6a2
7
- data.tar.gz: f7fefe6f2e4db1f86652dbac011bc3a47b5ddda8ce132fc72db88a85a02d649403a4d830280ea50be8c05d272793a541c592fe6e7861d631c82f5a8e25793acd
6
+ metadata.gz: c032947e4382d77011413d0b3836ec421c705ea45c7bb1bfa9a5acee2ec82e29a55d911aa58c205c460d593e04c104d39fa67a2204e19ea12c5c13ba1c783f66
7
+ data.tar.gz: d13d358cec383eae31e3fda5dfed3297fae8b3fb2bc13e19fb7d40480dfaf29b891dd399250e3f779160b57e206b447e32f98334253cd1c4813ddc3051720e24
@@ -1,6 +1,13 @@
1
1
  ---
2
- version: "4.0.28"
2
+ version: "4.1.0"
3
3
  changelog:
4
+ -
5
+ changes:
6
+ -
7
+ text: "Added 'message_count' API endpoint"
8
+ type: feature
9
+ date: 28-2-2019
10
+ version: "4.1.0"
4
11
  -
5
12
  changes:
6
13
  -
@@ -265,6 +272,7 @@ features:
265
272
  - STORAGE-START-END
266
273
  - STORAGE-COUNT
267
274
  - STORAGE-DELETE-MESSAGES
275
+ - STORAGE-MESSAGE-COUNT
268
276
  subscribe:
269
277
  - SUBSCRIBE-CHANNELS
270
278
  - SUBSCRIBE-CHANNEL-GROUPS
@@ -17,7 +17,6 @@ rvm:
17
17
  - 2.5.1
18
18
  - 2.4.4
19
19
  - 2.3.7
20
- - 2.2.10
21
20
 
22
21
  matrix:
23
22
  include:
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pubnub (4.0.28)
4
+ pubnub (4.1.0)
5
5
  concurrent-ruby (~> 1.0.5)
6
6
  concurrent-ruby-edge (~> 0.3.1)
7
7
  dry-validation (~> 0.10)
@@ -22,7 +22,6 @@ GEM
22
22
  simplecov
23
23
  coderay (1.1.2)
24
24
  concurrent-ruby (1.0.5)
25
- concurrent-ruby (1.0.5-java)
26
25
  concurrent-ruby-edge (0.3.1)
27
26
  concurrent-ruby (= 1.0.5)
28
27
  crack (0.4.3)
@@ -35,7 +34,7 @@ GEM
35
34
  dry-container (0.6.0)
36
35
  concurrent-ruby (~> 1.0)
37
36
  dry-configurable (~> 0.1, >= 0.1.3)
38
- dry-core (0.4.6)
37
+ dry-core (0.4.7)
39
38
  concurrent-ruby (~> 1.0)
40
39
  dry-equalizer (0.2.1)
41
40
  dry-inflector (0.1.2)
@@ -50,7 +49,7 @@ GEM
50
49
  dry-equalizer (~> 0.2)
51
50
  dry-inflector (~> 0.1, >= 0.1.2)
52
51
  dry-logic (~> 0.4, >= 0.4.2)
53
- dry-validation (0.12.0)
52
+ dry-validation (0.12.1)
54
53
  concurrent-ruby (~> 1.0)
55
54
  dry-configurable (~> 0.1, >= 0.1.3)
56
55
  dry-core (~> 0.2, >= 0.2.1)
@@ -60,8 +59,6 @@ GEM
60
59
  ffi (1.9.25-java)
61
60
  hashdiff (0.3.7)
62
61
  hitimes (1.3.0)
63
- hitimes (1.3.0-java)
64
- hitimes (1.3.0-x64-mingw32)
65
62
  httpclient (2.8.3)
66
63
  interception (0.5)
67
64
  jaro_winkler (1.5.1)
data/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  # Complete Documentation
8
8
  Available at https://www.pubnub.com/docs/ruby/pubnub-ruby-sdk-v4 **v4.x**
9
9
 
10
- ## PubNub Gem version 4.0.27
10
+ ## PubNub Gem version 4.1.0
11
11
 
12
12
  ##### YOU MUST HAVE A PUBNUB ACCOUNT TO USE THE API.
13
13
  ##### http://www.pubnub.com/account
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.0.28
1
+ 4.1.0
@@ -0,0 +1,46 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://balancer1g.bronze.aws-pdx-1.ps.pn/v3/history/sub-key/demo-36/message-counts/a,b,c,d?auth=ruby-test-auth-client-one&pnsdk=PubNub-Ruby/4.1.0&timetoken=12123&uuid=ruby-test-uuid-client-one
6
+ body:
7
+ encoding: UTF-8
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - HTTPClient/1.0 (2.8.3, ruby 2.4.2 (2017-09-14))
12
+ Accept:
13
+ - "*/*"
14
+ Date:
15
+ - Wed, 27 Feb 2019 20:08:09 GMT
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Date:
22
+ - Wed, 27 Feb 2019 20:08:09 GMT
23
+ Content-Type:
24
+ - text/javascript; charset="UTF-8"
25
+ Content-Length:
26
+ - '91'
27
+ Connection:
28
+ - keep-alive
29
+ Cache-Control:
30
+ - no-cache
31
+ Access-Control-Allow-Origin:
32
+ - "*"
33
+ Access-Control-Allow-Methods:
34
+ - GET, DELETE, OPTIONS
35
+ Accept-Ranges:
36
+ - bytes
37
+ Age:
38
+ - '0'
39
+ Server:
40
+ - Pubnub
41
+ body:
42
+ encoding: UTF-8
43
+ string: '{"status": 200, "error": false, "error_message": "", "channels": {"a":0,"c":0,"b":1,"d":0}}'
44
+ http_version:
45
+ recorded_at: Wed, 27 Feb 2019 20:08:10 GMT
46
+ recorded_with: VCR 4.0.0
@@ -47,6 +47,7 @@ require 'pubnub/validators/subscribe'
47
47
  require 'pubnub/validators/time'
48
48
  require 'pubnub/validators/where_now'
49
49
  require 'pubnub/validators/delete'
50
+ require 'pubnub/validators/message_counts'
50
51
 
51
52
  require 'pubnub/events/audit'
52
53
  require 'pubnub/events/channel_registration'
@@ -54,6 +55,7 @@ require 'pubnub/events/grant'
54
55
  require 'pubnub/events/heartbeat'
55
56
  require 'pubnub/events/here_now'
56
57
  require 'pubnub/events/history'
58
+ require 'pubnub/events/message_counts'
57
59
  require 'pubnub/events/leave'
58
60
  require 'pubnub/events/presence'
59
61
  require 'pubnub/events/publish'
@@ -5,7 +5,7 @@ module Pubnub
5
5
  # Module that holds generator for all events
6
6
  module Events
7
7
  EVENTS = %w[publish subscribe presence leave history here_now audit grant delete_messages
8
- revoke time heartbeat where_now set_state state channel_registration].freeze
8
+ revoke time heartbeat where_now set_state state channel_registration message_counts].freeze
9
9
 
10
10
  EVENTS.each do |event_name|
11
11
  define_method event_name do |options = {}, &block|
@@ -60,12 +60,13 @@ module Pubnub
60
60
  OPERATION_DELETE = :delete
61
61
  OPERATION_LIST_ALL_CHANNEL_GROUPS = :list_all_channel_groups
62
62
  OPERATION_LIST_ALL_CHANNELS_IN_CHANNEL_GROUP = :list_all_channels_in_channel_group
63
+ OPERATION_MESSAGE_COUNTS = :message_counts
63
64
 
64
65
  OPERATIONS = [
65
66
  OPERATION_SUBSCRIBE, OPERATION_HEARTBEAT, OPERATION_PRESENCE, OPERATION_TIME, OPERATION_HISTORY,
66
67
  OPERATION_HERE_NOW, OPERATION_GLOBAL_HERE_NOW, OPERATION_GET_STATE, OPERATION_LIST_ALL_CHANNEL_GROUPS,
67
68
  OPERATION_LIST_ALL_CHANNELS_IN_CHANNEL_GROUP, OPERATION_CHANNEL_GROUP_ADD, OPERATION_CHANNEL_GROUP_REMOVE,
68
- OPERATION_AUDIT, OPERATION_GRANT, OPERATION_REVOKE, OPERATION_WHERE_NOW
69
+ OPERATION_AUDIT, OPERATION_GRANT, OPERATION_REVOKE, OPERATION_WHERE_NOW, OPERATION_MESSAGE_COUNTS
69
70
  ].freeze
70
71
 
71
72
  # Announcements
@@ -0,0 +1,90 @@
1
+ # Toplevel Pubnub module.
2
+ module Pubnub
3
+ # Holds history functionality
4
+ class MessageCounts < SingleEvent
5
+ include Concurrent::Async
6
+ include Pubnub::Validator::MessageCounts
7
+
8
+ def initialize(options, app)
9
+ @event = :message_counts
10
+ @telemetry_name = :l_mc
11
+ @timetokens = parse_timetokens options[:channel_timetokens] || []
12
+ super
13
+ end
14
+
15
+ private
16
+
17
+ def current_operation
18
+ Pubnub::Constants::OPERATION_MESSAGE_COUNTS
19
+ end
20
+
21
+ def response_message(parsed_response)
22
+ parsed_response[1]
23
+ rescue StandardError
24
+ nil
25
+ end
26
+
27
+ def path
28
+ '/' + [
29
+ 'v3',
30
+ 'history',
31
+ 'sub-key',
32
+ @subscribe_key,
33
+ 'message-counts',
34
+ Formatter.channels_for_url(@channel)
35
+ ].join('/')
36
+ end
37
+
38
+ def parameters(*_args)
39
+ params = super
40
+ if @timetokens.length == 1
41
+ params[:timetoken] = @timetokens.first
42
+ elsif @timetokens.length > 1
43
+ params[:channelTimetokens] = @timetokens.join(',')
44
+ end
45
+ params
46
+ end
47
+
48
+ def valid_envelope(parsed_response, req_res_objects)
49
+ Pubnub::Envelope.new(
50
+ event: @event,
51
+ event_options: @given_options,
52
+ timetoken: nil,
53
+ status: {
54
+ code: req_res_objects[:response].code,
55
+ client_request: req_res_objects[:request],
56
+ server_response: req_res_objects[:response],
57
+
58
+ category: Pubnub::Constants::STATUS_ACK,
59
+ error: false,
60
+ auto_retried: false,
61
+
62
+ data: nil,
63
+ current_timetoken: nil,
64
+ last_timetoken: nil,
65
+ subscribed_channels: nil,
66
+ subscribed_channel_groups: nil,
67
+
68
+ config: get_config
69
+ },
70
+ result: {
71
+ code: req_res_objects[:response].code,
72
+ operation: Pubnub::Constants::OPERATION_HISTORY,
73
+ client_request: req_res_objects[:request],
74
+ server_response: req_res_objects[:response],
75
+ data: parsed_response
76
+ }
77
+ )
78
+ end
79
+
80
+ def parse_timetokens(timetokens)
81
+ timetokens ||= []
82
+ if timetokens.is_a? String
83
+ timetokens = timetokens.split(/\s*,\s*/)
84
+ elsif timetokens.is_a? Integer
85
+ timetokens = [timetokens]
86
+ end
87
+ timetokens.map(&:to_i)
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,42 @@
1
+ # Toplevel Pubnub module.
2
+ module Pubnub
3
+ # Validator module that holds all validators modules
4
+ module Validator
5
+ # Validator for History event
6
+ module MessageCounts
7
+ include CommonValidator
8
+
9
+ def validate!
10
+ return if @skip_validate
11
+
12
+ validate_channel!
13
+ end
14
+
15
+ private
16
+
17
+ def validate_channel!
18
+ chans = @channels
19
+ chans = @channels.split(',') if @channels.is_a? String
20
+ tokens = @timetokens
21
+
22
+ if tokens.length.zero?
23
+ raise(
24
+ ArgumentError.new(
25
+ object: self,
26
+ message: 'channel_timetokens: must contain single or multiple timetokens equaling to number of channels given must be provided.'
27
+ ),
28
+ 'channel_timetokens: must contain single or multiple timetokens equaling to number of channels given must be provided.'
29
+ )
30
+ elsif tokens.length > 1 && tokens.length != chans.length
31
+ raise(
32
+ ArgumentError.new(
33
+ object: self,
34
+ message: 'Number of channel_timetokens: elements must be 1 or same as number of provided channels.'
35
+ ),
36
+ 'Number of channel_timetokens: elements must be 1 or same as number of provided channels.'
37
+ )
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -1,4 +1,4 @@
1
1
  # Toplevel Pubnub module.
2
2
  module Pubnub
3
- VERSION = '4.0.28'.freeze
3
+ VERSION = '4.1.0'.freeze
4
4
  end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+ require 'pry'
3
+
4
+ describe Pubnub::Presence do
5
+
6
+ let(:client) {Pubnub.new(subscribe_key: :key)}
7
+
8
+ around :each do |example|
9
+ example.run_with_retry retry: 10
10
+ end
11
+
12
+ it 'client has \'message_counts\' method' do
13
+ expect(client).to respond_to(:message_counts)
14
+ end
15
+
16
+
17
+ it 'raises an exception when no channel is provided' do
18
+ expect{client.message_counts()}.to raise_error(Pubnub::ArgumentError)
19
+ end
20
+
21
+ context 'when number of timetokens is one' do
22
+ it 'does not raise exception' do
23
+ expect{client.message_counts(channels: 'a', channel_timetokens: 123123123)}.not_to raise_error
24
+ end
25
+ end
26
+
27
+ context 'when number of timetokens in greater than one' do
28
+ it 'raises an exception when number of timetokens and channels mismatches' do
29
+ params = {
30
+ channels: ['12', '123'],
31
+ channel_timetokens: [123123, 123123, 1231231254]
32
+ }
33
+
34
+ expect{client.message_counts(**params)}.to raise_error(Pubnub::ArgumentError)
35
+ end
36
+
37
+ it 'does not raise an exception when number of timetokens and channels is the same' do
38
+ params = {
39
+ channels: ['123123', '12312312'],
40
+ channel_timetokens: [123123, 123123]
41
+ }
42
+
43
+ expect{client.message_counts(**params)}.not_to raise_error
44
+ end
45
+ end
46
+
47
+ context 'integration test' do
48
+ it 'returns valid response' do
49
+ VCR.use_cassette('examples/message_counts/1', record: :none) do
50
+ pubnub = Pubnub.new(
51
+ publish_key: 'demo-36',
52
+ subscribe_key: 'demo-36',
53
+ uuid: 'ruby-test-uuid-client-one',
54
+ auth_key: 'ruby-test-auth-client-one',
55
+ origin: 'balancer1g.bronze.aws-pdx-1.ps.pn'
56
+ )
57
+ envelope = pubnub.message_counts(channel:['a,b,c,d'], channel_timetokens: 12123).value
58
+ res = envelope.result[:data]
59
+ expect(res.keys).to contain_exactly("channels", "error", "error_message", "status")
60
+ expect(res["channels"].keys).to contain_exactly("a", "b", "c", "d")
61
+ end
62
+ end
63
+ end
64
+ 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.28
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - PubNub
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-30 00:00:00.000000000 Z
11
+ date: 2019-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -3863,6 +3863,7 @@ files:
3863
3863
  - fixtures/vcr_cassettes/examples/leave/7.yml
3864
3864
  - fixtures/vcr_cassettes/examples/leave/8.yml
3865
3865
  - fixtures/vcr_cassettes/examples/leave/9.yml
3866
+ - fixtures/vcr_cassettes/examples/message_counts/1.yml
3866
3867
  - fixtures/vcr_cassettes/examples/presence/0.yml
3867
3868
  - fixtures/vcr_cassettes/examples/presence/1.yml
3868
3869
  - fixtures/vcr_cassettes/examples/presence/10.yml
@@ -10577,6 +10578,7 @@ files:
10577
10578
  - lib/pubnub/events/here_now.rb
10578
10579
  - lib/pubnub/events/history.rb
10579
10580
  - lib/pubnub/events/leave.rb
10581
+ - lib/pubnub/events/message_counts.rb
10580
10582
  - lib/pubnub/events/presence.rb
10581
10583
  - lib/pubnub/events/publish.rb
10582
10584
  - lib/pubnub/events/revoke.rb
@@ -10612,6 +10614,7 @@ files:
10612
10614
  - lib/pubnub/validators/here_now.rb
10613
10615
  - lib/pubnub/validators/history.rb
10614
10616
  - lib/pubnub/validators/leave.rb
10617
+ - lib/pubnub/validators/message_counts.rb
10615
10618
  - lib/pubnub/validators/presence.rb
10616
10619
  - lib/pubnub/validators/publish.rb
10617
10620
  - lib/pubnub/validators/revoke.rb
@@ -10652,6 +10655,7 @@ files:
10652
10655
  - spec/lib/events/here_now_spec.rb
10653
10656
  - spec/lib/events/history_spec.rb
10654
10657
  - spec/lib/events/leave_spec.rb
10658
+ - spec/lib/events/message_counts_spec.rb
10655
10659
  - spec/lib/events/presence_delta_spec.rb
10656
10660
  - spec/lib/events/presence_spec.rb
10657
10661
  - spec/lib/events/publish_spec.rb
@@ -10725,6 +10729,7 @@ test_files:
10725
10729
  - spec/lib/events/here_now_spec.rb
10726
10730
  - spec/lib/events/history_spec.rb
10727
10731
  - spec/lib/events/leave_spec.rb
10732
+ - spec/lib/events/message_counts_spec.rb
10728
10733
  - spec/lib/events/presence_delta_spec.rb
10729
10734
  - spec/lib/events/presence_spec.rb
10730
10735
  - spec/lib/events/publish_spec.rb