devise-onesignal 2.0.1 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/DEPRECATIONS.md +4 -0
- data/README.md +25 -10
- data/devise-onesignal.gemspec +1 -2
- data/lib/devise-onesignal/configuration.rb +0 -2
- data/lib/devise-onesignal/device_concern.rb +9 -5
- data/lib/devise-onesignal/device_helper.rb +4 -4
- data/lib/devise-onesignal/version.rb +1 -1
- data/lib/generators/templates/device_model.rb +1 -1
- data/lib/generators/templates/devices_migration.rb.erb +1 -1
- data/lib/generators/templates/initializer.rb +0 -10
- data/vendor/assets/javascripts/devise-onesignal.js.erb +7 -10
- metadata +4 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb032ba7dc17d0e039d2e4639d045017315cfccd837e57360f138635eb68a1af
|
4
|
+
data.tar.gz: fd986da1ce7fede417100cb77203cee79654d9dd1a69ade70d5a980614dd00cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3775ea071a90365e87cb8296735b78f5f9ae5858a551f746440ab0dc4e7e71271fa8aa1ec830c80fb8d93cb20b12c08abc9b0efe04469ae8cc32ca2827ac4fb
|
7
|
+
data.tar.gz: 0bb3c6fb16252a8a99c334c6de7c596343f4684b278f172efa128b732797245d67b53a79ace98645b98fe576497912cd82e23de7d4b58f89bc84bb85e00da38b
|
data/CHANGELOG.md
CHANGED
data/DEPRECATIONS.md
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/devise-onesignal.svg)](https://badge.fury.io/rb/devise-onesignal) <img src="https://travis-ci.org/jonhue/devise-onesignal.svg?branch=master" />
|
4
4
|
|
5
|
-
Implement user targeted cross-platform notifications with OneSignal & Devise in your Rails app.
|
5
|
+
Implement user targeted cross-platform notifications with OneSignal & Devise in your Rails app. This gem can also be used without Devise, but it is primarily intended to be used along with some sort of user-management-system.
|
6
6
|
|
7
7
|
This gem works well together with [notifications-rails](https://github.com/jonhue/notifications-rails) which introduces a notifications handling & pushing API. To build a cross-platform notification solution also add the [native](https://github.com/NativeGap/native-ruby) gem to your app.
|
8
8
|
|
@@ -20,6 +20,7 @@ This gem works well together with [notifications-rails](https://github.com/jonhu
|
|
20
20
|
* [To Do](#to-do)
|
21
21
|
* [Contributing](#contributing)
|
22
22
|
* [Contributors](#contributors)
|
23
|
+
* [Semantic versioning](#semantic-versioning)
|
23
24
|
* [License](#license)
|
24
25
|
|
25
26
|
---
|
@@ -56,15 +57,13 @@ To wrap things up, migrate the changes into your database:
|
|
56
57
|
|
57
58
|
It is time to [create your OneSignal app](https://onesignal.com) if you haven't already and set your application ID in the created initializer (`config/initializers/devise-onesignal.rb`).
|
58
59
|
|
59
|
-
|
60
|
+
Define an association in those models whose objects are supposed to be associated with OneSignal players. For example `User` in `app/models/user.rb`.
|
60
61
|
|
61
62
|
```ruby
|
62
63
|
has_many :devices
|
63
64
|
```
|
64
65
|
|
65
|
-
|
66
|
-
|
67
|
-
Now let's include the neccessary javascript files in our application (`apps/assets/javascripts/application.js`):
|
66
|
+
Now let us include the neccessary javascript files in our application (`apps/assets/javascripts/application.js`):
|
68
67
|
|
69
68
|
```js
|
70
69
|
//= require OneSignalSDK
|
@@ -81,6 +80,20 @@ document.addEventListener( 'turbolinks:load', function() {
|
|
81
80
|
|
82
81
|
## Usage
|
83
82
|
|
83
|
+
### Devise object
|
84
|
+
|
85
|
+
You most likely want to associate your devise object (e.g. `current_user`) with your OneSignal integration. Now, if your Devise model is called `User` and the `current_user` method is available you don't have to worry about that.
|
86
|
+
|
87
|
+
Let's say our Devise model is named `Admin`. Just add `private` method to your `ApplicationController`:
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
def set_device_owner
|
91
|
+
current_admin if current_admin
|
92
|
+
end
|
93
|
+
```
|
94
|
+
|
95
|
+
**Note:** Essentially `set_device_owner` has to return a class object *or* `nil`.
|
96
|
+
|
84
97
|
### Device methods
|
85
98
|
|
86
99
|
devise-onesignal introduces a `Device` activerecord model. Every object of your devise class can have multiple devices, one for each device / browser they enabled OneSignal at least once.
|
@@ -88,8 +101,8 @@ devise-onesignal introduces a `Device` activerecord model. Every object of your
|
|
88
101
|
```ruby
|
89
102
|
d = Device.first
|
90
103
|
|
91
|
-
# Returns
|
92
|
-
d.
|
104
|
+
# Returns object associated with device. Can return `nil`.
|
105
|
+
d.owner
|
93
106
|
|
94
107
|
# Returns OneSignal player id
|
95
108
|
d.onesignal_id
|
@@ -131,7 +144,7 @@ If you want to completely remove a user from OneSignal, call `OneSignalUnsubscri
|
|
131
144
|
|
132
145
|
## Configuration
|
133
146
|
|
134
|
-
You can configure devise-onesignal by passing a block to `configure`:
|
147
|
+
You can configure devise-onesignal by passing a block to `configure`. This can be done in `config/initializers/devise-onesignal.rb`:
|
135
148
|
|
136
149
|
```ruby
|
137
150
|
DeviseOnesignal.configure do |config|
|
@@ -141,8 +154,6 @@ end
|
|
141
154
|
|
142
155
|
**`app_id` (required)** Your OneSignal app id. Takes a string. Create one here: https://onesignal.com
|
143
156
|
|
144
|
-
**`devise_class`** Specify your devise class. Takes a string. Defaults to `'User'`.
|
145
|
-
|
146
157
|
**`auto_register`** Automatically try to subscribe the user when loading a page. Takes a boolean. Defaults to `false`.
|
147
158
|
|
148
159
|
**`persist_notification`** Automatically dismiss the notification after ~20 seconds in Chrome. Takes a boolean. Defaults to `false`.
|
@@ -171,6 +182,10 @@ Give the people some :heart: who are working on this project. See them all at:
|
|
171
182
|
|
172
183
|
https://github.com/jonhue/devise-onesignal/graphs/contributors
|
173
184
|
|
185
|
+
### Semantic Versioning
|
186
|
+
|
187
|
+
Sandboxy follows Semantic Versioning 2.0 as defined at http://semver.org.
|
188
|
+
|
174
189
|
## License
|
175
190
|
|
176
191
|
MIT License
|
data/devise-onesignal.gemspec
CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |gem|
|
|
6
6
|
gem.version = DeviseOnesignal::VERSION
|
7
7
|
gem.platform = Gem::Platform::RUBY
|
8
8
|
gem.summary = 'Implement user targeted cross-platform notifications in your Rails app'
|
9
|
-
gem.description = 'Implement user targeted cross-platform notifications with OneSignal & Devise in your Rails app.'
|
9
|
+
gem.description = 'Implement user targeted cross-platform notifications with OneSignal & Devise in your Rails app. This gem can also be used without Devise, but it is primarily intended to be used along with some sort of user-management-system.'
|
10
10
|
gem.authors = 'Jonas Hübotter'
|
11
11
|
gem.email = 'jonas.huebotter@gmail.com'
|
12
12
|
gem.homepage = 'https://github.com/jonhue/devise-onesignal'
|
@@ -22,5 +22,4 @@ Gem::Specification.new do |gem|
|
|
22
22
|
gem.add_development_dependency 'bundler', '~> 1.16'
|
23
23
|
gem.add_development_dependency 'rake', '~> 10.0'
|
24
24
|
gem.add_dependency 'rails', '>= 5.0'
|
25
|
-
gem.add_dependency 'devise', '~> 4.3'
|
26
25
|
end
|
@@ -2,13 +2,11 @@ module DeviseOnesignal
|
|
2
2
|
class Configuration
|
3
3
|
|
4
4
|
attr_accessor :app_id
|
5
|
-
attr_accessor :devise_class
|
6
5
|
attr_accessor :auto_register
|
7
6
|
attr_accessor :persist_notification
|
8
7
|
attr_accessor :subscribe_with_modal
|
9
8
|
|
10
9
|
def initialize
|
11
|
-
@devise_class = 'User'
|
12
10
|
@auto_register = false
|
13
11
|
@persist_notification = false
|
14
12
|
@subscribe_with_modal = false
|
@@ -12,15 +12,19 @@ module DeviseOnesignal
|
|
12
12
|
private
|
13
13
|
|
14
14
|
def set_device
|
15
|
-
unless cookies[:
|
16
|
-
|
17
|
-
device = Device.find_or_create_by! onesignal_id:
|
18
|
-
device.
|
19
|
-
device.onesignal_permission = cookies[:oneSignalUserPermission]
|
15
|
+
unless cookies[:oneSignalPlayerId].nil?
|
16
|
+
onesignal_player_id = cookies[:oneSignalPlayerId]
|
17
|
+
device = Device.find_or_create_by! onesignal_id: onesignal_player_id
|
18
|
+
device.onesignal_permission = cookies[:oneSignalPlayerPermission]
|
20
19
|
device.last_used = Time.now
|
20
|
+
device.owner = set_device_owner
|
21
21
|
device.save!
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
+
def set_device_owner
|
26
|
+
current_user if current_user
|
27
|
+
end
|
28
|
+
|
25
29
|
end
|
26
30
|
end
|
@@ -2,13 +2,13 @@ module DeviseOnesignal
|
|
2
2
|
module DeviceHelper
|
3
3
|
|
4
4
|
def current_device
|
5
|
-
if cookies[:
|
5
|
+
if cookies[:oneSignalPlayerId].nil?
|
6
6
|
device = Device.new
|
7
|
-
device.
|
8
|
-
device.
|
7
|
+
device.onesignal_permission = cookies[:oneSignalPlayerPermission]
|
8
|
+
device.owner = set_device_owner
|
9
9
|
device.last_used = Time.now
|
10
10
|
else
|
11
|
-
device = Device.find_by
|
11
|
+
device = Device.find_by onesignal_id: cookies[:oneSignalPlayerId]
|
12
12
|
end
|
13
13
|
device
|
14
14
|
end
|
@@ -2,7 +2,7 @@ class DeviseOnesignalMigration < ActiveRecord::Migration<%= migration_version %>
|
|
2
2
|
def change
|
3
3
|
create_table :devices do |t|
|
4
4
|
|
5
|
-
t.references
|
5
|
+
t.references :owner, polymorphic: true, index: true
|
6
6
|
|
7
7
|
t.string :onesignal_id, index: true, unique: true
|
8
8
|
t.string :onesignal_permission
|
@@ -1,19 +1,9 @@
|
|
1
1
|
DeviseOnesignal.configure do |config|
|
2
2
|
|
3
|
-
### ONESIGNAL ###
|
4
|
-
|
5
3
|
# Your OneSignal app id. Create one here: https://onesignal.com
|
6
4
|
config.app_id = ''
|
7
5
|
|
8
6
|
|
9
|
-
### DEVISE ###
|
10
|
-
|
11
|
-
# Specify your devise class. Defaults to `'User'`.
|
12
|
-
# config.devise_class = 'User'
|
13
|
-
|
14
|
-
|
15
|
-
### CUSTOMIZATION ###
|
16
|
-
|
17
7
|
# Automatically try to subscribe the user when loading a page. Defaults to `false`.
|
18
8
|
# config.auto_register = false
|
19
9
|
|
@@ -1,13 +1,11 @@
|
|
1
|
-
var
|
1
|
+
var OneSignalPlayerId = null;
|
2
2
|
var OneSignal = window.OneSignal || [];
|
3
3
|
|
4
4
|
|
5
5
|
|
6
6
|
function OneSignalInit() {
|
7
7
|
|
8
|
-
// Do NOT call init() twice
|
9
8
|
OneSignal.push([ 'init', {
|
10
|
-
// Your other init options here
|
11
9
|
appId: '<%= DeviseOnesignal.configuration.app_id %>',
|
12
10
|
autoRegister: <%= DeviseOnesignal.configuration.auto_register ? 'true' : 'false' %>,
|
13
11
|
welcomeNotification: {
|
@@ -21,15 +19,14 @@ function OneSignalInit() {
|
|
21
19
|
persistNotification: <%= DeviseOnesignal.configuration.persist_notification ? 'true' : 'false' %> // Automatically dismiss the notification after ~20 seconds in Chrome Desktop v47+
|
22
20
|
}]);
|
23
21
|
|
24
|
-
// Firstly this will check user id
|
25
22
|
OneSignal.push(function() {
|
26
|
-
OneSignal.getUserId().then(function(
|
27
|
-
if (
|
28
|
-
|
29
|
-
document.cookie = '
|
23
|
+
OneSignal.getUserId().then(function(playerId) {
|
24
|
+
if ( playerId != null ) {
|
25
|
+
OneSignalPlayerId = playerId;
|
26
|
+
document.cookie = 'oneSignalPlayerId=' + playerId;
|
30
27
|
};
|
31
28
|
OneSignal.push([ 'getNotificationPermission', function(permission) {
|
32
|
-
document.cookie = '
|
29
|
+
document.cookie = 'oneSignalPlayerPermission=' + permission;
|
33
30
|
}]);
|
34
31
|
});
|
35
32
|
});
|
@@ -39,7 +36,7 @@ function OneSignalInit() {
|
|
39
36
|
|
40
37
|
|
41
38
|
function OneSignalSubscribe() {
|
42
|
-
if (
|
39
|
+
if ( OneSignalPlayerId != null ) {
|
43
40
|
OneSignal.setSubscription(true);
|
44
41
|
} else {
|
45
42
|
OneSignal.registerForPushNotifications({
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devise-onesignal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonas Hübotter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-12-
|
11
|
+
date: 2017-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,22 +52,9 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '5.0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: devise
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '4.3'
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '4.3'
|
69
55
|
description: Implement user targeted cross-platform notifications with OneSignal &
|
70
|
-
Devise in your Rails app.
|
56
|
+
Devise in your Rails app. This gem can also be used without Devise, but it is primarily
|
57
|
+
intended to be used along with some sort of user-management-system.
|
71
58
|
email: jonas.huebotter@gmail.com
|
72
59
|
executables: []
|
73
60
|
extensions: []
|