Skip to content

Commit 86e613f

Browse files
authored
Merge pull request #134 from pusher/pusher-channels
"Pusher" is now called "Pusher Channels"
2 parents 1abd389 + 695d864 commit 86e613f

File tree

1 file changed

+39
-38
lines changed

1 file changed

+39
-38
lines changed

README.md

Lines changed: 39 additions & 38 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

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

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

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

126127
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).
127128

128129
``` ruby
129-
Pusher.trigger('channel', 'event', {foo: 'bar'}, {socket_id: '123.456'})
130+
channels_client.trigger('channel', 'event', {foo: 'bar'}, {socket_id: '123.456'})
130131
```
131132

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

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

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

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

156-
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 endpoints.
157+
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 endpoints.
157158

158159
The following methods are provided by the gem.
159160

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

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

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

166167
### Asynchronous requests
167168

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

170-
* 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
171+
* 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
171172
* Your application is running in an event loop and you need to avoid blocking the reactor
172173

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

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

177-
* `Pusher.get_async`
178-
* `Pusher.post_async`
179-
* `Pusher.trigger_async`
178+
* `channels_client.get_async`
179+
* `channels_client.post_async`
180+
* `channels_client.trigger_async`
180181

181-
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.
182+
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.
182183

183-
#### With eventmachine
184+
#### With EventMachine
184185

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

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

190191
``` ruby
191-
Pusher.get_async("/channels").callback { |response|
192-
# use response[:channels]
192+
channels_client.get_async("/channels").callback { |response|
193+
# use reponse[:channels]
193194
}.errback { |error|
194195
# error is an instance of Pusher::Error
195196
}
196197
```
197198

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

200-
#### Without eventmachine
201+
#### Without EventMachine
201202

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

204205
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.
205206

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

213214
``` ruby
214-
Pusher.authenticate('private-my_channel', params[:socket_id])
215+
channels_client.authenticate('private-my_channel', params[:socket_id])
215216
```
216217

217218
### Presence channels
218219

219220
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:
220221

221222
``` ruby
222-
Pusher.authenticate('presence-my_channel', params[:socket_id],
223+
channels_client.authenticate('presence-my_channel', params[:socket_id],
223224
user_id: 'user_id',
224225
user_info: {} # optional
225226
)
@@ -230,7 +231,7 @@ Pusher.authenticate('presence-my_channel', params[:socket_id],
230231
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).
231232

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

0 commit comments

Comments
 (0)