pushradar 2.0.2 → 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 +5 -5
- data/.document +5 -0
- data/.gemtest +0 -0
- data/.gitignore +35 -10
- data/.idea/.gitignore +8 -0
- data/.idea/inspectionProfiles/Project_Default.xml +5 -5
- data/.idea/misc.xml +3 -3
- data/.idea/modules.xml +7 -7
- data/.idea/{PushRadarRuby.iml → pushradar-server-ruby.iml} +15 -12
- data/.idea/vcs.xml +5 -5
- data/CHANGELOG.md +6 -31
- data/Gemfile +1 -4
- data/LICENSE +2 -2
- data/README.md +114 -78
- data/Rakefile +2 -1
- data/VERSION +1 -1
- data/lib/pushradar.rb +10 -0
- data/lib/pushradar/client.rb +119 -0
- data/lib/pushradar/version.rb +3 -0
- data/pushradar.gemspec +26 -0
- metadata +47 -23
- data/.idea/.rakeTasks +0 -7
- data/.idea/workspace.xml +0 -677
- data/PushRadar.gemspec +0 -25
- data/bin/console +0 -6
- data/bin/setup +0 -6
- data/lib/PushRadar.rb +0 -384
- data/lib/PushRadar/APIClient.rb +0 -53
- data/lib/PushRadar/Targeting.rb +0 -173
- data/lib/PushRadar/Utils.rb +0 -558
- data/lib/PushRadar/version.rb +0 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
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/.document
ADDED
data/.gemtest
ADDED
|
File without changes
|
data/.gitignore
CHANGED
|
@@ -1,10 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
.DS_Store
|
|
2
|
+
*.tmproj
|
|
3
|
+
tmtags
|
|
4
|
+
*~
|
|
5
|
+
\#*
|
|
6
|
+
.\#*
|
|
7
|
+
*.swp
|
|
8
|
+
coverage
|
|
9
|
+
rdoc
|
|
10
|
+
pkg
|
|
11
|
+
.yardoc
|
|
12
|
+
Gemfile.lock
|
|
13
|
+
.bundle
|
|
14
|
+
|
|
15
|
+
/node_modules
|
|
16
|
+
/public/hot
|
|
17
|
+
/public/storage
|
|
18
|
+
/storage/*.key
|
|
19
|
+
/vendor
|
|
20
|
+
.env
|
|
21
|
+
.env.backup
|
|
22
|
+
.env.production
|
|
23
|
+
.phpunit.result.cache
|
|
24
|
+
docker-compose.override.yml
|
|
25
|
+
Homestead.json
|
|
26
|
+
Homestead.yaml
|
|
27
|
+
npm-debug.log
|
|
28
|
+
yarn-error.log
|
|
29
|
+
composer.lock
|
|
30
|
+
phpunit.xml
|
|
31
|
+
tests/config.php
|
|
32
|
+
vendor
|
|
33
|
+
/src/_notUsed
|
|
34
|
+
/_pr-test
|
|
35
|
+
/_notUsed
|
data/.idea/.gitignore
ADDED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
<component name="InspectionProjectProfileManager">
|
|
2
|
-
<profile version="1.0">
|
|
3
|
-
<option name="myName" value="Project Default" />
|
|
4
|
-
<inspection_tool class="Rubocop" enabled="false" level="WARNING" enabled_by_default="false" />
|
|
5
|
-
</profile>
|
|
1
|
+
<component name="InspectionProjectProfileManager">
|
|
2
|
+
<profile version="1.0">
|
|
3
|
+
<option name="myName" value="Project Default" />
|
|
4
|
+
<inspection_tool class="Rubocop" enabled="false" level="WARNING" enabled_by_default="false" />
|
|
5
|
+
</profile>
|
|
6
6
|
</component>
|
data/.idea/misc.xml
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<project version="4">
|
|
3
|
-
<component name="ProjectRootManager" version="2" project-jdk-name="ruby-2.
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="ProjectRootManager" version="2" project-jdk-name="ruby-2.6.3-p62" project-jdk-type="RUBY_SDK" />
|
|
4
4
|
</project>
|
data/.idea/modules.xml
CHANGED
|
@@ -1,8 +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/
|
|
6
|
-
</modules>
|
|
7
|
-
</component>
|
|
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
8
|
</project>
|
|
@@ -1,13 +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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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>
|
|
13
16
|
</module>
|
data/.idea/vcs.xml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<project version="4">
|
|
3
|
-
<component name="VcsDirectoryMappings">
|
|
4
|
-
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
|
5
|
-
</component>
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="VcsDirectoryMappings">
|
|
4
|
+
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
|
5
|
+
</component>
|
|
6
6
|
</project>
|
data/CHANGELOG.md
CHANGED
|
@@ -1,36 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
## 3.1.0 (2021-04-05)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[NEW] Added support for client data registration
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## 3.0.0 (2021-02-18)
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
[NEW] Updated for release of PushRadar v3
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
## 3.0.0-alpha.1 (2021-02-08)
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
### 1.8.1 (2019-07-04)
|
|
14
|
-
|
|
15
|
-
* Changed channel auth token generation
|
|
16
|
-
|
|
17
|
-
### 1.8.0 (2019-07-04)
|
|
18
|
-
|
|
19
|
-
* New PushRadar API
|
|
20
|
-
* Added channel authentication
|
|
21
|
-
|
|
22
|
-
### 1.0.2 (2017-08-21)
|
|
23
|
-
|
|
24
|
-
* Launch of PushRadar
|
|
25
|
-
|
|
26
|
-
### 1.0.1 (2017-08-16)
|
|
27
|
-
|
|
28
|
-
* Modifications to continent targeting
|
|
29
|
-
|
|
30
|
-
### 1.0.0 (2017-08-16)
|
|
31
|
-
|
|
32
|
-
* Closed beta release
|
|
33
|
-
|
|
34
|
-
### 0.9.1 (2017-08-13)
|
|
35
|
-
|
|
36
|
-
* Pre-release of PushRadar's Ruby server library
|
|
11
|
+
[NEW] Work on base code of package, compatible with the next release of PushRadar
|
data/Gemfile
CHANGED
data/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
The MIT License
|
|
1
|
+
The MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2021. PushRadar
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
data/README.md
CHANGED
|
@@ -1,78 +1,114 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
radar.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
1
|
+
<p align="center"><a href="https://pushradar.com" target="_blank"><img src="https://pushradar.com/images/logo/pushradar-logo-dark.svg" width="300"></a></p>
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<a href="https://rubygems.org/gems/pushradar"><img src="https://img.shields.io/gem/v/pushradar?cacheSeconds=60&color=5b86e5"></a>
|
|
5
|
+
<a href="https://rubygems.org/gems/pushradar"><img src="https://img.shields.io/gem/dt/pushradar?cacheSeconds=60&color=5b86e5"></a>
|
|
6
|
+
<a href="https://rubygems.org/gems/pushradar"><img src="https://img.shields.io/packagist/l/pushradar/pushradar-server-php?cacheSeconds=60&color=5b86e5"></a>
|
|
7
|
+
</p>
|
|
8
|
+
<br />
|
|
9
|
+
|
|
10
|
+
## PushRadar Ruby Server Library
|
|
11
|
+
|
|
12
|
+
[PushRadar](https://pushradar.com) is a realtime API service for the web. The service uses a simple publish-subscribe model, allowing you to broadcast "messages" on "channels" that are subscribed to by one or more clients. Messages are pushed in realtime to those clients.
|
|
13
|
+
|
|
14
|
+
This is PushRadar's official Ruby server library.
|
|
15
|
+
|
|
16
|
+
## Prerequisites
|
|
17
|
+
|
|
18
|
+
In order to use this library, please ensure that you have the following:
|
|
19
|
+
|
|
20
|
+
- Ruby 2.4+
|
|
21
|
+
- A PushRadar account - you can sign up at [pushradar.com](https://pushradar.com)
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
The easiest way to get up and running is to install the library using bundler. Add the following to your Gemfile:
|
|
26
|
+
|
|
27
|
+
```ruby
|
|
28
|
+
gem 'pushradar'
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
And then run bundle install:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
$ bundle install
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Alterntively, install manually by running `$ gem install pushradar`
|
|
38
|
+
|
|
39
|
+
## Broadcasting Messages
|
|
40
|
+
|
|
41
|
+
```ruby
|
|
42
|
+
require 'pushradar'
|
|
43
|
+
|
|
44
|
+
radar = PushRadar::Client.new('your-secret-key')
|
|
45
|
+
radar.broadcast('channel-1', { message: 'Hello world!' })
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Receiving Messages
|
|
49
|
+
|
|
50
|
+
```html
|
|
51
|
+
<script src="https://pushradar.com/js/v3/pushradar.min.js"></script>
|
|
52
|
+
<script>
|
|
53
|
+
var radar = new PushRadar('your-public-key');
|
|
54
|
+
radar.subscribe.to('channel-1', function (data) {
|
|
55
|
+
console.log(data.message);
|
|
56
|
+
});
|
|
57
|
+
</script>
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Private Channels
|
|
61
|
+
|
|
62
|
+
Private channels require authentication and start with the prefix **private-**. We recommend that you use private channels by default to prevent unauthorised access to channels.
|
|
63
|
+
|
|
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
|
+
|
|
66
|
+
```ruby
|
|
67
|
+
radar = PushRadar::Client.new('your-secret-key')
|
|
68
|
+
channel_name = params[:channelName]
|
|
69
|
+
socket_id = params[:socketID]
|
|
70
|
+
# is user allowed to access channel?
|
|
71
|
+
if true
|
|
72
|
+
return { 'token': radar.auth(channel_name, socket_id) }.to_json
|
|
73
|
+
end
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Then register your authentication endpoint by calling the `auth(...)` method client-side:
|
|
77
|
+
|
|
78
|
+
```javascript
|
|
79
|
+
radar.auth('/auth');
|
|
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
|
+
|
|
107
|
+
## Complete Documentation
|
|
108
|
+
|
|
109
|
+
Complete documentation for PushRadar's Ruby server library can be found at: <https://pushradar.com/docs/3.x/ruby>
|
|
110
|
+
|
|
111
|
+
## License
|
|
112
|
+
|
|
113
|
+
Copyright © 2021, PushRadar. PushRadar's Ruby server library is licensed under the MIT license:
|
|
114
|
+
<https://opensource.org/licenses/mit-license.php>
|
data/Rakefile
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
require 'bundler
|
|
1
|
+
require 'bundler'
|
|
2
|
+
Bundler::GemHelper.install_tasks
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
3.1.0
|
data/lib/pushradar.rb
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
require 'net/http'
|
|
2
|
+
require 'json'
|
|
3
|
+
require 'cgi'
|
|
4
|
+
|
|
5
|
+
module PushRadar
|
|
6
|
+
class Client
|
|
7
|
+
def initialize(secret_key)
|
|
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_')
|
|
13
|
+
raise PushRadar::Error, 'Please provide your PushRadar secret key. You can find it on the API page of your dashboard.'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
@secret_key = secret_key
|
|
17
|
+
@api_endpoint = 'https://api.pushradar.com/v3'
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def validate_channel_name(channel_name)
|
|
21
|
+
if /[^A-Za-z0-9_\-=@,.;]/.match(channel_name)
|
|
22
|
+
raise PushRadar::Error, "Invalid channel name: #{channel_name}. Channel names cannot contain spaces, and must consist of only " +
|
|
23
|
+
"upper and lowercase letters, numbers, underscores, equals characters, @ characters, commas, periods, semicolons, " +
|
|
24
|
+
"and hyphens (A-Za-z0-9_=@,.;-)."
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
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
|
+
|
|
33
|
+
if channel_name.nil? || channel_name.strip.empty?
|
|
34
|
+
raise PushRadar::Error, 'Channel name empty. Please provide a channel name.'
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
validate_channel_name(channel_name)
|
|
38
|
+
response = do_http_request('POST', @api_endpoint + "/broadcasts", { channel: channel_name, data: data.to_json })
|
|
39
|
+
|
|
40
|
+
if response[:status] === 200
|
|
41
|
+
true
|
|
42
|
+
else
|
|
43
|
+
raise PushRadar::Error, 'An error occurred while calling the API. Server returned: ' + response[:body]
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
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
|
+
|
|
52
|
+
if channel_name.nil? || channel_name.strip.empty?
|
|
53
|
+
raise PushRadar::Error, 'Channel name empty. Please provide a channel name.'
|
|
54
|
+
end
|
|
55
|
+
|
|
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
|
+
end
|
|
59
|
+
|
|
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), {})
|
|
69
|
+
if response[:status] === 200
|
|
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
|
|
89
|
+
else
|
|
90
|
+
raise PushRadar::Error, 'An error occurred while calling the API. Server returned: ' + response[:body]
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def do_http_request(method, url, data)
|
|
95
|
+
uri = URI.parse(url)
|
|
96
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
97
|
+
http.use_ssl = true
|
|
98
|
+
|
|
99
|
+
if method.downcase === 'post'
|
|
100
|
+
req = Net::HTTP::Post.new(url)
|
|
101
|
+
req['X-PushRadar-Library'] = 'pushradar-server-ruby ' + VERSION
|
|
102
|
+
req['Authorization'] = "Bearer " + @secret_key
|
|
103
|
+
req.content_type = 'application/json'
|
|
104
|
+
data = data.to_json
|
|
105
|
+
req.body = data
|
|
106
|
+
else
|
|
107
|
+
req = Net::HTTP::Get.new(url)
|
|
108
|
+
req['X-PushRadar-Library'] = 'pushradar-server-ruby ' + VERSION
|
|
109
|
+
req['Authorization'] = "Bearer " + @secret_key
|
|
110
|
+
req.content_type = 'application/json'
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
response = http.request(req)
|
|
114
|
+
{ body: response.body, status: response.code.to_i }
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
private :validate_channel_name, :do_http_request
|
|
118
|
+
end
|
|
119
|
+
end
|