Class: Pubnub::Event
Overview
Event module holds most basic and required infrastructure for every pubnub event, there are also SingleEvent module and SubscribeEvent module
Direct Known Subclasses
Instance Attribute Summary collapse
-
#callback ⇒ Object
readonly
Returns the value of attribute callback.
-
#channel ⇒ Object
(also: #channels)
readonly
Returns the value of attribute channel.
-
#fresh_clone ⇒ Object
readonly
Returns the value of attribute fresh_clone.
-
#given_options ⇒ Object
readonly
Returns the value of attribute given_options.
-
#group ⇒ Object
readonly
Returns the value of attribute group.
-
#idle_timeout ⇒ Object
readonly
Returns the value of attribute idle_timeout.
-
#open_timeout ⇒ Object
readonly
Returns the value of attribute open_timeout.
-
#origin ⇒ Object
readonly
Returns the value of attribute origin.
-
#presence_callback ⇒ Object
readonly
Returns the value of attribute presence_callback.
-
#read_timeout ⇒ Object
readonly
Returns the value of attribute read_timeout.
-
#ssl ⇒ Object
readonly
Returns the value of attribute ssl.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#wildcard_channel ⇒ Object
readonly
Returns the value of attribute wildcard_channel.
Instance Method Summary collapse
- #finalized? ⇒ Boolean
- #fire ⇒ Object
-
#initialize(options, app) ⇒ Event
constructor
A new instance of Event.
- #send_request(compressed_body = '') ⇒ Object
- #sync? ⇒ Boolean
- #uri ⇒ Object
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(, app) @app = app @given_options = env = app.env.clone env.delete(:state) (env.merge()) @origin = @app.current_origin format_channels format_group validate! Pubnub.logger.debug('Pubnub::Event') { "Initialized #{self.class}" } end |
Instance Attribute Details
#callback ⇒ Object (readonly)
Returns the value of attribute callback.
6 7 8 |
# File 'lib/pubnub/event.rb', line 6 def callback @callback end |
#channel ⇒ Object (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_clone ⇒ Object (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_options ⇒ Object (readonly)
Returns the value of attribute given_options.
6 7 8 |
# File 'lib/pubnub/event.rb', line 6 def @given_options end |
#group ⇒ Object (readonly)
Returns the value of attribute group.
6 7 8 |
# File 'lib/pubnub/event.rb', line 6 def group @group end |
#idle_timeout ⇒ Object (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_timeout ⇒ Object (readonly)
Returns the value of attribute open_timeout.
6 7 8 |
# File 'lib/pubnub/event.rb', line 6 def open_timeout @open_timeout end |
#origin ⇒ Object (readonly)
Returns the value of attribute origin.
6 7 8 |
# File 'lib/pubnub/event.rb', line 6 def origin @origin end |
#presence_callback ⇒ Object (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_timeout ⇒ Object (readonly)
Returns the value of attribute read_timeout.
6 7 8 |
# File 'lib/pubnub/event.rb', line 6 def read_timeout @read_timeout end |
#ssl ⇒ Object (readonly)
Returns the value of attribute ssl.
6 7 8 |
# File 'lib/pubnub/event.rb', line 6 def ssl @ssl end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
6 7 8 |
# File 'lib/pubnub/event.rb', line 6 def state @state end |
#wildcard_channel ⇒ Object (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
59 60 61 |
# File 'lib/pubnub/event.rb', line 59 def finalized? @finalized || @stop end |
#fire ⇒ Object
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
63 64 65 |
# File 'lib/pubnub/event.rb', line 63 def sync? @http_sync ? true : false end |
#uri ⇒ Object
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 |