Skip to content

Commit

Permalink
Miscellaneous cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
tristandunn committed Feb 14, 2014
1 parent f0e1a96 commit 8553451
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion lib/pusher-fake.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module PusherFake
#
# @yield [Configuration] The current configuration.
def self.configure
yield(configuration)
yield configuration
end

# @return [Configuration] Current configuration.
Expand Down
6 changes: 3 additions & 3 deletions lib/pusher-fake/channel/public.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ def add(connection, options = {})
# @param [Hash] data The event data.
def emit(event, data, options = {})
connections.each do |connection|
next if connection.socket.object_id == options[:socket_id]

connection.emit(event, data, name)
unless connection.socket.object_id == options[:socket_id]
connection.emit(event, data, name)
end
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/pusher-fake/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ def initialize
#
# @param [Hash] options Custom options for Pusher client.
def to_options(options = {})
options.merge({
options.merge(
wsHost: socket_options[:host],
wsPort: socket_options[:port]
})
)
end
end
end
16 changes: 7 additions & 9 deletions lib/pusher-fake/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,20 @@ def establish
#
# @param [String] data The event data as JSON.
def process(data)
message = MultiJson.load(data, symbolize_keys: true)
data = message[:data]
event = message[:event]
channel_name = message[:channel] || data.delete(:channel)
channel = Channel.factory(channel_name)
message = MultiJson.load(data, symbolize_keys: true)
data = message[:data]
event = message[:event]
channel = Channel.factory(message[:channel] || data.delete(:channel))

case event
when "pusher:subscribe"
channel.add(self, data)
when "pusher:unsubscribe"
channel.remove(self)
when CLIENT_EVENT_MATCHER
return unless channel.is_a?(Channel::Private)
return unless channel.includes?(self)

channel.emit(event, data, socket_id: socket.object_id)
if channel.is_a?(Channel::Private) && channel.includes?(self)
channel.emit(event, data, socket_id: socket.object_id)
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/pusher-fake/server/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def self.channels(request)

filter = Regexp.new(%r{\A#{prefix}})
channels = PusherFake::Channel.channels || {}
channels.inject({ channels: {} }) do |result, (name, channel)|
channels.inject(channels: {}) do |result, (name, channel)|
unless filter && name !~ filter
channels = result[:channels]
channels[name] = {}
Expand Down
9 changes: 6 additions & 3 deletions lib/pusher-fake/webhook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ module PusherFake
class Webhook
class << self
def trigger(name, data = {})
payload = MultiJson.dump({
payload = MultiJson.dump(
events: [data.merge(name: name)],
time_ms: Time.now.to_i
})
)

PusherFake.configuration.webhooks.each do |url|
http = EventMachine::HttpRequest.new(url)
Expand All @@ -23,7 +23,10 @@ def headers_for(payload)
end

def signature_for(payload)
OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA256.new, PusherFake.configuration.secret, payload)
digest = OpenSSL::Digest::SHA256.new
secret = PusherFake.configuration.secret

OpenSSL::HMAC.hexdigest(digest, secret, payload)
end
end
end
Expand Down

0 comments on commit 8553451

Please sign in to comment.