Class: Pubnub::SetChannelMetadata

Inherits:
SingleEvent show all
Includes:
Concurrent::Async, Validator::SetChannelMetadata
Defined in:
lib/pubnub/events/set_channel_metadata.rb

Overview

Holds SetChannelMetadata functionality

Instance Attribute Summary

Attributes inherited from Event

#callback, #channel, #channel_group, #fresh_clone, #given_options, #group, #idle_timeout, #open_timeout, #origin, #presence_callback, #read_timeout, #ssl, #state, #wildcard_channel, #with_presence

Instance Method Summary collapse

Methods included from Validator::SetChannelMetadata

#validate!

Methods included from Validator::CommonValidator

#validate_origin, #validate_publish_key, #validate_subscribe_key, #validate_user_id

Methods inherited from Event

#finalized?, #send_request, #sync?, #uri

Methods included from Event::EFormatter

#format_channels, #format_envelopes, #format_group

Constructor Details

#initialize(options, app) ⇒ SetChannelMetadata

Returns a new instance of SetChannelMetadata.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/pubnub/events/set_channel_metadata.rb', line 10

def initialize(options, app)
  @event = current_operation
  @telemetry_name = :l_obj
  @channel = options[:channel]

  # Clean up user-provided metadata object from nils.
  @metadata = options[:metadata].delete_if { |_k, v| v.blank? } unless options[:metadata].nil?

  @include = []
  if options[:include]
    include = options[:include]
    @include.push('type') unless include[:type].nil? || [0, '0', false].include?(include[:type])
    @include.push('status') unless include[:status].nil? || [0, '0', false].include?(include[:status])
    @include.push('custom') unless include[:custom].nil? || [0, '0', false].include?(include[:custom])
  end

  # Single entity creation should return it's 'custom' field by default.
  @include = ['custom'] if @include.empty?
  super
end

Instance Method Details

#fireObject



31
32
33
34
35
36
37
38
39
40
# File 'lib/pubnub/events/set_channel_metadata.rb', line 31

def fire
  Pubnub.logger.debug('Pubnub::SetChannelMetadata') { "Fired event #{self.class}" }

  body = Formatter.format_message(@metadata, nil, false)
  response = send_request(body)

  envelopes = fire_callbacks(handle(response, uri))
  finalize_event(envelopes)
  envelopes
end