pushradar 3.0.0.pre.alpha.1 → 3.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 +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 +4 -0
- data/README.md +6 -5
- data/VERSION +1 -0
- data/lib/pushradar/client.rb +26 -6
- data/lib/pushradar/version.rb +1 -1
- metadata +11 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9edffa9f99b71bf60f915bfc6a4d91be7481491a29e84214fa36aa68e2e669cc
|
4
|
+
data.tar.gz: a3e47791e64cd2796ce5cb0820c0af3d5dc2c4b0282f693f256264e5a22015e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8b05a7441edc5070490c0a909b0800105fe361a99a7f34965d94d4e0253be4bab21c2b18c8128e3a8d24a35468555c691d0a2f0c1eebbe9df1a988c3f7eec4d
|
7
|
+
data.tar.gz: e6c32fc1588940ff1ea0f8cd991dcbc4256b47befa4c92cacadd316eda1df46b00efd36284d842ef5e09c238893bd73525405100d80cc1502711335df463c1fb
|
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
data/README.md
CHANGED
@@ -42,7 +42,7 @@ 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
|
@@ -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
|
|
@@ -84,5 +85,5 @@ Complete documentation for PushRadar's Ruby server library can be found at: <htt
|
|
84
85
|
|
85
86
|
## License
|
86
87
|
|
87
|
-
Copyright 2021, PushRadar. PushRadar's Ruby server library is licensed under the MIT license:
|
88
|
-
|
88
|
+
Copyright © 2021, PushRadar. PushRadar's Ruby server library is licensed under the MIT license:
|
89
|
+
<https://opensource.org/licenses/mit-license.php>
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.0.0
|
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,21 +26,29 @@ 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
|
@@ -45,11 +57,19 @@ module PushRadar
|
|
45
57
|
raise PushRadar::Error, 'Channel authentication can only be used with private 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']
|
51
71
|
else
|
52
|
-
raise PushRadar::Error, 'There was a problem receiving a channel authentication token. Server returned: ' + response[:body]
|
72
|
+
raise PushRadar::Error, 'There was a problem receiving a channel authentication token. Server returned: ' + response[:body]
|
53
73
|
end
|
54
74
|
end
|
55
75
|
|
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.0.0
|
4
|
+
version: 3.0.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-
|
11
|
+
date: 2021-02-18 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,9 +107,9 @@ 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
114
|
rubygems_version: 3.0.3
|
108
115
|
signing_key:
|