Class: Pubnub::Event

Inherits:
Object show all
Defined in:
lib/pubnub/event.rb

Overview

Event module holds most basic and required infrastructure for every pubnub event, there are also SingleEvent module and SubscribeEvent module

Direct Known Subclasses

SingleEvent, SubscribeEvent

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, app) ⇒ Event

Returns a new instance of Event.



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

def initialize(options, app)
  @app = app
  @given_options = options
  env = app.env.clone
  env.delete(:state)
  create_variables_from_options(env.merge(options))
  @origin = @app.current_origin
  format_channels
  format_group
  set_timestamp
  validate!
  Pubnub.logger.debug('Pubnub::Event') { "Initialized #{self.class}" }
end

Instance Attribute Details

#callbackObject (readonly)

Returns the value of attribute callback.



6
7
8
# File 'lib/pubnub/event.rb', line 6

def callback
  @callback
end

#channelObject (readonly) Also known as: channels

Returns the value of attribute channel.



6
7
8
# File 'lib/pubnub/event.rb', line 6

def channel
  @channel
end

#fresh_cloneObject (readonly)

Returns the value of attribute fresh_clone.



6
7
8
# File 'lib/pubnub/event.rb', line 6

def fresh_clone
  @fresh_clone
end

#given_optionsObject (readonly)

Returns the value of attribute given_options.



6
7
8
# File 'lib/pubnub/event.rb', line 6

def given_options
  @given_options
end

#groupObject (readonly)

Returns the value of attribute group.



6
7
8
# File 'lib/pubnub/event.rb', line 6

def group
  @group
end

#idle_timeoutObject (readonly)

Returns the value of attribute idle_timeout.



6
7
8
# File 'lib/pubnub/event.rb', line 6

def idle_timeout
  @idle_timeout
end

#open_timeoutObject (readonly)

Returns the value of attribute open_timeout.



6
7
8
# File 'lib/pubnub/event.rb', line 6

def open_timeout
  @open_timeout
end

#originObject (readonly)

Returns the value of attribute origin.



6
7
8
# File 'lib/pubnub/event.rb', line 6

def origin
  @origin
end

#presence_callbackObject (readonly)

Returns the value of attribute presence_callback.



6
7
8
# File 'lib/pubnub/event.rb', line 6

def presence_callback
  @presence_callback
end

#read_timeoutObject (readonly)

Returns the value of attribute read_timeout.



6
7
8
# File 'lib/pubnub/event.rb', line 6

def read_timeout
  @read_timeout
end

#sslObject (readonly)

Returns the value of attribute ssl.



6
7
8
# File 'lib/pubnub/event.rb', line 6

def ssl
  @ssl
end

#stateObject (readonly)

Returns the value of attribute state.



6
7
8
# File 'lib/pubnub/event.rb', line 6

def state
  @state
end

#wildcard_channelObject (readonly)

Returns the value of attribute wildcard_channel.



6
7
8
# File 'lib/pubnub/event.rb', line 6

def wildcard_channel
  @wildcard_channel
end

Instance Method Details

#finalized?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/pubnub/event.rb', line 59

def finalized?
  @finalized || @stop
end

#fireObject



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/pubnub/event.rb', line 27

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

  response = send_request

  envelopes = fire_callbacks(handle(response, uri))
  finalize_event(envelopes)
  envelopes
ensure
  terminate unless @stay_alive
end

#send_request(compressed_body = '') ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/pubnub/event.rb', line 39

def send_request(compressed_body = '')
  sender = request_dispatcher
  if compressed_body.empty?
    sender.get(uri.to_s)
  else
    sender.post(uri.to_s, body: compressed_body)
  end
rescue => error
  error
end

#sync?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/pubnub/event.rb', line 63

def sync?
  @http_sync ? true : false
end

#uriObject



50
51
52
53
54
55
56
57
# File 'lib/pubnub/event.rb', line 50

def uri
  uri = @ssl ? 'https://' : 'http://'
  uri += @origin
  uri += path
  uri += '?' + Formatter.params_hash_to_url_params(parameters)
  Pubnub.logger.debug('Pubnub::Event') { "Requested URI: #{uri}" }
  URI uri
end