pushradar 2.0.4 → 3.0.0.pre.alpha.1
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/CHANGELOG.md +2 -43
- data/Gemfile +1 -4
- data/LICENSE +2 -2
- data/README.md +88 -80
- data/Rakefile +2 -1
- data/lib/pushradar.rb +10 -0
- data/lib/pushradar/client.rb +81 -0
- data/lib/pushradar/version.rb +3 -0
- data/pushradar.gemspec +26 -0
- metadata +47 -30
- data/.idea/.rakeTasks +0 -7
- data/.idea/PushRadarRuby.iml +0 -13
- data/.idea/inspectionProfiles/Project_Default.xml +0 -6
- data/.idea/misc.xml +0 -4
- data/.idea/modules.xml +0 -8
- data/.idea/vcs.xml +0 -6
- data/.idea/workspace.xml +0 -674
- data/PushRadar.gemspec +0 -25
- data/VERSION +0 -1
- data/bin/console +0 -6
- data/bin/setup +0 -6
- data/lib/PushRadar.rb +0 -385
- 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: fea818e1295502c3c3361557ab50c818d6820c836283f3966efa3d6d78e7e6e3
|
4
|
+
data.tar.gz: 15fdd2749967ad5aa968aba4991c27940c36032e93ed2b429f7fc063f67f8252
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f07920a98b154a8fbb5b322caed9447bf61f231a258b6b6775208a7e98360bd45b11758de3902c419c7349fde0d37294756b54bc2181b33c4cd11ae327a00d16
|
7
|
+
data.tar.gz: d8e53e91270839a55509cf8e88c5a04600c7b51a133cde5d5c37e17875005331277f11d3c93238aab26f4d844667dd2ccd8d17c04b81dfec546ed5132bba1ae5
|
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/CHANGELOG.md
CHANGED
@@ -1,44 +1,3 @@
|
|
1
|
-
|
1
|
+
## 3.0.0-alpha.1 (2021-02-08)
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
### 2.0.3 (2019-07-04)
|
6
|
-
|
7
|
-
* Minor changes
|
8
|
-
|
9
|
-
### 2.0.2 (2019-07-04)
|
10
|
-
|
11
|
-
* Stable release for next version of PushRadar (PushRadar 2)
|
12
|
-
|
13
|
-
### 2.0.0 (2019-07-04)
|
14
|
-
|
15
|
-
* Version 2 of the platform
|
16
|
-
|
17
|
-
### 1.8.2 (2019-07-04)
|
18
|
-
|
19
|
-
* Broadcasting bug fixes
|
20
|
-
|
21
|
-
### 1.8.1 (2019-07-04)
|
22
|
-
|
23
|
-
* Changed channel auth token generation
|
24
|
-
|
25
|
-
### 1.8.0 (2019-07-04)
|
26
|
-
|
27
|
-
* New PushRadar API
|
28
|
-
* Added channel authentication
|
29
|
-
|
30
|
-
### 1.0.2 (2017-08-21)
|
31
|
-
|
32
|
-
* Launch of PushRadar
|
33
|
-
|
34
|
-
### 1.0.1 (2017-08-16)
|
35
|
-
|
36
|
-
* Modifications to continent targeting
|
37
|
-
|
38
|
-
### 1.0.0 (2017-08-16)
|
39
|
-
|
40
|
-
* Closed beta release
|
41
|
-
|
42
|
-
### 0.9.1 (2017-08-13)
|
43
|
-
|
44
|
-
* Pre-release of PushRadar's Ruby server library
|
3
|
+
[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,80 +1,88 @@
|
|
1
|
-
<p align="center"><img src="https://pushradar.
|
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
|
-
```ruby
|
42
|
-
require '
|
43
|
-
|
44
|
-
|
45
|
-
radar
|
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
|
-
|
79
|
-
|
80
|
-
|
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('sk_fdcaf6a6-bf6f-4dea-9406-16320cca95e6')
|
68
|
+
channel_name = params[:channelName]
|
69
|
+
# is user allowed to access channel?
|
70
|
+
if true
|
71
|
+
return {'token': radar.auth(channel_name)}.to_json
|
72
|
+
end
|
73
|
+
```
|
74
|
+
|
75
|
+
Then register your authentication endpoint by calling the `auth(...)` method client-side:
|
76
|
+
|
77
|
+
```javascript
|
78
|
+
radar.auth('/auth');
|
79
|
+
```
|
80
|
+
|
81
|
+
## Complete Documentation
|
82
|
+
|
83
|
+
Complete documentation for PushRadar's Ruby server library can be found at: <https://pushradar.com/docs/3.x?lang=ruby>
|
84
|
+
|
85
|
+
## License
|
86
|
+
|
87
|
+
Copyright 2021, PushRadar. PushRadar's Ruby server library is licensed under the MIT license:
|
88
|
+
http://www.opensource.org/licenses/mit-license.php
|
data/Rakefile
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
require 'bundler
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
data/lib/pushradar.rb
ADDED
@@ -0,0 +1,81 @@
|
|
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) && secret_key.start_with?('sk_')
|
9
|
+
raise PushRadar::Error, 'Please provide your PushRadar secret key. You can find it on the API page of your dashboard.'
|
10
|
+
end
|
11
|
+
|
12
|
+
@secret_key = secret_key
|
13
|
+
@api_endpoint = 'https://api.pushradar.com/v3'
|
14
|
+
end
|
15
|
+
|
16
|
+
def validate_channel_name(channel_name)
|
17
|
+
if /[^A-Za-z0-9_\-=@,.;]/.match(channel_name)
|
18
|
+
raise PushRadar::Error, "Invalid channel name: #{channel_name}. Channel names cannot contain spaces, and must consist of only " +
|
19
|
+
"upper and lowercase letters, numbers, underscores, equals characters, @ characters, commas, periods, semicolons, " +
|
20
|
+
"and hyphens (A-Za-z0-9_=@,.;-)."
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def broadcast(channel_name, data)
|
25
|
+
if channel_name.nil? || channel_name.strip.empty?
|
26
|
+
raise PushRadar::Error, 'Channel name empty. Please provide a channel name.'
|
27
|
+
end
|
28
|
+
|
29
|
+
validate_channel_name(channel_name)
|
30
|
+
response = do_http_request('POST', @api_endpoint + "/broadcasts", { channel: channel_name.strip, data: data })
|
31
|
+
|
32
|
+
if response[:status] === 200
|
33
|
+
true
|
34
|
+
else
|
35
|
+
raise PushRadar::Error, 'An error occurred while calling the API. Server returned: ' + response[:body].to_json
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def auth(channel_name)
|
40
|
+
if channel_name.nil? || channel_name.strip.empty?
|
41
|
+
raise PushRadar::Error, 'Channel name empty. Please provide a channel name.'
|
42
|
+
end
|
43
|
+
|
44
|
+
unless channel_name.start_with?('private-')
|
45
|
+
raise PushRadar::Error, 'Channel authentication can only be used with private channels.'
|
46
|
+
end
|
47
|
+
|
48
|
+
response = do_http_request('GET', @api_endpoint + "/channels/auth?channel=" + CGI.escape(channel_name), {})
|
49
|
+
if response[:status] === 200
|
50
|
+
JSON(response[:body])['token']
|
51
|
+
else
|
52
|
+
raise PushRadar::Error, 'There was a problem receiving a channel authentication token. Server returned: ' + response[:body].to_json
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def do_http_request(method, url, data)
|
57
|
+
uri = URI.parse(url)
|
58
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
59
|
+
http.use_ssl = true
|
60
|
+
|
61
|
+
if method.downcase === 'post'
|
62
|
+
req = Net::HTTP::Post.new(url)
|
63
|
+
req['X-PushRadar-Library'] = 'pushradar-server-ruby ' + VERSION
|
64
|
+
req['Authorization'] = "Bearer " + @secret_key
|
65
|
+
req.content_type = 'application/json'
|
66
|
+
data = data.to_json
|
67
|
+
req.body = data
|
68
|
+
else
|
69
|
+
req = Net::HTTP::Get.new(url)
|
70
|
+
req['X-PushRadar-Library'] = 'pushradar-server-ruby ' + VERSION
|
71
|
+
req['Authorization'] = "Bearer " + @secret_key
|
72
|
+
req.content_type = 'application/json'
|
73
|
+
end
|
74
|
+
|
75
|
+
response = http.request(req)
|
76
|
+
{ body: response.body, status: response.code.to_i }
|
77
|
+
end
|
78
|
+
|
79
|
+
private :validate_channel_name, :do_http_request
|
80
|
+
end
|
81
|
+
end
|
data/pushradar.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require File.expand_path('../lib/pushradar/version', __FILE__)
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "pushradar"
|
7
|
+
s.version = PushRadar::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["PushRadar"]
|
10
|
+
s.email = ["contact@pushradar.com"]
|
11
|
+
s.homepage = "https://github.com/PushRadar/pushradar-server-ruby"
|
12
|
+
s.summary = %q{PushRadar Ruby server library}
|
13
|
+
s.description = %q{PushRadar's official Ruby server library}
|
14
|
+
s.license = "MIT"
|
15
|
+
|
16
|
+
s.add_dependency "multi_json", "~> 1.15"
|
17
|
+
s.add_dependency "httpclient", "~> 2.8"
|
18
|
+
s.add_dependency "json", "~> 2.3"
|
19
|
+
|
20
|
+
s.add_development_dependency "rake", "~> 13.0"
|
21
|
+
|
22
|
+
s.files = `git ls-files`.split("\n")
|
23
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
24
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
25
|
+
s.require_paths = ["lib"]
|
26
|
+
end
|
metadata
CHANGED
@@ -1,73 +1,91 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pushradar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0.pre.alpha.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- PushRadar
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: multi_json
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.15'
|
20
|
-
type: :
|
20
|
+
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.15'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: httpclient
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.8'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.8'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: json
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.3'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.3'
|
27
55
|
- !ruby/object:Gem::Dependency
|
28
56
|
name: rake
|
29
57
|
requirement: !ruby/object:Gem::Requirement
|
30
58
|
requirements:
|
31
59
|
- - "~>"
|
32
60
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
61
|
+
version: '13.0'
|
34
62
|
type: :development
|
35
63
|
prerelease: false
|
36
64
|
version_requirements: !ruby/object:Gem::Requirement
|
37
65
|
requirements:
|
38
66
|
- - "~>"
|
39
67
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
41
|
-
description:
|
68
|
+
version: '13.0'
|
69
|
+
description: PushRadar's official Ruby server library
|
42
70
|
email:
|
43
71
|
- contact@pushradar.com
|
44
72
|
executables: []
|
45
73
|
extensions: []
|
46
74
|
extra_rdoc_files: []
|
47
75
|
files:
|
76
|
+
- ".document"
|
77
|
+
- ".gemtest"
|
48
78
|
- ".gitignore"
|
49
|
-
- ".idea/.rakeTasks"
|
50
|
-
- ".idea/PushRadarRuby.iml"
|
51
|
-
- ".idea/inspectionProfiles/Project_Default.xml"
|
52
|
-
- ".idea/misc.xml"
|
53
|
-
- ".idea/modules.xml"
|
54
|
-
- ".idea/vcs.xml"
|
55
|
-
- ".idea/workspace.xml"
|
56
79
|
- CHANGELOG.md
|
57
80
|
- Gemfile
|
58
81
|
- LICENSE
|
59
|
-
- PushRadar.gemspec
|
60
82
|
- README.md
|
61
83
|
- Rakefile
|
62
|
-
-
|
63
|
-
-
|
64
|
-
-
|
65
|
-
-
|
66
|
-
|
67
|
-
- lib/PushRadar/Targeting.rb
|
68
|
-
- lib/PushRadar/Utils.rb
|
69
|
-
- lib/PushRadar/version.rb
|
70
|
-
homepage: https://github.com/pushradar/pushradar-ruby
|
84
|
+
- lib/pushradar.rb
|
85
|
+
- lib/pushradar/client.rb
|
86
|
+
- lib/pushradar/version.rb
|
87
|
+
- pushradar.gemspec
|
88
|
+
homepage: https://github.com/PushRadar/pushradar-server-ruby
|
71
89
|
licenses:
|
72
90
|
- MIT
|
73
91
|
metadata: {}
|
@@ -82,13 +100,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
82
100
|
version: '0'
|
83
101
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
102
|
requirements:
|
85
|
-
- - "
|
103
|
+
- - ">"
|
86
104
|
- !ruby/object:Gem::Version
|
87
|
-
version:
|
105
|
+
version: 1.3.1
|
88
106
|
requirements: []
|
89
|
-
|
90
|
-
rubygems_version: 2.6.11
|
107
|
+
rubygems_version: 3.0.3
|
91
108
|
signing_key:
|
92
109
|
specification_version: 4
|
93
|
-
summary: PushRadar
|
110
|
+
summary: PushRadar Ruby server library
|
94
111
|
test_files: []
|