onsignal 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +112 -0
- data/LICENSE +21 -0
- data/README.md +254 -0
- data/app/controllers/concerns/on_signal_controller.rb +26 -0
- data/app/helpers/on_signal_helper.rb +15 -0
- data/app/models/concerns/on_signal_model.rb +24 -0
- data/app/models/on_signal/device.rb +15 -0
- data/lib/generators/onsignal_generator.rb +42 -0
- data/lib/generators/templates/README.md +1 -0
- data/lib/generators/templates/device_model.rb +2 -0
- data/lib/generators/templates/devices_migration.rb.erb +16 -0
- data/lib/generators/templates/initializer.rb +6 -0
- data/lib/on_signal/configuration.rb +21 -0
- data/lib/on_signal/engine.rb +6 -0
- data/lib/on_signal/railtie.rb +17 -0
- data/lib/on_signal/version.rb +5 -0
- data/lib/onsignal.rb +10 -0
- metadata +179 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0dd60aab5dd2f9f314707ff831ef5daa5b5a001eddb01373ea45146354469150
|
4
|
+
data.tar.gz: c7e6bf9704c846825fdedb473aa21d692c7a3a33dd375055dc634a47723ee51b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cba30256ba8470dcec04dc3fce6332e9191bf1d425d0e4d1cca3c74cdbb3017a0d4a409cff89259709da2fb202869ef24695866cc3ed1c5217492604f3a113f5
|
7
|
+
data.tar.gz: 514059dc5200cee8adba10b81bdf7af50a666cbf33c25daeb69cf03a5be53f63fa442baf0f1899d4ecac519f216ab5c7943fb8d9c350cf17bd37f8fdd5d21c9b
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
### master
|
4
|
+
|
5
|
+
* nothing yet
|
6
|
+
|
7
|
+
### 5.0.0 - 2018/02/09
|
8
|
+
|
9
|
+
* features
|
10
|
+
* new ES6 JavaScript API
|
11
|
+
* streamlined `Device` model (Rails API)
|
12
|
+
|
13
|
+
### 4.0.1 - 2018/02/08
|
14
|
+
|
15
|
+
* bugfixes
|
16
|
+
* fixed not exporting `init()` function
|
17
|
+
|
18
|
+
### 4.0.0 - 2018/02/08
|
19
|
+
|
20
|
+
* features
|
21
|
+
* add ES6/Webpack support
|
22
|
+
|
23
|
+
### 3.2.0 - 2018/01/21
|
24
|
+
|
25
|
+
* features
|
26
|
+
* add `OneSignalSubscribed()` function
|
27
|
+
|
28
|
+
### 3.1.5 - 2018/01/06
|
29
|
+
|
30
|
+
* enhancements
|
31
|
+
* cleaning up gem files
|
32
|
+
|
33
|
+
### 3.1.4 - 2018/01/02
|
34
|
+
|
35
|
+
* bugfixes
|
36
|
+
* fixed overriding `set_device_owner` method
|
37
|
+
|
38
|
+
### 3.1.3 - 2018/01/02
|
39
|
+
|
40
|
+
* bugfixes
|
41
|
+
* fixed overriding `set_device_owner` method
|
42
|
+
|
43
|
+
### 3.1.2 - 2017/12/28
|
44
|
+
|
45
|
+
* bugfixes
|
46
|
+
* fix `has_devices` method
|
47
|
+
|
48
|
+
### 3.1.1 - 2017/12/28
|
49
|
+
|
50
|
+
* bugfixes
|
51
|
+
* fix `has_devices` method
|
52
|
+
|
53
|
+
### 3.1.0 - 2017/12/27
|
54
|
+
|
55
|
+
* features
|
56
|
+
* add `has_devices` method
|
57
|
+
|
58
|
+
### 3.0.2 - 2017/12/21
|
59
|
+
|
60
|
+
* bugfixes
|
61
|
+
* fixed `undefined method 'set_device_owner' for ApplicationController:Class`
|
62
|
+
|
63
|
+
### 3.0.1 - 2017/12/21
|
64
|
+
|
65
|
+
* bugfixes
|
66
|
+
* custom `set_device_owner` method was not overriding default
|
67
|
+
|
68
|
+
### 3.0.0 - 2017/12/21
|
69
|
+
|
70
|
+
* features
|
71
|
+
* made Devise optional
|
72
|
+
* added `owner` association to `Device` model
|
73
|
+
* enhancements
|
74
|
+
* renamed elements of the javascript API
|
75
|
+
|
76
|
+
### 2.0.1 - 2017/12/20
|
77
|
+
|
78
|
+
* bugfixes
|
79
|
+
* fixed `undefined method 'permission=' for #<Device>`
|
80
|
+
|
81
|
+
### 2.0.0 - 2017/12/19
|
82
|
+
|
83
|
+
* features
|
84
|
+
* automatically include helpers and concerns
|
85
|
+
* configuration by passing a block to `configure`
|
86
|
+
* introducing `Device` activerecord model
|
87
|
+
* enhancements
|
88
|
+
* rename `current_onesignal` method to `current_device`
|
89
|
+
|
90
|
+
### 1.2.1 - 2017/12/18
|
91
|
+
|
92
|
+
* enhancements
|
93
|
+
* add more configuration options
|
94
|
+
|
95
|
+
### 1.1.1 - 2017/12/18
|
96
|
+
|
97
|
+
* bugfixes
|
98
|
+
* fixed use of wrong class name
|
99
|
+
|
100
|
+
### 1.1.0 - 2017/12/18
|
101
|
+
|
102
|
+
* enhancements
|
103
|
+
* dont't include keys in `current_onesignal` hash whose values are `nil`
|
104
|
+
|
105
|
+
### 1.0.1 - 2017/12/18
|
106
|
+
|
107
|
+
* bugfixes
|
108
|
+
* fixed `Stack Level too deep` when using `current_onesignal`
|
109
|
+
|
110
|
+
### 1.0.0 - 2017/12/18
|
111
|
+
|
112
|
+
* initial release
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2017 Jonas Hübotter
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,254 @@
|
|
1
|
+
# OnSignal
|
2
|
+
|
3
|
+
![NPM Version](https://img.shields.io/npm/v/onsignal.svg) [![Gem Version](https://badge.fury.io/rb/onsignal.svg)](https://badge.fury.io/rb/onsignal) <img src="https://travis-ci.org/jonhue/onsignal.svg?branch=master" />
|
4
|
+
|
5
|
+
A OneSignal API wrapper simplifying user targeted cross platform notifications. OnSignal consists of a JavaScript and a Rails API:
|
6
|
+
|
7
|
+
* [JavaScript API](#javascript-api): Handle user subscriptions to OneSignal in your frontend code.
|
8
|
+
* [Rails API](#javascript-api): Attach OneSignal players to user records provided by an authentication solution.
|
9
|
+
|
10
|
+
---
|
11
|
+
|
12
|
+
## Table of Contents
|
13
|
+
|
14
|
+
* [JavaScript API](#javascript-api)
|
15
|
+
* [Overview](#overview)
|
16
|
+
* [Subscribing](#subscribing)
|
17
|
+
* [Unsubscribing](#unsubscribing)
|
18
|
+
* [Additional functions](#additional-functions)
|
19
|
+
* [Rails API](#javascript-api)
|
20
|
+
* [Installation](#installation)
|
21
|
+
* [User associations](#user-associations)
|
22
|
+
* [Devices](#devices)
|
23
|
+
* [Methods](#methods)
|
24
|
+
* [Helpers](#helpers)
|
25
|
+
* [Configuration](#configuration)
|
26
|
+
* [To Do](#to-do)
|
27
|
+
* [Contributing](#contributing)
|
28
|
+
* [Contributors](#contributors)
|
29
|
+
* [Semantic versioning](#semantic-versioning)
|
30
|
+
* [License](#license)
|
31
|
+
|
32
|
+
---
|
33
|
+
|
34
|
+
## JavaScript API
|
35
|
+
|
36
|
+
Handle user subscriptions to OneSignal in your frontend code.
|
37
|
+
|
38
|
+
### Overview
|
39
|
+
|
40
|
+
```javascript
|
41
|
+
import OnSignal from 'onsignal';
|
42
|
+
let onSignal = new OnSignal( 'OneSignal App ID', {
|
43
|
+
autoRegister: false
|
44
|
+
});
|
45
|
+
|
46
|
+
// Object to call OneSignal API from
|
47
|
+
onSignal.oneSignal;
|
48
|
+
|
49
|
+
// Current users player ID
|
50
|
+
onSignal.playerId;
|
51
|
+
|
52
|
+
// Current users permission
|
53
|
+
onSignal.permission;
|
54
|
+
```
|
55
|
+
|
56
|
+
#### Options
|
57
|
+
|
58
|
+
Pass options to OneSignal's `push(['init', {...}])` function as a hash. Default values are:
|
59
|
+
|
60
|
+
* `autoRegister` Automatically try to subscribe the user when loading a page. Accepts a boolean. Defaults to `false`.
|
61
|
+
* `persistNotification` Automatically dismiss notifications after ~20 seconds in Chrome Desktop v47+. Accepts a boolean. Defaults to `false`.
|
62
|
+
* `welcomeNotification` Hash configuring the default OneSignal welcome notification. Accepts a hash. Defaults to `{ disable: true }`.
|
63
|
+
* `notifyButton` Hash configuring the default OneSignal notify button at the bottom right of the screen. Accepts a hash. Defaults to `{ enable: false }`.
|
64
|
+
|
65
|
+
### Subscribing
|
66
|
+
|
67
|
+
Just call `onSignal.subscribe();` and OneSignal will ask your user for permission to send notifications if he is not subscribed yet. _On the following request an existing `Device` object will either get updated or a new one will get created. (if using the Rails API)_
|
68
|
+
|
69
|
+
#### Options
|
70
|
+
|
71
|
+
Pass options to OneSignal's `registerForPushNotifications()` function as a hash. Default values are:
|
72
|
+
|
73
|
+
* `modalPrompt` Whether or not to use a custom prompt instead of the browsers default to ask for permission. Accepts a boolean. Defaults to `false`.
|
74
|
+
|
75
|
+
### Unsubscribing
|
76
|
+
|
77
|
+
**Note:** You most likely don't want to let your users unsubscribe from receiving notifications, but instead allow them to manually disable receiving any new notifications. For that purpose use the [notifications-rails](https://github.com/jonhue/notifications-rails) gem, which adds a notification API and detailed user settings.
|
78
|
+
|
79
|
+
If you want to completely remove a user from OneSignal, call `onSignal.unsubscribe();`.
|
80
|
+
|
81
|
+
### Additional functions
|
82
|
+
|
83
|
+
```javascript
|
84
|
+
// Check if a user is subscribed to OneSignal
|
85
|
+
onSignal.isSubscribed()
|
86
|
+
```
|
87
|
+
|
88
|
+
---
|
89
|
+
|
90
|
+
## Rails API
|
91
|
+
|
92
|
+
Attach OneSignal players to user records provided by an authentication solution.
|
93
|
+
|
94
|
+
### Installation
|
95
|
+
|
96
|
+
OnSignal works with Rails 5 onwards. You can add it to your `Gemfile` with:
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
gem 'onsignal'
|
100
|
+
```
|
101
|
+
|
102
|
+
And then execute:
|
103
|
+
|
104
|
+
$ bundle
|
105
|
+
|
106
|
+
Or install it yourself as:
|
107
|
+
|
108
|
+
$ gem install onsignal
|
109
|
+
|
110
|
+
If you always want to be up to date fetch the latest from GitHub in your `Gemfile`:
|
111
|
+
|
112
|
+
```ruby
|
113
|
+
gem 'onsignal', github: 'jonhue/onsignal'
|
114
|
+
```
|
115
|
+
|
116
|
+
Now run the generator:
|
117
|
+
|
118
|
+
$ rails g onsignal
|
119
|
+
|
120
|
+
To wrap things up, migrate the changes into your database:
|
121
|
+
|
122
|
+
$ rails db:migrate
|
123
|
+
|
124
|
+
### User associations
|
125
|
+
|
126
|
+
Define an association in models whose objects are supposed to be associated with OneSignal players. For example `Admin` in `app/models/admin.rb`.
|
127
|
+
|
128
|
+
```ruby
|
129
|
+
class Admin < ApplicationRecord
|
130
|
+
onsignal
|
131
|
+
end
|
132
|
+
```
|
133
|
+
|
134
|
+
Next attach a user object by defining a `set_onsignal_user` method. Let's say model is named `Admin` and `current_admin` is available at controller level. Just add a method to your `ApplicationController`:
|
135
|
+
|
136
|
+
```ruby
|
137
|
+
def set_onsignal_user
|
138
|
+
current_admin if current_admin
|
139
|
+
end
|
140
|
+
```
|
141
|
+
|
142
|
+
**Note:** If a `current_user` method is available at controller level this method is not required.
|
143
|
+
|
144
|
+
You are now able to get OneSignal players for a specific user:
|
145
|
+
|
146
|
+
```ruby
|
147
|
+
a = Admin.first
|
148
|
+
|
149
|
+
# All device records of a user
|
150
|
+
a.devices
|
151
|
+
|
152
|
+
# All OneSignal Player ID's of a user returned as an array
|
153
|
+
a.onesignal_player_ids
|
154
|
+
```
|
155
|
+
|
156
|
+
### Devices
|
157
|
+
|
158
|
+
OnSignal introduces a `Device` ActiveRecord model. You can [configure](#configuration) its name. Every record of an associated user class can have multiple devices - one for each device / browser they enabled OneSignal on.
|
159
|
+
|
160
|
+
#### Methods
|
161
|
+
|
162
|
+
```ruby
|
163
|
+
d = Device.first
|
164
|
+
|
165
|
+
# Returns user associated with device. Can return `nil`.
|
166
|
+
d.owner
|
167
|
+
|
168
|
+
# Returns OneSignal player id
|
169
|
+
d.onesignal_id
|
170
|
+
|
171
|
+
# Returns OneSignal permission ( `granted` / `denied` / `default` )
|
172
|
+
d.onesignal_permission
|
173
|
+
|
174
|
+
# Some timestamps
|
175
|
+
d.last_used
|
176
|
+
d.created_at
|
177
|
+
d.updated_at
|
178
|
+
|
179
|
+
|
180
|
+
# If device is ready to receive notifications
|
181
|
+
d.onesignal_enabled?
|
182
|
+
|
183
|
+
# If device has been disabled to receive notifications
|
184
|
+
d.onesignal_disabled?
|
185
|
+
|
186
|
+
# If device has been set previously to receive notifications or not
|
187
|
+
d.onesignal_set?
|
188
|
+
```
|
189
|
+
|
190
|
+
#### Helpers
|
191
|
+
|
192
|
+
In your controllers and views you can access a `current_onsignal` method that returns the `Device` object of the current OneSignal subscription. If the user browsing your site is not subscribed to OneSignal, `current_onsignal` returns an uncommitted `Device` object with some helpful information, like the `permission` attribute, set.
|
193
|
+
|
194
|
+
### Configuration
|
195
|
+
|
196
|
+
You can configure OnSignal by passing a block to `configure`. This can be done in `config/initializers/onsignal.rb`:
|
197
|
+
|
198
|
+
```ruby
|
199
|
+
OnSignal.configure do |config|
|
200
|
+
config.device_const = 'Device'
|
201
|
+
end
|
202
|
+
```
|
203
|
+
|
204
|
+
* `device_const` Name of the constant exposing devices. Takes a constant name (string). Defaults to `'Device'`.
|
205
|
+
|
206
|
+
---
|
207
|
+
|
208
|
+
## To Do
|
209
|
+
|
210
|
+
[Here](https://github.com/jonhue/devise-onesignal/projects/1) is the full list of current projects.
|
211
|
+
|
212
|
+
To propose your ideas, initiate the discussion by adding a [new issue](https://github.com/jonhue/devise-onesignal/issues/new).
|
213
|
+
|
214
|
+
---
|
215
|
+
|
216
|
+
## Contributing
|
217
|
+
|
218
|
+
We hope that you will consider contributing to devise-onesignal. Please read this short overview for some information about how to get started:
|
219
|
+
|
220
|
+
[Learn more about contributing to this repository](https://github.com/jonhue/devise-onesignal/blob/master/CONTRIBUTING.md), [Code of Conduct](https://github.com/jonhue/devise-onesignal/blob/master/CODE_OF_CONDUCT.md)
|
221
|
+
|
222
|
+
### Contributors
|
223
|
+
|
224
|
+
Give the people some :heart: who are working on this project. See them all at:
|
225
|
+
|
226
|
+
https://github.com/jonhue/devise-onesignal/graphs/contributors
|
227
|
+
|
228
|
+
### Semantic Versioning
|
229
|
+
|
230
|
+
devise-onesignal follows Semantic Versioning 2.0 as defined at http://semver.org.
|
231
|
+
|
232
|
+
## License
|
233
|
+
|
234
|
+
MIT License
|
235
|
+
|
236
|
+
Copyright (c) 2017 Jonas Hübotter
|
237
|
+
|
238
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
239
|
+
of this software and associated documentation files (the "Software"), to deal
|
240
|
+
in the Software without restriction, including without limitation the rights
|
241
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
242
|
+
copies of the Software, and to permit persons to whom the Software is
|
243
|
+
furnished to do so, subject to the following conditions:
|
244
|
+
|
245
|
+
The above copyright notice and this permission notice shall be included in all
|
246
|
+
copies or substantial portions of the Software.
|
247
|
+
|
248
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
249
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
250
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
251
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
252
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
253
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
254
|
+
SOFTWARE.
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module OnSignalController
|
2
|
+
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
before_action :set_onsignal
|
7
|
+
end
|
8
|
+
|
9
|
+
def set_onsignal_user
|
10
|
+
current_user if current_user
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def set_onsignal
|
16
|
+
unless cookies[:oneSignalPlayerId].nil?
|
17
|
+
onesignal_player_id = cookies[:oneSignalPlayerId]
|
18
|
+
device = OnSignal.configuration.device_const.constantize.find_or_create_by! onesignal_id: onesignal_player_id
|
19
|
+
device.onesignal_permission = cookies[:oneSignalPlayerPermission]
|
20
|
+
device.last_used = Time.now
|
21
|
+
device.owner = set_onesignal_user
|
22
|
+
device.save!
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module OnSignalHelper
|
2
|
+
|
3
|
+
def current_onsignal
|
4
|
+
if cookies[:oneSignalPlayerId].nil?
|
5
|
+
device = OnSignal.configuration.device_const.constantize.new
|
6
|
+
device.onesignal_permission = cookies[:oneSignalPlayerPermission]
|
7
|
+
device.owner = set_onsignal_owner
|
8
|
+
device.last_used = Time.now
|
9
|
+
else
|
10
|
+
device = OnSignal.configuration.device_const.constantize.find_by onesignal_id: cookies[:oneSignalPlayerId]
|
11
|
+
end
|
12
|
+
device
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module OnSignalModel
|
2
|
+
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
def onsignal
|
7
|
+
has_many :devices, as: :owner, class_name: OnSignal.configuration.device_const, dependent: :destroy
|
8
|
+
include OnSignal::Owner::InstanceMethods
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
module InstanceMethods
|
13
|
+
|
14
|
+
def onesignal_player_ids
|
15
|
+
onesignal_player_ids = []
|
16
|
+
self.devices.each do |device|
|
17
|
+
onesignal_player_ids << device.onesignal_id
|
18
|
+
end
|
19
|
+
onesignal_player_ids
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class OnSignal::Device < ApplicationRecord
|
2
|
+
|
3
|
+
def onesignal_enabled?
|
4
|
+
self.onesignal_permission == 'granted'
|
5
|
+
end
|
6
|
+
def onesignal_disabled?
|
7
|
+
self.onesignal_permission == 'denied'
|
8
|
+
end
|
9
|
+
def onesignal_set?
|
10
|
+
!self.onesignal_permission == 'default'
|
11
|
+
end
|
12
|
+
|
13
|
+
belongs_to :owner, polymorphic: true, optional: true
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
|
4
|
+
class OnsignalGenerator < Rails::Generators::Base
|
5
|
+
|
6
|
+
include Rails::Generators::Migration
|
7
|
+
|
8
|
+
source_root File.join File.dirname(__FILE__), 'templates'
|
9
|
+
desc 'Install OnSignal'
|
10
|
+
|
11
|
+
def self.next_migration_number dirname
|
12
|
+
if ActiveRecord::Base.timestamped_migrations
|
13
|
+
Time.now.utc.strftime '%Y%m%d%H%M%S'
|
14
|
+
else
|
15
|
+
"%.3d" % ( current_migration_number(dirname) + 1 )
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def create_initializer
|
20
|
+
template 'initializer.rb', 'config/initializers/onsignal.rb'
|
21
|
+
end
|
22
|
+
|
23
|
+
def create_device_migration_file
|
24
|
+
migration_template 'devices_migration.rb.erb', 'db/migrate/onsignal_migration.rb', migration_version: migration_version
|
25
|
+
end
|
26
|
+
def create_device_model
|
27
|
+
template 'device_model.rb', 'app/models/device.rb'
|
28
|
+
end
|
29
|
+
|
30
|
+
def show_readme
|
31
|
+
readme 'README.md'
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def migration_version
|
37
|
+
if Rails.version >= '5.0.0'
|
38
|
+
"[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Now run `rails db:migrate` to add onsignal to your database.
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class OnsignalMigration < ActiveRecord::Migration<%= migration_version %>
|
2
|
+
def change
|
3
|
+
create_table :devices do |t|
|
4
|
+
|
5
|
+
t.references :owner, polymorphic: true, index: true
|
6
|
+
|
7
|
+
t.string :onesignal_id, index: true, unique: true
|
8
|
+
t.string :onesignal_permission
|
9
|
+
|
10
|
+
t.datetime :last_used
|
11
|
+
|
12
|
+
t.timestamps
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module OnSignal
|
2
|
+
|
3
|
+
class << self
|
4
|
+
attr_accessor :configuration
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.configure
|
8
|
+
self.configuration ||= Configuration.new
|
9
|
+
yield configuration
|
10
|
+
end
|
11
|
+
|
12
|
+
class Configuration
|
13
|
+
|
14
|
+
attr_accessor :device_const
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
@device_const = 'Device'
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rails/railtie'
|
2
|
+
|
3
|
+
module OnSignal
|
4
|
+
class Railtie < Rails::Railtie
|
5
|
+
|
6
|
+
initializer 'onsignal.initialize' do
|
7
|
+
ActiveSupport.on_load :action_controller do
|
8
|
+
include OnSignalHelper
|
9
|
+
include OnSignalController
|
10
|
+
end
|
11
|
+
ActiveSupport.on_load :active_record do
|
12
|
+
include OnSignalModel
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
data/lib/onsignal.rb
ADDED
metadata
ADDED
@@ -0,0 +1,179 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: onsignal
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 5.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jonas Hübotter
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-02-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: railties
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activerecord
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: actionview
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: actionpack
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '5.0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '5.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.7'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.7'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.52'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.52'
|
111
|
+
description: OneSignal API wrapper simplifying user targeted cross platform notifications.
|
112
|
+
email: me@jonhue.me
|
113
|
+
executables: []
|
114
|
+
extensions: []
|
115
|
+
extra_rdoc_files: []
|
116
|
+
files:
|
117
|
+
- CHANGELOG.md
|
118
|
+
- LICENSE
|
119
|
+
- README.md
|
120
|
+
- app/controllers/concerns/on_signal_controller.rb
|
121
|
+
- app/helpers/on_signal_helper.rb
|
122
|
+
- app/models/concerns/on_signal_model.rb
|
123
|
+
- app/models/on_signal/device.rb
|
124
|
+
- lib/generators/onsignal_generator.rb
|
125
|
+
- lib/generators/templates/README.md
|
126
|
+
- lib/generators/templates/device_model.rb
|
127
|
+
- lib/generators/templates/devices_migration.rb.erb
|
128
|
+
- lib/generators/templates/initializer.rb
|
129
|
+
- lib/on_signal/configuration.rb
|
130
|
+
- lib/on_signal/engine.rb
|
131
|
+
- lib/on_signal/railtie.rb
|
132
|
+
- lib/on_signal/version.rb
|
133
|
+
- lib/onsignal.rb
|
134
|
+
homepage: https://github.com/jonhue/onsignal
|
135
|
+
licenses:
|
136
|
+
- MIT
|
137
|
+
metadata: {}
|
138
|
+
post_install_message: |
|
139
|
+
**Thank you for installing OnSignal!**
|
140
|
+
|
141
|
+
|
142
|
+
There are four wo more steps to take:
|
143
|
+
|
144
|
+
1) Run `rails g devise_onesignal` and `rails db:migrate`
|
145
|
+
2) Enter your OneSignal App ID in config/initializers/devise-onesignal.rb
|
146
|
+
3) Add:
|
147
|
+
|
148
|
+
import 'devise-onesignal/dist/OneSignalSDK';
|
149
|
+
import * as deviseOneSignal from 'devise-onesignal';
|
150
|
+
|
151
|
+
to your webpack pack in app/javascript/packs/application.js
|
152
|
+
4) Add:
|
153
|
+
|
154
|
+
has_devices
|
155
|
+
|
156
|
+
to your authentication model
|
157
|
+
|
158
|
+
|
159
|
+
Learn more at https://github.com/jonhue/devise-onesignal
|
160
|
+
rdoc_options: []
|
161
|
+
require_paths:
|
162
|
+
- lib
|
163
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
164
|
+
requirements:
|
165
|
+
- - ">="
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: '2.3'
|
168
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
169
|
+
requirements:
|
170
|
+
- - ">="
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: '0'
|
173
|
+
requirements: []
|
174
|
+
rubyforge_project:
|
175
|
+
rubygems_version: 2.7.4
|
176
|
+
signing_key:
|
177
|
+
specification_version: 4
|
178
|
+
summary: OneSignal API wrapper simplifying user targeted cross platform notifications
|
179
|
+
test_files: []
|