Class: Pubnub::SetChannelMembers

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

Overview

Holds SetChannelMembers 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::SetChannelMembers

#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) ⇒ SetChannelMembers

Returns a new instance of SetChannelMembers.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/pubnub/events/set_channel_members.rb', line 10

def initialize(options, app)
  @event = current_operation
  @telemetry_name = :l_obj
  @channel = options[:channel]
  @limit = [options[:limit], 100].min unless options[:limit].nil?
  @sort = options[:sort].join(',') if options[:sort] && !options[:sort].empty?
  @filter = options[:filter] if options[:filter] && !options[:filter].empty?
  @start = options[:start] if options[:start] && !options[:start].empty?
  @end = options[:end] if options[:start] && !options[:end].empty?

  @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])
    @include.push('uuid') unless include[:uuid_metadata].nil? || [0, '0', false].include?(include[:uuid_metadata])
    @include.push('uuid.type') unless include[:uuid_type].nil? || [0, '0', false].include?(include[:uuid_type])
    @include.push('uuid.status') unless include[:uuid_status].nil? || [0, '0', false].include?(include[:uuid_status])
    @include.push('uuid.custom') unless include[:uuid_custom].nil? || [0, '0', false].include?(include[:uuid_custom])
    @include_count = [0, '0', false].include?(include[:count]) ? '0' : '1' unless include[:count].nil?
  end

  @uuids = options[:uuids] if options[:uuids] && !options[:uuids].empty?

  # Collections by default return number of available entries.
  @include_count = '1' if @include_count.nil?

  super
end

Instance Method Details

#fireObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/pubnub/events/set_channel_members.rb', line 41

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

  members = @uuids.map do |member|
    member_object = { uuid: { id: member[:uuid] } }
    member_object[:custom] = member[:custom] if member[:custom] && !member[:custom].empty?
    member_object[:type] = member[:type] if member[:type] && !member[:type].empty?
    member_object[:status] = member[:status] if member[:status] && !member[:status].empty?

    member_object
  end

  body = Formatter.format_message({ set: members }, nil, false)
  response = send_request(body)

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