pusher 0.17.0 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c321a0933bab4b4ccfbefa2c9e83eadab92d622c
4
- data.tar.gz: ecb892017e868a125e8a11bdb130c8f9069d9dcb
2
+ SHA256:
3
+ metadata.gz: 71dc5eb4f9d389dce37f6ec8c1f78390402b31bd94edcb6f22094c70edeb2d72
4
+ data.tar.gz: 3b2d0db0ffe052cbd8c71b252ced1d5910ece64a08100a92c0f17b5ac9b6fa8a
5
5
  SHA512:
6
- metadata.gz: 9db9cd31686cab8565d2fc2a0b4c57270728b69dc592c2dbb5baaa7c7df509b1c40836e3f9d550703e2e330b5c5198defc7935e5033ab7039bba91015ea3c5b7
7
- data.tar.gz: cea7de20ba9b57db2ff5e58fbc8bed35dfd8cf02ca88fb31b3929ba34b7a6036fef6b94fba0e244e0cc3b0549c288b5d3bf8d3d348e9acee0587542c31ab2e87
6
+ metadata.gz: 2f644cc58f1b8accd8785eeffc3fc74bad4c20677032455d96e655944ee0818f99802ed339a3f5f9049acd57ea1166817f6c01feba926c9b61256260239c6354
7
+ data.tar.gz: c0d4edd095918225bea29707df4e8e0364b16218c367b40f72c5541fe98232e4698e83e58ea8260b7caeeea54d314ec343ea25050f1f7847747d01a003c68221
data/CHANGELOG.md CHANGED
@@ -1,59 +1,133 @@
1
- 0.17.0 / 2016-02-22
2
- ==================
1
+ # Changelog
3
2
 
4
- * Introduce the `cluster` option.
3
+ ## 2.0.3
5
4
 
6
- 0.16.0 / 2016-01-21
7
- ==================
5
+ * [FIXED] Corrected the channels limit when publishing events. Upped from 10 to 100.
8
6
 
9
- * Bump httpclient version to 2.7
10
- * Ruby 1.8.7 is not supported anymore.
7
+ ## 2.0.2
11
8
 
12
- 0.15.2 / 2015-12-03
13
- ==================
9
+ * [CHANGED] made encryption_master_key_base64 globally configurable
14
10
 
15
- * Documented `Pusher.channel_info`, `Pusher.channels`
16
- * Added `Pusher.channel_users`
11
+ ## 2.0.1
17
12
 
18
- 0.15.1 / 2015-11-03
19
- ==================
13
+ * [CHANGED] Only include lib and essential docs in gem.
20
14
 
21
- * Fixed a bug where the `authenticate` method added in 0.15.0 wasn't exposed on the Pusher class.
15
+ ## 2.0.0
22
16
 
23
- 0.15.0 / 2015-11-02
24
- ==================
17
+ * [CHANGED] Use TLS by default.
18
+ * [REMOVED] Support for Ruby 2.4 and 2.5.
19
+ * [FIXED] Handle empty or nil configuration.
20
+ * [REMOVED] Legacy Push Notification integration.
21
+ * [ADDED] Stalebot and Github actions.
25
22
 
26
- * Added `Pusher.authenticate` method for authenticating private and presence channels.
27
- This is prefered over the older `Pusher['a_channel'].authenticate(...)` style.
23
+ ## 1.4.3
28
24
 
29
- 0.14.6 / 2015-09-29
30
- ==================
31
- * Updated to use the `pusher-signature` gem instead of `signature`.
32
- This resolves namespace related issues.
25
+ * [FIXED] Remove newline from end of base64 encoded strings, some decoders don't like
26
+ them.
33
27
 
34
- 0.14.5 / 2015-05-11
28
+ ## 1.4.2
35
29
  ==================
36
30
 
37
- * SECURITY: Prevent auth delegation trough crafted socket IDs
31
+ * [FIXED] Return `shared_secret` to support authenticating encrypted channels. Thanks
32
+ @Benjaminpjacobs
38
33
 
39
- 0.14.4 / 2015-01-20
40
- ==================
34
+ ## 1.4.1
41
35
 
42
- * SECURITY: Prevent timing attack, update signature to v0.1.8
43
- * SECURITY: Prevent POODLE. Disable SSLv3, update httpclient to v2.5
44
- * Fix channel name character limit.
45
- * Adds support for listing users on a presence channel
36
+ * [CHANGED] Remove rbnacl from dependencies so we don't get errors when it isn't
37
+ required. Thanks @y-yagi!
46
38
 
47
- 0.14.3 / 2015-01-20
48
- ==================
39
+ ## 1.4.0
49
40
 
50
- Yanked, bad release
41
+ * [ADDED] Support for end-to-end encryption.
51
42
 
52
- 0.14.2 / 2014-10-16
53
- ==================
43
+ ## 1.3.3
44
+
45
+ * [CHANGED] Rewording to clarify "Pusher Channels" or simply "Channels" product name.
46
+
47
+ ## 1.3.2
48
+
49
+ * [FIXED] Return a specific error for "Request Entity Too Large" (body over 10KB).
50
+ * [ADDED] Add a `use_tls` option for SSL (defaults to false).
51
+ * [ADDED] Add a `from_url` client method (in addition to existing `from_env` option).
52
+ * [CHANGED] Improved documentation and fixed typos.
53
+ * [ADDED] Add Ruby 2.4 to test matrix.
54
+
55
+ ## 1.3.1
56
+
57
+ * [FIXED] Added missing client batch methods to default client delegations
58
+ * [CHANGED] Document raised exception in the `authenticate` method
59
+ * [FIXED] Fixes em-http-request from using v2.5.0 of `addressable` breaking builds.
60
+
61
+ ## 1.3.0
62
+
63
+ * [ADDED] Add support for sending push notifications on up to 10 interests.
64
+
65
+ ## 1.2.1
66
+
67
+ * [FIXED] Fixes Rails 5 compatibility. Use duck-typing to detect request object
68
+
69
+ ## 1.2.0
70
+
71
+ * [CHANGED] Minor release for Native notifications
72
+
73
+ ## 1.2.0.rc1
74
+
75
+ * [ADDED] Add support for Native notifications
76
+
77
+ ## 1.1.0
78
+
79
+ * [ADDED] Add support for batch events
80
+
81
+ ## 1.0.0
82
+
83
+ * [CHANGED] No breaking changes, this release is just to follow semver and show that we
84
+ are stable.
85
+
86
+ ## 0.18.0
87
+
88
+ * [ADDED] Introduce `Pusher::Client.from_env`
89
+ * [FIXED] Improve error handling on missing config
90
+
91
+ ## 0.17.0
92
+
93
+ * [ADDED] Introduce the `cluster` option.
94
+
95
+ ## 0.16.0
96
+
97
+ * [CHANGED] Bump httpclient version to 2.7
98
+ * [REMOVED] Ruby 1.8.7 is not supported anymore.
99
+
100
+ ## 0.15.2
101
+
102
+ * [CHANGED] Documented `Pusher.channel_info`, `Pusher.channels`
103
+ * [ADDED] Added `Pusher.channel_users`
104
+
105
+ ## 0.15.1
106
+
107
+ * [FIXED] Fixed a bug where the `authenticate` method added in 0.15.0 wasn't exposed on the Pusher class.
108
+
109
+ ## 0.15.0
110
+
111
+ * [ADDED] Added `Pusher.authenticate` method for authenticating private and presence channels.
112
+ This is prefered over the older `Pusher['a_channel'].authenticate(...)` style.
113
+
114
+ ## 0.14.6
115
+
116
+ * [CHANGED] Updated to use the `pusher-signature` gem instead of `signature`.
117
+ This resolves namespace related issues.
118
+
119
+ ## 0.14.5
120
+
121
+ * [SECURITY] Prevent auth delegation trough crafted socket IDs
122
+
123
+ ## 0.14.4
54
124
 
55
- First release with a changelog !
125
+ * [SECURITY] Prevent timing attack, update signature to v0.1.8
126
+ * [SECURITY] Prevent POODLE. Disable SSLv3, update httpclient to v2.5
127
+ * [FIXED] Fix channel name character limit.
128
+ * [ADDED] Adds support for listing users on a presence channel
56
129
 
57
- * Bump httpclient to v2.4. See #62 (POODLE SSL)
58
- * Fix limited channel count at README.md. Thanks @tricknotes
130
+ ## 0.14.2
59
131
 
132
+ * [CHANGED] Bump httpclient to v2.4. See #62 (POODLE SSL)
133
+ * [CHANGED] Fix limited channel count at README.md. Thanks @tricknotes
data/README.md CHANGED
@@ -1,11 +1,16 @@
1
- Pusher gem
2
- ==========
1
+ # Gem for Pusher Channels
3
2
 
4
- [![Build Status](https://secure.travis-ci.org/pusher/pusher-http-ruby.svg?branch=master)](http://travis-ci.org/pusher/pusher-http-ruby)
3
+ This Gem provides a Ruby interface to [the Pusher HTTP API for Pusher Channels](https://pusher.com/docs/channels/library_auth_reference/rest-api).
5
4
 
6
- ## Installation & Configuration
5
+ [![Build Status](https://github.com/pusher/pusher-http-ruby/workflows/Tests/badge.svg)](https://github.com/pusher/pusher-http-ruby/actions?query=workflow%3ATests+branch%3Amaster) [![Gem](https://img.shields.io/gem/v/pusher)](https://rubygems.org/gems/pusher) [![Gem](https://img.shields.io/gem/dt/pusher)](https://rubygems.org/gems/pusher)
7
6
 
8
- Add pusher to your Gemfile, and then run `bundle install`
7
+ ## Supported Platforms
8
+
9
+ * Ruby - supports **Ruby 2.6 or greater**.
10
+
11
+ ## Installation and Configuration
12
+
13
+ Add `pusher` to your Gemfile, and then run `bundle install`
9
14
 
10
15
  ``` ruby
11
16
  gem 'pusher'
@@ -17,56 +22,60 @@ or install via gem
17
22
  gem install pusher
18
23
  ```
19
24
 
20
- After registering at <http://pusher.com> configure your app with the security credentials.
25
+ After registering at [Pusher](https://dashboard.pusher.com/accounts/sign_up), configure your Channels app with the security credentials.
21
26
 
22
- ### Instantiating a Pusher client
27
+ ### Instantiating a Pusher Channels client
23
28
 
24
- Creating a new Pusher `client` can be done as follows.
29
+ Creating a new Pusher Channels `client` can be done as follows.
25
30
 
26
31
  ``` ruby
27
- pusher_client = Pusher::Client.new(
28
- app_id: 'your-pusher-app-id',
29
- key: 'your-pusher-key',
30
- secret: 'your-pusher-secret'
32
+ require 'pusher'
33
+
34
+ pusher = Pusher::Client.new(
35
+ app_id: 'your-app-id',
36
+ key: 'your-app-key',
37
+ secret: 'your-app-secret',
38
+ cluster: 'your-app-cluster',
39
+ use_tls: true
31
40
  )
32
41
  ```
33
42
 
34
- If you want to set a custom `host` value for your client then you can do so when instantiating a Pusher client like so:
43
+ The `cluster` value will set the `host` to `api-<cluster>.pusher.com`. The `use_tls` value is optional and defaults to `true`. It will set the `scheme` and `port`. A custom `port` value takes precendence over `use_tls`.
44
+
45
+ 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:
35
46
 
36
47
  ``` ruby
37
- pusher_client = Pusher::Client.new(
38
- app_id: 'your-pusher-app-id',
39
- key: 'your-pusher-key',
40
- secret: 'your-pusher-secret',
41
- host: 'your-pusher-host'
48
+ require 'pusher'
49
+
50
+ pusher = Pusher::Client.new(
51
+ app_id: 'your-app-id',
52
+ key: 'your-app-key',
53
+ secret: 'your-app-secret',
54
+ host: 'your-app-host'
42
55
  )
43
56
  ```
44
57
 
45
- If you created your app in a different cluster to the default cluster, you must pass the `cluster` option as follows:
58
+ If you pass both `host` and `cluster` options, the `host` will take precendence and `cluster` will be ignored.
59
+
60
+ Finally, if you have the configuration set in an `PUSHER_URL` environment
61
+ variable, you can use:
46
62
 
47
63
  ``` ruby
48
- pusher_client = Pusher::Client.new(
49
- app_id: 'your-pusher-app-id',
50
- key: 'your-pusher-key',
51
- secret: 'your-pusher-secret',
52
- cluster: 'your-app-cluster'
53
- )
64
+ pusher = Pusher::Client.from_env
54
65
  ```
55
66
 
56
- This will set the `host` to `api-<cluster>.pusher.com`. If you pass both `host` and `cluster` options, the `host` will take precendence and `cluster` will be ignored.
57
-
58
- ### Global (Deprecated)
67
+ ### Global configuration
59
68
 
60
- Configuring Pusher can also be done globally on the Pusher class.
61
- *NOTE! This is a deprecated feature and will be removed in future versions of this library!*
69
+ The library can also be configured globally on the `Pusher` class.
62
70
 
63
71
  ``` ruby
64
- Pusher.app_id = 'your-pusher-app-id'
65
- Pusher.key = 'your-pusher-key'
66
- Pusher.secret = 'your-pusher-secret'
72
+ Pusher.app_id = 'your-app-id'
73
+ Pusher.key = 'your-app-key'
74
+ Pusher.secret = 'your-app-secret'
75
+ Pusher.cluster = 'your-app-cluster'
67
76
  ```
68
77
 
69
- Global configuration will automatically be set from the `PUSHER_URL` environment variable if it exists. This should be in the form `http://KEY:SECRET@api.pusherapp.com/apps/APP_ID`. On Heroku this environment variable will already be set.
78
+ Global configuration will automatically be set from the `PUSHER_URL` environment variable if it exists. This should be in the form `http://KEY:SECRET@HOST/apps/APP_ID`. On Heroku this environment variable will already be set.
70
79
 
71
80
  If you need to make requests via a HTTP proxy then it can be configured
72
81
 
@@ -74,10 +83,11 @@ If you need to make requests via a HTTP proxy then it can be configured
74
83
  Pusher.http_proxy = 'http://(user):(password)@(host):(port)'
75
84
  ```
76
85
 
77
- By default API requests are made over HTTP. HTTPS can be used by setting
86
+ By default API requests are made over HTTPS. HTTP can be used by setting `use_tls` to `false`.
87
+ Issuing this command is going to reset `port` value if it was previously specified.
78
88
 
79
89
  ``` ruby
80
- Pusher.encrypted = true
90
+ Pusher.use_tls = false
81
91
  ```
82
92
 
83
93
  As of version 0.12, SSL certificates are verified when using the synchronous http client. If you need to disable this behaviour for any reason use:
@@ -86,9 +96,9 @@ As of version 0.12, SSL certificates are verified when using the synchronous htt
86
96
  Pusher.default_client.sync_http_client.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE
87
97
  ```
88
98
 
89
- ## Interacting with the Pusher service
99
+ ## Interacting with the Channels HTTP API
90
100
 
91
- The Pusher gem contains a number of helpers for interacting with the service. As a general rule, the library adheres to a set of conventions that we have aimed to make universal.
101
+ The `pusher` gem contains a number of helpers for interacting with the API. As a general rule, the library adheres to a set of conventions that we have aimed to make universal.
92
102
 
93
103
  ### Handling errors
94
104
 
@@ -96,7 +106,7 @@ Handle errors by rescuing `Pusher::Error` (all errors are descendants of this er
96
106
 
97
107
  ``` ruby
98
108
  begin
99
- Pusher.trigger('a_channel', 'an_event', :some => 'data')
109
+ pusher.trigger('a_channel', 'an_event', :some => 'data')
100
110
  rescue Pusher::Error => e
101
111
  # (Pusher::AuthenticationError, Pusher::HTTPError, or Pusher::Error)
102
112
  end
@@ -115,14 +125,26 @@ Pusher.logger = Rails.logger
115
125
  An event can be published to one or more channels (limited to 10) in one API call:
116
126
 
117
127
  ``` ruby
118
- Pusher.trigger('channel', 'event', foo: 'bar')
119
- Pusher.trigger(['channel_1', 'channel_2'], 'event_name', foo: 'bar')
128
+ pusher.trigger('channel', 'event', foo: 'bar')
129
+ pusher.trigger(['channel_1', 'channel_2'], 'event_name', foo: 'bar')
120
130
  ```
121
131
 
122
- 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).
132
+ 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](https://pusher.com/docs/channels/server_api/excluding-event-recipients).
123
133
 
124
134
  ``` ruby
125
- Pusher.trigger('channel', 'event', {foo: 'bar'}, {socket_id: '123.456'})
135
+ pusher.trigger('channel', 'event', {foo: 'bar'}, {socket_id: '123.456'})
136
+ ```
137
+
138
+ #### Batches
139
+
140
+ It's also possible to send multiple events with a single API call (max 10
141
+ events per call on multi-tenant clusters):
142
+
143
+ ``` ruby
144
+ pusher.trigger_batch([
145
+ {channel: 'channel_1', name: 'event_name', data: { foo: 'bar' }},
146
+ {channel: 'channel_1', name: 'event_name', data: { hello: 'world' }}
147
+ ])
126
148
  ```
127
149
 
128
150
  #### Deprecated publisher API
@@ -133,69 +155,69 @@ Most examples and documentation will refer to the following syntax for triggerin
133
155
  Pusher['a_channel'].trigger('an_event', :some => 'data')
134
156
  ```
135
157
 
136
- This will continue to work, but has been replaced by `Pusher.trigger` which supports one or multiple channels.
158
+ This will continue to work, but has been replaced by `pusher.trigger` which supports one or multiple channels.
137
159
 
138
- ### Using the Pusher REST API
160
+ ### Getting information about the channels in your Pusher Channels app
139
161
 
140
- 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.
162
+ This gem provides methods for accessing information from the [Channels HTTP API](https://pusher.com/docs/channels/library_auth_reference/rest-api). The documentation also shows an example of the responses from each of the API endpoints.
141
163
 
142
164
  The following methods are provided by the gem.
143
165
 
144
- - `Pusher.channel_info('channel_name')` returns information about that channel.
166
+ - `pusher.channel_info('channel_name', {info:"user_count,subscription_count"})` returns a hash describing the state of the channel([docs](https://pusher.com/docs/channels/library_auth_reference/rest-api#get-channels-fetch-info-for-multiple-channels-)).
145
167
 
146
- - `Pusher.channel_users('channel_name')` returns a list of all the users subscribed to the channel.
168
+ - `pusher.channel_users('presence-channel_name')` returns a list of all the users subscribed to the channel (only for Presence Channels) ([docs](https://pusher.com/docs/channels/library_auth_reference/rest-api#get-channels-fetch-info-for-multiple-channels-)).
147
169
 
148
- - `Pusher.channels` returns information about all the channels in your Pusher application.
170
+ - `pusher.channels({filter_by_prefix: 'presence-', info: 'user_count'})` returns a hash of occupied channels (optionally filtered by prefix, f.i. `presence-`), and optionally attributes for these channels ([docs](https://pusher.com/docs/channels/library_auth_reference/rest-api#get-channels-fetch-info-for-multiple-channels-)).
149
171
 
150
172
  ### Asynchronous requests
151
173
 
152
174
  There are two main reasons for using the `_async` methods:
153
175
 
154
- * 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
176
+ * In a web application where the response from the Channels HTTP API is not used, but you'd like to avoid a blocking call in the request-response cycle
155
177
  * Your application is running in an event loop and you need to avoid blocking the reactor
156
178
 
157
179
  Asynchronous calls are supported either by using an event loop (eventmachine, preferred), or via a thread.
158
180
 
159
181
  The following methods are available (in each case the calling interface matches the non-async version):
160
182
 
161
- * `Pusher.get_async`
162
- * `Pusher.post_async`
163
- * `Pusher.trigger_async`
183
+ * `pusher.get_async`
184
+ * `pusher.post_async`
185
+ * `pusher.trigger_async`
164
186
 
165
- 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.
187
+ It is of course also possible to make calls to the Channels HTTP API via a job queue. This approach is recommended if you're sending a large number of events.
166
188
 
167
- #### With eventmachine
189
+ #### With EventMachine
168
190
 
169
191
  * Add the `em-http-request` gem to your Gemfile (it's not a gem dependency).
170
- * Run the eventmachine reactor (either using `EM.run` or by running inside an evented server such as Thin).
192
+ * Run the EventMachine reactor (either using `EM.run` or by running inside an evented server such as Thin).
171
193
 
172
194
  The `_async` methods return an `EM::Deferrable` which you can bind callbacks to:
173
195
 
174
196
  ``` ruby
175
- Pusher.get_async("/channels").callback { |response|
197
+ pusher.get_async("/channels").callback { |response|
176
198
  # use reponse[:channels]
177
199
  }.errback { |error|
178
200
  # error is an instance of Pusher::Error
179
201
  }
180
202
  ```
181
203
 
182
- A HTTP error or an error response from pusher will cause the errback to be called with an appropriate error object.
204
+ A HTTP error or an error response from Channels will cause the errback to be called with an appropriate error object.
183
205
 
184
- #### Without eventmachine
206
+ #### Without EventMachine
185
207
 
186
- If the eventmachine reactor is not running, async requests will be made using threads (managed by the httpclient gem).
208
+ If the EventMachine reactor is not running, async requests will be made using threads (managed by the httpclient gem).
187
209
 
188
210
  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.
189
211
 
190
212
 
191
213
  ## Authenticating subscription requests
192
214
 
193
- It's possible to use the gem to authenticate subscription requests to private or presence channels. The `authenticate` method is available on a channel object for this purpose and returns a JSON object that can be returned to the client that made the request. More information on this authentication scheme can be found in the docs on <http://pusher.com>
215
+ It's possible to use the gem to authenticate subscription requests to private or presence channels. The `authenticate` method is available on a channel object for this purpose and returns a JSON object that can be returned to the client that made the request. More information on this authentication scheme can be found in the docs on <https://pusher.com/docs/channels/server_api/authenticating-users>
194
216
 
195
217
  ### Private channels
196
218
 
197
219
  ``` ruby
198
- Pusher.authenticate('private-my_channel', params[:socket_id])
220
+ pusher.authenticate('private-my_channel', params[:socket_id])
199
221
  ```
200
222
 
201
223
  ### Presence channels
@@ -203,7 +225,7 @@ Pusher.authenticate('private-my_channel', params[:socket_id])
203
225
  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:
204
226
 
205
227
  ``` ruby
206
- Pusher.authenticate('presence-my_channel', params[:socket_id],
228
+ pusher.authenticate('presence-my_channel', params[:socket_id],
207
229
  user_id: 'user_id',
208
230
  user_info: {} # optional
209
231
  )
@@ -214,7 +236,7 @@ Pusher.authenticate('presence-my_channel', params[:socket_id],
214
236
  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).
215
237
 
216
238
  ``` ruby
217
- webhook = Pusher.webhook(request)
239
+ webhook = pusher.webhook(request)
218
240
  if webhook.valid?
219
241
  webhook.events.each do |event|
220
242
  case event["name"]
@@ -229,3 +251,51 @@ else
229
251
  render text: 'invalid', status: 401
230
252
  end
231
253
  ```
254
+
255
+ ### End-to-end encryption
256
+
257
+ This library supports [end-to-end encrypted channels](https://pusher.com/docs/channels/using_channels/encrypted-channels). This means that only you and your connected clients will be able to read your messages. Pusher cannot decrypt them. You can enable this feature by following these steps:
258
+
259
+ 1. Add the `rbnacl` gem to your Gemfile (it's not a gem dependency).
260
+
261
+ 2. Install [Libsodium](https://github.com/jedisct1/libsodium), which we rely on to do the heavy lifting. [Follow the installation instructions for your platform.](https://github.com/RubyCrypto/rbnacl/wiki/Installing-libsodium)
262
+
263
+ 3. Encrypted channel subscriptions must be authenticated in the exact same way as private channels. You should therefore [create an authentication endpoint on your server](https://pusher.com/docs/authenticating_users).
264
+
265
+ 4. Next, generate your 32 byte master encryption key, encode it as base64 and pass it to the Pusher constructor.
266
+
267
+ This is secret and you should never share this with anyone.
268
+ Not even Pusher.
269
+
270
+ ```bash
271
+ openssl rand -base64 32
272
+ ```
273
+
274
+ ```rb
275
+ pusher = new Pusher::Client.new({
276
+ app_id: 'your-app-id',
277
+ key: 'your-app-key',
278
+ secret: 'your-app-secret',
279
+ cluster: 'your-app-cluster',
280
+ use_tls: true
281
+ encryption_master_key_base64: '<KEY GENERATED BY PREVIOUS COMMAND>',
282
+ });
283
+ ```
284
+
285
+ 5. Channels where you wish to use end-to-end encryption should be prefixed with `private-encrypted-`.
286
+
287
+ 6. Subscribe to these channels in your client, and you're done! You can verify it is working by checking out the debug console on the [https://dashboard.pusher.com/](dashboard) and seeing the scrambled ciphertext.
288
+
289
+ **Important note: This will __not__ encrypt messages on channels that are not prefixed by `private-encrypted-`.**
290
+
291
+ **Limitation**: you cannot trigger a single event on multiple channels in a call to `trigger`, e.g.
292
+
293
+ ```rb
294
+ pusher.trigger(
295
+ ['channel-1', 'private-encrypted-channel-2'],
296
+ 'test_event',
297
+ { message: 'hello world' },
298
+ )
299
+ ```
300
+
301
+ Rationale: the methods in this library map directly to individual Channels HTTP API requests. If we allowed triggering a single event on multiple channels (some encrypted, some unencrypted), then it would require two API requests: one where the event is encrypted to the encrypted channels, and one where the event is unencrypted for unencrypted channels.
@@ -2,18 +2,17 @@ require 'openssl'
2
2
  require 'multi_json'
3
3
 
4
4
  module Pusher
5
- # Trigger events on Channels
5
+ # Delegates operations for a specific channel from a client
6
6
  class Channel
7
7
  attr_reader :name
8
8
  INVALID_CHANNEL_REGEX = /[^A-Za-z0-9_\-=@,.;]/
9
- def initialize(base_url, name, client = Pusher)
10
- @uri = base_url.dup
9
+
10
+ def initialize(_, name, client = Pusher)
11
11
  if Pusher::Channel::INVALID_CHANNEL_REGEX.match(name)
12
12
  raise Pusher::Error, "Illegal channel name '#{name}'"
13
- elsif name.length > 164
13
+ elsif name.length > 200
14
14
  raise Pusher::Error, "Channel name too long (limit 164 characters) '#{name}'"
15
15
  end
16
- @uri.path = @uri.path + "/channels/#{name}/"
17
16
  @name = name
18
17
  @client = client
19
18
  end
@@ -87,27 +86,31 @@ module Pusher
87
86
 
88
87
  # Request info for a channel
89
88
  #
89
+ # @example Response
90
+ # [{:occupied=>true, :subscription_count => 12}]
91
+ #
90
92
  # @param info [Array] Array of attributes required (as lowercase strings)
91
93
  # @return [Hash] Hash of requested attributes for this channel
92
94
  # @raise [Pusher::Error] on invalid Pusher response - see the error message for more details
93
95
  # @raise [Pusher::HTTPError] on any error raised inside http client - the original error is available in the original_error attribute
94
96
  #
95
97
  def info(attributes = [])
96
- @client.get("/channels/#{name}", :info => attributes.join(','))
98
+ @client.channel_info(name, :info => attributes.join(','))
97
99
  end
98
100
 
99
101
  # Request users for a presence channel
100
102
  # Only works on presence channels (see: http://pusher.com/docs/client_api_guide/client_presence_channels and https://pusher.com/docs/rest_api)
101
103
  #
102
104
  # @example Response
103
- # [{"id"=>"4"}]
105
+ # [{:id=>"4"}]
104
106
  #
107
+ # @param params [Hash] Hash of parameters for the API - see REST API docs
105
108
  # @return [Hash] Array of user hashes for this channel
106
109
  # @raise [Pusher::Error] on invalid Pusher response - see the error message for more details
107
110
  # @raise [Pusher::HTTPError] on any error raised inside Net::HTTP - the original error is available in the original_error attribute
108
111
  #
109
- def users
110
- @client.get("/channels/#{name}/users")[:users]
112
+ def users(params = {})
113
+ @client.channel_users(name, params)[:users]
111
114
  end
112
115
 
113
116
  # Compute authentication string required as part of the authentication
@@ -120,6 +123,8 @@ module Pusher
120
123
  # @param custom_string [String] Allows signing additional data
121
124
  # @return [String]
122
125
  #
126
+ # @raise [Pusher::Error] if socket_id or custom_string invalid
127
+ #
123
128
  def authentication_string(socket_id, custom_string = nil)
124
129
  validate_socket_id(socket_id)
125
130
 
@@ -144,7 +149,7 @@ module Pusher
144
149
  # render :json => Pusher['private-my_channel'].authenticate(params[:socket_id])
145
150
  #
146
151
  # @example Presence channels
147
- # render :json => Pusher['private-my_channel'].authenticate(params[:socket_id], {
152
+ # render :json => Pusher['presence-my_channel'].authenticate(params[:socket_id], {
148
153
  # :user_id => current_user.id, # => required
149
154
  # :user_info => { # => optional - for example
150
155
  # :name => current_user.name,
@@ -157,6 +162,8 @@ module Pusher
157
162
  #
158
163
  # @return [Hash]
159
164
  #
165
+ # @raise [Pusher::Error] if socket_id or custom_data is invalid
166
+ #
160
167
  # @private Custom data is sent to server as JSON-encoded string
161
168
  #
162
169
  def authenticate(socket_id, custom_data = nil)
@@ -167,6 +174,15 @@ module Pusher
167
174
  r
168
175
  end
169
176
 
177
+ def shared_secret(encryption_master_key)
178
+ return unless encryption_master_key
179
+
180
+ secret_string = @name + encryption_master_key
181
+ digest = OpenSSL::Digest::SHA256.new
182
+ digest << secret_string
183
+ digest.digest
184
+ end
185
+
170
186
  private
171
187
 
172
188
  def validate_socket_id(socket_id)