Class: PusherFake::Channel::Private
- Defined in:
- lib/pusher-fake/channel/private.rb
Overview
A private channel.
Direct Known Subclasses
Constant Summary
Constants inherited from Public
PusherFake::Channel::Public::CACHE_CHANNEL_PREFIX
Instance Attribute Summary
Attributes inherited from Public
Instance Method Summary collapse
-
#add(connection, options = {}) ⇒ Object
Add the connection to the channel if they are authorized.
-
#authentication_for(id, data = nil) ⇒ String
Generate an authentication string from the channel based on the connection ID provided.
-
#authorized?(connection, options) ⇒ Boolean
Determine if the connection is authorized for the channel.
Methods inherited from Public
#emit, #includes?, #initialize, #remove, #subscription_data, #trigger
Constructor Details
This class inherits a constructor from PusherFake::Channel::Public
Instance Method Details
#add(connection, options = {}) ⇒ Object
Add the connection to the channel if they are authorized.
13 14 15 16 17 18 19 |
# File 'lib/pusher-fake/channel/private.rb', line 13 def add(connection, = {}) if (connection, ) subscription_succeeded(connection, ) else connection.emit("pusher_internal:subscription_error", {}, name) end end |
#authentication_for(id, data = nil) ⇒ String
Generate an authentication string from the channel based on the connection ID provided.
39 40 41 42 43 44 45 46 47 |
# File 'lib/pusher-fake/channel/private.rb', line 39 def authentication_for(id, data = nil) configuration = PusherFake.configuration data = [id, name, data].compact.map(&:to_s).join(":") digest = OpenSSL::Digest.new("SHA256") signature = OpenSSL::HMAC.hexdigest(digest, configuration.secret, data) "#{configuration.key}:#{signature}" end |
#authorized?(connection, options) ⇒ Boolean
Determine if the connection is authorized for the channel.
27 28 29 30 |
# File 'lib/pusher-fake/channel/private.rb', line 27 def (connection, ) authentication_for(connection.id, [:channel_data]) == [:auth] end |