Class: Pubnub::SetMemberships
- Inherits:
-
SingleEvent
- Object
- Event
- SingleEvent
- Pubnub::SetMemberships
- Includes:
- Concurrent::Async, Validator::SetMemberships
- Defined in:
- lib/pubnub/events/set_memberships.rb
Overview
Holds SetMemberships 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
- #fire ⇒ Object
-
#initialize(options, app) ⇒ SetMemberships
constructor
A new instance of SetMemberships.
Methods included from Validator::SetMemberships
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) ⇒ SetMemberships
Returns a new instance of SetMemberships.
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 |
# File 'lib/pubnub/events/set_memberships.rb', line 10 def initialize(, app) @event = current_operation @telemetry_name = :l_obj @uuid = [:uuid].nil? ? app.user_id : [:uuid] @limit = [[:limit], 100].min unless [:limit].nil? @sort = [:sort].join(",") if [:sort] && ![:sort].empty? @filter = [:filter] if [:filter] && ![:filter].empty? @start = [:start] if [:start] && ![:start].empty? @end = [:end] if [:start] && ![:end].empty? if [:include] include = [:include] @include_count = [0, '0', false].include?(include[:count]) ? "0" : "1" unless include[:count].nil? @include_custom = "custom" if !include[:custom].nil? && ![0, '0', false].include?(include[:custom]) @include_channel_metadata = "channel" if !include[:channel_metadata].nil? && ![0, '0', false].include?(include[:channel_metadata]) @include_channel_custom = "channel.custom" if !include[:channel_custom].nil? && ![0, '0', false].include?(include[:channel_custom]) @include = [@include_custom, @include_channel_metadata, @include_channel_custom].reject { |flag| flag.to_s.empty? } end @channels = [:channels] if [:channels] && ![:channels].empty? # Collections by default return number of available entries. @include_count = "1" if @include_count.nil? super end |
Instance Method Details
#fire ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/pubnub/events/set_memberships.rb', line 38 def fire Pubnub.logger.debug('Pubnub::SetMemberships') { "Fired event #{self.class}" } memberships = @channels.map do |membership| membership_object = { channel: { id: membership[:channel] } } membership_object[:custom] = membership[:custom] if membership[:custom] && !membership[:custom].empty? membership_object end body = Formatter.({ set: memberships }, nil, false) response = send_request(body) envelopes = fire_callbacks(handle(response, uri)) finalize_event(envelopes) envelopes end |