pubnub 5.3.5 → 5.5.0

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.
@@ -12,23 +12,26 @@ module Pubnub
12
12
  @telemetry_name = :l_obj
13
13
  @channel = options[:channel]
14
14
  @limit = [options[:limit], 100].min unless options[:limit].nil?
15
- @sort = options[:sort].join(",") if options[:sort] && !options[:sort].empty?
15
+ @sort = options[:sort].join(',') if options[:sort] && !options[:sort].empty?
16
16
  @filter = options[:filter] if options[:filter] && !options[:filter].empty?
17
17
  @start = options[:start] if options[:start] && !options[:start].empty?
18
18
  @end = options[:end] if options[:start] && !options[:end].empty?
19
19
 
20
+ @include = []
20
21
  if options[:include]
21
22
  include = options[:include]
22
- @include_count = [0, '0', false].include?(include[:count]) ? "0" : "1" unless include[:count].nil?
23
- @include_custom = "custom" if !include[:custom].nil? && ![0, '0', false].include?(include[:custom])
24
- @include_uuid_metadata = "uuid" if !include[:uuid_metadata].nil? && ![0, '0', false].include?(include[:uuid_metadata])
25
- @include_uuid_custom = "uuid.custom" if !include[:uuid_custom].nil? && ![0, '0', false].include?(include[:uuid_custom])
26
-
27
- @include = [@include_custom, @include_uuid_metadata, @include_uuid_custom].reject { |flag| flag.to_s.empty? }
23
+ @include.push('type') unless include[:type].nil? || [0, '0', false].include?(include[:type])
24
+ @include.push('status') unless include[:status].nil? || [0, '0', false].include?(include[:status])
25
+ @include.push('custom') unless include[:custom].nil? || [0, '0', false].include?(include[:custom])
26
+ @include.push('uuid') unless include[:uuid_metadata].nil? || [0, '0', false].include?(include[:uuid_metadata])
27
+ @include.push('uuid.type') unless include[:uuid_type].nil? || [0, '0', false].include?(include[:uuid_type])
28
+ @include.push('uuid.status') unless include[:uuid_status].nil? || [0, '0', false].include?(include[:uuid_status])
29
+ @include.push('uuid.custom') unless include[:uuid_custom].nil? || [0, '0', false].include?(include[:uuid_custom])
30
+ @include_count = [0, '0', false].include?(include[:count]) ? '0' : '1' unless include[:count].nil?
28
31
  end
29
32
 
30
33
  # Collections by default return number of available entries.
31
- @include_count = "1" if @include_count.nil?
34
+ @include_count = '1' if @include_count.nil?
32
35
 
33
36
  super
34
37
  end
@@ -47,7 +50,7 @@ module Pubnub
47
50
  parameters[:start] = @start unless @start.nil?
48
51
  parameters[:end] = @end if @end && !@start
49
52
  parameters[:count] = @include_count unless @include_count.nil?
50
- parameters[:include] = @include.sort.join(",") if @include && !@include.empty?
53
+ parameters[:include] = @include.sort.join(',') unless @include.empty?
51
54
 
52
55
  parameters
53
56
  end
@@ -64,20 +67,20 @@ module Pubnub
64
67
  end
65
68
 
66
69
  def valid_envelope(parsed_response, req_res_objects)
67
- members = parsed_response['data'].map { |channel_member|
68
- member = Hash.new
69
- channel_member.each{ |k,v| member[k.to_sym] = v }
70
+ members = parsed_response['data'].map do |channel_member|
71
+ member = {}
72
+ channel_member.each { |k, v| member[k.to_sym] = v }
70
73
 
71
74
  unless member[:uuid].nil?
72
- uuid_metadata = Hash.new
73
- member[:uuid].each{ |k,v| uuid_metadata[k.to_sym] = v }
75
+ uuid_metadata = {}
76
+ member[:uuid].each { |k, v| uuid_metadata[k.to_sym] = v }
74
77
  uuid_metadata[:updated] = Date._parse(uuid_metadata[:updated]) unless uuid_metadata[:updated].nil?
75
78
  member[:uuid] = uuid_metadata
76
79
  end
77
80
  member[:updated] = Date._parse(member[:updated]) unless member[:updated].nil?
78
81
 
79
82
  member
80
- }
83
+ end
81
84
 
82
85
  Pubnub::Envelope.new(
83
86
  event: @event,
@@ -12,12 +12,16 @@ module Pubnub
12
12
  @telemetry_name = :l_obj
13
13
  @channel = options[:channel]
14
14
 
15
+ @include = []
15
16
  if options[:include]
16
- @include = "custom" unless [0, '0', false].include?(options[:include][:custom])
17
+ include = options[:include]
18
+ @include.push('type') unless include[:type].nil? || [0, '0', false].include?(include[:type])
19
+ @include.push('status') unless include[:status].nil? || [0, '0', false].include?(include[:status])
20
+ @include.push('custom') unless include[:custom].nil? || [0, '0', false].include?(include[:custom])
17
21
  end
18
22
 
19
23
  # Single entity creation should return it's 'custom' field by default.
20
- @include = "custom" if @include.nil?
24
+ @include = ['custom'] if @include.empty?
21
25
  super
22
26
  end
23
27
 
@@ -29,7 +33,7 @@ module Pubnub
29
33
 
30
34
  def parameters(signature = false)
31
35
  parameters = super(signature)
32
- parameters[:include] = @include
36
+ parameters[:include] = @include.sort.join(',') unless @include.empty?
33
37
 
34
38
  parameters
35
39
  end
@@ -46,8 +50,8 @@ module Pubnub
46
50
 
47
51
  def valid_envelope(parsed_response, req_res_objects)
48
52
  data = parsed_response['data']
49
- metadata = Hash.new
50
- data.each{ |k,v| metadata[k.to_sym] = v }
53
+ metadata = {}
54
+ data.each { |k, v| metadata[k.to_sym] = v }
51
55
  metadata[:updated] = Date._parse(metadata[:updated]) unless metadata[:updated].nil?
52
56
 
53
57
  Pubnub::Envelope.new(
@@ -12,23 +12,26 @@ module Pubnub
12
12
  @telemetry_name = :l_obj
13
13
  @uuid = options[:uuid].nil? ? app.user_id : options[:uuid]
14
14
  @limit = [options[:limit], 100].min unless options[:limit].nil?
15
- @sort = options[:sort].join(",") if options[:sort] && !options[:sort].empty?
15
+ @sort = options[:sort].join(',') if options[:sort] && !options[:sort].empty?
16
16
  @filter = options[:filter] if options[:filter] && !options[:filter].empty?
17
17
  @start = options[:start] if options[:start] && !options[:start].empty?
18
18
  @end = options[:end] if options[:start] && !options[:end].empty?
19
19
 
20
+ @include = []
20
21
  if options[:include]
21
22
  include = options[:include]
22
- @include_count = [0, '0', false].include?(include[:count]) ? "0" : "1" unless include[:count].nil?
23
- @include_custom = "custom" if !include[:custom].nil? && ![0, '0', false].include?(include[:custom])
24
- @include_channel_metadata = "channel" if !include[:channel_metadata].nil? && ![0, '0', false].include?(include[:channel_metadata])
25
- @include_channel_custom = "channel.custom" if !include[:channel_custom].nil? && ![0, '0', false].include?(include[:channel_custom])
26
-
27
- @include = [@include_custom, @include_channel_metadata, @include_channel_custom].reject { |flag| flag.to_s.empty? }
23
+ @include.push('type') unless include[:type].nil? || [0, '0', false].include?(include[:type])
24
+ @include.push('status') unless include[:status].nil? || [0, '0', false].include?(include[:status])
25
+ @include.push('custom') unless include[:custom].nil? || [0, '0', false].include?(include[:custom])
26
+ @include.push('channel') unless include[:channel_metadata].nil? || [0, '0', false].include?(include[:channel_metadata])
27
+ @include.push('channel.type') unless include[:channel_type].nil? || [0, '0', false].include?(include[:channel_type])
28
+ @include.push('channel.status') unless include[:channel_status].nil? || [0, '0', false].include?(include[:channel_status])
29
+ @include.push('channel.custom') unless include[:channel_custom].nil? || [0, '0', false].include?(include[:channel_custom])
30
+ @include_count = [0, '0', false].include?(include[:count]) ? '0' : '1' unless include[:count].nil?
28
31
  end
29
32
 
30
33
  # Collections by default return number of available entries.
31
- @include_count = "1" if @include_count.nil?
34
+ @include_count = '1' if @include_count.nil?
32
35
 
33
36
  super
34
37
  end
@@ -47,7 +50,7 @@ module Pubnub
47
50
  parameters[:start] = @start unless @start.nil?
48
51
  parameters[:end] = @end if @end && !@start
49
52
  parameters[:count] = @include_count unless @include_count.nil?
50
- parameters[:include] = @include.sort.join(",") if @include && !@include.empty?
53
+ parameters[:include] = @include.sort.join(',') unless @include.empty?
51
54
 
52
55
  parameters
53
56
  end
@@ -64,20 +67,20 @@ module Pubnub
64
67
  end
65
68
 
66
69
  def valid_envelope(parsed_response, req_res_objects)
67
- memberships = parsed_response['data'].map { |uuid_membership|
68
- membership = Hash.new
69
- uuid_membership.each{ |k,v| membership[k.to_sym] = v }
70
+ memberships = parsed_response['data'].map do |uuid_membership|
71
+ membership = {}
72
+ uuid_membership.each { |k, v| membership[k.to_sym] = v }
70
73
 
71
74
  unless membership[:channel].nil?
72
- channel_metadata = Hash.new
73
- membership[:channel].each{ |k,v| channel_metadata[k.to_sym] = v }
75
+ channel_metadata = {}
76
+ membership[:channel].each { |k, v| channel_metadata[k.to_sym] = v }
74
77
  channel_metadata[:updated] = Date._parse(channel_metadata[:updated]) unless channel_metadata[:updated].nil?
75
78
  membership[:channel] = channel_metadata
76
79
  end
77
80
  membership[:updated] = Date._parse(membership[:updated]) unless membership[:updated].nil?
78
81
 
79
82
  membership
80
- }
83
+ end
81
84
 
82
85
  Pubnub::Envelope.new(
83
86
  event: @event,
@@ -12,12 +12,16 @@ module Pubnub
12
12
  @telemetry_name = :l_obj
13
13
  @uuid = options[:uuid].nil? ? app.user_id : options[:uuid]
14
14
 
15
+ @include = []
15
16
  if options[:include]
16
- @include = "custom" unless [0, '0', false].include?(options[:include][:custom])
17
+ include = options[:include]
18
+ @include.push('type') unless include[:type].nil? || [0, '0', false].include?(include[:type])
19
+ @include.push('status') unless include[:status].nil? || [0, '0', false].include?(include[:status])
20
+ @include.push('custom') unless include[:custom].nil? || [0, '0', false].include?(include[:custom])
17
21
  end
18
22
 
19
23
  # Single entity creation should return it's 'custom' field by default.
20
- @include = "custom" if @include.nil?
24
+ @include = ['custom'] if @include.empty?
21
25
  super
22
26
  end
23
27
 
@@ -29,7 +33,7 @@ module Pubnub
29
33
 
30
34
  def parameters(signature = false)
31
35
  parameters = super(signature)
32
- parameters[:include] = @include
36
+ parameters[:include] = @include.sort.join(',') unless @include.empty?
33
37
 
34
38
  parameters
35
39
  end
@@ -46,8 +50,8 @@ module Pubnub
46
50
 
47
51
  def valid_envelope(parsed_response, req_res_objects)
48
52
  data = parsed_response['data']
49
- metadata = Hash.new
50
- data.each{ |k,v| metadata[k.to_sym] = v }
53
+ metadata = {}
54
+ data.each { |k, v| metadata[k.to_sym] = v }
51
55
  metadata[:updated] = Date._parse(metadata[:updated]) unless metadata[:updated].nil?
52
56
 
53
57
  Pubnub::Envelope.new(
@@ -52,6 +52,7 @@ module Pubnub
52
52
  params = super
53
53
 
54
54
  empty_if_blank = {
55
+ custom_message_type: @custom_message_type,
55
56
  store: @store,
56
57
  meta: @meta,
57
58
  ttl: @ttl
@@ -12,25 +12,28 @@ module Pubnub
12
12
  @telemetry_name = :l_obj
13
13
  @channel = options[:channel]
14
14
  @limit = [options[:limit], 100].min unless options[:limit].nil?
15
- @sort = options[:sort].join(",") if options[:sort] && !options[:sort].empty?
15
+ @sort = options[:sort].join(',') if options[:sort] && !options[:sort].empty?
16
16
  @filter = options[:filter] if options[:filter] && !options[:filter].empty?
17
17
  @start = options[:start] if options[:start] && !options[:start].empty?
18
18
  @end = options[:end] if options[:start] && !options[:end].empty?
19
19
 
20
+ @include = []
20
21
  if options[:include]
21
22
  include = options[:include]
22
- @include_count = [0, '0', false].include?(include[:count]) ? "0" : "1" unless include[:count].nil?
23
- @include_custom = "custom" if !include[:custom].nil? && ![0, '0', false].include?(include[:custom])
24
- @include_uuid_metadata = "uuid" if !include[:uuid_metadata].nil? && ![0, '0', false].include?(include[:uuid_metadata])
25
- @include_uuid_custom = "uuid.custom" if !include[:uuid_custom].nil? && ![0, '0', false].include?(include[:uuid_custom])
26
-
27
- @include = [@include_custom, @include_uuid_metadata, @include_uuid_custom].reject { |flag| flag.to_s.empty? }
23
+ @include.push('type') unless include[:type].nil? || [0, '0', false].include?(include[:type])
24
+ @include.push('status') unless include[:status].nil? || [0, '0', false].include?(include[:status])
25
+ @include.push('custom') unless include[:custom].nil? || [0, '0', false].include?(include[:custom])
26
+ @include.push('uuid') unless include[:uuid_metadata].nil? || [0, '0', false].include?(include[:uuid_metadata])
27
+ @include.push('uuid.type') unless include[:uuid_type].nil? || [0, '0', false].include?(include[:uuid_type])
28
+ @include.push('uuid.status') unless include[:uuid_status].nil? || [0, '0', false].include?(include[:uuid_status])
29
+ @include.push('uuid.custom') unless include[:uuid_custom].nil? || [0, '0', false].include?(include[:uuid_custom])
30
+ @include_count = [0, '0', false].include?(include[:count]) ? '0' : '1' unless include[:count].nil?
28
31
  end
29
32
 
30
33
  @uuids = options[:uuids] if options[:uuids] && !options[:uuids].empty?
31
34
 
32
35
  # Collections by default return number of available entries.
33
- @include_count = "1" if @include_count.nil?
36
+ @include_count = '1' if @include_count.nil?
34
37
 
35
38
  super
36
39
  end
@@ -41,6 +44,8 @@ module Pubnub
41
44
  members = @uuids.map do |member|
42
45
  member_object = { uuid: { id: member[:uuid] } }
43
46
  member_object[:custom] = member[:custom] if member[:custom] && !member[:custom].empty?
47
+ member_object[:type] = member[:type] if member[:type] && !member[:type].empty?
48
+ member_object[:status] = member[:status] if member[:status] && !member[:status].empty?
44
49
 
45
50
  member_object
46
51
  end
@@ -67,7 +72,7 @@ module Pubnub
67
72
  parameters[:start] = @start unless @start.nil?
68
73
  parameters[:end] = @end if @end && !@start
69
74
  parameters[:count] = @include_count unless @include_count.nil?
70
- parameters[:include] = @include.sort.join(",") if @include && !@include.empty?
75
+ parameters[:include] = @include.sort.join(',') unless @include.empty?
71
76
 
72
77
  parameters
73
78
  end
@@ -84,12 +89,12 @@ module Pubnub
84
89
  end
85
90
 
86
91
  def valid_envelope(parsed_response, req_res_objects)
87
- members = parsed_response['data'].map { |channel_member|
88
- member = Hash.new
92
+ members = parsed_response['data'].map do |channel_member|
93
+ member = {}
89
94
  channel_member.each { |k, v| member[k.to_sym] = v }
90
95
 
91
96
  unless member[:uuid].nil?
92
- uuid_metadata = Hash.new
97
+ uuid_metadata = {}
93
98
  member[:uuid].each { |k, v| uuid_metadata[k.to_sym] = v }
94
99
  uuid_metadata[:updated] = Date._parse(uuid_metadata[:updated]) unless uuid_metadata[:updated].nil?
95
100
  member[:uuid] = uuid_metadata
@@ -97,7 +102,7 @@ module Pubnub
97
102
  member[:updated] = Date._parse(member[:updated]) unless member[:updated].nil?
98
103
 
99
104
  member
100
- }
105
+ end
101
106
 
102
107
  Pubnub::Envelope.new(
103
108
  event: @event,
@@ -15,12 +15,16 @@ module Pubnub
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?
17
17
 
18
+ @include = []
18
19
  if options[:include]
19
- @include = [0, '0', false].include?(options[:include][:custom]) ? "0" : "1" unless options[:include][:custom].nil?
20
+ include = options[:include]
21
+ @include.push('type') unless include[:type].nil? || [0, '0', false].include?(include[:type])
22
+ @include.push('status') unless include[:status].nil? || [0, '0', false].include?(include[:status])
23
+ @include.push('custom') unless include[:custom].nil? || [0, '0', false].include?(include[:custom])
20
24
  end
21
25
 
22
26
  # Single entity creation should return it's 'custom' field by default.
23
- @include = "custom" if @include.nil?
27
+ @include = ['custom'] if @include.empty?
24
28
  super
25
29
  end
26
30
 
@@ -43,7 +47,7 @@ module Pubnub
43
47
 
44
48
  def parameters(signature = false)
45
49
  parameters = super(signature)
46
- parameters[:include] = @include
50
+ parameters[:include] = @include.sort.join(',') unless @include.empty?
47
51
  parameters
48
52
  end
49
53
 
@@ -59,7 +63,7 @@ module Pubnub
59
63
 
60
64
  def valid_envelope(parsed_response, req_res_objects)
61
65
  data = parsed_response['data']
62
- metadata = Hash.new
66
+ metadata = {}
63
67
  data.each { |k, v| metadata[k.to_sym] = v }
64
68
  metadata[:updated] = Date._parse(metadata[:updated]) unless metadata[:updated].nil?
65
69
 
@@ -12,25 +12,28 @@ module Pubnub
12
12
  @telemetry_name = :l_obj
13
13
  @uuid = options[:uuid].nil? ? app.user_id : options[:uuid]
14
14
  @limit = [options[:limit], 100].min unless options[:limit].nil?
15
- @sort = options[:sort].join(",") if options[:sort] && !options[:sort].empty?
15
+ @sort = options[:sort].join(',') if options[:sort] && !options[:sort].empty?
16
16
  @filter = options[:filter] if options[:filter] && !options[:filter].empty?
17
17
  @start = options[:start] if options[:start] && !options[:start].empty?
18
18
  @end = options[:end] if options[:start] && !options[:end].empty?
19
19
 
20
+ @include = []
20
21
  if options[:include]
21
22
  include = options[:include]
22
- @include_count = [0, '0', false].include?(include[:count]) ? "0" : "1" unless include[:count].nil?
23
- @include_custom = "custom" if !include[:custom].nil? && ![0, '0', false].include?(include[:custom])
24
- @include_channel_metadata = "channel" if !include[:channel_metadata].nil? && ![0, '0', false].include?(include[:channel_metadata])
25
- @include_channel_custom = "channel.custom" if !include[:channel_custom].nil? && ![0, '0', false].include?(include[:channel_custom])
26
-
27
- @include = [@include_custom, @include_channel_metadata, @include_channel_custom].reject { |flag| flag.to_s.empty? }
23
+ @include.push('type') unless include[:type].nil? || [0, '0', false].include?(include[:type])
24
+ @include.push('status') unless include[:status].nil? || [0, '0', false].include?(include[:status])
25
+ @include.push('custom') unless include[:custom].nil? || [0, '0', false].include?(include[:custom])
26
+ @include.push('channel') unless include[:channel_metadata].nil? || [0, '0', false].include?(include[:channel_metadata])
27
+ @include.push('channel.type') unless include[:channel_type].nil? || [0, '0', false].include?(include[:channel_type])
28
+ @include.push('channel.status') unless include[:channel_status].nil? || [0, '0', false].include?(include[:channel_status])
29
+ @include.push('channel.custom') unless include[:channel_custom].nil? || [0, '0', false].include?(include[:channel_custom])
30
+ @include_count = [0, '0', false].include?(include[:count]) ? '0' : '1' unless include[:count].nil?
28
31
  end
29
32
 
30
33
  @channels = options[:channels] if options[:channels] && !options[:channels].empty?
31
34
 
32
35
  # Collections by default return number of available entries.
33
- @include_count = "1" if @include_count.nil?
36
+ @include_count = '1' if @include_count.nil?
34
37
 
35
38
  super
36
39
  end
@@ -41,6 +44,8 @@ module Pubnub
41
44
  memberships = @channels.map do |membership|
42
45
  membership_object = { channel: { id: membership[:channel] } }
43
46
  membership_object[:custom] = membership[:custom] if membership[:custom] && !membership[:custom].empty?
47
+ membership_object[:type] = membership[:type] if membership[:type] && !membership[:type].empty?
48
+ membership_object[:status] = membership[:status] if membership[:status] && !membership[:status].empty?
44
49
 
45
50
  membership_object
46
51
  end
@@ -67,7 +72,7 @@ module Pubnub
67
72
  parameters[:start] = @start unless @start.nil?
68
73
  parameters[:end] = @end if @end && !@start
69
74
  parameters[:count] = @include_count unless @include_count.nil?
70
- parameters[:include] = @include.sort.join(",") if @include && !@include.empty?
75
+ parameters[:include] = @include.sort.join(',') unless @include.empty?
71
76
 
72
77
  parameters
73
78
  end
@@ -84,12 +89,12 @@ module Pubnub
84
89
  end
85
90
 
86
91
  def valid_envelope(parsed_response, req_res_objects)
87
- memberships = parsed_response['data'].map { |uuid_membership|
88
- membership = Hash.new
92
+ memberships = parsed_response['data'].map do |uuid_membership|
93
+ membership = {}
89
94
  uuid_membership.each { |k, v| membership[k.to_sym] = v }
90
95
 
91
96
  unless membership[:channel].nil?
92
- channel_metadata = Hash.new
97
+ channel_metadata = {}
93
98
  membership[:channel].each { |k, v| channel_metadata[k.to_sym] = v }
94
99
  channel_metadata[:updated] = Date._parse(channel_metadata[:updated]) unless channel_metadata[:updated].nil?
95
100
  membership[:channel] = channel_metadata
@@ -97,7 +102,7 @@ module Pubnub
97
102
  membership[:updated] = Date._parse(membership[:updated]) unless membership[:updated].nil?
98
103
 
99
104
  membership
100
- }
105
+ end
101
106
 
102
107
  Pubnub::Envelope.new(
103
108
  event: @event,
@@ -15,12 +15,16 @@ module Pubnub
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?
17
17
 
18
+ @include = []
18
19
  if options[:include]
19
- @include = [0, '0', false].include?(options[:include][:custom]) ? "0" : "1" unless options[:include][:custom].nil?
20
+ include = options[:include]
21
+ @include.push('type') unless include[:type].nil? || [0, '0', false].include?(include[:type])
22
+ @include.push('status') unless include[:status].nil? || [0, '0', false].include?(include[:status])
23
+ @include.push('custom') unless include[:custom].nil? || [0, '0', false].include?(include[:custom])
20
24
  end
21
25
 
22
26
  # Single entity creation should return it's 'custom' field by default.
23
- @include = "custom" if @include.nil?
27
+ @include = ['custom'] if @include.empty?
24
28
 
25
29
  super
26
30
  end
@@ -44,7 +48,7 @@ module Pubnub
44
48
 
45
49
  def parameters(signature = false)
46
50
  parameters = super(signature)
47
- parameters[:include] = @include
51
+ parameters[:include] = @include.sort.join(',') unless @include.empty?
48
52
  parameters
49
53
  end
50
54
 
@@ -60,7 +64,7 @@ module Pubnub
60
64
 
61
65
  def valid_envelope(parsed_response, req_res_objects)
62
66
  data = parsed_response['data']
63
- metadata = Hash.new
67
+ metadata = {}
64
68
  data.each { |k, v| metadata[k.to_sym] = v }
65
69
  metadata[:updated] = Date._parse(metadata[:updated]) unless metadata[:updated].nil?
66
70
 
@@ -26,6 +26,10 @@ module Pubnub
26
26
  def parameters(*_args)
27
27
  params = super
28
28
 
29
+ empty_if_blank = { custom_message_type: @custom_message_type }
30
+ empty_if_blank.delete_if { |_k, v| v.blank? }
31
+
32
+ params = params.merge(empty_if_blank)
29
33
  params = params.merge(seqn: @sequence_number,
30
34
  ortt: { t: @origination_time_token })
31
35
  params
@@ -60,6 +60,7 @@ module Pubnub
60
60
  end
61
61
 
62
62
  def plain_envelope(req_res_objects, timetoken)
63
+ operation = get_operation
63
64
  Pubnub::Envelope.new(
64
65
  event: @event,
65
66
  event_options: @given_options,
@@ -82,7 +83,7 @@ module Pubnub
82
83
  },
83
84
  result: {
84
85
  code: req_res_objects[:response].code,
85
- operation: get_operation,
86
+ operation: operation,
86
87
  client_request: req_res_objects[:request],
87
88
  server_response: req_res_objects[:response],
88
89
 
@@ -92,6 +93,20 @@ module Pubnub
92
93
  end
93
94
 
94
95
  def encrypted_envelope(req_res_objects, message, timetoken)
96
+ operation = get_operation(message)
97
+ data = {
98
+ message: decipher_payload(message),
99
+ subscribed_channel: message[:subscription_match] || message[:channel],
100
+ actual_channel: message[:channel],
101
+ publish_time_object: message[:publish_timetoken],
102
+ message_meta_data: message[:user_meta_data],
103
+ presence_event: get_presence_event(message),
104
+ presence: get_presence_data(message)
105
+ }
106
+ if !data[:actual_channel].end_with?('-pnpres') && (message[:type].nil? || [1, 4].include?(message[:type]))
107
+ data[:custom_message_type] = message[:custom_message_type]
108
+ end
109
+
95
110
  Pubnub::Envelope.new(
96
111
  event: @event,
97
112
  event_options: @given_options,
@@ -114,19 +129,11 @@ module Pubnub
114
129
  },
115
130
  result: {
116
131
  code: req_res_objects[:response].code,
117
- operation: get_operation(message),
132
+ operation: operation,
118
133
  client_request: req_res_objects[:request],
119
134
  server_response: req_res_objects[:response],
120
135
 
121
- data: {
122
- message: decipher_payload(message),
123
- subscribed_channel: message[:subscription_match] || message[:channel],
124
- actual_channel: message[:channel],
125
- publish_time_object: message[:publish_timetoken],
126
- message_meta_data: message[:user_meta_data],
127
- presence_event: get_presence_event(message),
128
- presence: get_presence_data(message)
129
- }
136
+ data: data
130
137
  }
131
138
  )
132
139
  end
@@ -142,10 +149,10 @@ module Pubnub
142
149
  Pubnub::Schemas::Envelope::StatusSchema.new.call status
143
150
  end
144
151
 
145
- if (results_validation + statuses_validation).map(&:failure?).index(true)
146
- Pubnub.logger.error('Pubnub::SubscribeEvent::Formatter') { 'Invalid formatted envelope.' }
147
- raise Exception, 'Invalid formatted envelope.'
148
- end
152
+ return unless (results_validation + statuses_validation).map(&:failure?).index(true)
153
+
154
+ Pubnub.logger.error('Pubnub::SubscribeEvent::Formatter') { 'Invalid formatted envelope.' }
155
+ raise Exception, 'Invalid formatted envelope.'
149
156
  end
150
157
 
151
158
  def format_envelopes(response, request)
@@ -216,6 +223,7 @@ module Pubnub
216
223
 
217
224
  def get_presence_data(message)
218
225
  return nil unless get_operation(message) == Pubnub::Constants::OPERATION_PRESENCE
226
+
219
227
  {
220
228
  uuid: message[:payload]['uuid'],
221
229
  timestamp: message[:payload]['timestamp'],
@@ -226,6 +234,7 @@ module Pubnub
226
234
 
227
235
  def get_presence_event(message)
228
236
  return nil unless get_operation(message) == Pubnub::Constants::OPERATION_PRESENCE
237
+
229
238
  message[:payload]['action']
230
239
  rescue StandardError
231
240
  nil
@@ -233,7 +242,7 @@ module Pubnub
233
242
 
234
243
  def expand_messages_keys(messages)
235
244
  messages.map do |m|
236
- {
245
+ envelope = {
237
246
  shard: m['a'],
238
247
  channel: m['c'],
239
248
  subscription_match: m['b'],
@@ -250,11 +259,15 @@ module Pubnub
250
259
  origination_time_token: expand_timetoken(m['o']),
251
260
  publish_timetoken: expand_timetoken(m['p'])
252
261
  }
262
+ envelope[:custom_message_type] = m['cmt'] if !m['c'].end_with?('-pnpres') && (envelope[:type].nil? || [1, 4].include?(envelope[:type]))
263
+
264
+ envelope
253
265
  end
254
266
  end
255
267
 
256
268
  def expand_timetoken(timetoken)
257
269
  return nil unless timetoken
270
+
258
271
  {
259
272
  timetoken: timetoken['t'],
260
273
  region_code: timetoken['r']
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pubnub
4
+ # Validator module that holds all validators modules.
5
+ module Validator
6
+ # Validator for FetchMessages event.
7
+ module FetchMessages
8
+ include CommonValidator
9
+
10
+ def validate!
11
+ return if @skip_validate
12
+
13
+ validate_subscribe_key!
14
+ validate_channel_or_channels!
15
+ end
16
+
17
+ private
18
+
19
+ def validate_subscribe_key!
20
+ return unless @subscribe_key.nil?
21
+
22
+ raise(
23
+ ArgumentError.new(object: self, message: ':subscribe_key is required for fetch messages event'),
24
+ ':subscribe_key is required for fetch messages event'
25
+ )
26
+ end
27
+
28
+ def validate_channel_or_channels!
29
+ error_message = nil
30
+ if @include_message_actions
31
+ error_message = ":channels can't be used with :include_custom_message_type set to 'true'" unless @channels.nil?
32
+ error_message = ":channel is required with :include_custom_message_type set to 'true'" if @channel.nil?
33
+ elsif @channels.nil? || @channels.empty?
34
+ error_message = ':channels is required for fetch message event'
35
+ end
36
+
37
+ raise(ArgumentError.new(object: self, message: error_message), error_message) unless error_message.nil?
38
+ end
39
+ end
40
+ end
41
+ end