pusher 1.3.1 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/.travis.yml +1 -0
- data/README.md +59 -125
- data/lib/pusher.rb +1 -1
- data/lib/pusher/channel.rb +5 -2
- data/lib/pusher/client.rb +12 -1
- data/lib/pusher/request.rb +2 -0
- data/lib/pusher/version.rb +1 -1
- data/spec/channel_spec.rb +6 -4
- data/spec/client_spec.rb +57 -4
- metadata +27 -27
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
Mjk3MmUwODFhNDcxY2U1ZjVhZTlkMGUzYmZlMGE3NWY0ZGNkZGE3Mg==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d7b2bbdf8bc09f38d44a290d712f4e4cfea3c02d
|
4
|
+
data.tar.gz: 72350a25756be9e9bff440195d2efba5d6f91a17
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
ZTBiNzUyODYzYWE4NjQxNDE5OWQ2ZjIxMTMwYzUwYTdhNjkyNTY0OWZmMDQ2
|
11
|
-
YTA4NWVmMTJmMmZhMmFiNGY0NTM4Mjg5YjhlMDRhM2FkNDcxYWE=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
ZGZmNzQ0YmExMGMzZjlkY2U2Yzk5MzgyMWUwOTJhNzFmYjkxNTFkMGZmODNl
|
14
|
-
MmI4OGJlMmI0OGJiZjZhN2MwYzE3MDJiZWUzNzlhNzE1NDQ0OTQzODQxNTdj
|
15
|
-
ZGMwNGExNDljYTU4MjY1OTBjMWYzZTIzM2Q2YTdkMTY4OWI2Mzc=
|
6
|
+
metadata.gz: 177ffe40c85c424260852a5928196bd56d0bd40984635426d82f57d5ec6f126f4ce0e6eb99ee87b2e821a29b35e9640abde5a80895f0f71795f2d99c809d7a9a
|
7
|
+
data.tar.gz: 76a3284cc6ec3ea2686066cad60a020ca34399bdec353ccf5b2dc776ff8f57b9d1f68c2ce4a5ad10e2166de4757c995d16500b7c42b8af235338493dcf2b315a
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,11 +1,12 @@
|
|
1
|
-
Pusher
|
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).
|
3
4
|
|
4
5
|
[![Build Status](https://secure.travis-ci.org/pusher/pusher-http-ruby.svg?branch=master)](http://travis-ci.org/pusher/pusher-http-ruby)
|
5
6
|
|
6
|
-
## Installation
|
7
|
+
## Installation and Configuration
|
7
8
|
|
8
|
-
Add pusher to your Gemfile, and then run `bundle install`
|
9
|
+
Add `pusher` to your Gemfile, and then run `bundle install`
|
9
10
|
|
10
11
|
``` ruby
|
11
12
|
gem 'pusher'
|
@@ -17,68 +18,60 @@ or install via gem
|
|
17
18
|
gem install pusher
|
18
19
|
```
|
19
20
|
|
20
|
-
After registering at <
|
21
|
+
After registering at <https://dashboard.pusher.com/>, configure your Pusher Channels app with the security credentials.
|
21
22
|
|
22
|
-
### Instantiating a Pusher client
|
23
|
+
### Instantiating a Pusher Channels client
|
23
24
|
|
24
|
-
Creating a new Pusher `client` can be done as follows.
|
25
|
+
Creating a new Pusher Channels `client` can be done as follows.
|
25
26
|
|
26
27
|
``` ruby
|
27
|
-
|
28
|
-
app_id: 'your-pusher-app-id',
|
29
|
-
key: 'your-pusher-key',
|
30
|
-
secret: 'your-pusher-secret'
|
31
|
-
)
|
32
|
-
```
|
33
|
-
|
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:
|
28
|
+
require 'pusher'
|
35
29
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
30
|
+
channels_client = Pusher::Client.new(
|
31
|
+
app_id: 'your-app-id',
|
32
|
+
key: 'your-app-key',
|
33
|
+
secret: 'your-app-secret',
|
34
|
+
cluster: 'your-app-cluster',
|
35
|
+
use_tls: true
|
42
36
|
)
|
43
37
|
```
|
44
38
|
|
45
|
-
|
39
|
+
The `cluster` value will set the `host` to `api-<cluster>.pusher.com`. The `use_tls` value is optional and defaults to `false`. It will set the `scheme` and `port`. Custom `scheme` and `port` values take precendence over `use_tls`.
|
40
|
+
|
41
|
+
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:
|
46
42
|
|
47
43
|
``` ruby
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
44
|
+
require 'pusher'
|
45
|
+
|
46
|
+
channels_client = Pusher::Client.new(
|
47
|
+
app_id: 'your-app-id',
|
48
|
+
key: 'your-app-key',
|
49
|
+
secret: 'your-app-secret',
|
50
|
+
host: 'your-app-host'
|
53
51
|
)
|
54
52
|
```
|
55
53
|
|
56
|
-
|
54
|
+
If you pass both `host` and `cluster` options, the `host` will take precendence and `cluster` will be ignored.
|
57
55
|
|
58
56
|
Finally, if you have the configuration set in an `PUSHER_URL` environment
|
59
57
|
variable, you can use:
|
60
58
|
|
61
59
|
``` ruby
|
62
|
-
|
60
|
+
channels_client = Pusher::Client.from_env
|
63
61
|
```
|
64
62
|
|
65
|
-
### Global
|
63
|
+
### Global configuration
|
66
64
|
|
67
65
|
Configuring Pusher can also be done globally on the Pusher class.
|
68
66
|
|
69
67
|
``` ruby
|
70
|
-
Pusher.app_id = 'your-
|
71
|
-
Pusher.key = 'your-
|
72
|
-
Pusher.secret = 'your-
|
73
|
-
```
|
74
|
-
|
75
|
-
If you created your app in a different cluster to the default cluster, you must set it as follows:
|
76
|
-
|
77
|
-
``` ruby
|
68
|
+
Pusher.app_id = 'your-app-id'
|
69
|
+
Pusher.key = 'your-app-key'
|
70
|
+
Pusher.secret = 'your-app-secret'
|
78
71
|
Pusher.cluster = 'your-app-cluster'
|
79
72
|
```
|
80
73
|
|
81
|
-
Global configuration will automatically be set from the `PUSHER_URL` environment variable if it exists. This should be in the form `http://KEY:SECRET@
|
74
|
+
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.
|
82
75
|
|
83
76
|
If you need to make requests via a HTTP proxy then it can be configured
|
84
77
|
|
@@ -86,7 +79,8 @@ If you need to make requests via a HTTP proxy then it can be configured
|
|
86
79
|
Pusher.http_proxy = 'http://(user):(password)@(host):(port)'
|
87
80
|
```
|
88
81
|
|
89
|
-
By default API requests are made over HTTP. HTTPS can be used by setting
|
82
|
+
By default API requests are made over HTTP. HTTPS can be used by setting `encrypted` to `true`.
|
83
|
+
Issuing this command is going to reset `port` value if it was previously specified.
|
90
84
|
|
91
85
|
``` ruby
|
92
86
|
Pusher.encrypted = true
|
@@ -108,7 +102,7 @@ Handle errors by rescuing `Pusher::Error` (all errors are descendants of this er
|
|
108
102
|
|
109
103
|
``` ruby
|
110
104
|
begin
|
111
|
-
|
105
|
+
channels_client.trigger('a_channel', 'an_event', :some => 'data')
|
112
106
|
rescue Pusher::Error => e
|
113
107
|
# (Pusher::AuthenticationError, Pusher::HTTPError, or Pusher::Error)
|
114
108
|
end
|
@@ -127,14 +121,14 @@ Pusher.logger = Rails.logger
|
|
127
121
|
An event can be published to one or more channels (limited to 10) in one API call:
|
128
122
|
|
129
123
|
``` ruby
|
130
|
-
|
131
|
-
|
124
|
+
channels_client.trigger('channel', 'event', foo: 'bar')
|
125
|
+
channels_client.trigger(['channel_1', 'channel_2'], 'event_name', foo: 'bar')
|
132
126
|
```
|
133
127
|
|
134
128
|
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).
|
135
129
|
|
136
130
|
``` ruby
|
137
|
-
|
131
|
+
channels_client.trigger('channel', 'event', {foo: 'bar'}, {socket_id: '123.456'})
|
138
132
|
```
|
139
133
|
|
140
134
|
#### Batches
|
@@ -143,8 +137,8 @@ It's also possible to send multiple events with a single API call (max 10
|
|
143
137
|
events per call on multi-tenant clusters):
|
144
138
|
|
145
139
|
``` ruby
|
146
|
-
|
147
|
-
{channel: 'channel_1', name: 'event_name', data: { foo: 'bar' }}
|
140
|
+
channels_client.trigger_batch([
|
141
|
+
{channel: 'channel_1', name: 'event_name', data: { foo: 'bar' }},
|
148
142
|
{channel: 'channel_1', name: 'event_name', data: { hello: 'world' }}
|
149
143
|
])
|
150
144
|
```
|
@@ -157,46 +151,46 @@ Most examples and documentation will refer to the following syntax for triggerin
|
|
157
151
|
Pusher['a_channel'].trigger('an_event', :some => 'data')
|
158
152
|
```
|
159
153
|
|
160
|
-
This will continue to work, but has been replaced by `
|
154
|
+
This will continue to work, but has been replaced by `channels_client.trigger` which supports one or multiple channels.
|
161
155
|
|
162
|
-
###
|
156
|
+
### Getting information about the channels in your Pusher Channels app
|
163
157
|
|
164
|
-
This gem provides methods for accessing information from the [Pusher
|
158
|
+
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.
|
165
159
|
|
166
160
|
The following methods are provided by the gem.
|
167
161
|
|
168
|
-
- `
|
162
|
+
- `channels_client.channel_info('channel_name')` returns information about that channel.
|
169
163
|
|
170
|
-
- `
|
164
|
+
- `channels_client.channel_users('channel_name')` returns a list of all the users subscribed to the channel.
|
171
165
|
|
172
|
-
- `
|
166
|
+
- `channels_client.channels` returns information about all the channels in your Pusher application.
|
173
167
|
|
174
168
|
### Asynchronous requests
|
175
169
|
|
176
170
|
There are two main reasons for using the `_async` methods:
|
177
171
|
|
178
|
-
* 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
|
172
|
+
* 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
|
179
173
|
* Your application is running in an event loop and you need to avoid blocking the reactor
|
180
174
|
|
181
175
|
Asynchronous calls are supported either by using an event loop (eventmachine, preferred), or via a thread.
|
182
176
|
|
183
177
|
The following methods are available (in each case the calling interface matches the non-async version):
|
184
178
|
|
185
|
-
* `
|
186
|
-
* `
|
187
|
-
* `
|
179
|
+
* `channels_client.get_async`
|
180
|
+
* `channels_client.post_async`
|
181
|
+
* `channels_client.trigger_async`
|
188
182
|
|
189
|
-
It is of course also possible to make calls to
|
183
|
+
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.
|
190
184
|
|
191
|
-
#### With
|
185
|
+
#### With EventMachine
|
192
186
|
|
193
187
|
* Add the `em-http-request` gem to your Gemfile (it's not a gem dependency).
|
194
|
-
* Run the
|
188
|
+
* Run the EventMachine reactor (either using `EM.run` or by running inside an evented server such as Thin).
|
195
189
|
|
196
190
|
The `_async` methods return an `EM::Deferrable` which you can bind callbacks to:
|
197
191
|
|
198
192
|
``` ruby
|
199
|
-
|
193
|
+
channels_client.get_async("/channels").callback { |response|
|
200
194
|
# use reponse[:channels]
|
201
195
|
}.errback { |error|
|
202
196
|
# error is an instance of Pusher::Error
|
@@ -205,9 +199,9 @@ Pusher.get_async("/channels").callback { |response|
|
|
205
199
|
|
206
200
|
A HTTP error or an error response from pusher will cause the errback to be called with an appropriate error object.
|
207
201
|
|
208
|
-
#### Without
|
202
|
+
#### Without EventMachine
|
209
203
|
|
210
|
-
If the
|
204
|
+
If the EventMachine reactor is not running, async requests will be made using threads (managed by the httpclient gem).
|
211
205
|
|
212
206
|
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.
|
213
207
|
|
@@ -219,7 +213,7 @@ It's possible to use the gem to authenticate subscription requests to private or
|
|
219
213
|
### Private channels
|
220
214
|
|
221
215
|
``` ruby
|
222
|
-
|
216
|
+
channels_client.authenticate('private-my_channel', params[:socket_id])
|
223
217
|
```
|
224
218
|
|
225
219
|
### Presence channels
|
@@ -227,7 +221,7 @@ Pusher.authenticate('private-my_channel', params[:socket_id])
|
|
227
221
|
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:
|
228
222
|
|
229
223
|
``` ruby
|
230
|
-
|
224
|
+
channels_client.authenticate('presence-my_channel', params[:socket_id],
|
231
225
|
user_id: 'user_id',
|
232
226
|
user_info: {} # optional
|
233
227
|
)
|
@@ -238,7 +232,7 @@ Pusher.authenticate('presence-my_channel', params[:socket_id],
|
|
238
232
|
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).
|
239
233
|
|
240
234
|
``` ruby
|
241
|
-
webhook =
|
235
|
+
webhook = channels_client.webhook(request)
|
242
236
|
if webhook.valid?
|
243
237
|
webhook.events.each do |event|
|
244
238
|
case event["name"]
|
@@ -253,63 +247,3 @@ else
|
|
253
247
|
render text: 'invalid', status: 401
|
254
248
|
end
|
255
249
|
```
|
256
|
-
|
257
|
-
## Push Notifications (BETA)
|
258
|
-
|
259
|
-
Pusher now allows sending native notifications to iOS and Android devices. Check out the [documentation](https://pusher.com/docs/push_notifications) for information on how to set up push notifications on Android and iOS. There is no additional setup required to use it with this library. It works out of the box with the same Pusher instance. All you need are the same pusher credentials.
|
260
|
-
|
261
|
-
### Sending native pushes
|
262
|
-
|
263
|
-
The native notifications API is hosted at `nativepush-cluster1.pusher.com` and only accepts https requests.
|
264
|
-
|
265
|
-
You can send pushes by using the `notify` method, either globally or on the instance. The method takes two parameters:
|
266
|
-
|
267
|
-
- `interests`: An Array of strings which represents the interests your devices are subscribed to. These are akin to channels in the DDN with less of an epehemeral nature. Note that currently, you can only publish to, at most, _ten_ interests.
|
268
|
-
- `data`: The content of the notification represented by a Hash. You must supply either the `gcm` or `apns` key. For a detailed list of the acceptable keys, take a look at the [iOS](https://pusher.com/docs/push_notifications/ios/server) and [Android](https://pusher.com/docs/push_notifications/android/server) docs.
|
269
|
-
|
270
|
-
Example:
|
271
|
-
|
272
|
-
```ruby
|
273
|
-
data = {
|
274
|
-
apns: {
|
275
|
-
aps: {
|
276
|
-
alert: {
|
277
|
-
body: 'tada'
|
278
|
-
}
|
279
|
-
}
|
280
|
-
}
|
281
|
-
}
|
282
|
-
|
283
|
-
pusher.notify(["my-favourite-interest"], data)
|
284
|
-
```
|
285
|
-
|
286
|
-
### Errors
|
287
|
-
|
288
|
-
Push notification requests, once submitted to the service are executed asynchronously. To make reporting errors easier, you can supply a `webhook_url` field in the body of the request. This will be used by the service to send a webhook to the supplied URL if there are errors.
|
289
|
-
|
290
|
-
You may also supply a `webhook_level` field in the body, which can either be INFO or DEBUG. It defaults to INFO - where INFO only reports customer facing errors, while DEBUG reports all errors.
|
291
|
-
|
292
|
-
For example:
|
293
|
-
|
294
|
-
```ruby
|
295
|
-
data = {
|
296
|
-
apns: {
|
297
|
-
aps: {
|
298
|
-
alert: {
|
299
|
-
body: "hello"
|
300
|
-
}
|
301
|
-
}
|
302
|
-
},
|
303
|
-
gcm: {
|
304
|
-
notification: {
|
305
|
-
title: "hello",
|
306
|
-
icon: "icon"
|
307
|
-
}
|
308
|
-
},
|
309
|
-
webhook_url: "http://yolo.com",
|
310
|
-
webhook_level: "INFO"
|
311
|
-
}
|
312
|
-
```
|
313
|
-
|
314
|
-
**NOTE:** This is currently a BETA feature and there might be minor bugs and issues. Changes to the API will be kept to a minimum, but changes are expected. If you come across any bugs or issues, please do get in touch via [support](support@pusher.com) or create an issue here.
|
315
|
-
|
data/lib/pusher.rb
CHANGED
@@ -32,7 +32,7 @@ module Pusher
|
|
32
32
|
def_delegators :default_client, :scheme=, :host=, :port=, :app_id=, :key=, :secret=, :http_proxy=
|
33
33
|
def_delegators :default_client, :notification_host=, :notification_scheme=
|
34
34
|
|
35
|
-
def_delegators :default_client, :authentication_token, :url
|
35
|
+
def_delegators :default_client, :authentication_token, :url, :cluster
|
36
36
|
def_delegators :default_client, :encrypted=, :url=, :cluster=
|
37
37
|
def_delegators :default_client, :timeout=, :connect_timeout=, :send_timeout=, :receive_timeout=, :keep_alive_timeout=
|
38
38
|
|
data/lib/pusher/channel.rb
CHANGED
@@ -86,6 +86,9 @@ module Pusher
|
|
86
86
|
|
87
87
|
# Request info for a channel
|
88
88
|
#
|
89
|
+
# @example Response
|
90
|
+
# [{:occupied=>true, :subscription_count => 12}]
|
91
|
+
#
|
89
92
|
# @param info [Array] Array of attributes required (as lowercase strings)
|
90
93
|
# @return [Hash] Hash of requested attributes for this channel
|
91
94
|
# @raise [Pusher::Error] on invalid Pusher response - see the error message for more details
|
@@ -99,7 +102,7 @@ module Pusher
|
|
99
102
|
# Only works on presence channels (see: http://pusher.com/docs/client_api_guide/client_presence_channels and https://pusher.com/docs/rest_api)
|
100
103
|
#
|
101
104
|
# @example Response
|
102
|
-
# [{
|
105
|
+
# [{:id=>"4"}]
|
103
106
|
#
|
104
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
|
@@ -146,7 +149,7 @@ module Pusher
|
|
146
149
|
# render :json => Pusher['private-my_channel'].authenticate(params[:socket_id])
|
147
150
|
#
|
148
151
|
# @example Presence channels
|
149
|
-
# render :json => Pusher['
|
152
|
+
# render :json => Pusher['presence-my_channel'].authenticate(params[:socket_id], {
|
150
153
|
# :user_id => current_user.id, # => required
|
151
154
|
# :user_info => { # => optional - for example
|
152
155
|
# :name => current_user.name,
|
data/lib/pusher/client.rb
CHANGED
@@ -12,6 +12,11 @@ module Pusher
|
|
12
12
|
# Loads the configuration from an url in the environment
|
13
13
|
def self.from_env(key = 'PUSHER_URL')
|
14
14
|
url = ENV[key] || raise(ConfigurationError, key)
|
15
|
+
from_url(url)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Loads the configuration from a url
|
19
|
+
def self.from_url(url)
|
15
20
|
client = new
|
16
21
|
client.url = url
|
17
22
|
client
|
@@ -22,6 +27,12 @@ module Pusher
|
|
22
27
|
:scheme => 'http',
|
23
28
|
:port => 80,
|
24
29
|
}
|
30
|
+
|
31
|
+
if options[:use_tls] || options[:encrypted]
|
32
|
+
default_options[:scheme] = "https"
|
33
|
+
default_options[:port] = 443
|
34
|
+
end
|
35
|
+
|
25
36
|
merged_options = default_options.merge(options)
|
26
37
|
|
27
38
|
if options.has_key?(:host)
|
@@ -127,7 +138,7 @@ module Pusher
|
|
127
138
|
@connect_timeout, @send_timeout, @receive_timeout = value, value, value
|
128
139
|
end
|
129
140
|
|
130
|
-
##
|
141
|
+
## INTERACT WITH THE API ##
|
131
142
|
|
132
143
|
def resource(path)
|
133
144
|
Resource.new(self, path)
|
data/lib/pusher/request.rb
CHANGED
@@ -94,6 +94,8 @@ module Pusher
|
|
94
94
|
raise Error, "404 Not found (#{@uri.path})"
|
95
95
|
when 407
|
96
96
|
raise Error, "Proxy Authentication Required"
|
97
|
+
when 413
|
98
|
+
raise Error, "Payload Too Large > 10KB"
|
97
99
|
else
|
98
100
|
raise Error, "Unknown error (status code #{status_code}): #{body}"
|
99
101
|
end
|
data/lib/pusher/version.rb
CHANGED
data/spec/channel_spec.rb
CHANGED
@@ -71,15 +71,17 @@ describe Pusher::Channel do
|
|
71
71
|
|
72
72
|
describe '#info' do
|
73
73
|
it "should call the Client#channel_info" do
|
74
|
-
expect(@client).to receive(:get)
|
74
|
+
expect(@client).to receive(:get)
|
75
|
+
.with("/channels/mychannel", anything)
|
76
|
+
.and_return({:occupied => true, :subscription_count => 12})
|
75
77
|
@channel = @client['mychannel']
|
76
78
|
@channel.info
|
77
79
|
end
|
78
80
|
|
79
81
|
it "should assemble the requested attributes into the info option" do
|
80
|
-
expect(@client).to receive(:get)
|
81
|
-
|
82
|
-
|
82
|
+
expect(@client).to receive(:get)
|
83
|
+
.with(anything, {:info => "user_count,connection_count"})
|
84
|
+
.and_return({:occupied => true, :subscription_count => 12, :user_count => 12})
|
83
85
|
@channel = @client['presence-foo']
|
84
86
|
@channel.info(%w{user_count connection_count})
|
85
87
|
end
|
data/spec/client_spec.rb
CHANGED
@@ -87,19 +87,53 @@ describe Pusher do
|
|
87
87
|
expect(@client.host).to eq('api.staging.pusherapp.com')
|
88
88
|
end
|
89
89
|
|
90
|
-
it 'should
|
90
|
+
it 'should override the url configuration if it comes after' do
|
91
91
|
@client.url = "http://somekey:somesecret@api.staging.pusherapp.com:8080/apps/87"
|
92
92
|
@client.cluster = 'eu'
|
93
93
|
expect(@client.host).to eq('api-eu.pusher.com')
|
94
94
|
end
|
95
95
|
|
96
|
-
it 'should
|
96
|
+
it 'should override the host configuration if it comes after' do
|
97
97
|
@client.host = 'api.staging.pusher.com'
|
98
98
|
@client.cluster = 'eu'
|
99
99
|
expect(@client.host).to eq('api-eu.pusher.com')
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
103
|
+
describe 'configuring TLS' do
|
104
|
+
it 'should set port and scheme if "use_tls" enabled' do
|
105
|
+
client = Pusher::Client.new({
|
106
|
+
:use_tls => true,
|
107
|
+
})
|
108
|
+
expect(client.scheme).to eq('https')
|
109
|
+
expect(client.port).to eq(443)
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'should set port and scheme if "encrypted" enabled' do
|
113
|
+
client = Pusher::Client.new({
|
114
|
+
:encrypted => true,
|
115
|
+
})
|
116
|
+
expect(client.scheme).to eq('https')
|
117
|
+
expect(client.port).to eq(443)
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'should use non-TLS port and scheme if "encrypted" or "use_tls" are not set' do
|
121
|
+
client = Pusher::Client.new
|
122
|
+
expect(client.scheme).to eq('http')
|
123
|
+
expect(client.port).to eq(80)
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'should override port if "use_tls" option set but a different port is specified' do
|
127
|
+
client = Pusher::Client.new({
|
128
|
+
:use_tls => true,
|
129
|
+
:port => 8443
|
130
|
+
})
|
131
|
+
expect(client.scheme).to eq('https')
|
132
|
+
expect(client.port).to eq(8443)
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
136
|
+
|
103
137
|
describe 'configuring a http proxy' do
|
104
138
|
it "should be possible to configure everything by setting the http_proxy" do
|
105
139
|
@client.http_proxy = 'http://someuser:somepassword@proxy.host.com:8080'
|
@@ -109,6 +143,10 @@ describe Pusher do
|
|
109
143
|
end
|
110
144
|
|
111
145
|
describe 'configuring from env' do
|
146
|
+
after do
|
147
|
+
ENV['PUSHER_URL'] = nil
|
148
|
+
end
|
149
|
+
|
112
150
|
it "works" do
|
113
151
|
url = "http://somekey:somesecret@api.staging.pusherapp.com:8080/apps/87"
|
114
152
|
ENV['PUSHER_URL'] = url
|
@@ -118,7 +156,18 @@ describe Pusher do
|
|
118
156
|
expect(client.secret).to eq("somesecret")
|
119
157
|
expect(client.app_id).to eq("87")
|
120
158
|
expect(client.url.to_s).to eq("http://api.staging.pusherapp.com:8080/apps/87")
|
121
|
-
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
describe 'configuring from url' do
|
163
|
+
it "works" do
|
164
|
+
url = "http://somekey:somesecret@api.staging.pusherapp.com:8080/apps/87"
|
165
|
+
|
166
|
+
client = Pusher::Client.from_url(url)
|
167
|
+
expect(client.key).to eq("somekey")
|
168
|
+
expect(client.secret).to eq("somesecret")
|
169
|
+
expect(client.app_id).to eq("87")
|
170
|
+
expect(client.url.to_s).to eq("http://api.staging.pusherapp.com:8080/apps/87")
|
122
171
|
end
|
123
172
|
end
|
124
173
|
|
@@ -415,6 +464,11 @@ describe Pusher do
|
|
415
464
|
expect { call_api }.to raise_error(Pusher::Error, 'Proxy Authentication Required')
|
416
465
|
end
|
417
466
|
|
467
|
+
it "should raise Pusher::Error if pusher returns 413" do
|
468
|
+
stub_request(verb, @url_regexp).to_return({:status => 413})
|
469
|
+
expect { call_api }.to raise_error(Pusher::Error, 'Payload Too Large > 10KB')
|
470
|
+
end
|
471
|
+
|
418
472
|
it "should raise Pusher::Error if pusher returns 500" do
|
419
473
|
stub_request(verb, @url_regexp).to_return({:status => 500, :body => "some error"})
|
420
474
|
expect { call_api }.to raise_error(Pusher::Error, 'Unknown error (status code 500): some error')
|
@@ -612,4 +666,3 @@ describe Pusher do
|
|
612
666
|
end
|
613
667
|
end
|
614
668
|
end
|
615
|
-
|
metadata
CHANGED
@@ -1,97 +1,97 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pusher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pusher
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: pusher-signature
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 0.1.8
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.1.8
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: httpclient
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '2.7'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '2.7'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - ~>
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '3.0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - ~>
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: webmock
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: em-http-request
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - ~>
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: 1.1.0
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - ~>
|
94
|
+
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: 1.1.0
|
97
97
|
- !ruby/object:Gem::Dependency
|
@@ -112,42 +112,42 @@ dependencies:
|
|
112
112
|
name: rake
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- - ~>
|
115
|
+
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: 10.4.2
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- - ~>
|
122
|
+
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: 10.4.2
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: rack
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- - ~>
|
129
|
+
- - "~>"
|
130
130
|
- !ruby/object:Gem::Version
|
131
131
|
version: 1.6.4
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
|
-
- - ~>
|
136
|
+
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: 1.6.4
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: json
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
|
-
- - ~>
|
143
|
+
- - "~>"
|
144
144
|
- !ruby/object:Gem::Version
|
145
145
|
version: 1.8.3
|
146
146
|
type: :development
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
|
-
- - ~>
|
150
|
+
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: 1.8.3
|
153
153
|
description: Wrapper for pusher.com REST api
|
@@ -157,10 +157,10 @@ executables: []
|
|
157
157
|
extensions: []
|
158
158
|
extra_rdoc_files: []
|
159
159
|
files:
|
160
|
-
- .document
|
161
|
-
- .gemtest
|
162
|
-
- .gitignore
|
163
|
-
- .travis.yml
|
160
|
+
- ".document"
|
161
|
+
- ".gemtest"
|
162
|
+
- ".gitignore"
|
163
|
+
- ".travis.yml"
|
164
164
|
- CHANGELOG.md
|
165
165
|
- Gemfile
|
166
166
|
- LICENSE
|
@@ -190,17 +190,17 @@ require_paths:
|
|
190
190
|
- lib
|
191
191
|
required_ruby_version: !ruby/object:Gem::Requirement
|
192
192
|
requirements:
|
193
|
-
- -
|
193
|
+
- - ">="
|
194
194
|
- !ruby/object:Gem::Version
|
195
195
|
version: '0'
|
196
196
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
197
197
|
requirements:
|
198
|
-
- -
|
198
|
+
- - ">="
|
199
199
|
- !ruby/object:Gem::Version
|
200
200
|
version: '0'
|
201
201
|
requirements: []
|
202
202
|
rubyforge_project:
|
203
|
-
rubygems_version: 2.6.
|
203
|
+
rubygems_version: 2.6.11
|
204
204
|
signing_key:
|
205
205
|
specification_version: 4
|
206
206
|
summary: Pusher API client
|