Class: Viaduct::WebPush::Channel
- Inherits:
-
Object
- Object
- Viaduct::WebPush::Channel
- Defined in:
- lib/viaduct/web_push/channel.rb
Instance Attribute Summary collapse
-
#bindings ⇒ Object
Returns the value of attribute bindings.
-
#name ⇒ Object
Returns the value of attribute name.
-
#subscribed ⇒ Object
Returns the value of attribute subscribed.
Class Method Summary collapse
-
.generate_signature(session_id, channel) ⇒ Object
Generate a HMAC signature for private channels.
-
.multi_trigger(channels, event, data = {}) ⇒ Object
Trigger an event on multiple channels simultaneously.
-
.trigger(channel, event, data = {}) ⇒ Object
Trigger a single even on a given channel.
Instance Method Summary collapse
-
#global? ⇒ Boolean
Blank name indicates global channel.
-
#initialize(name) ⇒ Channel
constructor
A new instance of Channel.
-
#trigger(event, data = {}) ⇒ Object
Trigger an event on this channel.
-
#trigger!(event, data = {}) ⇒ Object
Trigger an event on the channel in its own thread.
Constructor Details
#initialize(name) ⇒ Channel
Returns a new instance of Channel.
9 10 11 |
# File 'lib/viaduct/web_push/channel.rb', line 9 def initialize(name) @name = name end |
Instance Attribute Details
#bindings ⇒ Object
Returns the value of attribute bindings.
7 8 9 |
# File 'lib/viaduct/web_push/channel.rb', line 7 def bindings @bindings end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/viaduct/web_push/channel.rb', line 7 def name @name end |
#subscribed ⇒ Object
Returns the value of attribute subscribed.
7 8 9 |
# File 'lib/viaduct/web_push/channel.rb', line 7 def subscribed @subscribed end |
Class Method Details
.generate_signature(session_id, channel) ⇒ Object
Generate a HMAC signature for private channels
54 55 56 |
# File 'lib/viaduct/web_push/channel.rb', line 54 def self.generate_signature(session_id, channel) OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA256.new, WebPush.secret, "#{session_id}:#{channel}") end |
.multi_trigger(channels, event, data = {}) ⇒ Object
Trigger an event on multiple channels simultaneously
46 47 48 49 |
# File 'lib/viaduct/web_push/channel.rb', line 46 def self.multi_trigger(channels, event, data = {}) raise Error, "`channels` must an arrayof strings" unless channels.all? { |c| c.is_a?(String) } WebPush.request('trigger', {:channel => channels.join(','), :event => event, :data => data.to_json}) end |
.trigger(channel, event, data = {}) ⇒ Object
Trigger a single even on a given channel
39 40 41 |
# File 'lib/viaduct/web_push/channel.rb', line 39 def self.trigger(channel, event, data = {}) WebPush.request('trigger', {:channel => channel, :event => event, :data => data.to_json}) end |
Instance Method Details
#global? ⇒ Boolean
Blank name indicates global channel
16 17 18 |
# File 'lib/viaduct/web_push/channel.rb', line 16 def global? @name.nil? end |
#trigger(event, data = {}) ⇒ Object
Trigger an event on this channel
23 24 25 |
# File 'lib/viaduct/web_push/channel.rb', line 23 def trigger(event, data = {}) self.class.trigger(@name, event, data) end |
#trigger!(event, data = {}) ⇒ Object
Trigger an event on the channel in its own thread
30 31 32 33 34 |
# File 'lib/viaduct/web_push/channel.rb', line 30 def trigger!(event, data = {}) Thread.new do self.class.trigger(@name, event, data) end end |