Class: Pubnub::Event
- Includes:
- EFormatter, Signature
- Defined in:
- lib/pubnub/event.rb,
lib/pubnub/event/formatter.rb,
lib/pubnub/event/signature.rb
Overview
Event class lib/pubnub/event.rb
Direct Known Subclasses
Defined Under Namespace
Modules: EFormatter, Signature
Instance Attribute Summary collapse
-
#callback ⇒ Object
readonly
Returns the value of attribute callback.
-
#channel ⇒ Object
(also: #channels)
readonly
Returns the value of attribute channel.
-
#channel_group ⇒ Object
(also: #channel_groups)
readonly
Returns the value of attribute channel_group.
-
#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.
-
#with_presence ⇒ Object
readonly
Returns the value of attribute with_presence.
Instance Method Summary collapse
- #finalized? ⇒ Boolean
- #fire ⇒ Object
-
#initialize(options, app) ⇒ Event
constructor
A new instance of Event.
- #send_request(compressed_body = '', header = {}) ⇒ Object
- #sync? ⇒ Boolean
- #uri(memo = true) ⇒ Object
Methods included from EFormatter
#format_channels, #format_envelopes, #format_group
Constructor Details
#initialize(options, app) ⇒ Event
Returns a new instance of Event.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/pubnub/event.rb', line 20 def initialize(, app) @app = app @given_options = env = app.env.clone env.delete(:state) (env.merge()) @origin = @app.current_origin format_channels if enable_format_channels? format_group if enable_format_group? validate! telemetry = @app.telemetry_for(@telemetry_name) @compressed_body = nil @current_telemetry = telemetry ? telemetry.round(3) : nil Pubnub.logger.debug('Pubnub::Event') { "Initialized #{self.class}" } end |
Instance Attribute Details
#callback ⇒ Object (readonly)
Returns the value of attribute callback.
9 10 11 |
# File 'lib/pubnub/event.rb', line 9 def callback @callback end |
#channel ⇒ Object (readonly) Also known as: channels
Returns the value of attribute channel.
9 10 11 |
# File 'lib/pubnub/event.rb', line 9 def channel @channel end |
#channel_group ⇒ Object (readonly) Also known as: channel_groups
Returns the value of attribute channel_group.
9 10 11 |
# File 'lib/pubnub/event.rb', line 9 def channel_group @channel_group end |
#fresh_clone ⇒ Object (readonly)
Returns the value of attribute fresh_clone.
9 10 11 |
# File 'lib/pubnub/event.rb', line 9 def fresh_clone @fresh_clone end |
#given_options ⇒ Object (readonly)
Returns the value of attribute given_options.
9 10 11 |
# File 'lib/pubnub/event.rb', line 9 def @given_options end |
#group ⇒ Object (readonly)
Returns the value of attribute group.
9 10 11 |
# File 'lib/pubnub/event.rb', line 9 def group @group end |
#idle_timeout ⇒ Object (readonly)
Returns the value of attribute idle_timeout.
9 10 11 |
# File 'lib/pubnub/event.rb', line 9 def idle_timeout @idle_timeout end |
#open_timeout ⇒ Object (readonly)
Returns the value of attribute open_timeout.
9 10 11 |
# File 'lib/pubnub/event.rb', line 9 def open_timeout @open_timeout end |
#origin ⇒ Object (readonly)
Returns the value of attribute origin.
9 10 11 |
# File 'lib/pubnub/event.rb', line 9 def origin @origin end |
#presence_callback ⇒ Object (readonly)
Returns the value of attribute presence_callback.
9 10 11 |
# File 'lib/pubnub/event.rb', line 9 def presence_callback @presence_callback end |
#read_timeout ⇒ Object (readonly)
Returns the value of attribute read_timeout.
9 10 11 |
# File 'lib/pubnub/event.rb', line 9 def read_timeout @read_timeout end |
#ssl ⇒ Object (readonly)
Returns the value of attribute ssl.
9 10 11 |
# File 'lib/pubnub/event.rb', line 9 def ssl @ssl end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
9 10 11 |
# File 'lib/pubnub/event.rb', line 9 def state @state end |
#wildcard_channel ⇒ Object (readonly)
Returns the value of attribute wildcard_channel.
9 10 11 |
# File 'lib/pubnub/event.rb', line 9 def wildcard_channel @wildcard_channel end |
#with_presence ⇒ Object (readonly)
Returns the value of attribute with_presence.
9 10 11 |
# File 'lib/pubnub/event.rb', line 9 def with_presence @with_presence end |
Instance Method Details
#finalized? ⇒ Boolean
95 96 97 |
# File 'lib/pubnub/event.rb', line 95 def finalized? @finalized || @stop end |
#fire ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/pubnub/event.rb', line 37 def fire Pubnub.logger.debug('Pubnub::Event') { "Fired event #{self.class}" } response = send_request envelopes = fire_callbacks(handle(response, uri)) finalize_event(envelopes) envelopes end |
#send_request(compressed_body = '', header = {}) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/pubnub/event.rb', line 47 def send_request(compressed_body = '', header = {}) Pubnub.logger.debug('Pubnub::Event') { '#send_request called' } @compressed_body = compressed_body sender = request_dispatcher Pubnub.logger.debug('Pubnub::Event') { '#send_request got sender' } telemetry_time_start = ::Time.now.to_f response = case operation_http_method when 'get' sender.get(uri.to_s, header: header) when 'post' sender.post(uri.to_s, body: compressed_body, header: header) when 'patch' sender.patch(uri.to_s, body: compressed_body, header: header) else sender.delete(uri.to_s, header: header) end begin @app.record_telemetry(@telemetry_name, telemetry_time_start, ::Time.now.to_f) rescue StandardError => e Pubnub.logger.warn('Pubnub::Event') { "Couldn't record telemetry because of #{e}\n#{e.backtrace.join("\n")}" } end response rescue StandardError => e Pubnub.logger.error('Pubnub::Event') { e } e end |
#sync? ⇒ Boolean
99 100 101 |
# File 'lib/pubnub/event.rb', line 99 def sync? @http_sync ? true : false end |
#uri(memo = true) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/pubnub/event.rb', line 78 def uri(memo = true) unless is_a? SubscribeEvent return @uri = uri(false) if memo return @uri if @uri end sa_signature = super_admin_signature(operation_http_method, @compressed_body) unless parameters.include?(:signature) uri = @ssl ? 'https://' : 'http://' uri += @origin uri += path uri += '?' + Formatter.params_hash_to_url_params(parameters) uri += "&signature=#{sa_signature}" if sa_signature Pubnub.logger.debug('Pubnub::Event') { "Requested URI: #{uri}" } URI uri end |