Sha256: d305840f817d55352a47b8543dfb21a1c973f7d93774dcfb151afbdb1f473ea1
Contents?: true
Size: 1.2 KB
Versions: 4
Compression:
Stored size: 1.2 KB
Contents
require 'sinatra' require 'sinatra/cookies' require 'sinatra/json' require 'pusher' # You can get these variables from http://dashboard.pusher.com pusher = Pusher::Client.new( app_id: 'your-app-id', key: 'your-app-key', secret: 'your-app-secret', cluster: 'your-app-cluster' ) set :public_folder, 'public' get "/" do redirect '/presence_channels.html' end # Emulate rails behaviour where this information would be stored in session get '/signin' do cookies[:user_id] = 'example_cookie' 'Ok' end # Auth endpoint: https://pusher.com/docs/channels/server_api/authenticating-users post '/pusher/auth' do channel_data = { user_id: 'example_user', user_info: { name: 'example_name', email: 'example_email' } } if cookies[:user_id] == 'example_cookie' response = pusher.authenticate(params[:channel_name], params[:socket_id], channel_data) json response else status 403 end end get '/pusher_trigger' do channels = ['presence-channel-test']; begin pusher.trigger(channels, 'test-event', { message: 'hello world' }) rescue Pusher::Error => e # (Pusher::AuthenticationError, Pusher::HTTPError, or Pusher::Error) end 'Triggered!' end
Version data entries
4 entries across 4 versions & 1 rubygems