Class: Pubnub::SubscribeEvent

Inherits:
Event show all
Includes:
Formatter, Adding, Callbacks, Heartbeat, Removing
Defined in:
lib/pubnub/subscribe_event.rb,
lib/pubnub/subscribe_event/adding.rb,
lib/pubnub/subscribe_event/removing.rb,
lib/pubnub/subscribe_event/callbacks.rb,
lib/pubnub/subscribe_event/formatter.rb,
lib/pubnub/subscribe_event/heartbeat.rb

Overview

SubscribeEvent module holds infrastructure for subscribe events.

Direct Known Subclasses

Presence, Subscribe

Defined Under Namespace

Modules: Adding, Callbacks, Formatter, Heartbeat, Removing

Instance Attribute Summary collapse

Attributes inherited from Event

#callback, #fresh_clone, #given_options, #idle_timeout, #open_timeout, #origin, #presence_callback, #read_timeout, #ssl, #state

Instance Method Summary collapse

Methods included from Formatter

channels_for_url, classify_method, encode, format_channel, format_group, format_message, format_presence_channel, make_channel_array, params_hash_to_url_params, parse_json

Methods included from Removing

#remove, #remove_channels, #remove_groups

Methods included from Adding

#add, #add_channels, #add_groups

Methods inherited from Event

#finalized?, #sync?, #uri

Constructor Details

#initialize(options, app) ⇒ SubscribeEvent

Returns a new instance of SubscribeEvent.



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/pubnub/subscribe_event.rb', line 12

def initialize(options, app)
  super
  @heartbeat = @app.env[:heartbeat]
  setup_cb_pools

  @wildcard_channel = @channel.select { |e| e.index('.*') } || []
  @channel -= @wildcard_channel

  add_channel_cb_to_cb_pools
  add_group_cb_to_cb_pools
  add_wc_channel_cb_to_cb_pools
end

Instance Attribute Details

#c_cb_poolObject (readonly)

Returns the value of attribute c_cb_pool.



10
11
12
# File 'lib/pubnub/subscribe_event.rb', line 10

def c_cb_pool
  @c_cb_pool
end

#channelObject (readonly)

Returns the value of attribute channel.



10
11
12
# File 'lib/pubnub/subscribe_event.rb', line 10

def channel
  @channel
end

#g_cb_poolObject (readonly)

Returns the value of attribute g_cb_pool.



10
11
12
# File 'lib/pubnub/subscribe_event.rb', line 10

def g_cb_pool
  @g_cb_pool
end

#groupObject (readonly)

Returns the value of attribute group.



10
11
12
# File 'lib/pubnub/subscribe_event.rb', line 10

def group
  @group
end

#heartObject (readonly)

Returns the value of attribute heart.



10
11
12
# File 'lib/pubnub/subscribe_event.rb', line 10

def heart
  @heart
end

#wc_cb_poolObject (readonly)

Returns the value of attribute wc_cb_pool.



10
11
12
# File 'lib/pubnub/subscribe_event.rb', line 10

def wc_cb_pool
  @wc_cb_pool
end

#wildcard_channelObject (readonly)

Returns the value of attribute wildcard_channel.



10
11
12
# File 'lib/pubnub/subscribe_event.rb', line 10

def wildcard_channel
  @wildcard_channel
end

Instance Method Details

#build(options) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/pubnub/subscribe_event.rb', line 53

def build(options)
  @c_cb_pool = options[:callbacks][:channels]
  @g_cb_pool = options[:callbacks][:groups]
  @wc_cb_pool = options[:callbacks][:wildcard_channels]

  @channel = options[:channels]
  @group = options[:groups]
  @wildcard_channel = options[:wildcard_channels]
end

#fireObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/pubnub/subscribe_event.rb', line 25

def fire
  return false if @finalized

  Pubnub.logger.debug('Pubnub') { "Fired event #{self.class}" }

  consider_heartbeat

  response = send_request

  return false if @app.subscriber.current_subscription_id != object_id && @http_sync != true

  Pubnub.logger.debug('Pubnub') { 'Fire before fire_callback' }

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

  async.fire unless @http_sync

  envelopes
end

#leave_allObject



45
46
47
48
49
50
51
# File 'lib/pubnub/subscribe_event.rb', line 45

def leave_all
  Pubnub.logger.debug('Pubnub') { 'Leaving all subscriptions' }
  @channel.each do |channel|
    @app.leave(channel: channel, skip_restart: true, http_sync: true)
  end
  finish
end