Skip to content

Commit

Permalink
Allow channel to be specified instead of channels
Browse files Browse the repository at this point in the history
  • Loading branch information
Tybot204 authored and tristandunn committed Nov 4, 2016
1 parent 368f714 commit 30a032e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/pusher-fake/server/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def self.events(request)
event = MultiJson.load(request.body.read)
data = MultiJson.load(event["data"]) rescue event["data"]

event["channels"] ||= [event["channel"]]
event["channels"].each do |channel_name|
channel = Channel.factory(channel_name)
channel.emit(event["name"], data, socket_id: event["socket_id"])
Expand All @@ -56,13 +57,14 @@ def self.events(request)
# @param [Rack::Request] request The HTTP request.
# @return [Hash] An empty hash.
#
# rubocop:disable Style/RescueModifier
# rubocop:disable Style/RescueModifier, Metrics/AbcSize
def self.batch_events(request)
batch = MultiJson.load(request.body.read)["batch"]

batch.each do |event|
data = MultiJson.load(event["data"]) rescue event["data"]

event["channels"] ||= [event["channel"]]
event["channels"].each do |channel_name|
channel = Channel.factory(channel_name)
channel.emit(event["name"], data, socket_id: event["socket_id"])
Expand All @@ -71,7 +73,7 @@ def self.batch_events(request)

{}
end
# rubocop:enable Style/RescueModifier
# rubocop:enable Style/RescueModifier, Metrics/AbcSize

# Return a hash of channel information.
#
Expand Down

0 comments on commit 30a032e

Please sign in to comment.