Class: PusherFake::Channel::Private
- Defined in:
- lib/pusher-fake/channel/private.rb
Direct Known Subclasses
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
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.
10 11 12 13 14 15 16 |
# File 'lib/pusher-fake/channel/private.rb', line 10 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.
35 36 37 38 39 40 41 42 |
# File 'lib/pusher-fake/channel/private.rb', line 35 def authentication_for(id, data = nil) configuration = PusherFake.configuration string = [id, name, data].compact.map(&:to_s).join(":") digest = OpenSSL::Digest::SHA256.new signature = OpenSSL::HMAC.hexdigest(digest, configuration.secret, string) "#{configuration.key}:#{signature}" end |
#authorized?(connection, options) ⇒ Boolean
Determine if the connection is authorized for the channel.
24 25 26 |
# File 'lib/pusher-fake/channel/private.rb', line 24 def (connection, ) authentication_for(connection.id, [:channel_data]) == [:auth] end |