Skip to content

Commit be5cf73

Browse files
authored
"Pusher" is now called "Pusher Channels"
1 parent 7487db2 commit be5cf73

File tree

1 file changed

+38
-37
lines changed

1 file changed

+38
-37
lines changed

README.md

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
Pusher gem
2-
==========
1+
# Gem for Pusher Channels
2+
3+
This Gem provides a Ruby interface to [the Pusher HTTP API for Pusher Channels](https://pusher.com/docs/rest_api).
34

45
[![Build Status](https://secure.travis-ci.org/pusher/pusher-http-ruby.svg?branch=master)](http://travis-ci.org/pusher/pusher-http-ruby)
56

6-
## Installation & Configuration
7+
## Installation and Configuration
78

8-
Add pusher to your Gemfile, and then run `bundle install`
9+
Add `pusher` to your Gemfile, and then run `bundle install`
910

1011
``` ruby
1112
gem 'pusher'
@@ -17,30 +18,31 @@ or install via gem
1718
gem install pusher
1819
```
1920

20-
After registering at <http://pusher.com> configure your app with the security credentials.
21+
After registering at <https://dashboard.pusher.com/>, configure your Pusher Channels app with the security credentials.
2122

22-
### Instantiating a Pusher client
23+
### Instantiating a Pusher Channels client
2324

24-
Creating a new Pusher `client` can be done as follows.
25+
Creating a new Pusher Channels `client` can be done as follows.
2526

2627
``` ruby
2728
require 'pusher'
2829

29-
pusher_client = Pusher::Client.new(
30+
channels_client = Pusher::Client.new(
3031
app_id: 'your-app-id',
3132
key: 'your-app-key',
3233
secret: 'your-app-secret',
3334
cluster: 'your-app-cluster',
3435
)
3536
```
37+
3638
The cluster value will set the `host` to `api-<cluster>.pusher.com`.
3739

38-
If you want to set a custom `host` value for your client then you can do so when instantiating a Pusher client like so:
40+
If you want to set a custom `host` value for your client then you can do so when instantiating a Pusher Channels client like so:
3941

4042
``` ruby
4143
require 'pusher'
4244

43-
pusher_client = Pusher::Client.new(
45+
channels_client = Pusher::Client.new(
4446
app_id: 'your-app-id',
4547
key: 'your-app-key',
4648
secret: 'your-app-secret',
@@ -50,15 +52,14 @@ pusher_client = Pusher::Client.new(
5052

5153
If you pass both `host` and `cluster` options, the `host` will take precendence and `cluster` will be ignored.
5254

53-
5455
Finally, if you have the configuration set in an `PUSHER_URL` environment
5556
variable, you can use:
5657

5758
``` ruby
58-
pusher_client = Pusher::Client.from_env
59+
channels_client = Pusher::Client.from_env
5960
```
6061

61-
### Global
62+
### Global configuration
6263

6364
Configuring Pusher can also be done globally on the Pusher class.
6465

@@ -99,7 +100,7 @@ Handle errors by rescuing `Pusher::Error` (all errors are descendants of this er
99100

100101
``` ruby
101102
begin
102-
Pusher.trigger('a_channel', 'an_event', :some => 'data')
103+
channels_client.trigger('a_channel', 'an_event', :some => 'data')
103104
rescue Pusher::Error => e
104105
# (Pusher::AuthenticationError, Pusher::HTTPError, or Pusher::Error)
105106
end
@@ -118,14 +119,14 @@ Pusher.logger = Rails.logger
118119
An event can be published to one or more channels (limited to 10) in one API call:
119120

120121
``` ruby
121-
Pusher.trigger('channel', 'event', foo: 'bar')
122-
Pusher.trigger(['channel_1', 'channel_2'], 'event_name', foo: 'bar')
122+
channels_client.trigger('channel', 'event', foo: 'bar')
123+
channels_client.trigger(['channel_1', 'channel_2'], 'event_name', foo: 'bar')
123124
```
124125

125126
An optional fourth argument may be used to send additional parameters to the API, for example to [exclude a single connection from receiving the event](http://pusher.com/docs/publisher_api_guide/publisher_excluding_recipients).
126127

127128
``` ruby
128-
Pusher.trigger('channel', 'event', {foo: 'bar'}, {socket_id: '123.456'})
129+
channels_client.trigger('channel', 'event', {foo: 'bar'}, {socket_id: '123.456'})
129130
```
130131

131132
#### Batches
@@ -134,7 +135,7 @@ It's also possible to send multiple events with a single API call (max 10
134135
events per call on multi-tenant clusters):
135136

136137
``` ruby
137-
Pusher.trigger_batch([
138+
channels_client.trigger_batch([
138139
{channel: 'channel_1', name: 'event_name', data: { foo: 'bar' }}
139140
{channel: 'channel_1', name: 'event_name', data: { hello: 'world' }}
140141
])
@@ -148,46 +149,46 @@ Most examples and documentation will refer to the following syntax for triggerin
148149
Pusher['a_channel'].trigger('an_event', :some => 'data')
149150
```
150151

151-
This will continue to work, but has been replaced by `Pusher.trigger` which supports one or multiple channels.
152+
This will continue to work, but has been replaced by `channels_client.trigger` which supports one or multiple channels.
152153

153-
### Using the Pusher REST API
154+
### Getting information about the channels in your Pusher Channels app
154155

155-
This gem provides methods for accessing information from the [Pusher REST API](https://pusher.com/docs/rest_api). The documentation also shows an example of the responses from each of the API endpionts.
156+
This gem provides methods for accessing information from the [Pusher HTTP API](https://pusher.com/docs/rest_api). The documentation also shows an example of the responses from each of the API endpionts.
156157

157158
The following methods are provided by the gem.
158159

159-
- `Pusher.channel_info('channel_name')` returns information about that channel.
160+
- `channels_client.channel_info('channel_name')` returns information about that channel.
160161

161-
- `Pusher.channel_users('channel_name')` returns a list of all the users subscribed to the channel.
162+
- `channels_client.channel_users('channel_name')` returns a list of all the users subscribed to the channel.
162163

163-
- `Pusher.channels` returns information about all the channels in your Pusher application.
164+
- `channels_client.channels` returns information about all the channels in your Pusher application.
164165

165166
### Asynchronous requests
166167

167168
There are two main reasons for using the `_async` methods:
168169

169-
* In a web application where the response from Pusher is not used, but you'd like to avoid a blocking call in the request-response cycle
170+
* In a web application where the response from the Pusher Channels HTTP API is not used, but you'd like to avoid a blocking call in the request-response cycle
170171
* Your application is running in an event loop and you need to avoid blocking the reactor
171172

172173
Asynchronous calls are supported either by using an event loop (eventmachine, preferred), or via a thread.
173174

174175
The following methods are available (in each case the calling interface matches the non-async version):
175176

176-
* `Pusher.get_async`
177-
* `Pusher.post_async`
178-
* `Pusher.trigger_async`
177+
* `channels_client.get_async`
178+
* `channels_client.post_async`
179+
* `channels_client.trigger_async`
179180

180-
It is of course also possible to make calls to pusher via a job queue. This approach is recommended if you're sending a large number of events to pusher.
181+
It is of course also possible to make calls to the Pusher Channels HTTP API via a job queue. This approach is recommended if you're sending a large number of events.
181182

182-
#### With eventmachine
183+
#### With EventMachine
183184

184185
* Add the `em-http-request` gem to your Gemfile (it's not a gem dependency).
185-
* Run the eventmachine reactor (either using `EM.run` or by running inside an evented server such as Thin).
186+
* Run the EventMachine reactor (either using `EM.run` or by running inside an evented server such as Thin).
186187

187188
The `_async` methods return an `EM::Deferrable` which you can bind callbacks to:
188189

189190
``` ruby
190-
Pusher.get_async("/channels").callback { |response|
191+
channels_client.get_async("/channels").callback { |response|
191192
# use reponse[:channels]
192193
}.errback { |error|
193194
# error is an instance of Pusher::Error
@@ -196,9 +197,9 @@ Pusher.get_async("/channels").callback { |response|
196197

197198
A HTTP error or an error response from pusher will cause the errback to be called with an appropriate error object.
198199

199-
#### Without eventmachine
200+
#### Without EventMachine
200201

201-
If the eventmachine reactor is not running, async requests will be made using threads (managed by the httpclient gem).
202+
If the EventMachine reactor is not running, async requests will be made using threads (managed by the httpclient gem).
202203

203204
An `HTTPClient::Connection` object is returned immediately which can be [interrogated](http://rubydoc.info/gems/httpclient/HTTPClient/Connection) to discover the status of the request. The usual response checking and processing is not done when the request completes, and frankly this method is most useful when you're not interested in waiting for the response.
204205

@@ -210,15 +211,15 @@ It's possible to use the gem to authenticate subscription requests to private or
210211
### Private channels
211212

212213
``` ruby
213-
Pusher.authenticate('private-my_channel', params[:socket_id])
214+
channels_client.authenticate('private-my_channel', params[:socket_id])
214215
```
215216

216217
### Presence channels
217218

218219
These work in a very similar way, but require a unique identifier for the user being authenticated, and optionally some attributes that are provided to clients via presence events:
219220

220221
``` ruby
221-
Pusher.authenticate('presence-my_channel', params[:socket_id],
222+
channels_client.authenticate('presence-my_channel', params[:socket_id],
222223
user_id: 'user_id',
223224
user_info: {} # optional
224225
)
@@ -229,7 +230,7 @@ Pusher.authenticate('presence-my_channel', params[:socket_id],
229230
A WebHook object may be created to validate received WebHooks against your app credentials, and to extract events. It should be created with the `Rack::Request` object (available as `request` in Rails controllers or Sinatra handlers for example).
230231

231232
``` ruby
232-
webhook = Pusher.webhook(request)
233+
webhook = channels_client.webhook(request)
233234
if webhook.valid?
234235
webhook.events.each do |event|
235236
case event["name"]

0 commit comments

Comments
 (0)