pandapush 1.0.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 +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +114 -0
- data/Rakefile +6 -0
- data/lib/pandapush.rb +27 -0
- data/lib/pandapush/client.rb +62 -0
- data/lib/pandapush/version.rb +3 -0
- metadata +135 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ebb3e7ba70e437ae721f98024ffc4bc745765e76
|
4
|
+
data.tar.gz: c0d945e17bbcb367f445cd96f1d4a5ddf04bcd9a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 385c36ba0abcc3765eba953db895769afd22eaffbbf27e3c88ac67a194300e5380a85e722c784ec87286466e06f7b1f4035520ab22c93a31b4dd670e5fddf55c
|
7
|
+
data.tar.gz: 879ead1eadb40cdddec612ea7014c3c35249447fe1373d6e187ed4cdb724594c97f021a5ead6a9b657201e539b585099706aefbbc6a61add7a993ee616cfcd81
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2015 Neil Gupta
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
# Pandapush
|
2
|
+
|
3
|
+
[https://www.github.com/neilgupta/pandapush](https://www.github.com/neilgupta/pandapush)
|
4
|
+
|
5
|
+
[](http://badge.fury.io/rb/pandapush)
|
6
|
+
|
7
|
+
Pandapush is an event push system similar to Pusher for internal Instructure use.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Install the gem on your machine:
|
12
|
+
|
13
|
+
```
|
14
|
+
gem install pandapush
|
15
|
+
```
|
16
|
+
|
17
|
+
Or add it to your `Gemfile`:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'pandapush'
|
21
|
+
```
|
22
|
+
|
23
|
+
## Setup
|
24
|
+
|
25
|
+
Create `/config/initializers/pandapush.rb` and add:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
Pandapush.app_id = 'YOUR APP ID'
|
29
|
+
Pandapush.key = 'YOUR APP KEY'
|
30
|
+
Pandapush.secret = 'YOUR APP SECRET'
|
31
|
+
```
|
32
|
+
|
33
|
+
## Usage
|
34
|
+
|
35
|
+
To publish a message:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
Pandapush.publish('messages', {user: {id: 1, name: 'Neil Gupta', email: 'neil@instructure.com'}})
|
39
|
+
```
|
40
|
+
|
41
|
+
To generate a token for a JS client:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
Pandapush.generate_token('messages')
|
45
|
+
```
|
46
|
+
|
47
|
+
If, for some reason, you need to use multiple Pandapush API keys, you can also initialize your own client with
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
client = Pandapush::Client.new({
|
51
|
+
app_id: 'YOUR APP ID',
|
52
|
+
key: 'YOUR APP KEY',
|
53
|
+
secret: 'YOUR APP SECRET'
|
54
|
+
})
|
55
|
+
|
56
|
+
client.publish('messages', {user: {id: 1, name: 'Neil Gupta', email: 'neil@instructure.com'}})
|
57
|
+
```
|
58
|
+
|
59
|
+
## Documentation
|
60
|
+
|
61
|
+
### Pandapush.publish(channel, message, is_public)
|
62
|
+
|
63
|
+
Sends a message to a Pandapush channel.
|
64
|
+
|
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
|
68
|
+
|
69
|
+
Example:
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
Pandapush.publish('messages', {user: {id: 1, name: 'Neil Gupta', email: 'neil@instructure.com'}})
|
73
|
+
```
|
74
|
+
|
75
|
+
### Pandapush.generate_token(channel, is_public, pub, sub)
|
76
|
+
|
77
|
+
Generates a JWT token for client authentication.
|
78
|
+
|
79
|
+
* `channel` - The channel name the token works for
|
80
|
+
* `is_public` - boolean for whether this channel is public. Defaults to false
|
81
|
+
* `pub` - true if this token allows publishing. Defaults to true
|
82
|
+
* `sub` - true if this token allows subscribing. Note that sub on a public channel is redundant. Defaults to true
|
83
|
+
|
84
|
+
Example:
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
Pandapush.generate_token('messages')
|
88
|
+
```
|
89
|
+
|
90
|
+
### Pandapush.app_id
|
91
|
+
|
92
|
+
Getter and setter for your app id.
|
93
|
+
|
94
|
+
### Pandapush.key
|
95
|
+
|
96
|
+
Getter and setter for your app key.
|
97
|
+
|
98
|
+
### Pandapush.secret
|
99
|
+
|
100
|
+
Getter and setter for your app secret.
|
101
|
+
|
102
|
+
### Pandapush.url
|
103
|
+
|
104
|
+
Getter and setter to override the default url we use for Pandapush. This should never be used/needed.
|
105
|
+
|
106
|
+
All methods can also be accessed from `Pandapush::Client.new`.
|
107
|
+
|
108
|
+
## Author
|
109
|
+
|
110
|
+
Neil Gupta [http://metamorphium.com](http://metamorphium.com)
|
111
|
+
|
112
|
+
## License
|
113
|
+
|
114
|
+
The MIT License (MIT) Copyright (c) 2015 Neil Gupta. See [MIT-LICENSE](https://raw.github.com/neilgupta/pandapush/master/MIT-LICENSE)
|
data/Rakefile
ADDED
data/lib/pandapush.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
require 'pandapush/client'
|
3
|
+
|
4
|
+
module Pandapush
|
5
|
+
# All errors descend from this class so they can be easily rescued
|
6
|
+
#
|
7
|
+
# @example
|
8
|
+
# begin
|
9
|
+
# Pandapush.publish('channel_name', {some: 'data'})
|
10
|
+
# rescue Pandapush::Error => e
|
11
|
+
# # Do something on error
|
12
|
+
# end
|
13
|
+
class Error < RuntimeError; end
|
14
|
+
class ConfigurationError < Error; end
|
15
|
+
|
16
|
+
class << self
|
17
|
+
extend Forwardable
|
18
|
+
|
19
|
+
def_delegators :client, :app_id, :key, :secret, :url
|
20
|
+
def_delegators :client, :app_id=, :key=, :secret=, :url=
|
21
|
+
def_delegators :client, :publish, :generate_token
|
22
|
+
|
23
|
+
def client
|
24
|
+
@client ||= Pandapush::Client.new
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'jwt'
|
3
|
+
|
4
|
+
module Pandapush
|
5
|
+
class Client
|
6
|
+
|
7
|
+
attr_accessor :app_id, :key, :secret, :url
|
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)
|
15
|
+
end
|
16
|
+
|
17
|
+
# 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
|
+
#
|
22
|
+
# @example
|
23
|
+
# client.publish('messages', {user: {id: 1, name: 'Neil Gupta', email: 'neil@instructure.com'}})
|
24
|
+
def publish(channel, message, is_public = false)
|
25
|
+
raise ConfigurationError, 'Missing client configuration: please check that key, secret and app_id are configured.' unless configured?
|
26
|
+
|
27
|
+
HTTParty.post(channel_uri(channel, is_public, true),
|
28
|
+
basic_auth: { username: key, password: secret },
|
29
|
+
body: message.to_json,
|
30
|
+
headers: {"Content-Type" => "application/json"})
|
31
|
+
end
|
32
|
+
|
33
|
+
# generate_token - returns a JWT token for client authentication
|
34
|
+
# channel - The channel name the token works for
|
35
|
+
# is_public - boolean for whether this channel is public or private. Defaults to false
|
36
|
+
# pub - true if this token allows publishing. Defaults to true
|
37
|
+
# sub - true if this token allows subscribing. Note that sub on a public channel is redundant. Defaults to true
|
38
|
+
#
|
39
|
+
# @example
|
40
|
+
# client.generate_token('messages')
|
41
|
+
def generate_token(channel, is_public = false, pub = true, sub = true)
|
42
|
+
raise ConfigurationError, 'Missing client configuration: please check that key, secret and app_id are configured.' unless configured?
|
43
|
+
|
44
|
+
JWT.encode({
|
45
|
+
keyId: key,
|
46
|
+
channel: channel_uri(channel, is_public),
|
47
|
+
pub: pub,
|
48
|
+
sub: sub
|
49
|
+
}, secret)
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def configured?
|
55
|
+
app_id && key && secret && url
|
56
|
+
end
|
57
|
+
|
58
|
+
def channel_uri(channel, is_public = false, include_base_url = false)
|
59
|
+
"#{include_base_url ? url : ''}/#{app_id}/#{is_public ? 'public' : 'private'}/#{channel}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pandapush
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Neil Gupta
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.13'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: jwt
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.5'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 3.0.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 3.0.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: webmock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.18.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.18.0
|
97
|
+
description: Pandapush is Instructure's internal pub/sub server. This is a ruby client
|
98
|
+
for that server.
|
99
|
+
email: neil@instructure.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- MIT-LICENSE
|
105
|
+
- README.md
|
106
|
+
- Rakefile
|
107
|
+
- lib/pandapush.rb
|
108
|
+
- lib/pandapush/client.rb
|
109
|
+
- lib/pandapush/version.rb
|
110
|
+
homepage: https://github.com/neilgupta/pandapush
|
111
|
+
licenses:
|
112
|
+
- MIT
|
113
|
+
metadata: {}
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
requirements: []
|
129
|
+
rubyforge_project:
|
130
|
+
rubygems_version: 2.4.6
|
131
|
+
signing_key:
|
132
|
+
specification_version: 4
|
133
|
+
summary: Ruby client for pushing to Pandapush
|
134
|
+
test_files: []
|
135
|
+
has_rdoc:
|