devise-onesignal 1.2.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c0f650e900ff08e671a6ae3d04385c6c57e64f310ffbc06cf9fbbdd11b3bd917
4
- data.tar.gz: 11a32381521ca68f8c60b3a657218dcc79e17bb06f2acd2284094c2da07a6c64
3
+ metadata.gz: b88207054f8bb5822b6c47f4932517eee81812ecb3ed7319087ed9660ff0ea88
4
+ data.tar.gz: f86553157eafcb7d9ef43c5fe7761c17a5d243470a40f95c03c3f1407da52277
5
5
  SHA512:
6
- metadata.gz: a2f640c82b049573428632254904d39347777ea20071012b79fd3405c9bca69df558d2a0182d9090a15d2077d6bc71460e923e030650573b5b40ba56047757cc
7
- data.tar.gz: 67033ef583f45281dca2c2e1ec09e60b0224fc08b11dbda877fb262135292ab097ad61003e59a47f0694ac06d619c4a6b52cecb2322105f219ba568c131eb487
6
+ metadata.gz: 2dc9e06943bf79803d871b8458874643791b7123ae78c8909303bed17405d67c80620fd717ee21bf7e0972d1d2c56aea1c43f87c7304261e67d38dc3ea7a2fe5
7
+ data.tar.gz: b99727eb1b459caa119dc3b57be474c9bc597264196823007ab15f6b306f50371167a2ec59378e23ffb0a8d1fc38d15ad67a34cf5c4b70480d467f26ae8dd157
@@ -4,6 +4,15 @@
4
4
 
5
5
  * nothing yet
6
6
 
7
+ ### 2.0.0 - 2017-12-19
8
+
9
+ * features
10
+ * automatically include helpers and concerns
11
+ * configuration by passing a block to `configure`
12
+ * introducing `Device` activerecord model
13
+ * enhancements
14
+ * rename `current_onesignal` method to `current_device`
15
+
7
16
  ### 1.2.1 - 2017-12-18
8
17
 
9
18
  * enhancements
@@ -1,3 +1,5 @@
1
1
  # Deprecations
2
2
 
3
- No deprecations
3
+ ### 2.0.0 - 2017-12-19
4
+
5
+ * you should now configure devise-onesignal through a `configure` block
data/INSTALL.md CHANGED
@@ -4,7 +4,7 @@
4
4
  There are three wo more steps to take:
5
5
 
6
6
  1) Enter your OneSignal App ID in config/initializers/devise-onesignal.rb
7
- 2) Run `rails g devise_one_signal` and `rails db:migrate`
7
+ 2) Run `rails g devise-onesignal` and `rails db:migrate`
8
8
  3) Add:
9
9
 
10
10
  //= require OneSignalSDK
@@ -13,4 +13,4 @@ There are three wo more steps to take:
13
13
  to your javascript index in app/assets/javascripts/application.js
14
14
 
15
15
 
16
- Learn more at https://github.com/jonhue/devise-onesignal.
16
+ Learn more at https://github.com/jonhue/devise-onesignal
data/README.md CHANGED
@@ -2,7 +2,9 @@
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. Working well together with [onesignal-ruby](https://github.com/tbalthazar/onesignal-ruby) to access the OneSignal API.
5
+ Implement user targeted cross-platform notifications with OneSignal & Devise in your Rails app.
6
+
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.
6
8
 
7
9
  ---
8
10
 
@@ -10,6 +12,10 @@ Implement user targeted cross-platform notifications with OneSignal & Devise in
10
12
 
11
13
  * [Installation](#installation)
12
14
  * [Usage](#usage)
15
+ * [Device methods](#device-methods)
16
+ * [current_device](#current_device)
17
+ * [Subscribing](#subscribing)
18
+ * [Unsubscribing](#unsubscribing)
13
19
  * [Configuration](#configuration)
14
20
  * [To Do](#to-do)
15
21
  * [Contributing](#contributing)
@@ -20,7 +26,7 @@ Implement user targeted cross-platform notifications with OneSignal & Devise in
20
26
 
21
27
  ## Installation
22
28
 
23
- `devise-onesignal` works with Rails 4.0 onwards. You can add it to your `Gemfile` with:
29
+ devise-onesignal works with Rails 5.0 onwards. You can add it to your `Gemfile` with:
24
30
 
25
31
  ```ruby
26
32
  gem 'devise-onesignal'
@@ -42,17 +48,21 @@ gem 'devise-onesignal', github: 'jonhue/devise-onesignal'
42
48
 
43
49
  Now run the generator:
44
50
 
45
- $ rails g devise_one_signal
51
+ $ rails g devise_onesignal
46
52
 
47
53
  To wrap things up, migrate the changes into your database:
48
54
 
49
55
  $ rails db:migrate
50
56
 
51
- **Note:** Use `rake db:migrate` instead if you run Rails < 5.
57
+ 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`).
52
58
 
53
- ## Usage
59
+ Then add ...
54
60
 
55
- First of all [create your OneSignal app](https://onesignal.com) and set your application ID in the created initializer (`config/initializers/devise-onesignal.rb`).
61
+ ```ruby
62
+ has_many :devices
63
+ ```
64
+
65
+ ... to your devise class. For example `User` in `app/models/user.rb`.
56
66
 
57
67
  Now let's include the neccessary javascript files in our application (`apps/assets/javascripts/application.js`):
58
68
 
@@ -61,15 +71,7 @@ Now let's include the neccessary javascript files in our application (`apps/asse
61
71
  //= require devise-onesignal
62
72
  ```
63
73
 
64
- Then include the `OneSignalUser` concern in your `ApplicationController`:
65
-
66
- ```ruby
67
- class ApplicationController < ActionController::Base
68
- include OneSignalUser
69
- end
70
- ```
71
-
72
- As a last step initialize the javascript component when your assets load. If you are using Rails 5 with Turbolinks, this could look like this:
74
+ Finally initialize the javascript component when your assets load. If you are using Rails 5 with Turbolinks, this could look like this:
73
75
 
74
76
  ```js
75
77
  document.addEventListener( 'turbolinks:load', function() {
@@ -77,52 +79,71 @@ document.addEventListener( 'turbolinks:load', function() {
77
79
  });
78
80
  ```
79
81
 
80
- ### Subscribing / unsubscribing users
82
+ ## Usage
81
83
 
82
- This gem makes it fairly easy to subscribe and unsubscribe users from OneSignal. Just call the respective JavaScript function:
84
+ ### Device methods
83
85
 
84
- ```js
85
- OneSignalSubscribe();
86
- OneSignalUnsubscribe();
87
- ```
86
+ 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.
87
+
88
+ ```ruby
89
+ d = Device.first
88
90
 
89
- ### Backend
91
+ # Returns user (or other devise object) that this device belongs to. Can return `nil`.
92
+ d.user
90
93
 
91
- devise-onesignal introduces an `current_onesignal` method available in your controllers and views. It returns a hash:
94
+ # Returns OneSignal player id
95
+ d.onesignal_id
92
96
 
93
- ```ruby
94
- $ current_onesignal
95
- {id: 'e9b66bc5-a1e5-4f3f-8a3e-894f576b193a', permission: 'granted', user: UserObject}
96
- ```
97
+ # Returns OneSignal permission ( `granted`/`denied`/`default` )
98
+ d.onesignal_permission
97
99
 
98
- **Note:** When no user is associated with that ID, the returned hash does not include the key.
100
+ # Some timestamps
101
+ d.last_used
102
+ d.created_at
103
+ d.updated_at
99
104
 
100
- **Note:** If the user has not enabled OneSignal yet, the hash won't return an ID / user but it still returns the permission. In this case `denied` or `default`.
101
105
 
102
- You can access the OneSignal PlayerId and Permission from the User object:
106
+ # If device is ready to receive notifications
107
+ d.onesignal_enabled?
103
108
 
104
- ```ruby
105
- $ User.first.onesignal_id
106
- 'e9b66bc5-a1e5-4f3f-8a3e-894f576b193a'
107
- $ User.first.onesignal_permission
108
- 'granted'
109
+ # If device has been disabled to receive notifications
110
+ d.onesignal_disabled?
111
+
112
+ # If device has been set previously to receive notifications or not
113
+ d.onesignal_set?
109
114
  ```
110
115
 
116
+ ### current_device
117
+
118
+ In your controllers and views you can access a `current_device` method that returns the `Device` object of the current OneSignal subscription. If the user browsing your site is not subscribed to OneSignal, `current_device` returns an uncommitted `Device` object with some helpful information, like the `permission` attribute, set.
119
+
120
+ ### Subscribing
121
+
122
+ Just call `OneSignalSubscribe();` in your frontend code and OneSignal will ask your user for permission to send notifications. On the following request an existing `Device` object will either get updated or a new one will get created.
123
+
124
+ ### Unsubscribing
125
+
126
+ **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.
127
+
128
+ If you want to completely remove a user from OneSignal, call `OneSignalSubscribe();` in your javascript.
129
+
111
130
  ---
112
131
 
113
132
  ## Configuration
114
133
 
134
+ You can configure devise-onesignal by passing a block to `configure`:
135
+
115
136
  ```ruby
116
- DeviseOneSignal::Configuration.app_id = 'OneSignal APP ID'
137
+ DeviseOnesignal.configure do |config|
138
+ config.app_id = ''
139
+ end
117
140
  ```
118
141
 
119
- | Option | Description | Default |
120
- | ---------------------- | -------------------------------------------------------------------------- | -------- |
121
- | `app_id` (required) | OneSignal application ID | `nil` |
122
- | `devise_class` | Devise class | `'User'` |
123
- | `auto_register` | Whether or not the app should automatically try to subscribe the user | `false` |
124
- | `persist_notification` | Automatically dismiss the notification after ~20 seconds in Chrome | `false` |
125
- | `subscribe_with_modal` | Show a modal instead of a native window when subscribing user to OneSignal | `false` |
142
+ **`app_id` (required)** Your OneSignal app id. Create one here: https://onesignal.com
143
+ **`devise_class`** Specify your devise class. Defaults to `'User'`.
144
+ **`auto_register`** Automatically try to subscribe the user when loading a page. Defaults to `false`.
145
+ **`persist_notification`** Automatically dismiss the notification after ~20 seconds in Chrome. Defaults to `false`.
146
+ **`subscribe_with_modal`** Show a modal instead of a native browser window when subscribing a user to OneSignal. Defaults to `false`.
126
147
 
127
148
  ---
128
149
 
data/Rakefile CHANGED
@@ -1,2 +1,2 @@
1
- require 'bundler/gem_tasks'
2
- task default: :spec
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -3,7 +3,7 @@ require File.expand_path(File.join('..', 'lib', 'devise-onesignal', 'version'),
3
3
 
4
4
  Gem::Specification.new do |gem|
5
5
  gem.name = 'devise-onesignal'
6
- gem.version = DeviseOneSignal::VERSION
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
9
  gem.description = 'Implement user targeted cross-platform notifications with OneSignal & Devise in your Rails app.'
@@ -21,6 +21,6 @@ Gem::Specification.new do |gem|
21
21
 
22
22
  gem.add_development_dependency 'bundler', '~> 1.16'
23
23
  gem.add_development_dependency 'rake', '~> 10.0'
24
- gem.add_dependency 'rails', '>= 4.0'
24
+ gem.add_dependency 'rails', '>= 5.0'
25
25
  gem.add_dependency 'devise', '~> 4.3'
26
26
  end
@@ -1,9 +1,24 @@
1
1
  require 'devise-onesignal/version'
2
2
 
3
- module DeviseOneSignal
3
+ module DeviseOnesignal
4
4
 
5
5
  autoload :Configuration, 'devise-onesignal/configuration'
6
6
 
7
+ class << self
8
+ attr_accessor :configuration
9
+ end
10
+
11
+ def self.configure
12
+ self.configuration ||= Configuration.new
13
+ yield configuration
14
+ end
15
+
16
+ autoload :DeviceLib, 'devise-onesignal/device_lib'
17
+
18
+ autoload :DeviceConcern, 'devise-onesignal/device_concern'
19
+ autoload :DeviceHelper, 'devise-onesignal/device_helper'
20
+ require 'devise-onesignal/railtie'
21
+
7
22
  class Engine < ::Rails::Engine
8
23
  end
9
24
 
@@ -1,27 +1,18 @@
1
- module DeviseOneSignal
1
+ module DeviseOnesignal
2
2
  class Configuration
3
3
 
4
- cattr_accessor :app_id, instance_accessor: false
4
+ attr_accessor :app_id
5
+ attr_accessor :devise_class
6
+ attr_accessor :auto_register
7
+ attr_accessor :persist_notification
8
+ attr_accessor :subscribe_with_modal
5
9
 
6
- def self.devise_class
7
- @@devise_class || 'User'
10
+ def initialize
11
+ @devise_class = 'User'
12
+ @auto_register = false
13
+ @persist_notification = false
14
+ @subscribe_with_modal = false
8
15
  end
9
- cattr_writer :devise_class, instance_accessor: false
10
-
11
- def self.auto_register
12
- @@auto_register || false
13
- end
14
- cattr_writer :auto_register, instance_accessor: false
15
-
16
- def self.persist_notification
17
- @@persist_notification || false
18
- end
19
- cattr_writer :persist_notification, instance_accessor: false
20
-
21
- def self.subscribe_with_modal
22
- @@subscribe_with_modal || false
23
- end
24
- cattr_writer :subscribe_with_modal, instance_accessor: false
25
16
 
26
17
  end
27
18
  end
@@ -0,0 +1,26 @@
1
+ module DeviseOnesignal
2
+ module DeviceConcern
3
+
4
+ extend ActiveSupport::Concern
5
+
6
+ extend DeviseOnesignal::DeviceHelper
7
+
8
+ included do
9
+ before_action :set_device
10
+ end
11
+
12
+ private
13
+
14
+ def set_device
15
+ unless cookies[:oneSignalUserId].nil?
16
+ onesignal_user_id = cookies[:oneSignalUserId]
17
+ device = Device.find_or_create_by! onesignal_id: onesignal_user_id
18
+ device.user = current_user if current_user
19
+ device.permission = cookies[:oneSignalUserPermission]
20
+ device.last_used = Time.now
21
+ device.save!
22
+ end
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,17 @@
1
+ module DeviseOnesignal
2
+ module DeviceHelper
3
+
4
+ def current_device
5
+ if cookies[:oneSignalUserId].nil?
6
+ device = Device.new
7
+ device.user = current_user if current_user
8
+ device.permission = cookies[:oneSignalUserPermission]
9
+ device.last_used = Time.now
10
+ else
11
+ device = Device.find_by(onesignal_id: cookies[:oneSignalUserId])
12
+ end
13
+ device
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ module DeviseOnesignal
2
+ module DeviceLib
3
+
4
+ def onesignal_enabled?
5
+ self.permission == 'granted'
6
+ end
7
+ def onesignal_disabled?
8
+ self.permission == 'denied'
9
+ end
10
+ def onesignal_set?
11
+ !self.permission == 'default'
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ require 'rails'
2
+
3
+ module DeviseOnesignal
4
+ class Railtie < Rails::Railtie
5
+
6
+ initializer 'devise-onesignal.initialize' do
7
+ abort 'Set your OneSignal app id in `config/initializers/devise-onesignal.rb`' if DeviseOnesignal.configuration && ( DeviseOnesignal.configuration.app_id.nil? || DeviseOnesignal.configuration.app_id == '' )
8
+ ActiveSupport.on_load :action_controller do
9
+ include DeviseOnesignal::DeviceConcern
10
+ end
11
+ ActiveSupport.on_load :action_view do
12
+ include DeviseOnesignal::DeviceHelper
13
+ end
14
+ end
15
+
16
+ end
17
+ end
@@ -1,5 +1,5 @@
1
- module DeviseOneSignal
1
+ module DeviseOnesignal
2
2
 
3
- VERSION = '1.2.1'
3
+ VERSION = '2.0.0'
4
4
 
5
5
  end
@@ -1,7 +1,7 @@
1
1
  require 'rails/generators'
2
2
  require 'rails/generators/migration'
3
3
 
4
- class DeviseOneSignalGenerator < Rails::Generators::Base
4
+ class DeviseOnesignalGenerator < Rails::Generators::Base
5
5
 
6
6
  include Rails::Generators::Migration
7
7
 
@@ -12,18 +12,21 @@ class DeviseOneSignalGenerator < Rails::Generators::Base
12
12
  if ActiveRecord::Base.timestamped_migrations
13
13
  Time.now.utc.strftime '%Y%m%d%H%M%S'
14
14
  else
15
- "%.3d" % (current_migration_number(dirname) + 1)
15
+ "%.3d" % ( current_migration_number(dirname) + 1 )
16
16
  end
17
17
  end
18
18
 
19
- def create_migration_file
20
- migration_template 'migration.rb.erb', 'db/migrate/devise_one_signal_migration.rb', migration_version: migration_version
21
- end
22
-
23
19
  def create_initializer
24
20
  template 'initializer.rb', 'config/initializers/devise-onesignal.rb'
25
21
  end
26
22
 
23
+ def create_device_migration_file
24
+ migration_template 'devices_migration.rb.erb', 'db/migrate/devise_onesignal_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
+
27
30
  def show_readme
28
31
  readme 'README.md'
29
32
  end
@@ -0,0 +1,7 @@
1
+ class Device < ActiveRecord::Base
2
+
3
+ extend DeviseOnesignal::DeviceLib
4
+
5
+ belongs_to DeviseOnesignal.configuration.devise_class.downcase.to_sym, optional: true
6
+
7
+ end
@@ -0,0 +1,16 @@
1
+ class DeviseOnesignalMigration < ActiveRecord::Migration<%= migration_version %>
2
+ def change
3
+ create_table :devices do |t|
4
+
5
+ t.references DeviseOnesignal.configuration.devise_class.downcase.to_sym, 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
@@ -1 +1,26 @@
1
- DeviseOneSignal::Configuration.app_id = 'OneSignal APP ID'
1
+ DeviseOnesignal.configure do |config|
2
+
3
+ ### ONESIGNAL ###
4
+
5
+ # Your OneSignal app id. Create one here: https://onesignal.com
6
+ config.app_id = ''
7
+
8
+
9
+ ### DEVISE ###
10
+
11
+ # Specify your devise class. Defaults to `'User'`.
12
+ # config.devise_class = 'User'
13
+
14
+
15
+ ### CUSTOMIZATION ###
16
+
17
+ # Automatically try to subscribe the user when loading a page. Defaults to `false`.
18
+ # config.auto_register = false
19
+
20
+ # Automatically dismiss the notification after ~20 seconds in Chrome. Defaults to `false`.
21
+ # config.persist_notification = false
22
+
23
+ # Show a modal instead of a native browser window when subscribing a user to OneSignal. Defaults to `false`.
24
+ # config.subscribe_with_modal = false
25
+
26
+ end
@@ -8,8 +8,8 @@ function OneSignalInit() {
8
8
  // Do NOT call init() twice
9
9
  OneSignal.push([ 'init', {
10
10
  // Your other init options here
11
- appId: '<%= DeviseOneSignal::Configuration.app_id %>',
12
- autoRegister: <%= DeviseOneSignal::Configuration.auto_register ? 'true' : 'false' %>,
11
+ appId: '<%= DeviseOnesignal.configuration.app_id %>',
12
+ autoRegister: <%= DeviseOnesignal.configuration.auto_register ? 'true' : 'false' %>,
13
13
  welcomeNotification: {
14
14
  disable: true,
15
15
  title: '',
@@ -18,7 +18,7 @@ function OneSignalInit() {
18
18
  notifyButton: {
19
19
  enable: false
20
20
  },
21
- persistNotification: <%= DeviseOneSignal::Configuration.persist_notification ? 'true' : 'false' %> // Automatically dismiss the notification after ~20 seconds in Chrome Desktop v47+
21
+ persistNotification: <%= DeviseOnesignal.configuration.persist_notification ? 'true' : 'false' %> // Automatically dismiss the notification after ~20 seconds in Chrome Desktop v47+
22
22
  }]);
23
23
 
24
24
  // Firstly this will check user id
@@ -43,7 +43,7 @@ function OneSignalSubscribe() {
43
43
  OneSignal.setSubscription(true);
44
44
  } else {
45
45
  OneSignal.registerForPushNotifications({
46
- modalPrompt: <%= DeviseOneSignal::Configuration.subscribe_with_modal ? 'true' : 'false' %>
46
+ modalPrompt: <%= DeviseOnesignal.configuration.subscribe_with_modal ? 'true' : 'false' %>
47
47
  });
48
48
  };
49
49
  }
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: 1.2.1
4
+ version: 2.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-18 00:00:00.000000000 Z
11
+ date: 2017-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '4.0'
47
+ version: '5.0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '4.0'
54
+ version: '5.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: devise
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -86,16 +86,20 @@ files:
86
86
  - LICENSE
87
87
  - README.md
88
88
  - Rakefile
89
- - app/controllers/concerns/one_signal_user.rb
90
89
  - devise-onesignal.gemspec
91
90
  - init.rb
92
91
  - lib/devise-onesignal.rb
93
92
  - lib/devise-onesignal/configuration.rb
93
+ - lib/devise-onesignal/device_concern.rb
94
+ - lib/devise-onesignal/device_helper.rb
95
+ - lib/devise-onesignal/device_lib.rb
96
+ - lib/devise-onesignal/railtie.rb
94
97
  - lib/devise-onesignal/version.rb
95
- - lib/generators/devise_one_signal_generator.rb
98
+ - lib/generators/devise_onesignal_generator.rb
96
99
  - lib/generators/templates/README.md
100
+ - lib/generators/templates/device_model.rb
101
+ - lib/generators/templates/devices_migration.rb.erb
97
102
  - lib/generators/templates/initializer.rb
98
- - lib/generators/templates/migration.rb.erb
99
103
  - vendor/assets/javascripts/OneSignalSDK.js
100
104
  - vendor/assets/javascripts/devise-onesignal.js.erb
101
105
  homepage: https://github.com/jonhue/devise-onesignal
@@ -109,7 +113,7 @@ post_install_message: |
109
113
  There are three wo more steps to take:
110
114
 
111
115
  1) Enter your OneSignal App ID in config/initializers/devise-onesignal.rb
112
- 2) Run `rails g devise_one_signal` and `rails db:migrate`
116
+ 2) Run `rails g devise-onesignal` and `rails db:migrate`
113
117
  3) Add:
114
118
 
115
119
  //= require OneSignalSDK
@@ -118,7 +122,7 @@ post_install_message: |
118
122
  to your javascript index in app/assets/javascripts/application.js
119
123
 
120
124
 
121
- Learn more at https://github.com/jonhue/devise-onesignal.
125
+ Learn more at https://github.com/jonhue/devise-onesignal
122
126
  rdoc_options: []
123
127
  require_paths:
124
128
  - lib
@@ -1,34 +0,0 @@
1
- module OneSignalUser
2
-
3
- extend ActiveSupport::Concern
4
-
5
- included do
6
- before_action :set_onesignal_user
7
- helper_method :current_onesignal
8
- end
9
-
10
- def current_onesignal
11
- current_onesignal = {}
12
- current_onesignal[:id] = cookies[:oneSignalUserId]
13
- current_onesignal[:permission] = cookies[:oneSignalUserPermission]
14
- current_onesignal[DeviseOneSignal::Configuration.devise_class.downcase.to_sym] = DeviseOneSignal::Configuration.devise_class.constantize&.find_by(onesignal_id: current_onesignal[:id]) if cookies.has_key?(:oneSignalUserId)
15
- current_onesignal.each do |key, value|
16
- current_onesignal.delete(key) if value == nil
17
- end
18
- current_onesignal
19
- end
20
-
21
- private
22
-
23
- def set_onesignal_user
24
- if current_user
25
- onesignal_user_id = cookies[:oneSignalUserId]
26
- if onesignal_user_id.nil?
27
- current_user.update_attributes onesignal_id: nil, onesignal_permission: nil
28
- else
29
- current_user.update_attributes onesignal_id: onesignal_user_id, onesignal_permission: cookies[:oneSignalUserPermission]
30
- end
31
- end
32
- end
33
-
34
- end
@@ -1,6 +0,0 @@
1
- class DeviseOneSignalMigration < ActiveRecord::Migration<%= migration_version %>
2
- def change
3
- add_column :<%= DeviseOneSignal::Configuration.devise_class.downcase.pluralize %>, :onesignal_id, :string, index: true, unique: true
4
- add_column :<%= DeviseOneSignal::Configuration.devise_class.downcase.pluralize %>, :onesignal_permission, :string
5
- end
6
- end