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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9edffa9f99b71bf60f915bfc6a4d91be7481491a29e84214fa36aa68e2e669cc
4
- data.tar.gz: a3e47791e64cd2796ce5cb0820c0af3d5dc2c4b0282f693f256264e5a22015e9
3
+ metadata.gz: 4cb5a3926082d52f847bbb57e800e4c964cb9ea35c005e67c3df6246ceb17a07
4
+ data.tar.gz: a942aaea6376412ca2addd8d8e760df9919bb99ffe5c4de7164c148c5b306a57
5
5
  SHA512:
6
- metadata.gz: e8b05a7441edc5070490c0a909b0800105fe361a99a7f34965d94d4e0253be4bab21c2b18c8128e3a8d24a35468555c691d0a2f0c1eebbe9df1a988c3f7eec4d
7
- data.tar.gz: e6c32fc1588940ff1ea0f8cd991dcbc4256b47befa4c92cacadd316eda1df46b00efd36284d842ef5e09c238893bd73525405100d80cc1502711335df463c1fb
6
+ metadata.gz: 99a48b950b8d6d196bbb621c3fb9c7d7a3f08fd9fdc80f8e1edbe7b100358743c48eb68314ebc237e8e64bbdc239391f71992b4e251578200463072d088f06cf
7
+ data.tar.gz: b7b05961ebc5e0492b55430fc223954fa497b3186eef2a15214da55920acc9af346a654d15096ac8d190749d860860f87c93c7d5e09c8584910ef5882b292dd7
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 3.1.0 (2021-04-05)
2
+
3
+ [NEW] Added support for client data registration
4
+
1
5
  ## 3.0.0 (2021-02-18)
2
6
 
3
7
  [NEW] Updated for release of PushRadar v3
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?lang=ruby>
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.0.0
1
+ 3.1.0
@@ -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
- JSON(response[:body])['token']
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)
@@ -1,3 +1,3 @@
1
1
  module PushRadar
2
- VERSION = '3.0.0'
2
+ VERSION = '3.1.0'
3
3
  end
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.0.0
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-02-18 00:00:00.000000000 Z
11
+ date: 2021-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json