pushradar 3.0.0 → 3.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 +4 -0
- data/README.md +26 -1
- data/VERSION +1 -1
- data/lib/pushradar/client.rb +21 -3
- data/lib/pushradar/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4cb5a3926082d52f847bbb57e800e4c964cb9ea35c005e67c3df6246ceb17a07
|
4
|
+
data.tar.gz: a942aaea6376412ca2addd8d8e760df9919bb99ffe5c4de7164c148c5b306a57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99a48b950b8d6d196bbb621c3fb9c7d7a3f08fd9fdc80f8e1edbe7b100358743c48eb68314ebc237e8e64bbdc239391f71992b4e251578200463072d088f06cf
|
7
|
+
data.tar.gz: b7b05961ebc5e0492b55430fc223954fa497b3186eef2a15214da55920acc9af346a654d15096ac8d190749d860860f87c93c7d5e09c8584910ef5882b292dd7
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -79,9 +79,34 @@ Then register your authentication endpoint by calling the `auth(...)` method cli
|
|
79
79
|
radar.auth('/auth');
|
80
80
|
```
|
81
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
|
+
|
82
107
|
## Complete Documentation
|
83
108
|
|
84
|
-
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>
|
85
110
|
|
86
111
|
## License
|
87
112
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.
|
1
|
+
3.1.0
|
data/lib/pushradar/client.rb
CHANGED
@@ -53,8 +53,8 @@ module PushRadar
|
|
53
53
|
raise PushRadar::Error, 'Channel name empty. Please provide a channel name.'
|
54
54
|
end
|
55
55
|
|
56
|
-
unless channel_name.start_with?('private-')
|
57
|
-
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.'
|
58
58
|
end
|
59
59
|
|
60
60
|
unless socket_id.is_a?(String)
|
@@ -67,12 +67,30 @@ module PushRadar
|
|
67
67
|
|
68
68
|
response = do_http_request('GET', @api_endpoint + "/channels/auth?channel=" + CGI.escape(channel_name) + "&socketID=" + CGI.escape(socket_id), {})
|
69
69
|
if response[:status] === 200
|
70
|
-
|
70
|
+
JSON(response[:body])['token']
|
71
71
|
else
|
72
72
|
raise PushRadar::Error, 'There was a problem receiving a channel authentication token. Server returned: ' + response[:body]
|
73
73
|
end
|
74
74
|
end
|
75
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
|
89
|
+
else
|
90
|
+
raise PushRadar::Error, 'An error occurred while calling the API. Server returned: ' + response[:body]
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
76
94
|
def do_http_request(method, url, data)
|
77
95
|
uri = URI.parse(url)
|
78
96
|
http = Net::HTTP.new(uri.host, uri.port)
|
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.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- PushRadar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|