pusher 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +12 -0
- data/lib/pusher/client.rb +41 -15
- data/pusher.gemspec +1 -3
- data/spec/client_spec.rb +31 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6daeeb10cfc7c29540cc4640cda4379f08c97a0a
|
4
|
+
data.tar.gz: d1387f40e14a45e68c5b7c2ba457d68d0e6f04e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68870356440d4b596c15ad6a51d65769d89cb036e782cffaedccc9f47d4d4707020c4e02671919ccd3c519019da9bb02505a6bfa9739e7e96fe358e38adfef4c
|
7
|
+
data.tar.gz: 3eeaa5528655dd1fc071e93adff493a39fc21843aea95f38b9076f8f9aebbb025f5b68afcd06f82bea733f985fa29f5e07611305051d5cc7bc4b8b04b95471af
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -131,6 +131,18 @@ An optional fourth argument may be used to send additional parameters to the API
|
|
131
131
|
Pusher.trigger('channel', 'event', {foo: 'bar'}, {socket_id: '123.456'})
|
132
132
|
```
|
133
133
|
|
134
|
+
#### Batches
|
135
|
+
|
136
|
+
It's also possible to send multiple events with a single API call (max 10
|
137
|
+
events per call on multi-tenant clusters):
|
138
|
+
|
139
|
+
``` ruby
|
140
|
+
Pusher.trigger_batch([
|
141
|
+
{channel: 'channel_1', name: 'event_name', data: { foo: 'bar' }}
|
142
|
+
{channel: 'channel_1', name: 'event_name', data: { hello: 'world' }}
|
143
|
+
])
|
144
|
+
```
|
145
|
+
|
134
146
|
#### Deprecated publisher API
|
135
147
|
|
136
148
|
Most examples and documentation will refer to the following syntax for triggering an event:
|
data/lib/pusher/client.rb
CHANGED
@@ -269,6 +269,21 @@ module Pusher
|
|
269
269
|
post('/events', trigger_params(channels, event_name, data, params))
|
270
270
|
end
|
271
271
|
|
272
|
+
# Trigger multiple events at the same time
|
273
|
+
#
|
274
|
+
# POST /apps/[app_id]/batch_events
|
275
|
+
#
|
276
|
+
# @param events [Array] List of events to publish
|
277
|
+
#
|
278
|
+
# @return [Hash] See Pusher API docs
|
279
|
+
#
|
280
|
+
# @raise [Pusher::Error] Unsuccessful response - see the error message
|
281
|
+
# @raise [Pusher::HTTPError] Error raised inside http client. The original error is wrapped in error.original_error
|
282
|
+
#
|
283
|
+
def trigger_batch(*events)
|
284
|
+
post('/batch_events', trigger_batch_params(events.flatten))
|
285
|
+
end
|
286
|
+
|
272
287
|
# Trigger an event on one or more channels asynchronously.
|
273
288
|
# For parameters see #trigger
|
274
289
|
#
|
@@ -276,6 +291,13 @@ module Pusher
|
|
276
291
|
post_async('/events', trigger_params(channels, event_name, data, params))
|
277
292
|
end
|
278
293
|
|
294
|
+
# Trigger multiple events asynchronously.
|
295
|
+
# For parameters see #trigger_batch
|
296
|
+
#
|
297
|
+
def trigger_batch_async(*events)
|
298
|
+
post_async('/batch_events', trigger_batch_params(events.flatten))
|
299
|
+
end
|
300
|
+
|
279
301
|
# Generate the expected response for an authentication endpoint.
|
280
302
|
# See http://pusher.com/docs/authenticating_users for details.
|
281
303
|
#
|
@@ -351,23 +373,27 @@ module Pusher
|
|
351
373
|
channels = Array(channels).map(&:to_s)
|
352
374
|
raise Pusher::Error, "Too many channels (#{channels.length}), max 10" if channels.length > 10
|
353
375
|
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
376
|
+
params.merge({
|
377
|
+
name: event_name,
|
378
|
+
channels: channels,
|
379
|
+
data: encode_data(data),
|
380
|
+
})
|
381
|
+
end
|
382
|
+
|
383
|
+
def trigger_batch_params(events)
|
384
|
+
{
|
385
|
+
batch: events.map do |event|
|
386
|
+
event.dup.tap do |e|
|
387
|
+
e[:data] = encode_data(e[:data])
|
388
|
+
end
|
363
389
|
end
|
364
|
-
|
390
|
+
}
|
391
|
+
end
|
365
392
|
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
})
|
393
|
+
# JSON-encode the data if it's not a string
|
394
|
+
def encode_data(data)
|
395
|
+
return data if data.is_a? String
|
396
|
+
MultiJson.encode(data)
|
371
397
|
end
|
372
398
|
|
373
399
|
def configured?
|
data/pusher.gemspec
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
|
4
2
|
Gem::Specification.new do |s|
|
5
3
|
s.name = "pusher"
|
6
|
-
s.version = "1.
|
4
|
+
s.version = "1.1.0"
|
7
5
|
s.platform = Gem::Platform::RUBY
|
8
6
|
s.authors = ["Pusher"]
|
9
7
|
s.email = ["support@pusher.com"]
|
data/spec/client_spec.rb
CHANGED
@@ -274,6 +274,37 @@ describe Pusher do
|
|
274
274
|
end
|
275
275
|
end
|
276
276
|
|
277
|
+
describe '#trigger_batch' do
|
278
|
+
before :each do
|
279
|
+
@api_path = %r{/apps/20/batch_events}
|
280
|
+
stub_request(:post, @api_path).to_return({
|
281
|
+
:status => 200,
|
282
|
+
:body => MultiJson.encode({})
|
283
|
+
})
|
284
|
+
end
|
285
|
+
|
286
|
+
it "should call correct URL" do
|
287
|
+
expect(@client.trigger_batch(channel: 'mychannel', name: 'event', data: {'some' => 'data'})).
|
288
|
+
to eq({})
|
289
|
+
end
|
290
|
+
|
291
|
+
it "should convert non string data to JSON before posting" do
|
292
|
+
@client.trigger_batch(
|
293
|
+
{channel: 'mychannel', name: 'event', data: {'some' => 'data'}},
|
294
|
+
{channel: 'mychannel', name: 'event', data: 'already encoded'},
|
295
|
+
)
|
296
|
+
expect(WebMock).to have_requested(:post, @api_path).with { |req|
|
297
|
+
parsed = MultiJson.decode(req.body)
|
298
|
+
expect(parsed).to eq(
|
299
|
+
"batch" => [
|
300
|
+
{ "channel" => "mychannel", "name" => "event", "data" => "{\"some\":\"data\"}"},
|
301
|
+
{ "channel" => "mychannel", "name" => "event", "data" => "already encoded"}
|
302
|
+
]
|
303
|
+
)
|
304
|
+
}
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
277
308
|
describe '#trigger_async' do
|
278
309
|
before :each do
|
279
310
|
@api_path = %r{/apps/20/events}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pusher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pusher
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|