pushradar 3.0.0.pre.alpha.1 → 3.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.idea/.gitignore +8 -0
- data/.idea/inspectionProfiles/Project_Default.xml +6 -0
- data/.idea/misc.xml +4 -0
- data/.idea/modules.xml +8 -0
- data/.idea/pushradar-server-ruby.iml +16 -0
- data/.idea/vcs.xml +6 -0
- data/CHANGELOG.md +12 -0
- data/README.md +33 -7
- data/VERSION +1 -0
- data/lib/pushradar/client.rb +47 -9
- data/lib/pushradar/version.rb +1 -1
- metadata +12 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3f0b3697a50e61ecbfc19f3a3013e0d3f96d9a2de94bdf009d51bc597dc2494
|
4
|
+
data.tar.gz: c17c7b4153c113cda86396d09e63735cd1351bcc7207c69eaa599c525046db0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d8124eb2217e3c4493a0af5ca5fc6e0c802e24ff2b813f7c14fc44f6129d10129893ebc7cb0c028163cee5aa94d443f49d0744bb035c51ec94a7d4331bee4c9
|
7
|
+
data.tar.gz: fc0d142f4d794d6e021f5f2e322bb5f7b42f4ce2510d23b30d0f6344455d817ffc2916bfae860d17f7a27322a4274d585c353cd3f6d595f065314d4538ee8aa5
|
data/.idea/.gitignore
ADDED
data/.idea/misc.xml
ADDED
data/.idea/modules.xml
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project version="4">
|
3
|
+
<component name="ProjectModuleManager">
|
4
|
+
<modules>
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/pushradar-server-ruby.iml" filepath="$PROJECT_DIR$/.idea/pushradar-server-ruby.iml" />
|
6
|
+
</modules>
|
7
|
+
</component>
|
8
|
+
</project>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<module type="RUBY_MODULE" version="4">
|
3
|
+
<component name="ModuleRunConfigurationManager">
|
4
|
+
<shared />
|
5
|
+
</component>
|
6
|
+
<component name="NewModuleRootManager">
|
7
|
+
<content url="file://$MODULE_DIR$">
|
8
|
+
<sourceFolder url="file://$MODULE_DIR$/features" isTestSource="true" />
|
9
|
+
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
|
10
|
+
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
11
|
+
</content>
|
12
|
+
<orderEntry type="inheritedJdk" />
|
13
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
14
|
+
<orderEntry type="library" scope="PROVIDED" name="bundler (v1.17.2, ruby-2.6.3-p62) [gem]" level="application" />
|
15
|
+
</component>
|
16
|
+
</module>
|
data/.idea/vcs.xml
ADDED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
## 3.1.1 (2022-06-25)
|
2
|
+
|
3
|
+
[CHANGED] Modified documentation
|
4
|
+
|
5
|
+
## 3.1.0 (2021-04-05)
|
6
|
+
|
7
|
+
[NEW] Added support for client data registration
|
8
|
+
|
9
|
+
## 3.0.0 (2021-02-18)
|
10
|
+
|
11
|
+
[NEW] Updated for release of PushRadar v3
|
12
|
+
|
1
13
|
## 3.0.0-alpha.1 (2021-02-08)
|
2
14
|
|
3
15
|
[NEW] Work on base code of package, compatible with the next release of PushRadar
|
data/README.md
CHANGED
@@ -42,13 +42,13 @@ Alterntively, install manually by running `$ gem install pushradar`
|
|
42
42
|
require 'pushradar'
|
43
43
|
|
44
44
|
radar = PushRadar::Client.new('your-secret-key')
|
45
|
-
radar.broadcast('channel-1', {message: 'Hello world!'})
|
45
|
+
radar.broadcast('channel-1', { message: 'Hello world!' })
|
46
46
|
```
|
47
47
|
|
48
48
|
## Receiving Messages
|
49
49
|
|
50
50
|
```html
|
51
|
-
<script src="https://pushradar.com/
|
51
|
+
<script src="https://js.pushradar.com/v3/pushradar.min.js"></script>
|
52
52
|
<script>
|
53
53
|
var radar = new PushRadar('your-public-key');
|
54
54
|
radar.subscribe.to('channel-1', function (data) {
|
@@ -64,11 +64,12 @@ Private channels require authentication and start with the prefix **private-**.
|
|
64
64
|
You will need to set up an authentication endpoint that returns a token using the `auth(...)` method if the user is allowed to subscribe to the channel. For example:
|
65
65
|
|
66
66
|
```ruby
|
67
|
-
radar = PushRadar::Client.new('
|
67
|
+
radar = PushRadar::Client.new('your-secret-key')
|
68
68
|
channel_name = params[:channelName]
|
69
|
+
socket_id = params[:socketID]
|
69
70
|
# is user allowed to access channel?
|
70
71
|
if true
|
71
|
-
|
72
|
+
return { 'token': radar.auth(channel_name, socket_id) }.to_json
|
72
73
|
end
|
73
74
|
```
|
74
75
|
|
@@ -78,11 +79,36 @@ Then register your authentication endpoint by calling the `auth(...)` method cli
|
|
78
79
|
radar.auth('/auth');
|
79
80
|
```
|
80
81
|
|
82
|
+
## Presence Channels
|
83
|
+
|
84
|
+
Presence channels require authentication and start with the prefix **presence-**. Presence channels are eligible for 'presence messages' containing information about channel subscribers.
|
85
|
+
|
86
|
+
You will need to set up an authentication endpoint as with private channels (see above). You should then register a `onPresence(...)` callback which will be called periodically. Your callback should accept two parameters: subscriber count and subscriber data. For example:
|
87
|
+
|
88
|
+
```javascript
|
89
|
+
radar.auth('/auth');
|
90
|
+
radar.call.on.connection('/connected');
|
91
|
+
|
92
|
+
radar.subscribe.to('presence-channel-1', function (data) {
|
93
|
+
console.log(data.message);
|
94
|
+
}).onPresence(function (count, clientData) {
|
95
|
+
console.log(count);
|
96
|
+
});
|
97
|
+
```
|
98
|
+
|
99
|
+
If you wish to pass through subscriber (client) data, you can set up an endpoint and pass its URL to the `call.on.connection(...)` method. Your endpoint will be called when a user first connects to the service. From your endpoint you can register client data as follows:
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
radar = PushRadar::Client.new('your-secret-key')
|
103
|
+
socket_id = params[:socketID]
|
104
|
+
radar.register_client_data(socket_id, { '##uniqueID': 1, 'name': 'James Smith' })
|
105
|
+
```
|
106
|
+
|
81
107
|
## Complete Documentation
|
82
108
|
|
83
|
-
Complete documentation for PushRadar's Ruby server library can be found at: <https://pushradar.com/docs/3.x
|
109
|
+
Complete documentation for PushRadar's Ruby server library can be found at: <https://pushradar.com/docs/3.x/ruby>
|
84
110
|
|
85
111
|
## License
|
86
112
|
|
87
|
-
Copyright 2021, PushRadar. PushRadar's Ruby server library is licensed under the MIT license:
|
88
|
-
|
113
|
+
Copyright © 2021, PushRadar. PushRadar's Ruby server library is licensed under the MIT license:
|
114
|
+
<https://opensource.org/licenses/mit-license.php>
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.1.1
|
data/lib/pushradar/client.rb
CHANGED
@@ -5,7 +5,11 @@ require 'cgi'
|
|
5
5
|
module PushRadar
|
6
6
|
class Client
|
7
7
|
def initialize(secret_key)
|
8
|
-
unless secret_key.is_a?(String)
|
8
|
+
unless secret_key.is_a?(String)
|
9
|
+
raise PushRadar::Error, 'Secret key must be a string.'
|
10
|
+
end
|
11
|
+
|
12
|
+
unless secret_key.start_with?('sk_')
|
9
13
|
raise PushRadar::Error, 'Please provide your PushRadar secret key. You can find it on the API page of your dashboard.'
|
10
14
|
end
|
11
15
|
|
@@ -22,34 +26,68 @@ module PushRadar
|
|
22
26
|
end
|
23
27
|
|
24
28
|
def broadcast(channel_name, data)
|
29
|
+
unless channel_name.is_a?(String)
|
30
|
+
raise PushRadar::Error, 'Channel name must be a string.'
|
31
|
+
end
|
32
|
+
|
25
33
|
if channel_name.nil? || channel_name.strip.empty?
|
26
34
|
raise PushRadar::Error, 'Channel name empty. Please provide a channel name.'
|
27
35
|
end
|
28
36
|
|
29
37
|
validate_channel_name(channel_name)
|
30
|
-
response = do_http_request('POST', @api_endpoint + "/broadcasts", { channel: channel_name
|
38
|
+
response = do_http_request('POST', @api_endpoint + "/broadcasts", { channel: channel_name, data: data.to_json })
|
31
39
|
|
32
40
|
if response[:status] === 200
|
33
41
|
true
|
34
42
|
else
|
35
|
-
raise PushRadar::Error, 'An error occurred while calling the API. Server returned: ' + response[:body]
|
43
|
+
raise PushRadar::Error, 'An error occurred while calling the API. Server returned: ' + response[:body]
|
36
44
|
end
|
37
45
|
end
|
38
46
|
|
39
|
-
def auth(channel_name)
|
47
|
+
def auth(channel_name, socket_id)
|
48
|
+
unless channel_name.is_a?(String)
|
49
|
+
raise PushRadar::Error, 'Channel name must be a string.'
|
50
|
+
end
|
51
|
+
|
40
52
|
if channel_name.nil? || channel_name.strip.empty?
|
41
53
|
raise PushRadar::Error, 'Channel name empty. Please provide a channel name.'
|
42
54
|
end
|
43
55
|
|
44
|
-
unless channel_name.start_with?('private-')
|
45
|
-
raise PushRadar::Error, 'Channel authentication can only be used with private channels.'
|
56
|
+
unless channel_name.start_with?('private-') || channel_name.start_with?('presence-')
|
57
|
+
raise PushRadar::Error, 'Channel authentication can only be used with private and presence channels.'
|
46
58
|
end
|
47
59
|
|
48
|
-
|
60
|
+
unless socket_id.is_a?(String)
|
61
|
+
raise PushRadar::Error, 'Socket ID must be a string.'
|
62
|
+
end
|
63
|
+
|
64
|
+
if socket_id.nil? || socket_id.strip.empty?
|
65
|
+
raise PushRadar::Error, 'Socket ID empty. Please pass through a socket ID.'
|
66
|
+
end
|
67
|
+
|
68
|
+
response = do_http_request('GET', @api_endpoint + "/channels/auth?channel=" + CGI.escape(channel_name) + "&socketID=" + CGI.escape(socket_id), {})
|
49
69
|
if response[:status] === 200
|
50
|
-
|
70
|
+
JSON(response[:body])['token']
|
71
|
+
else
|
72
|
+
raise PushRadar::Error, 'There was a problem receiving a channel authentication token. Server returned: ' + response[:body]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def register_client_data(socket_id, client_data)
|
77
|
+
unless socket_id.is_a?(String)
|
78
|
+
raise PushRadar::Error, 'Socket ID must be a string.'
|
79
|
+
end
|
80
|
+
|
81
|
+
if socket_id.nil? || socket_id.strip.empty?
|
82
|
+
raise PushRadar::Error, 'Socket ID empty. Please pass through a socket ID.'
|
83
|
+
end
|
84
|
+
|
85
|
+
response = do_http_request('POST', @api_endpoint + "/client-data", { socketID: socket_id, clientData: client_data.to_json })
|
86
|
+
|
87
|
+
if response[:status] === 200
|
88
|
+
true
|
51
89
|
else
|
52
|
-
raise PushRadar::Error, '
|
90
|
+
raise PushRadar::Error, 'An error occurred while calling the API. Server returned: ' + response[:body]
|
53
91
|
end
|
54
92
|
end
|
55
93
|
|
data/lib/pushradar/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pushradar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- PushRadar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
@@ -76,11 +76,18 @@ files:
|
|
76
76
|
- ".document"
|
77
77
|
- ".gemtest"
|
78
78
|
- ".gitignore"
|
79
|
+
- ".idea/.gitignore"
|
80
|
+
- ".idea/inspectionProfiles/Project_Default.xml"
|
81
|
+
- ".idea/misc.xml"
|
82
|
+
- ".idea/modules.xml"
|
83
|
+
- ".idea/pushradar-server-ruby.iml"
|
84
|
+
- ".idea/vcs.xml"
|
79
85
|
- CHANGELOG.md
|
80
86
|
- Gemfile
|
81
87
|
- LICENSE
|
82
88
|
- README.md
|
83
89
|
- Rakefile
|
90
|
+
- VERSION
|
84
91
|
- lib/pushradar.rb
|
85
92
|
- lib/pushradar/client.rb
|
86
93
|
- lib/pushradar/version.rb
|
@@ -100,11 +107,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
100
107
|
version: '0'
|
101
108
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
109
|
requirements:
|
103
|
-
- - "
|
110
|
+
- - ">="
|
104
111
|
- !ruby/object:Gem::Version
|
105
|
-
version:
|
112
|
+
version: '0'
|
106
113
|
requirements: []
|
107
|
-
rubygems_version: 3.0.3
|
114
|
+
rubygems_version: 3.0.3.1
|
108
115
|
signing_key:
|
109
116
|
specification_version: 4
|
110
117
|
summary: PushRadar Ruby server library
|