pubnub 5.3.5 → 5.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/pubnub/client.rb CHANGED
@@ -1,85 +1,86 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'base64'
4
-
5
- require 'pubnub/error'
6
- require 'pubnub/uuid'
7
- require 'pubnub/formatter'
8
- require 'pubnub/constants'
9
- require 'pubnub/configuration'
10
- require 'pubnub/subscribe_callback'
11
-
12
- require 'pubnub/modules/crypto/module'
13
-
14
- require 'pubnub/schemas/envelope_schema'
15
-
16
- require 'pubnub/event'
17
- require 'pubnub/single_event'
18
- require 'pubnub/subscribe_event/callbacks'
19
- require 'pubnub/subscribe_event/formatter'
20
- require 'pubnub/subscribe_event/heartbeat'
21
- require 'pubnub/subscribe_event/adding'
22
- require 'pubnub/subscribe_event/removing'
23
- require 'pubnub/subscribe_event'
24
- require 'pubnub/pam'
25
- require 'pubnub/heart'
26
- require 'pubnub/subscriber'
27
- require 'pubnub/telemetry'
28
-
29
- require 'pubnub/envelope'
30
- require 'pubnub/error_envelope'
31
-
32
- require 'pubnub/client/events'
33
- require 'pubnub/client/paged_history'
34
- require 'pubnub/client/helpers'
35
- require 'pubnub/client/getters_setters'
36
-
37
- require 'pubnub/validators/get_message_actions'
38
- require 'pubnub/validators/add_message_action'
39
- require 'pubnub/validators/remove_message_action'
40
- require 'pubnub/validators/common_validator'
41
- require 'pubnub/validators/client'
42
- require 'pubnub/validators/audit'
43
- require 'pubnub/validators/channel_registration'
44
- require 'pubnub/validators/grant'
45
- require 'pubnub/validators/grant_token'
46
- require 'pubnub/validators/revoke_token'
47
- require 'pubnub/validators/heartbeat'
48
- require 'pubnub/validators/here_now'
49
- require 'pubnub/validators/history'
50
- require 'pubnub/validators/leave'
51
- require 'pubnub/validators/presence'
52
- require 'pubnub/validators/publish'
53
- require 'pubnub/validators/revoke'
54
- require 'pubnub/validators/set_state'
55
- require 'pubnub/validators/state'
56
- require 'pubnub/validators/subscribe'
57
- require 'pubnub/validators/time'
58
- require 'pubnub/validators/where_now'
59
- require 'pubnub/validators/delete'
60
- require 'pubnub/validators/message_counts'
61
- require 'pubnub/validators/add_channels_to_push'
62
- require 'pubnub/validators/list_push_provisions'
63
- require 'pubnub/validators/remove_channels_from_push'
64
- require 'pubnub/validators/remove_device_from_push'
65
- require 'pubnub/validators/signal'
66
- require 'pubnub/validators/set_uuid_metadata'
67
- require 'pubnub/validators/set_channel_metadata'
68
- require 'pubnub/validators/remove_uuid_metadata'
69
- require 'pubnub/validators/remove_channel_metadata'
70
- require 'pubnub/validators/get_uuid_metadata'
71
- require 'pubnub/validators/get_all_uuid_metadata'
72
- require 'pubnub/validators/get_channel_metadata'
73
- require 'pubnub/validators/get_all_channels_metadata'
74
- require 'pubnub/validators/get_channel_members'
75
- require 'pubnub/validators/get_memberships'
76
- require 'pubnub/validators/set_channel_members'
77
- require 'pubnub/validators/set_memberships'
78
- require 'pubnub/validators/remove_channel_members'
79
- require 'pubnub/validators/remove_memberships'
80
- require 'pubnub/cbor'
81
-
82
- Dir[File.join(File.dirname(__dir__), 'pubnub', 'events', '*.rb')].each do |file|
3
+ require "base64"
4
+
5
+ require "pubnub/error"
6
+ require "pubnub/uuid"
7
+ require "pubnub/formatter"
8
+ require "pubnub/constants"
9
+ require "pubnub/configuration"
10
+ require "pubnub/subscribe_callback"
11
+
12
+ require "pubnub/modules/crypto/module"
13
+
14
+ require "pubnub/schemas/envelope_schema"
15
+
16
+ require "pubnub/event"
17
+ require "pubnub/single_event"
18
+ require "pubnub/subscribe_event/callbacks"
19
+ require "pubnub/subscribe_event/formatter"
20
+ require "pubnub/subscribe_event/heartbeat"
21
+ require "pubnub/subscribe_event/adding"
22
+ require "pubnub/subscribe_event/removing"
23
+ require "pubnub/subscribe_event"
24
+ require "pubnub/pam"
25
+ require "pubnub/heart"
26
+ require "pubnub/subscriber"
27
+ require "pubnub/telemetry"
28
+
29
+ require "pubnub/envelope"
30
+ require "pubnub/error_envelope"
31
+
32
+ require "pubnub/client/events"
33
+ require "pubnub/client/paged_history"
34
+ require "pubnub/client/helpers"
35
+ require "pubnub/client/getters_setters"
36
+
37
+ require "pubnub/validators/get_message_actions"
38
+ require "pubnub/validators/add_message_action"
39
+ require "pubnub/validators/remove_message_action"
40
+ require "pubnub/validators/common_validator"
41
+ require "pubnub/validators/client"
42
+ require "pubnub/validators/audit"
43
+ require "pubnub/validators/channel_registration"
44
+ require "pubnub/validators/grant"
45
+ require "pubnub/validators/grant_token"
46
+ require "pubnub/validators/revoke_token"
47
+ require "pubnub/validators/heartbeat"
48
+ require "pubnub/validators/here_now"
49
+ require "pubnub/validators/history"
50
+ require "pubnub/validators/fetch_messages"
51
+ require "pubnub/validators/leave"
52
+ require "pubnub/validators/presence"
53
+ require "pubnub/validators/publish"
54
+ require "pubnub/validators/revoke"
55
+ require "pubnub/validators/set_state"
56
+ require "pubnub/validators/state"
57
+ require "pubnub/validators/subscribe"
58
+ require "pubnub/validators/time"
59
+ require "pubnub/validators/where_now"
60
+ require "pubnub/validators/delete"
61
+ require "pubnub/validators/message_counts"
62
+ require "pubnub/validators/add_channels_to_push"
63
+ require "pubnub/validators/list_push_provisions"
64
+ require "pubnub/validators/remove_channels_from_push"
65
+ require "pubnub/validators/remove_device_from_push"
66
+ require "pubnub/validators/signal"
67
+ require "pubnub/validators/set_uuid_metadata"
68
+ require "pubnub/validators/set_channel_metadata"
69
+ require "pubnub/validators/remove_uuid_metadata"
70
+ require "pubnub/validators/remove_channel_metadata"
71
+ require "pubnub/validators/get_uuid_metadata"
72
+ require "pubnub/validators/get_all_uuid_metadata"
73
+ require "pubnub/validators/get_channel_metadata"
74
+ require "pubnub/validators/get_all_channels_metadata"
75
+ require "pubnub/validators/get_channel_members"
76
+ require "pubnub/validators/get_memberships"
77
+ require "pubnub/validators/set_channel_members"
78
+ require "pubnub/validators/set_memberships"
79
+ require "pubnub/validators/remove_channel_members"
80
+ require "pubnub/validators/remove_memberships"
81
+ require "pubnub/cbor"
82
+
83
+ Dir[File.join(File.dirname(__dir__), "pubnub", "events", "*.rb")].each do |file|
83
84
  require file
84
85
  end
85
86
 
@@ -188,7 +189,7 @@ module Pubnub
188
189
  validate! @env
189
190
  setup_crypto_module
190
191
  @telemetry = Telemetry.new
191
- Pubnub.logger.debug('Pubnub::Client') do
192
+ Pubnub.logger.debug("Pubnub::Client") do
192
193
  "Created new Pubnub::Client instance. Version: #{Pubnub::VERSION}"
193
194
  end
194
195
  end
@@ -260,8 +261,8 @@ module Pubnub
260
261
  # created and returns it if created, otherwise creates it, assigns
261
262
  # it in @env and returns newly created dispatcher.
262
263
  def request_dispatcher(origin, event_type, sync)
263
- Pubnub.logger.debug('Pubnub::Client') do
264
- "Looking for requester for #{sync ? 'sync' : 'async'} #{event_type}"
264
+ Pubnub.logger.debug("Pubnub::Client") do
265
+ "Looking for requester for #{sync ? "sync" : "async"} #{event_type}"
265
266
  end
266
267
 
267
268
  if sync
@@ -289,21 +290,21 @@ module Pubnub
289
290
  # ==============
290
291
  # Terminates request dispatcher for given origin and event type. Usable while restarting subscription.
291
292
  def kill_request_dispatcher(origin, event_type)
292
- Pubnub.logger.debug('Pubnub::Client') { 'Killing requester' }
293
+ Pubnub.logger.debug("Pubnub::Client") { "Killing requester" }
293
294
  # @env[:req_dispatchers_pool][origin][event_type].async.terminate
294
295
  @env[:req_dispatchers_pool][:async][origin][event_type].reset_all
295
296
  @env[:req_dispatchers_pool][:async][origin][event_type] = nil
296
- rescue StandardError
297
- Pubnub.logger.debug('Pubnub::Client') { 'There\'s no requester' }
297
+ rescue
298
+ Pubnub.logger.debug("Pubnub::Client") { "There's no requester" }
298
299
  end
299
300
 
300
301
  def sequence_number_for_publish!
301
302
  @env[:sequence_number_for_publish] += 1
302
- @env[:sequence_number_for_publish] % 2 ** 32
303
+ @env[:sequence_number_for_publish] % 2**32
303
304
  end
304
305
 
305
306
  def apply_state(event)
306
- Pubnub.logger.debug('Pubnub::Client') { 'Apply state' }
307
+ Pubnub.logger.debug("Pubnub::Client") { "Apply state" }
307
308
  create_state_pools(event)
308
309
 
309
310
  return unless event.state
@@ -361,11 +362,11 @@ module Pubnub
361
362
  end
362
363
 
363
364
  def setup_httpclient(event_type)
364
- hc = if ENV['HTTP_PROXY']
365
- HTTPClient.new(ENV['HTTP_PROXY'])
366
- else
367
- HTTPClient.new
368
- end
365
+ hc = if ENV["HTTP_PROXY"]
366
+ HTTPClient.new(ENV["HTTP_PROXY"])
367
+ else
368
+ HTTPClient.new
369
+ end
369
370
 
370
371
  case event_type
371
372
  when :subscribe_event
@@ -394,14 +395,14 @@ module Pubnub
394
395
  end
395
396
 
396
397
  def setup_app(options)
397
- Pubnub.logger = options[:logger] || Logger.new('pubnub.log')
398
+ Pubnub.logger = options[:logger] || Logger.new("pubnub.log")
398
399
  Concurrent.global_logger = Pubnub.logger
399
400
  @subscriber = Subscriber.new(self)
400
401
  options[:user_id] = options[:uuid] if options[:user_id].nil?
401
402
 
402
403
  if options[:cipher_key] && options[:crypto_module]
403
- puts 'It is expected that only cipherKey or cryptoModule will be configured ' \
404
- 'at once. PubNub client will use the configured cryptoModule.'
404
+ puts "It is expected that only cipherKey or cryptoModule will be configured " \
405
+ "at once. PubNub client will use the configured cryptoModule."
405
406
  end
406
407
 
407
408
  @env = options
@@ -48,6 +48,8 @@ module Pubnub
48
48
  OPERATION_PRESENCE_LEAVE = :leave
49
49
  OPERATION_TIME = :time
50
50
  OPERATION_HISTORY = :history
51
+ OPERATION_FETCH_MESSAGES = :fetch_messages
52
+ OPERATION_FETCH_MESSAGES_WITH_ACTIONS = :fetch_messages_with_actions
51
53
  OPERATION_HERE_NOW = :here_now
52
54
  OPERATION_WHERE_NOW = :where_now
53
55
  OPERATION_GLOBAL_HERE_NOW = :global_here_now
@@ -89,7 +91,8 @@ module Pubnub
89
91
 
90
92
  OPERATIONS = [
91
93
  OPERATION_SUBSCRIBE, OPERATION_HEARTBEAT, OPERATION_PRESENCE, OPERATION_TIME, OPERATION_HISTORY,
92
- OPERATION_HERE_NOW, OPERATION_GLOBAL_HERE_NOW, OPERATION_GET_STATE, OPERATION_ADD_MESSAGE_ACTION,
94
+ OPERATION_FETCH_MESSAGES, OPERATION_FETCH_MESSAGES_WITH_ACTIONS, OPERATION_HERE_NOW,
95
+ OPERATION_GLOBAL_HERE_NOW, OPERATION_GET_STATE, OPERATION_ADD_MESSAGE_ACTION,
93
96
  OPERATION_REMOVE_MESSAGE_ACTION, OPERATION_GET_MESSAGE_ACTIONS, OPERATION_LIST_ALL_CHANNEL_GROUPS,
94
97
  OPERATION_LIST_ALL_CHANNELS_IN_CHANNEL_GROUP, OPERATION_CHANNEL_GROUP_ADD, OPERATION_CHANNEL_GROUP_REMOVE,
95
98
  OPERATION_AUDIT, OPERATION_GRANT, OPERATION_GRANT_TOKEN, OPERATION_REVOKE, OPERATION_WHERE_NOW,
data/lib/pubnub/event.rb CHANGED
@@ -65,14 +65,14 @@ module Pubnub
65
65
 
66
66
  begin
67
67
  @app.record_telemetry(@telemetry_name, telemetry_time_start, ::Time.now.to_f)
68
- rescue StandardError => error
69
- Pubnub.logger.warn('Pubnub::Event') { "Couldn't record telemetry because of #{error}\n#{error.backtrace.join("\n")}" }
68
+ rescue StandardError => e
69
+ Pubnub.logger.warn('Pubnub::Event') { "Couldn't record telemetry because of #{e}\n#{e.backtrace.join("\n")}" }
70
70
  end
71
71
 
72
72
  response
73
- rescue StandardError => error
74
- Pubnub.logger.error('Pubnub::Event') { error }
75
- error
73
+ rescue StandardError => e
74
+ Pubnub.logger.error('Pubnub::Event') { e }
75
+ e
76
76
  end
77
77
 
78
78
  def uri(memo = true)
@@ -133,8 +133,8 @@ module Pubnub
133
133
 
134
134
  def secure_call(cb, arg)
135
135
  cb.call arg
136
- rescue StandardError => error
137
- Pubnub.logger.error('Pubnub::Event') { "Error while calling callback #{error.inspect}" }
136
+ rescue StandardError => e
137
+ Pubnub.logger.error('Pubnub::Event') { "Error while calling callback #{e.inspect}" }
138
138
  end
139
139
 
140
140
  def fire_callbacks(envelope)
@@ -150,7 +150,7 @@ module Pubnub
150
150
 
151
151
  token = @app.env[:token]
152
152
  empty_if_blank = {
153
- auth: token ? token : @auth_key,
153
+ auth: token || @auth_key,
154
154
  uuid: @app.user_id,
155
155
  @telemetry_name => @current_telemetry
156
156
  }
@@ -169,21 +169,26 @@ module Pubnub
169
169
  end
170
170
 
171
171
  def create_variables_from_options(options)
172
- variables = %w[channel channels message http_sync callback
173
- ssl cipher_key random_iv crypto_module secret_key auth_key
174
- publish_key subscribe_key timetoken action_timetoken message_timetoken
175
- open_timeout read_timeout idle_timeout heartbeat
176
- group action read write delete manage ttl presence start
177
- end count limit reverse presence_callback store skip_validate
178
- state channel_group channel_groups compressed meta customs include_token
179
- replicate with_presence cipher_key_selector include_meta join update get
180
- add remove push_token push_gateway environment topic authorized_uuid
181
- authorized_user_id token type value
182
- ]
172
+ variables = %w[channel channels message http_sync callback ssl cipher_key random_iv
173
+ crypto_module secret_key auth_key publish_key subscribe_key timetoken
174
+ action_timetoken message_timetoken open_timeout read_timeout idle_timeout
175
+ heartbeat group action read write delete manage ttl presence start end count
176
+ limit max reverse presence_callback store skip_validate state channel_group
177
+ channel_groups compressed meta customs custom_message_type include_token
178
+ include_custom_message_type include_message_actions include_message_type
179
+ replicate with_presence cipher_key_selector include_meta include_uuid join
180
+ update get add remove push_token push_gateway environment topic
181
+ authorized_uuid authorized_user_id token type status value]
183
182
 
184
183
  options = options.each_with_object({}) { |option, obj| obj[option.first.to_sym] = option.last }
185
184
 
186
- variables.each { |variable| instance_variable_set('@' + variable, options[variable.to_sym]) unless variable.nil? }
185
+ # variables.each { |variable| instance_variable_set('@' + variable, options[variable.to_sym]) unless variable.nil? }
186
+ variables.each do |variable|
187
+ next if variable.nil?
188
+
189
+ ivar = "@#{variable}"
190
+ instance_variable_set(ivar, options[variable.to_sym]) unless instance_variable_defined?(ivar) && !instance_variable_get(ivar).nil?
191
+ end
187
192
 
188
193
  return if @event != :subscribe && @event != :presence
189
194
 
@@ -208,12 +213,14 @@ module Pubnub
208
213
  def compute_cipher_key(data)
209
214
  ck = @compute_cipher_key || @cipher_key || @app.env[:cipher_key_selector] || @app.env[:cipher_key].to_s
210
215
  return ck unless ck.respond_to?(:call)
216
+
211
217
  ck.call(data)
212
218
  end
213
219
 
214
220
  def compute_random_iv(data)
215
221
  ck = @compute_random_iv || @random_iv || @app.env[:random_iv_selector] || @app.env[:random_iv].to_s
216
222
  return ck unless ck.respond_to?(:call)
223
+
217
224
  ck.call(data)
218
225
  end
219
226
 
@@ -221,9 +228,7 @@ module Pubnub
221
228
  #
222
229
  # @return [Pubnub::Crypto::CryptoProvider, nil] Crypto module for data encryption and
223
230
  # decryption.
224
- def crypto_module
225
- @crypto_module
226
- end
231
+ attr_reader :crypto_module
227
232
 
228
233
  def error_message(parsed_response)
229
234
  parsed_response['message']
@@ -0,0 +1,128 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pubnub
4
+ # Holds functionality to fetch:
5
+ # - batch messages (for multiple channels)
6
+ # - messages with message actions.
7
+ class FetchMessages < SingleEvent
8
+ include Concurrent::Async
9
+ include Pubnub::Validator::FetchMessages
10
+
11
+ def initialize(options, app)
12
+ @telemetry_name = :l_hist
13
+ @include_custom_message_type = options.fetch(:include_custom_message_type, false)
14
+ @include_message_actions = options.fetch(:include_message_actions, false)
15
+ @include_message_type = options.fetch(:include_message_type, true)
16
+ @include_uuid = options.fetch(:include_uuid, true)
17
+ @include_meta = options.fetch(:include_meta, false)
18
+ @start = options[:start] if options.key?(:start)
19
+ @end = options[:end] if options.key?(:end)
20
+
21
+ channel = options[:channel] if options.key?(:channel) && !options[:channel].empty?
22
+ @channels = options[:channels] if options.key?(:channels) && !options[:channels].empty?
23
+ if @include_message_actions
24
+ @channel = channel
25
+ elsif @channels.nil? && !channel.nil?
26
+ @channels = [channel]
27
+ @channel = nil
28
+ options.delete :channel
29
+ end
30
+
31
+ maximum = @include_message_actions || @channels&.size == 1 ? 100 : 25
32
+ @max = [options[:max], maximum].min unless options[:max].nil?
33
+
34
+ @event = current_operation
35
+
36
+ # Override crypto module if custom cipher key has been used.
37
+ random_iv = options.key?(:random_iv) ? options[:random_iv] : true
38
+ options[:crypto_module] = Crypto::CryptoModule.new_legacy(options[:cipher_key], random_iv) if options[:cipher_key]
39
+
40
+ super
41
+ end
42
+
43
+ private
44
+
45
+ def current_operation
46
+ @include_message_actions ? Pubnub::Constants::OPERATION_FETCH_MESSAGES_WITH_ACTIONS : Pubnub::Constants::OPERATION_FETCH_MESSAGES
47
+ end
48
+
49
+ def parameters(signature: false)
50
+ parameters = super(signature)
51
+ parameters[:include_meta] = 'true' if @include_meta
52
+ parameters[:include_uuid] = 'true' if @include_uuid
53
+ parameters[:include_custom_message_type] = 'true' if @include_custom_message_type
54
+ parameters[:include_message_type] = 'true' if @include_message_type
55
+ parameters[:start] = @start unless @start.nil?
56
+ parameters[:end] = @end unless @end.nil?
57
+ parameters[:max] = @max unless @max.nil?
58
+
59
+ parameters
60
+ end
61
+
62
+ def path
63
+ storage_endpoint = @include_message_actions ? 'history-with-actions' : 'history'
64
+ "/v3/#{storage_endpoint}/sub-key/#{@subscribe_key}/channel/#{Pubnub::Formatter.channels_for_url((
65
+ unless @channel.nil?
66
+ [@channel]
67
+ end) || @channels)}"
68
+ end
69
+
70
+ def enable_format_channels?
71
+ false
72
+ end
73
+
74
+ def decrypt_history(crypto, message)
75
+ encrypted_message = Base64.strict_decode64(message['message'])
76
+ message['message'] = JSON.parse(crypto.decrypt(encrypted_message), quirks_mode: true)
77
+ message
78
+ rescue StandardError => e
79
+ puts "Pubnub :: DECRYPTION ERROR: #{e}"
80
+ message['decrypt_error'] = true
81
+ message
82
+ end
83
+
84
+ def valid_envelope(parsed_response, req_res_objects)
85
+ channels = parsed_response['channels'] unless parsed_response['error']
86
+ more = parsed_response['more'].transform_keys(&:to_sym) if parsed_response.key?('more')
87
+ more&.delete :url
88
+
89
+ if crypto_module && channels
90
+ crypto = crypto_module
91
+ channels.transform_values! do |channel_messages|
92
+ channel_messages.map(&method(:decrypt_history).curry[crypto])
93
+ end
94
+ end
95
+
96
+ Pubnub::Envelope.new(
97
+ event: @event,
98
+ event_options: @given_options,
99
+ timetoken: nil,
100
+ status: {
101
+ code: req_res_objects[:response].code,
102
+ client_request: req_res_objects[:request],
103
+ server_response: req_res_objects[:response],
104
+
105
+ category: Pubnub::Constants::STATUS_ACK,
106
+ error: false,
107
+ auto_retried: false,
108
+
109
+ data: nil,
110
+ current_timetoken: nil,
111
+ last_timetoken: nil,
112
+ subscribed_channels: nil,
113
+ subscribed_channel_groups: nil,
114
+
115
+ config: get_config
116
+ },
117
+ result: {
118
+ code: req_res_objects[:response].code,
119
+ operation: @event,
120
+ client_request: req_res_objects[:request],
121
+ server_response: req_res_objects[:response],
122
+
123
+ data: { channels: channels }.merge!(more.nil? ? {} : { more: more })
124
+ }
125
+ )
126
+ end
127
+ end
128
+ end
@@ -11,18 +11,22 @@ module Pubnub
11
11
  @event = current_operation
12
12
  @telemetry_name = :l_obj
13
13
  @limit = [options[:limit], 100].min unless options[:limit].nil?
14
- @sort = options[:sort].join(",") if options[:sort] && !options[:sort].empty?
14
+ @sort = options[:sort].join(',') if options[:sort] && !options[:sort].empty?
15
15
  @filter = options[:filter] if options[:filter] && !options[:filter].empty?
16
16
  @start = options[:start] if options[:start] && !options[:start].empty?
17
17
  @end = options[:end] if options[:start] && !options[:end].empty?
18
18
 
19
+ @include = []
19
20
  if options[:include]
20
- @include_count = [0, '0', false].include?(options[:include][:count]) ? "0" : "1" unless options[:include][:count].nil?
21
- @include = "custom" unless [0, '0', false].include?(options[:include][:custom])
21
+ include = options[:include]
22
+ @include.push('type') unless include[:type].nil? || [0, '0', false].include?(include[:type])
23
+ @include.push('status') unless include[:status].nil? || [0, '0', false].include?(include[:status])
24
+ @include.push('custom') unless include[:custom].nil? || [0, '0', false].include?(include[:custom])
25
+ @include_count = [0, '0', false].include?(include[:count]) ? '0' : '1' unless include[:count].nil?
22
26
  end
23
27
 
24
28
  # Collections by default return number of available entries.
25
- @include_count = "1" if @include_count.nil?
29
+ @include_count = '1' if @include_count.nil?
26
30
 
27
31
  super
28
32
  end
@@ -41,7 +45,7 @@ module Pubnub
41
45
  parameters[:start] = @start unless @start.nil?
42
46
  parameters[:end] = @end if @end && !@start
43
47
  parameters[:count] = @include_count unless @include_count.nil?
44
- parameters[:include] = @include unless @include.to_s.empty?
48
+ parameters[:include] = @include.sort.join(',') unless @include.empty?
45
49
 
46
50
  parameters
47
51
  end
@@ -56,12 +60,12 @@ module Pubnub
56
60
  end
57
61
 
58
62
  def valid_envelope(parsed_response, req_res_objects)
59
- channels_metadata = parsed_response['data'].map { |uuid_metadata|
60
- metadata = Hash.new
61
- uuid_metadata.each{ |k,v| metadata[k.to_sym] = v }
63
+ channels_metadata = parsed_response['data'].map do |uuid_metadata|
64
+ metadata = {}
65
+ uuid_metadata.each { |k, v| metadata[k.to_sym] = v }
62
66
  metadata[:updated] = Date._parse(metadata[:updated]) unless metadata[:updated].nil?
63
67
  metadata
64
- }
68
+ end
65
69
 
66
70
  Pubnub::Envelope.new(
67
71
  event: @event,
@@ -11,18 +11,22 @@ module Pubnub
11
11
  @event = current_operation
12
12
  @telemetry_name = :l_obj
13
13
  @limit = [options[:limit], 100].min unless options[:limit].nil?
14
- @sort = options[:sort].join(",") if options[:sort] && !options[:sort].empty?
14
+ @sort = options[:sort].join(',') if options[:sort] && !options[:sort].empty?
15
15
  @filter = options[:filter] if options[:filter] && !options[:filter].empty?
16
16
  @start = options[:start] if options[:start] && !options[:start].empty?
17
17
  @end = options[:end] if options[:start] && !options[:end].empty?
18
18
 
19
+ @include = []
19
20
  if options[:include]
20
- @include_count = [0, '0', false].include?(options[:include][:count]) ? "0" : "1" unless options[:include][:count].nil?
21
- @include = "custom" unless [0, '0', false].include?(options[:include][:custom])
21
+ include = options[:include]
22
+ @include.push('type') unless include[:type].nil? || [0, '0', false].include?(include[:type])
23
+ @include.push('status') unless include[:status].nil? || [0, '0', false].include?(include[:status])
24
+ @include.push('custom') unless include[:custom].nil? || [0, '0', false].include?(include[:custom])
25
+ @include_count = [0, '0', false].include?(include[:count]) ? '0' : '1' unless include[:count].nil?
22
26
  end
23
27
 
24
28
  # Collections by default return number of available entries.
25
- @include_count = "1" if @include_count.nil?
29
+ @include_count = '1' if @include_count.nil?
26
30
 
27
31
  super
28
32
  end
@@ -41,7 +45,7 @@ module Pubnub
41
45
  parameters[:start] = @start unless @start.nil?
42
46
  parameters[:end] = @end if @end && !@start
43
47
  parameters[:count] = @include_count unless @include_count.nil?
44
- parameters[:include] = @include unless @include.to_s.empty?
48
+ parameters[:include] = @include.sort.join(',') unless @include.empty?
45
49
 
46
50
  parameters
47
51
  end
@@ -56,12 +60,12 @@ module Pubnub
56
60
  end
57
61
 
58
62
  def valid_envelope(parsed_response, req_res_objects)
59
- uuids_metadata = parsed_response['data'].map { |uuid_metadata|
60
- metadata = Hash.new
61
- uuid_metadata.each{ |k,v| metadata[k.to_sym] = v }
63
+ uuids_metadata = parsed_response['data'].map do |uuid_metadata|
64
+ metadata = {}
65
+ uuid_metadata.each { |k, v| metadata[k.to_sym] = v }
62
66
  metadata[:updated] = Date._parse(metadata[:updated]) unless metadata[:updated].nil?
63
67
  metadata
64
- }
68
+ end
65
69
 
66
70
  Pubnub::Envelope.new(
67
71
  event: @event,