A getting started example when using the Pusher Ruby HTTP API library with Rails.
This repo gives you the absolute basics required to get started. It doesn't provide you with full examples so should be used as a quick getting started template or a reference.
Todo:
- Triggering the same event on multiple channels
- How to trigger an event from your client (client events)
- Querying application state
From the directory you've cloned into, install the example dependencies:
$ bundle install
Prior to running the Rails app you'll need some environmental variables to be set.
PUSHER_CHAT_APP_ID
- your Pusher application IDPUSHER_CHAT_APP_KEY
- your Pusher application keyPUSHER_CHAT_APP_SECRET
- your Pusher application secret
You can do this from the command line as part of running the application:
# Bash (OS X and Linux)
PUSHER_CHAT_APP_ID=YOUR_APP_ID PUSHER_CHAT_APP_KEY=YOUR_APP_KEY PUSHER_CHAT_APP_SECRET=YOUR_APP_SECRET rails s
# Windows command prompt:
set PUSHER_CHAT_APP_ID=YOUR_APP_ID&& set PUSHER_CHAT_APP_KEY=YOUR_APP_KEY&& set PUSHER_CHAT_APP_SECRET=YOUR_APP_SECRET&& rails s
# Windows PowerShell:
$env:PUSHER_CHAT_APP_ID="YOUR_APP_ID"; $env:PUSHER_CHAT_APP_KEY="YOUR_APP_KEY"; $env:PUSHER_CHAT_APP_SECRET="YOUR_APP_SECRET"; rails s
Or, probably much more easily, with the help of foreman and by setting these values in a .env
file:
PUSHER_CHAT_APP_ID=YOUR_APP_ID
PUSHER_CHAT_APP_KEY=YOUR_APP_KEY
PUSHER_CHAT_APP_SECRET=YOUR_APP_SECRET
Then run:
PORT=3000 foreman start
Foreman will load those values automatically when you start the Rails app.
Navigate to localhost:3000
(or the URL you see logged to the console) and take a look at the examples. View the JavaScript console for a log from the Pusher JavaScript library.
Make sure you've got the required environmental variables set up!