class PusherFake::Channel::Private
A private channel.
Public Instance Methods
add(connection, options = {})
click to toggle source
Add the connection to the channel if they are authorized.
@param [Connection] connection The connection to add. @param [Hash] options The options for the channel. @option options [String] :auth The authentication string. @option options [Hash] :channel_data Information for subscribed client.
# File lib/pusher-fake/channel/private.rb, line 13 def add(connection, options = {}) if authorized?(connection, options) subscription_succeeded(connection, options) else connection.emit("pusher_internal:subscription_error", {}, name) end end
authentication_for(id, data = nil)
click to toggle source
Generate an authentication string from the channel based on the connection ID provided.
@private @param [String] id The connection ID. @param [String] data Custom channel data. @return [String] The authentication string.
# 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