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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a81a450f2c39f7b4e56ca6c5c40671754962dad8
4
- data.tar.gz: 992d8b99f0154a689bba984f70ce27e41c46d2fa
2
+ SHA256:
3
+ metadata.gz: fea818e1295502c3c3361557ab50c818d6820c836283f3966efa3d6d78e7e6e3
4
+ data.tar.gz: 15fdd2749967ad5aa968aba4991c27940c36032e93ed2b429f7fc063f67f8252
5
5
  SHA512:
6
- metadata.gz: a74947a6e1a097c2787edc6fbe3f70978a6bc202c0d5073b8e15fac1e3d7cc533f987b4fd90cf554697a7c3e6353072dda9c9ca96c9cf505d0c70cb9719818cb
7
- data.tar.gz: b5b1ff5840040326bede1f0ec60973655bd92c8408be946c2a91395a9adabe3f60f900d4156f484b9f17e133735abcbb8f214767e2af88de503a2e5ae522d035
6
+ metadata.gz: f07920a98b154a8fbb5b322caed9447bf61f231a258b6b6775208a7e98360bd45b11758de3902c419c7349fde0d37294756b54bc2181b33c4cd11ae327a00d16
7
+ data.tar.gz: d8e53e91270839a55509cf8e88c5a04600c7b51a133cde5d5c37e17875005331277f11d3c93238aab26f4d844667dd2ccd8d17c04b81dfec546ed5132bba1ae5
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gemtest ADDED
File without changes
data/.gitignore CHANGED
@@ -1,10 +1,35 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- todo
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
- ### 2.0.4 (2019-07-06)
1
+ ## 3.0.0-alpha.1 (2021-02-08)
2
2
 
3
- * Changed to send channel name to server in channel_auth method
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
@@ -1,5 +1,2 @@
1
- source 'https://rubygems.org'
2
-
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
-
1
+ source "https://rubygems.org"
5
2
  gemspec
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
- The MIT License (MIT)
1
+ The MIT License
2
2
 
3
- Copyright (c) 2019. PushRadar
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.s3-eu-west-2.amazonaws.com/v2/img/pushradar_github.png"></p>
2
-
3
- ## Introduction
4
-
5
- [PushRadar](https://www.pushradar.com) is a realtime notifications API service for the web. The service uses a simple publish-subscribe model, allowing you to broadcast "notifications" on "channels" that are subscribed to by one or more clients. Notifications are pushed in realtime to those clients.
6
-
7
- PushRadar features advanced targeting options, including the ability to target clients by actions they have taken on your website or web app, geographical location (countries & continents), IP address, web browser and user ID.
8
-
9
- This is PushRadar's official Ruby library.
10
-
11
- ## Prerequisites
12
-
13
- In order to use this library, please ensure that you have the following:
14
-
15
- - A PushRadar account - you can sign up at [www.pushradar.com](https://www.pushradar.com).
16
-
17
- ## Installation
18
-
19
- To install PushRadar's Ruby gem, add this line to your application's Gemfile:
20
-
21
- ```ruby
22
- gem 'pushradar'
23
- ```
24
-
25
- And then execute:
26
-
27
- ```
28
- $ bundle
29
- ```
30
-
31
- Alternatively, you can install it yourself by running the command:
32
-
33
- ```
34
- $ gem install pushradar
35
- ```
36
-
37
- ## Getting Started
38
-
39
- "Hello World!" example:
40
-
41
- ```ruby
42
- require 'PushRadar'
43
- include PushRadar
44
-
45
- radar = Radar.new('your-secret-key')
46
- radar.broadcast('test-channel', {message: 'Hello World!'})
47
- ```
48
-
49
- ## Receiving Notifications
50
-
51
- To subscribe to channels and receive notifications broadcast on them, check out the documentation for PushRadar's [JavaScript client library](https://www.pushradar.com/documentation/latest/javascript).
52
-
53
- ## Fluent Syntax
54
-
55
- The library supports fluent method chaining to structure broadcasts. For example, to target a notification to website visitors in the US who have not used live chat before:
56
-
57
- ```ruby
58
- radar.target_country('US').target_not_action('live-chat').broadcast('test-channel',
59
- {message: 'Would you like to talk to one of our customer support team members on live chat?'})
60
- ```
61
-
62
- Please note that targeting options reset after each call to the `broadcast` method.
63
-
64
- ## Private and Presence Channels
65
-
66
- Private and presence channels require authentication before subscribers can receive messages on them.
67
-
68
- To generate a channel authentication token, PushRadar provides a convenient `channel_auth` method that you can call from your authentication endpoint:
69
-
70
- ```ruby
71
- {authToken: radar.channel_auth("channel-name")}
72
- ```
73
-
74
- Please note that private channels must start with the prefix 'private-' and presence channels must start with the prefix 'presence-'.
75
-
76
- Read the documentation on [private](https://www.pushradar.com/documentation/latest/private-channels) and [presence](https://www.pushradar.com/documentation/latest/presence-channels) channels to learn more.
77
-
78
- ## Documentation
79
-
80
- Full documentation for PushRadar's Ruby library can be found at: [www.pushradar.com/documentation/latest/ruby](https://www.pushradar.com/documentation/latest/ruby).
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/gem_tasks'
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/lib/pushradar.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'uri'
2
+ require 'forwardable'
3
+
4
+ require_relative 'pushradar/client'
5
+
6
+ module PushRadar
7
+ class Error < RuntimeError; end
8
+ end
9
+
10
+ require_relative 'pushradar/version'
@@ -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
@@ -0,0 +1,3 @@
1
+ module PushRadar
2
+ VERSION = '3.0.0-alpha.1'
3
+ 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: 2.0.4
4
+ version: 3.0.0.pre.alpha.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - PushRadar
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-06 00:00:00.000000000 Z
11
+ date: 2021-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
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: :development
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: '10.0'
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: '10.0'
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
- - VERSION
63
- - bin/console
64
- - bin/setup
65
- - lib/PushRadar.rb
66
- - lib/PushRadar/APIClient.rb
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: '0'
105
+ version: 1.3.1
88
106
  requirements: []
89
- rubyforge_project:
90
- rubygems_version: 2.6.11
107
+ rubygems_version: 3.0.3
91
108
  signing_key:
92
109
  specification_version: 4
93
- summary: PushRadar's official Ruby library, wrapping the PushRadar API.
110
+ summary: PushRadar Ruby server library
94
111
  test_files: []