pushradar 1.0.2 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ### 1.8.0 (2019-07-04)
2
+
3
+ * New PushRadar API
4
+ * Added channel authentication
5
+
1
6
  ### 1.0.2 (2017-08-21)
2
7
 
3
8
  * Launch of PushRadar
data/Gemfile CHANGED
@@ -1,5 +1,5 @@
1
- source 'https://rubygems.org'
2
-
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
-
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
5
  gemspec
data/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2017. PushRadar
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019. PushRadar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
21
  THE SOFTWARE.
data/PushRadar.gemspec CHANGED
@@ -1,25 +1,25 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'PushRadar/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = 'pushradar'
8
- spec.version = PushRadar::VERSION
9
- spec.authors = ['PushRadar']
10
- spec.email = ['contact@pushradar.com']
11
-
12
- spec.summary = %q{PushRadar's official Ruby library, wrapping the PushRadar API.}
13
- spec.homepage = 'https://github.com/pushradar/pushradar-ruby'
14
- spec.license = 'MIT'
15
-
16
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
- f.match(%r{^(test|spec|features)/})
18
- end
19
- spec.bindir = 'exe'
20
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
- spec.require_paths = ['lib']
22
-
23
- spec.add_development_dependency 'bundler', '~> 1.15'
24
- spec.add_development_dependency 'rake', '~> 10.0'
25
- end
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'PushRadar/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'pushradar'
8
+ spec.version = PushRadar::VERSION
9
+ spec.authors = ['PushRadar']
10
+ spec.email = ['contact@pushradar.com']
11
+
12
+ spec.summary = %q{PushRadar's official Ruby library, wrapping the PushRadar API.}
13
+ spec.homepage = 'https://github.com/pushradar/pushradar-ruby'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = 'exe'
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.15'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ end
data/README.md CHANGED
@@ -1,66 +1,80 @@
1
- <p align="center"><img src="https://www.pushradar.com/img/logo/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/docs/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
- ## Documentation
65
-
1
+ <p align="center"><img src="https://www.pushradar.com/img/logo/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/docs/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 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
+
66
80
  Full documentation for PushRadar's Ruby library can be found at: [www.pushradar.com/docs/ruby](https://www.pushradar.com/docs/latest/ruby).
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.2
1
+ 1.8.0
data/bin/console CHANGED
@@ -1,6 +1,6 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'bundler/setup'
4
- require 'irb'
5
-
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'irb'
5
+
6
6
  IRB.start(__FILE__)
data/bin/setup CHANGED
@@ -1,6 +1,6 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
6
  bundle install
@@ -17,7 +17,7 @@ module PushRadar
17
17
  @api_secret = api_secret
18
18
 
19
19
  # Set the API endpoint
20
- @api_endpoint = 'https://api.pushradar.com/v1'
20
+ @api_endpoint = 'https://api.pushradar.com/v2'
21
21
 
22
22
  end
23
23
 
@@ -25,9 +25,9 @@ module PushRadar
25
25
  def post(destination, data)
26
26
 
27
27
  # Add in the fields that should be sent with each request
28
- data['api_secret'] = @api_secret
29
- data['client_platform'] = 'ruby'
30
- data['request_sent_at'] = Time.now.to_i
28
+ data['apiSecret'] = @api_secret
29
+ data['clientPlatform'] = 'ruby'
30
+ data['timestamp'] = Time.now.to_i
31
31
 
32
32
  # Make sure the destination does not contain the base URL or forward slash characters
33
33
  destination = destination.gsub('/', '')
@@ -7,10 +7,6 @@ module PushRadar
7
7
  # Specifies the target audience of a PushRadar notification
8
8
  class Targeting
9
9
 
10
- # ------------------------------
11
- # Initialization & configuration
12
- # ------------------------------
13
-
14
10
  # Creates a new notification targeting object
15
11
  def initialize
16
12
 
@@ -25,10 +21,6 @@ module PushRadar
25
21
 
26
22
  end
27
23
 
28
- # ------------------------------
29
- # Browser targeting
30
- # ------------------------------
31
-
32
24
  # Adds a browser to the list of target browsers
33
25
  def target_browser(browser)
34
26
 
@@ -48,10 +40,6 @@ module PushRadar
48
40
 
49
41
  end
50
42
 
51
- # ------------------------------
52
- # Country targeting
53
- # ------------------------------
54
-
55
43
  # Adds a country to the list of target countries
56
44
  def target_country(country_code)
57
45
 
@@ -76,10 +64,6 @@ module PushRadar
76
64
 
77
65
  end
78
66
 
79
- # ------------------------------
80
- # Continent targeting
81
- # ------------------------------
82
-
83
67
  # Targets a continent by its continent code
84
68
  def target_continent(continent_code)
85
69
 
@@ -95,10 +79,6 @@ module PushRadar
95
79
 
96
80
  end
97
81
 
98
- # ------------------------------
99
- # IP address targeting
100
- # ------------------------------
101
-
102
82
  # Targets the notification to clients with the given IP address
103
83
  def target_ip(ip_address)
104
84
 
@@ -127,60 +107,52 @@ module PushRadar
127
107
 
128
108
  end
129
109
 
130
- # ------------------------------
131
- # Action targeting
132
- # ------------------------------
133
-
134
110
  # Targets the notification to clients who have taken the given action
135
- def target_action(action_identifier)
111
+ def target_action(action)
136
112
 
137
113
  # Trim the action identifier
138
- action_identifier.strip!
114
+ action.strip!
139
115
 
140
116
  # Make sure the action identifier is not empty
141
- if action_identifier == ''
117
+ if action == ''
142
118
  raise 'The action identifier cannot be empty'
143
119
  end
144
120
 
145
121
  # Make sure that the action is not in the target "not" actions list
146
- if @target_not_actions.include? action_identifier
147
- raise "Action '" + action_identifier + "' is already in the 'not' actions list."
122
+ if @target_not_actions.include? action
123
+ raise "Action '" + action + "' is already in the 'not' actions list."
148
124
  end
149
125
 
150
126
  # Add the action to the list
151
- unless @target_actions.include? action_identifier
152
- @target_actions.push action_identifier
127
+ unless @target_actions.include? action
128
+ @target_actions.push action
153
129
  end
154
130
 
155
131
  end
156
132
 
157
133
  # Targets the notification to clients who have not taken the given action
158
- def target_not_action(action_identifier)
134
+ def target_not_action(action)
159
135
 
160
136
  # Trim the action identifier
161
- action_identifier.strip!
137
+ action.strip!
162
138
 
163
139
  # Make sure the action identifier is not empty
164
- if action_identifier == ''
140
+ if action == ''
165
141
  raise 'The action identifier cannot be empty'
166
142
  end
167
143
 
168
144
  # Make sure that the action is not in the target actions list
169
- if @target_actions.include? action_identifier
170
- raise "Action '" + action_identifier + "' is already in the actions list."
145
+ if @target_actions.include? action
146
+ raise "Action '" + action + "' is already in the actions list."
171
147
  end
172
148
 
173
149
  # Add the action to the list
174
- unless @target_not_actions.include? action_identifier
175
- @target_not_actions.push action_identifier
150
+ unless @target_not_actions.include? action
151
+ @target_not_actions.push action
176
152
  end
177
153
 
178
154
  end
179
155
 
180
- # ------------------------------
181
- # User targeting
182
- # ------------------------------
183
-
184
156
  # Targets the notification to a specific user (identifier by their user ID)
185
157
  def target_user(user_id)
186
158
 
@@ -6,10 +6,6 @@ module PushRadar
6
6
  # Contains helpful methods that are used throughout the library
7
7
  class Utils
8
8
 
9
- # ------------------------------
10
- # Collection utilities
11
- # ------------------------------
12
-
13
9
  # Searches the given dictionary for values matching the value provided, and returns the keys of those elements
14
10
  def self.keys_where_value(dictionary, value)
15
11
 
@@ -26,10 +22,6 @@ module PushRadar
26
22
 
27
23
  end
28
24
 
29
- # ------------------------------
30
- # Location utilities
31
- # ------------------------------
32
-
33
25
  # Gets a hash that associates ISO 3166-1 alpha-2 country codes with country names
34
26
  def self.get_countries
35
27
 
@@ -549,10 +541,6 @@ module PushRadar
549
541
 
550
542
  end
551
543
 
552
- # ------------------------------
553
- # IP address utilities
554
- # ------------------------------
555
-
556
544
  # Checks whether the given IP address is valid
557
545
  def self.is_valid_ip(addr)
558
546
  case addr
@@ -1,3 +1,3 @@
1
- module PushRadar
2
- VERSION = '1.0.2'
1
+ module PushRadar
2
+ VERSION = '1.8.0'
3
3
  end