Skip to content

Commit

Permalink
Clean up the example application.
Browse files Browse the repository at this point in the history
  • Loading branch information
tristandunn committed Jan 11, 2014
1 parent 9a21943 commit 90efc89
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
21 changes: 12 additions & 9 deletions features/support/application.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
require "pusher"
require "sinatra"

Pusher.url = "http://PUSHER_API_KEY:PUSHER_API_SECRET@localhost:8081/apps/PUSHER_APP_ID"

class Sinatra::Application
set :root, Proc.new { File.join(File.dirname(__FILE__), "application") }
set :views, Proc.new { File.join(root, "views") }
Expand All @@ -15,13 +12,19 @@ class Sinatra::Application
end

post "/pusher/auth" do
data = nil
channel = Pusher[params[:channel_name]]
channel = Pusher[params[:channel_name]]
response = channel.authenticate(params[:socket_id], channel_data)

MultiJson.dump(response)
end

protected

if params[:channel_name] =~ /^presence-/
data = { user_id: params[:socket_id], user_info: { name: "Alan Turing" } }
end
def channel_data
return unless params[:channel_name] =~ /^presence-/

MultiJson.dump(channel.authenticate(params[:socket_id], data))
{ user_id: params[:socket_id],
user_info: { name: "Alan Turing" }
}
end
end
2 changes: 2 additions & 0 deletions features/support/pusher-fake.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Pusher.url = "http://PUSHER_API_KEY:PUSHER_API_SECRET@localhost:8081/apps/PUSHER_APP_ID"

Thread.new { PusherFake::Server.start }.tap do |thread|
at_exit { thread.exit }
end
Expand Down

0 comments on commit 90efc89

Please sign in to comment.