pandapush 1.0.2 → 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/README.md +20 -16
- data/lib/pandapush/client.rb +20 -24
- data/lib/pandapush/version.rb +1 -1
- 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: e8a77d5f3168132be3b18834c92d797ce3067dee
|
4
|
+
data.tar.gz: 65437b6baed64c1659b6fd2da239b0537432ecb0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ea71338a8eb17f99b27d376228a079d8ec1392bc5d19d03503c50fab401356a6d5f83a33c32e3d223c94164a5c183a196f4cb290cf279798365a51bb606d5c6
|
7
|
+
data.tar.gz: bba65a6930f72b19e9d8ac42fb1f2a22605cc2a5ff0fad10923099cbc4bbb355ed4fa8ea0a40d7f01287ecea5613a61ab3e0afb5f6fb3db14c89d67abeb6bf82
|
data/README.md
CHANGED
@@ -20,6 +20,8 @@ Or add it to your `Gemfile`:
|
|
20
20
|
gem 'pandapush'
|
21
21
|
```
|
22
22
|
|
23
|
+
Note: Pandapush 1.1.0+ requires Ruby 2.1+ due to its use of required named parameters.
|
24
|
+
|
23
25
|
## Setup
|
24
26
|
|
25
27
|
Create `/config/initializers/pandapush.rb` and add:
|
@@ -32,59 +34,61 @@ Pandapush.secret = 'YOUR APP SECRET'
|
|
32
34
|
|
33
35
|
## Usage
|
34
36
|
|
35
|
-
To publish a message
|
37
|
+
To publish a message to `/{your app id}/private/messages`:
|
36
38
|
|
37
39
|
```ruby
|
38
|
-
|
40
|
+
client.publish(channel: 'messages', message: {user: {id: 1, name: 'Neil Gupta', email: 'neil@instructure.com'}})
|
39
41
|
```
|
40
42
|
|
41
|
-
To generate a token for a JS client
|
43
|
+
To generate a token for a JS client to publish (but not subscribe) to `/{your app id}/private/messages`:
|
42
44
|
|
43
45
|
```ruby
|
44
|
-
Pandapush.generate_token('messages')
|
46
|
+
Pandapush.generate_token(channel: 'messages', sub: false)
|
45
47
|
```
|
46
48
|
|
47
49
|
If, for some reason, you need to use multiple Pandapush API keys, you can also initialize your own client with
|
48
50
|
|
49
51
|
```ruby
|
50
|
-
client = Pandapush::Client.new(
|
52
|
+
client = Pandapush::Client.new(
|
51
53
|
app_id: 'YOUR APP ID',
|
52
54
|
key: 'YOUR APP KEY',
|
53
55
|
secret: 'YOUR APP SECRET'
|
54
|
-
|
56
|
+
)
|
55
57
|
|
56
|
-
client.publish('messages', {user: {id: 1, name: 'Neil Gupta', email: 'neil@instructure.com'}})
|
58
|
+
client.publish(channel: 'messages', message: {user: {id: 1, name: 'Neil Gupta', email: 'neil@instructure.com'}})
|
57
59
|
```
|
58
60
|
|
59
61
|
## Documentation
|
60
62
|
|
61
|
-
### Pandapush.publish(channel
|
63
|
+
### Pandapush.publish(channel:, message, channel_type: 'private')
|
62
64
|
|
63
65
|
Sends a message to a Pandapush channel.
|
64
66
|
|
65
|
-
* `channel` - The name of the channel to push to
|
66
|
-
* `message` - hash that will be JSON encoded
|
67
|
-
* `
|
67
|
+
* `channel` - The name of the channel to push to (required)
|
68
|
+
* `message` - hash that will be JSON encoded (required)
|
69
|
+
* `channel_type` - 'public' or 'private'. Defaults to private
|
68
70
|
|
69
71
|
Example:
|
70
72
|
|
71
73
|
```ruby
|
72
|
-
Pandapush.publish('messages', {user: {id: 1, name: 'Neil Gupta', email: 'neil@instructure.com'}})
|
74
|
+
Pandapush.publish(channel: 'messages', message: {user: {id: 1, name: 'Neil Gupta', email: 'neil@instructure.com'}})
|
73
75
|
```
|
74
76
|
|
75
|
-
|
77
|
+
Note: `channel` is a string and can be any valid uri, such as `'users/1'`. Pandapush will handle generating the URL with your app id and channel type.
|
78
|
+
|
79
|
+
### Pandapush.generate_token(channel:, channel_type: 'private', pub: true, sub: true)
|
76
80
|
|
77
81
|
Generates a JWT token for client authentication.
|
78
82
|
|
79
|
-
* `channel` - The channel name the token works for
|
80
|
-
* `
|
83
|
+
* `channel` - The channel name the token works for (required)
|
84
|
+
* `channel_type` - 'public' or 'private'. Defaults to private
|
81
85
|
* `pub` - true if this token allows publishing. Defaults to true
|
82
86
|
* `sub` - true if this token allows subscribing. Note that sub on a public channel is redundant. Defaults to true
|
83
87
|
|
84
88
|
Example:
|
85
89
|
|
86
90
|
```ruby
|
87
|
-
Pandapush.generate_token('messages')
|
91
|
+
Pandapush.generate_token(channel: 'messages')
|
88
92
|
```
|
89
93
|
|
90
94
|
### Pandapush.app_id
|
data/lib/pandapush/client.rb
CHANGED
@@ -6,42 +6,38 @@ module Pandapush
|
|
6
6
|
|
7
7
|
attr_accessor :app_id, :key, :secret, :url
|
8
8
|
|
9
|
-
def initialize(
|
10
|
-
|
11
|
-
url: 'https://pp-beta.instructure.com/channel'
|
12
|
-
}.merge(options)
|
13
|
-
|
14
|
-
@app_id, @key, @secret, @url = options.values_at(:app_id, :key, :secret, :url)
|
9
|
+
def initialize(app_id: nil, key: nil, secret: nil, url: 'https://pp-beta.instructure.com/channel')
|
10
|
+
@app_id, @key, @secret, @url = app_id, key, secret, url
|
15
11
|
end
|
16
12
|
|
17
13
|
# publish - sends a message to a Pandapush channel
|
18
|
-
# channel - The name of the channel to push to
|
19
|
-
# message - hash that will be JSON encoded
|
20
|
-
#
|
21
|
-
#
|
14
|
+
# channel - The name of the channel to push to (required)
|
15
|
+
# message - hash that will be JSON encoded (required)
|
16
|
+
# channel_type - 'public' or 'private'. Defaults to private
|
17
|
+
#
|
22
18
|
# @example
|
23
|
-
# client.publish('messages', {user: {id: 1, name: 'Neil Gupta', email: 'neil@instructure.com'}})
|
24
|
-
def publish(channel
|
19
|
+
# client.publish(channel: 'messages', message: {user: {id: 1, name: 'Neil Gupta', email: 'neil@instructure.com'}})
|
20
|
+
def publish(channel:, message:, channel_type: 'private')
|
25
21
|
raise ConfigurationError, 'Missing client configuration: please check that key, secret and app_id are configured.' unless configured?
|
26
|
-
|
27
|
-
RestClient.post channel_uri(channel,
|
28
|
-
{:content_type => :json, :Authorization => "Token #{generate_token(channel,
|
22
|
+
|
23
|
+
RestClient.post channel_uri(channel, channel_type, include_base_url: true), message.to_json,
|
24
|
+
{:content_type => :json, :Authorization => "Token #{generate_token(channel: channel, channel_type: channel_type)}"}
|
29
25
|
end
|
30
26
|
|
31
27
|
# generate_token - returns a JWT token for client authentication
|
32
|
-
# channel - The channel name the token works for
|
33
|
-
#
|
28
|
+
# channel - The channel name the token works for (required)
|
29
|
+
# channel_type - 'public' or 'private'. Defaults to private
|
34
30
|
# pub - true if this token allows publishing. Defaults to true
|
35
|
-
# sub - true if this token allows subscribing.
|
36
|
-
#
|
31
|
+
# sub - true if this token allows subscribing. Defaults to true
|
32
|
+
#
|
37
33
|
# @example
|
38
|
-
# client.generate_token('messages')
|
39
|
-
def generate_token(channel
|
34
|
+
# client.generate_token(channel: 'messages', sub: false)
|
35
|
+
def generate_token(channel:, channel_type: 'private', pub: true, sub: true)
|
40
36
|
raise ConfigurationError, 'Missing client configuration: please check that key, secret and app_id are configured.' unless configured?
|
41
37
|
|
42
38
|
JWT.encode({
|
43
39
|
keyId: key,
|
44
|
-
channel: channel_uri(channel,
|
40
|
+
channel: channel_uri(channel, channel_type),
|
45
41
|
pub: pub,
|
46
42
|
sub: sub
|
47
43
|
}, secret)
|
@@ -53,8 +49,8 @@ module Pandapush
|
|
53
49
|
app_id && key && secret && url
|
54
50
|
end
|
55
51
|
|
56
|
-
def channel_uri(channel,
|
57
|
-
"#{include_base_url ? url : ''}/#{app_id}/#{
|
52
|
+
def channel_uri(channel, type, include_base_url: false)
|
53
|
+
"#{include_base_url ? url : ''}/#{app_id}/#{type}/#{channel}"
|
58
54
|
end
|
59
55
|
end
|
60
56
|
end
|
data/lib/pandapush/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pandapush
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Neil Gupta
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|