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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1124a21f335f2328c4c303a75158a03297426e5d
4
- data.tar.gz: 9059f4727900b469a8615220758bf3847beea5c7
3
+ metadata.gz: e8a77d5f3168132be3b18834c92d797ce3067dee
4
+ data.tar.gz: 65437b6baed64c1659b6fd2da239b0537432ecb0
5
5
  SHA512:
6
- metadata.gz: f737da5048654c97d087af1117f88198d8af44391d0d00588754f751b261a8f034db8665d3af0862660fae7085ac2796b0fc2d04b7a5b3eba6214d5f253eabee
7
- data.tar.gz: 2c02db28f3f164083755bded1c9c0046c75d43fc7d2f9c7a5fb262b3d191dccb003092c931d262c6064acc6ceb4310c112ab1250342b72067a1f693115766982
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
- Pandapush.publish('messages', {user: {id: 1, name: 'Neil Gupta', email: 'neil@instructure.com'}})
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, message, is_public)
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
- * `is_public` - boolean for whether this channel is public. Defaults to false
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
- ### Pandapush.generate_token(channel, is_public, pub, sub)
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
- * `is_public` - boolean for whether this channel is public. Defaults to false
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
@@ -6,42 +6,38 @@ module Pandapush
6
6
 
7
7
  attr_accessor :app_id, :key, :secret, :url
8
8
 
9
- def initialize(options = {})
10
- options = {
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
- # is_public - boolean for whether this channel is public or private. Defaults to false
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, message, is_public = false)
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, is_public, true), message.to_json,
28
- {:content_type => :json, :Authorization => "Token #{generate_token(channel, is_public)}"}
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
- # is_public - boolean for whether this channel is public or private. Defaults to false
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. Note that sub on a public channel is redundant. Defaults to true
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, is_public = false, pub = true, sub = true)
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, is_public),
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, is_public = false, include_base_url = false)
57
- "#{include_base_url ? url : ''}/#{app_id}/#{is_public ? 'public' : 'private'}/#{channel}"
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
@@ -1,3 +1,3 @@
1
1
  module Pandapush
2
- VERSION = "1.0.2"
2
+ VERSION = "1.1.0"
3
3
  end
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.2
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-06-11 00:00:00.000000000 Z
11
+ date: 2015-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client