pubnub 4.4.0 → 4.5.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.

Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/.pubnub.yml +18 -2
  3. data/.travis.yml +4 -2
  4. data/CHANGELOG.md +4 -0
  5. data/Gemfile.lock +10 -1
  6. data/README.md +56 -17
  7. data/VERSION +1 -1
  8. data/fixtures/vcr_cassettes/examples/add_channels_to_push/001.yml +45 -0
  9. data/fixtures/vcr_cassettes/examples/add_channels_to_push/002.yml +45 -0
  10. data/fixtures/vcr_cassettes/examples/add_channels_to_push/003.yml +45 -0
  11. data/fixtures/vcr_cassettes/examples/add_channels_to_push/004.yml +45 -0
  12. data/fixtures/vcr_cassettes/examples/grant/1946.yml +8 -9
  13. data/fixtures/vcr_cassettes/examples/grant/1947.yml +8 -9
  14. data/fixtures/vcr_cassettes/examples/grant/1948.yml +8 -9
  15. data/fixtures/vcr_cassettes/examples/list_push_provisions/001.yml +46 -0
  16. data/fixtures/vcr_cassettes/examples/list_push_provisions/002.yml +45 -0
  17. data/fixtures/vcr_cassettes/examples/list_push_provisions/003.yml +45 -0
  18. data/fixtures/vcr_cassettes/examples/remove_channels_from_push/001.yml +45 -0
  19. data/fixtures/vcr_cassettes/examples/remove_channels_from_push/002.yml +45 -0
  20. data/fixtures/vcr_cassettes/examples/remove_channels_from_push/003.yml +45 -0
  21. data/fixtures/vcr_cassettes/examples/remove_device_from_push/001.yml +45 -0
  22. data/fixtures/vcr_cassettes/examples/remove_device_from_push/002.yml +45 -0
  23. data/fixtures/vcr_cassettes/examples/remove_device_from_push/003.yml +45 -0
  24. data/fixtures/vcr_cassettes/lib/events/get_all_channels_metadata.yml +1 -1
  25. data/fixtures/vcr_cassettes/lib/events/get_channel_members.yml +1 -1
  26. data/fixtures/vcr_cassettes/lib/events/{get_memberships.yml → get_memberships1.yml} +1 -1
  27. data/fixtures/vcr_cassettes/lib/events/get_memberships2.yml +37 -0
  28. data/fixtures/vcr_cassettes/lib/events/{get_uuid_metadata.yml → get_uuid_metadata1.yml} +0 -0
  29. data/fixtures/vcr_cassettes/lib/events/get_uuid_metadata2.yml +76 -0
  30. data/fixtures/vcr_cassettes/lib/events/remove_channel_members.yml +1 -1
  31. data/fixtures/vcr_cassettes/lib/events/{remove_memberships.yml → remove_memberships1.yml} +0 -0
  32. data/fixtures/vcr_cassettes/lib/events/remove_memberships2.yml +39 -0
  33. data/fixtures/vcr_cassettes/lib/events/{remove_uuid_metadata.yml → remove_uuid_metadata1.yml} +0 -0
  34. data/fixtures/vcr_cassettes/lib/events/remove_uuid_metadata2.yml +76 -0
  35. data/fixtures/vcr_cassettes/lib/events/{set_memberships.yml → set_memberships1.yml} +0 -0
  36. data/fixtures/vcr_cassettes/lib/events/set_memberships2.yml +39 -0
  37. data/fixtures/vcr_cassettes/lib/events/{set_uuid_metadata.yml → set_uuid_metadata1.yml} +0 -0
  38. data/fixtures/vcr_cassettes/lib/events/set_uuid_metadata2.yml +78 -0
  39. data/lib/pubnub/client.rb +4 -1
  40. data/lib/pubnub/event.rb +3 -1
  41. data/lib/pubnub/events/add_channels_to_push.rb +29 -13
  42. data/lib/pubnub/events/get_all_channels_metadata.rb +13 -1
  43. data/lib/pubnub/events/get_all_uuid_metadata.rb +13 -1
  44. data/lib/pubnub/events/get_channel_members.rb +21 -1
  45. data/lib/pubnub/events/get_channel_metadata.rb +6 -1
  46. data/lib/pubnub/events/get_memberships.rb +22 -2
  47. data/lib/pubnub/events/get_uuid_metadata.rb +7 -2
  48. data/lib/pubnub/events/grant.rb +1 -1
  49. data/lib/pubnub/events/list_push_provisions.rb +29 -12
  50. data/lib/pubnub/events/remove_channel_members.rb +22 -2
  51. data/lib/pubnub/events/remove_channels_from_push.rb +29 -13
  52. data/lib/pubnub/events/remove_device_from_push.rb +30 -14
  53. data/lib/pubnub/events/remove_memberships.rb +23 -3
  54. data/lib/pubnub/events/remove_uuid_metadata.rb +1 -1
  55. data/lib/pubnub/events/set_channel_members.rb +21 -1
  56. data/lib/pubnub/events/set_channel_metadata.rb +6 -1
  57. data/lib/pubnub/events/set_memberships.rb +22 -2
  58. data/lib/pubnub/events/set_uuid_metadata.rb +7 -2
  59. data/lib/pubnub/formatter.rb +28 -1
  60. data/lib/pubnub/validators/add_channels_to_push.rb +52 -0
  61. data/lib/pubnub/validators/grant.rb +1 -1
  62. data/lib/pubnub/validators/list_push_provisions.rb +43 -0
  63. data/lib/pubnub/validators/remove_channels_from_push.rb +52 -0
  64. data/lib/pubnub/validators/remove_device_from_push.rb +43 -0
  65. data/lib/pubnub/version.rb +1 -1
  66. data/spec/examples/add_channels_to_push_spec.rb +178 -0
  67. data/spec/examples/{grant_examples_spec.rb → grant_examples_1_spec.rb} +0 -9009
  68. data/spec/examples/grant_examples_2_spec.rb +9107 -0
  69. data/spec/examples/list_push_provisions_spec.rb +164 -0
  70. data/spec/examples/presence_examples_spec.rb +222 -186
  71. data/spec/examples/remove_channels_from_push_spec.rb +164 -0
  72. data/spec/examples/remove_device_from_push_spec.rb +164 -0
  73. data/spec/examples/revoke_examples_1_spec.rb +27013 -0
  74. data/spec/examples/revoke_examples_2_spec.rb +27012 -0
  75. data/spec/examples/revoke_examples_3_spec.rb +17967 -0
  76. data/spec/examples/status_request_message_count_exceeded_spec.rb +4 -1
  77. data/spec/examples/subscribe_examples_1_spec.rb +26972 -0
  78. data/spec/examples/subscribe_examples_2_spec.rb +19575 -0
  79. data/spec/lib/connection_callback_spec.rb +4 -3
  80. data/spec/lib/events/membership_spec.rb +38 -11
  81. data/spec/lib/events/presence_delta_spec.rb +9 -6
  82. data/spec/lib/events/presence_spec.rb +13 -7
  83. data/spec/lib/events/subscribe_spec.rb +56 -32
  84. data/spec/lib/events/uuid_metadata_spec.rb +36 -6
  85. data/spec/lib/super_admin_spec.rb +8 -4
  86. data/spec/spec_helper.rb +23 -7
  87. metadata +53 -15
  88. data/lib/pubnub/validators/push.rb +0 -43
  89. data/spec/examples/revoke_examples_spec.rb +0 -71950
  90. data/spec/examples/subscribe_examples_spec.rb +0 -45184
@@ -3,12 +3,14 @@ module Pubnub
3
3
  # Push related event
4
4
  class RemoveDeviceFromPush < SingleEvent
5
5
  include Concurrent::Async
6
- include Pubnub::Validator::Push
6
+ include Pubnub::Validator::RemoveDeviceFromPush
7
7
 
8
8
  def initialize(options, app)
9
- super
10
9
  @event = current_operation
11
- @params = @given_options
10
+ @telemetry_name = :l_push
11
+ super
12
+ # `environment` should
13
+ @environment ||= 'development' if @push_gateway.eql? 'apns2'
12
14
  end
13
15
 
14
16
  private
@@ -24,21 +26,34 @@ module Pubnub
24
26
  end
25
27
 
26
28
  def path
27
- '/' + [
28
- 'v1',
29
- 'push',
30
- 'sub-key',
31
- @subscribe_key,
32
- 'devices',
33
- @params.fetch(:push_token),
34
- 'remove'
35
- ].join('/')
29
+ if @push_gateway.eql? 'apns2'
30
+ '/' + [
31
+ 'v2',
32
+ 'push',
33
+ 'sub-key',
34
+ @subscribe_key,
35
+ 'devices-apns2',
36
+ @push_token,
37
+ 'remove'
38
+ ].join('/')
39
+ else
40
+ '/' + [
41
+ 'v1',
42
+ 'push',
43
+ 'sub-key',
44
+ @subscribe_key,
45
+ 'devices',
46
+ @push_token,
47
+ 'remove'
48
+ ].join('/')
49
+ end
36
50
  end
37
51
 
38
52
  def parameters(*_args)
39
53
  params = super
40
- params.merge!(@params.select { |p, _| required_params.include?(p) })
41
- params[:uuid] = @params[:uuid] if @params.key?(:uuid)
54
+ params[:type] = @push_gateway unless @push_gateway.eql? 'apns2'
55
+ params[:environment] = @environment if @push_gateway.eql? 'apns2'
56
+ params[:topic] = @topic if @push_gateway.eql? 'apns2'
42
57
  params
43
58
  end
44
59
 
@@ -49,6 +64,7 @@ module Pubnub
49
64
  timetoken: nil,
50
65
  status: {
51
66
  code: req_res_objects[:response].code,
67
+ operation: current_operation,
52
68
  client_request: req_res_objects[:request],
53
69
  server_response: req_res_objects[:response],
54
70
 
@@ -10,7 +10,7 @@ module Pubnub
10
10
  def initialize(options, app)
11
11
  @event = current_operation
12
12
  @telemetry_name = :l_obj
13
- @uuid = options[:uuid]
13
+ @uuid = options[:uuid].nil? ? app.env[:uuid] : options[:uuid]
14
14
  @limit = [options[:limit], 100].min unless options[:limit].nil?
15
15
  @sort = options[:sort].join(",") if options[:sort] && !options[:sort].empty?
16
16
  @filter = options[:filter] if options[:filter] && !options[:filter].empty?
@@ -39,7 +39,7 @@ module Pubnub
39
39
  Pubnub.logger.debug('Pubnub::RemoveMemberships') { "Fired event #{self.class}" }
40
40
 
41
41
  memberships = @channels.map do |membership|
42
- { channel: { id: membership[:channel] } }
42
+ { channel: { id: membership } }
43
43
  end
44
44
 
45
45
  body = Formatter.format_message({ delete: memberships }, @cipher_key, false)
@@ -81,6 +81,21 @@ module Pubnub
81
81
  end
82
82
 
83
83
  def valid_envelope(parsed_response, req_res_objects)
84
+ memberships = parsed_response['data'].map { |uuid_membership|
85
+ membership = Hash.new
86
+ uuid_membership.each{ |k,v| membership[k.to_sym] = v }
87
+
88
+ unless membership[:channel].nil?
89
+ channel_metadata = Hash.new
90
+ membership[:channel].each{ |k,v| channel_metadata[k.to_sym] = v }
91
+ channel_metadata[:updated] = Date._parse(channel_metadata[:updated]) unless channel_metadata[:updated].nil?
92
+ membership[:channel] = channel_metadata
93
+ end
94
+ membership[:updated] = Date._parse(membership[:updated]) unless membership[:updated].nil?
95
+
96
+ membership
97
+ }
98
+
84
99
  Pubnub::Envelope.new(
85
100
  event: @event,
86
101
  event_options: @given_options,
@@ -91,7 +106,12 @@ module Pubnub
91
106
  operation: current_operation,
92
107
  client_request: req_res_objects[:request],
93
108
  server_response: req_res_objects[:response],
94
- data: parsed_response
109
+ data: {
110
+ memberships: memberships,
111
+ totalCount: parsed_response['totalCount'],
112
+ next: parsed_response['next'],
113
+ prev: parsed_response['prev']
114
+ }
95
115
  },
96
116
 
97
117
  status: {
@@ -10,7 +10,7 @@ module Pubnub
10
10
  def initialize(options, app)
11
11
  @event = current_operation
12
12
  @telemetry_name = :l_obj
13
- @uuid = options[:uuid]
13
+ @uuid = options[:uuid].nil? ? app.env[:uuid] : options[:uuid]
14
14
  super
15
15
  end
16
16
 
@@ -84,6 +84,21 @@ module Pubnub
84
84
  end
85
85
 
86
86
  def valid_envelope(parsed_response, req_res_objects)
87
+ members = parsed_response['data'].map { |channel_member|
88
+ member = Hash.new
89
+ channel_member.each{ |k,v| member[k.to_sym] = v }
90
+
91
+ unless member[:uuid].nil?
92
+ uuid_metadata = Hash.new
93
+ member[:uuid].each{ |k,v| uuid_metadata[k.to_sym] = v }
94
+ uuid_metadata[:updated] = Date._parse(uuid_metadata[:updated]) unless uuid_metadata[:updated].nil?
95
+ member[:uuid] = uuid_metadata
96
+ end
97
+ member[:updated] = Date._parse(member[:updated]) unless member[:updated].nil?
98
+
99
+ member
100
+ }
101
+
87
102
  Pubnub::Envelope.new(
88
103
  event: @event,
89
104
  event_options: @given_options,
@@ -94,7 +109,12 @@ module Pubnub
94
109
  operation: current_operation,
95
110
  client_request: req_res_objects[:request],
96
111
  server_response: req_res_objects[:response],
97
- data: parsed_response
112
+ data: {
113
+ members: members,
114
+ totalCount: parsed_response['totalCount'],
115
+ next: parsed_response['next'],
116
+ prev: parsed_response['prev']
117
+ }
98
118
  },
99
119
 
100
120
  status: {
@@ -58,6 +58,11 @@ module Pubnub
58
58
  end
59
59
 
60
60
  def valid_envelope(parsed_response, req_res_objects)
61
+ data = parsed_response['data']
62
+ metadata = Hash.new
63
+ data.each{ |k,v| metadata[k.to_sym] = v }
64
+ metadata[:updated] = Date._parse(metadata[:updated]) unless metadata[:updated].nil?
65
+
61
66
  Pubnub::Envelope.new(
62
67
  event: @event,
63
68
  event_options: @given_options,
@@ -68,7 +73,7 @@ module Pubnub
68
73
  operation: current_operation,
69
74
  client_request: req_res_objects[:request],
70
75
  server_response: req_res_objects[:response],
71
- data: parsed_response
76
+ data: metadata
72
77
  },
73
78
 
74
79
  status: {
@@ -10,7 +10,7 @@ module Pubnub
10
10
  def initialize(options, app)
11
11
  @event = current_operation
12
12
  @telemetry_name = :l_obj
13
- @uuid = options[:uuid]
13
+ @uuid = options[:uuid].nil? ? app.env[:uuid] : options[:uuid]
14
14
  @limit = [options[:limit], 100].min unless options[:limit].nil?
15
15
  @sort = options[:sort].join(",") if options[:sort] && !options[:sort].empty?
16
16
  @filter = options[:filter] if options[:filter] && !options[:filter].empty?
@@ -84,6 +84,21 @@ module Pubnub
84
84
  end
85
85
 
86
86
  def valid_envelope(parsed_response, req_res_objects)
87
+ memberships = parsed_response['data'].map { |uuid_membership|
88
+ membership = Hash.new
89
+ uuid_membership.each{ |k,v| membership[k.to_sym] = v }
90
+
91
+ unless membership[:channel].nil?
92
+ channel_metadata = Hash.new
93
+ membership[:channel].each{ |k,v| channel_metadata[k.to_sym] = v }
94
+ channel_metadata[:updated] = Date._parse(channel_metadata[:updated]) unless channel_metadata[:updated].nil?
95
+ membership[:channel] = channel_metadata
96
+ end
97
+ membership[:updated] = Date._parse(membership[:updated]) unless membership[:updated].nil?
98
+
99
+ membership
100
+ }
101
+
87
102
  Pubnub::Envelope.new(
88
103
  event: @event,
89
104
  event_options: @given_options,
@@ -94,7 +109,12 @@ module Pubnub
94
109
  operation: current_operation,
95
110
  client_request: req_res_objects[:request],
96
111
  server_response: req_res_objects[:response],
97
- data: parsed_response
112
+ data: {
113
+ memberships: memberships,
114
+ totalCount: parsed_response['totalCount'],
115
+ next: parsed_response['next'],
116
+ prev: parsed_response['prev']
117
+ }
98
118
  },
99
119
 
100
120
  status: {
@@ -10,7 +10,7 @@ module Pubnub
10
10
  def initialize(options, app)
11
11
  @event = current_operation
12
12
  @telemetry_name = :l_obj
13
- @uuid = options[:uuid]
13
+ @uuid = options[:uuid].nil? ? app.env[:uuid] : options[:uuid]
14
14
 
15
15
  # Clean up user-provided metadata object from nils.
16
16
  @metadata = options[:metadata].delete_if { |_k, v| v.blank? } unless options[:metadata].nil?
@@ -59,6 +59,11 @@ module Pubnub
59
59
  end
60
60
 
61
61
  def valid_envelope(parsed_response, req_res_objects)
62
+ data = parsed_response['data']
63
+ metadata = Hash.new
64
+ data.each{ |k,v| metadata[k.to_sym] = v }
65
+ metadata[:updated] = Date._parse(metadata[:updated]) unless metadata[:updated].nil?
66
+
62
67
  Pubnub::Envelope.new(
63
68
  event: @event,
64
69
  event_options: @given_options,
@@ -69,7 +74,7 @@ module Pubnub
69
74
  operation: current_operation,
70
75
  client_request: req_res_objects[:request],
71
76
  server_response: req_res_objects[:response],
72
- data: parsed_response
77
+ data: metadata
73
78
  },
74
79
 
75
80
  status: {
@@ -31,6 +31,16 @@ module Pubnub
31
31
  )
32
32
  end
33
33
 
34
+ def format_uuid(uuids, should_encode = true)
35
+ make_uuid_array(uuids).map do |uuid|
36
+ if should_encode
37
+ encode(uuid)
38
+ else
39
+ uuid.to_s
40
+ end
41
+ end
42
+ end
43
+
34
44
  # Transforms message to json and encode it
35
45
  def format_message(message, cipher_key, uri_escape = true)
36
46
  if cipher_key
@@ -70,6 +80,23 @@ module Pubnub
70
80
  end
71
81
  end
72
82
 
83
+ def make_uuid_array(uuid)
84
+ case uuid.class.to_s
85
+ when 'String'
86
+ uuid.to_s.split(',')
87
+ when 'Symbol'
88
+ uuid.to_s.split(',')
89
+ when 'Array'
90
+ uuid.map(&:to_s)
91
+ when 'NilClass'
92
+ []
93
+ else
94
+ raise Pubnub::ArgumentError.new(
95
+ message: 'UUID has to be String, Symbol or Array'
96
+ ), 'UUID has to be String, Symbol or Array'
97
+ end
98
+ end
99
+
73
100
  # Parses string to JSON
74
101
  def parse_json(string)
75
102
  [JSON.parse(string), nil]
@@ -84,7 +111,7 @@ module Pubnub
84
111
  if %w[meta ortt].include?(key.to_s)
85
112
  encoded_value = URI.encode_www_form_component(value.to_json).gsub('+', '%20')
86
113
  params << "#{key}=#{encoded_value}&"
87
- elsif %w[t state filter-expr].include?(key.to_s)
114
+ elsif %w[t state filter filter-expr].include?(key.to_s)
88
115
  params << "#{key}=#{value}&"
89
116
  else
90
117
  params << "#{key}=#{URI.encode_www_form_component(value).gsub('+', '%20')}&"
@@ -0,0 +1,52 @@
1
+ # Toplevel Pubnub module.
2
+ module Pubnub
3
+ # Validator module that holds all validators modules
4
+ module Validator
5
+ # Validator for AddChannelsToPush event
6
+ module AddChannelsToPush
7
+ include CommonValidator
8
+
9
+ def validate!
10
+ return if @skip_validate
11
+ validate_push_token!
12
+ validate_push_gateway!
13
+ validate_channel!
14
+ validate_topic! if @push_gateway.eql? 'apns2'
15
+ end
16
+
17
+ private
18
+
19
+ def validate_push_token!
20
+ return unless @push_token.nil? || @push_token.empty?
21
+ raise(
22
+ ArgumentError.new,
23
+ ':push_token is required for AddChannelsToPush event.'
24
+ )
25
+ end
26
+
27
+ def validate_push_gateway!
28
+ return unless @push_gateway.nil? || @push_gateway.empty?
29
+ raise(
30
+ ArgumentError.new,
31
+ ':push_gateway is required for AddChannelsToPush event.'
32
+ )
33
+ end
34
+
35
+ def validate_channel!
36
+ return unless @channel.nil? || @channel.empty?
37
+ raise(
38
+ ArgumentError.new,
39
+ ':channel is required for AddChannelsToPush event.'
40
+ )
41
+ end
42
+
43
+ def validate_topic!
44
+ return unless @topic.nil? || @topic.empty?
45
+ raise(
46
+ ArgumentError.new,
47
+ ':topic is required for AddChannelsToPush event.'
48
+ )
49
+ end
50
+ end
51
+ end
52
+ end
@@ -38,7 +38,7 @@ module Pubnub
38
38
  end
39
39
 
40
40
  def validate_uuids!
41
- return if @uuid.nil?
41
+ return if @uuids.nil?
42
42
 
43
43
  raise(
44
44
  ArgumentError.new(object: self, message: ':uuid should not be empty for grant event.'),
@@ -0,0 +1,43 @@
1
+ # Toplevel Pubnub module.
2
+ module Pubnub
3
+ # Validator module that holds all validators modules
4
+ module Validator
5
+ # Validator for ListPushProvisions event
6
+ module ListPushProvisions
7
+ include CommonValidator
8
+
9
+ def validate!
10
+ return if @skip_validate
11
+ validate_push_token!
12
+ validate_push_gateway!
13
+ validate_topic! if @push_gateway.eql? 'apns2'
14
+ end
15
+
16
+ private
17
+
18
+ def validate_push_token!
19
+ return unless @push_token.nil? || @push_token.empty?
20
+ raise(
21
+ ArgumentError.new,
22
+ ':push_token is required for ListPushProvisions event.'
23
+ )
24
+ end
25
+
26
+ def validate_push_gateway!
27
+ return unless @push_gateway.nil? || @push_gateway.empty?
28
+ raise(
29
+ ArgumentError.new,
30
+ ':push_gateway is required for ListPushProvisions event.'
31
+ )
32
+ end
33
+
34
+ def validate_topic!
35
+ return unless @topic.nil? || @topic.empty?
36
+ raise(
37
+ ArgumentError.new,
38
+ ':topic is required for ListPushProvisions event.'
39
+ )
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,52 @@
1
+ # Toplevel Pubnub module.
2
+ module Pubnub
3
+ # Validator module that holds all validators modules
4
+ module Validator
5
+ # Validator for RemoveChannelsFromPush event
6
+ module RemoveChannelsFromPush
7
+ include CommonValidator
8
+
9
+ def validate!
10
+ return if @skip_validate
11
+ validate_push_token!
12
+ validate_push_gateway!
13
+ validate_channel!
14
+ validate_topic! if @push_gateway.eql? 'apns2'
15
+ end
16
+
17
+ private
18
+
19
+ def validate_push_token!
20
+ return unless @push_token.nil? || @push_token.empty?
21
+ raise(
22
+ ArgumentError.new,
23
+ ':push_token is required for RemoveChannelsFromPush event.'
24
+ )
25
+ end
26
+
27
+ def validate_push_gateway!
28
+ return unless @push_gateway.nil? || @push_gateway.empty?
29
+ raise(
30
+ ArgumentError.new,
31
+ ':push_gateway is required for RemoveChannelsFromPush event.'
32
+ )
33
+ end
34
+
35
+ def validate_channel!
36
+ return unless @channel.nil? || @channel.empty?
37
+ raise(
38
+ ArgumentError.new,
39
+ ':channel is required for RemoveChannelsFromPush event.'
40
+ )
41
+ end
42
+
43
+ def validate_topic!
44
+ return unless @topic.nil? || @topic.empty?
45
+ raise(
46
+ ArgumentError.new,
47
+ ':topic is required for RemoveChannelsFromPush event.'
48
+ )
49
+ end
50
+ end
51
+ end
52
+ end