devise-onesignal 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0cae9341b2ac47712e879c7b7c03d7f0977ff691736b57b71616f6c05eb570b2
4
+ data.tar.gz: e94704597db1bde57076d4c27b5b3536b043f8381d359a36f0eeaffd1cf28097
5
+ SHA512:
6
+ metadata.gz: 53e9877f03d83a08dea653fccf068e59bdc86833bfbd190d8f078a156cd3d7ec2b8b09f62316af604ae7f1263a2b3f360d465de2e77cac14e6969cb6ee3742b7
7
+ data.tar.gz: 41d36b70e24805a1bf2b892b65ad0aaac2d29b2c6db45d66e379b6190959a66725c9c57e30d3d7b3fd1383b234a3093cc140f371086d80cadd9b606297a1883a
@@ -0,0 +1,14 @@
1
+ ### Expected behavior
2
+ Tell us what should happen
3
+
4
+ ### Actual behavior
5
+ Tell us what happens instead
6
+
7
+ ### Steps to reproduce
8
+ Show a way to reproduce
9
+
10
+ ### System configuration
11
+
12
+ **Ruby version**:
13
+
14
+ **Rails version**:
@@ -0,0 +1,21 @@
1
+ ### Summary
2
+
3
+ Provide a general description of the code changes in your pull
4
+ request... were there any bugs you had fixed? If so, mention them. If
5
+ these bugs have open GitHub issues, be sure to tag them here as well,
6
+ to keep the conversation linked together.
7
+
8
+ ### Other Information
9
+
10
+ If there's anything else that's important and relevant to your pull
11
+ request, mention that information here. This could include
12
+ benchmarks, or other information.
13
+
14
+ If you are updating any of the CHANGELOG files or are asked to update the
15
+ CHANGELOG files by reviewers, please add the CHANGELOG entry at the top of the file.
16
+
17
+ Finally, if your pull request affects documentation or any non-code
18
+ changes, guidelines for those changes are [available
19
+ here](https://github.com/jonhue/devise-onesignal/blob/master/CONTRIBUTING.md)
20
+
21
+ Thanks for contributing to `devise-onesignal`!
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ test/debug.log
2
+ coverage
3
+ rdoc
4
+ memory
5
+ *.gem
6
+ .rvmrc
7
+ Gemfile.lock
8
+ log
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.3
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # Changelog
2
+
3
+ ### master
4
+
5
+ * nothing yet
6
+
7
+ ### 1.0.0 - 2017-12-18
8
+
9
+ * initial release
@@ -0,0 +1,46 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ ## Our Standards
8
+
9
+ Examples of behavior that contributes to creating a positive environment include:
10
+
11
+ * Using welcoming and inclusive language
12
+ * Being respectful of differing viewpoints and experiences
13
+ * Gracefully accepting constructive criticism
14
+ * Focusing on what is best for the community
15
+ * Showing empathy towards other community members
16
+
17
+ Examples of unacceptable behavior by participants include:
18
+
19
+ * The use of sexualized language or imagery and unwelcome sexual attention or advances
20
+ * Trolling, insulting/derogatory comments, and personal or political attacks
21
+ * Public or private harassment
22
+ * Publishing others' private information, such as a physical or electronic address, without explicit permission
23
+ * Other conduct which could reasonably be considered inappropriate in a professional setting
24
+
25
+ ## Our Responsibilities
26
+
27
+ Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28
+
29
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30
+
31
+ ## Scope
32
+
33
+ This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34
+
35
+ ## Enforcement
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at help@slooob.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38
+
39
+ Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40
+
41
+ ## Attribution
42
+
43
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44
+
45
+ [homepage]: http://contributor-covenant.org
46
+ [version]: http://contributor-covenant.org/version/1/4/
data/CONTRIBUTING.md ADDED
@@ -0,0 +1 @@
1
+ # Contributing
data/DEPRECATIONS.md ADDED
@@ -0,0 +1,3 @@
1
+ # Deprecations
2
+
3
+ No deprecations
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'http://rubygems.org'
2
+
3
+ git_source :github do |repo_name|
4
+ "https://github.com/#{repo_name}"
5
+ end
6
+
7
+ gemspec
data/INSTALL.md ADDED
@@ -0,0 +1,16 @@
1
+ **Thank you for installing devise-onesignal!**
2
+
3
+
4
+ There are three wo more steps to take:
5
+
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`
8
+ 3) Add:
9
+
10
+ //= require OneSignalSDK
11
+ //= require devise-onesignal
12
+
13
+ to your javascript index in app/assets/javascripts/application.js
14
+
15
+
16
+ Learn more at https://github.com/jonhue/devise-onesignal.
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,168 @@
1
+ # devise-onesignal
2
+
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
+
5
+ Implement user targeted cross-platform notifications with OneSignal & Devise in your Rails app.
6
+
7
+ ---
8
+
9
+ ## Table of Contents
10
+
11
+ * [Installation](#installation)
12
+ * [Usage](#usage)
13
+ * [To Do](#to-do)
14
+ * [Contributing](#contributing)
15
+ * [Contributors](#contributors)
16
+ * [License](#license)
17
+
18
+ ---
19
+
20
+ ## Installation
21
+
22
+ `devise-onesignal` works with Rails 4.0 onwards. You can add it to your `Gemfile` with:
23
+
24
+ ```ruby
25
+ gem 'devise-onesignal'
26
+ ```
27
+
28
+ And then execute:
29
+
30
+ $ bundle
31
+
32
+ Or install it yourself as:
33
+
34
+ $ gem install devise-onesignal
35
+
36
+ If you always want to be up to date fetch the latest from GitHub in your `Gemfile`:
37
+
38
+ ```ruby
39
+ gem 'devise-onesignal', github: 'jonhue/devise-onesignal'
40
+ ```
41
+
42
+ Now run the generator:
43
+
44
+ $ rails g devise_one_signal
45
+
46
+ To wrap things up, migrate the changes into your database:
47
+
48
+ $ rails db:migrate
49
+
50
+ **Note:** Use `rake db:migrate` instead if you run Rails < 5.
51
+
52
+ ## Usage
53
+
54
+ First of all [create your OneSignal app](https://onesignal.com) and set your application ID in the created initializer (`config/initializers/devise-onesignal.rb`).
55
+
56
+ Now let's include the neccessary javascript files in our application (`apps/assets/javascripts/application.js`):
57
+
58
+ ```js
59
+ //= require OneSignalSDK
60
+ //= require devise-onesignal
61
+ ```
62
+
63
+ Then include the `OneSignalUser` concern in your `ApplicationController`:
64
+
65
+ ```ruby
66
+ class ApplicationController < ActionController::Base
67
+ include OneSignalUser
68
+ end
69
+ ```
70
+
71
+ 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:
72
+
73
+ ```js
74
+ document.addEventListener( 'turbolinks:load', function() {
75
+ OneSignalInit();
76
+ });
77
+ ```
78
+
79
+ ### Subscribing / unsubscribing users
80
+
81
+ This gem makes it fairly easy to subscribe and unsubscribe users from OneSignal. Just call the respective JavaScript function:
82
+
83
+ ```js
84
+ OneSignalSubscribe();
85
+ OneSignalUnsubscribe();
86
+ ```
87
+
88
+ ### Backend
89
+
90
+ devise-onesignal introduces an `current_onesignal` method available in your controllers and views. It returns a hash:
91
+
92
+ ```ruby
93
+ $ current_onesignal
94
+ {id: 'e9b66bc5-a1e5-4f3f-8a3e-894f576b193a', permission: 'allow', user: UserObject}
95
+ ```
96
+
97
+ **Note:** When no user is associated with that ID, the returned hash does not include the key.
98
+
99
+ **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`.
100
+
101
+ You can access the OneSignal PlayerId and Permission from the User object:
102
+
103
+ ```ruby
104
+ $ User.first.onesignal_id
105
+ 'e9b66bc5-a1e5-4f3f-8a3e-894f576b193a'
106
+ $ User.first.onesignal_permission
107
+ 'allow'
108
+ ```
109
+
110
+ ---
111
+
112
+ ## Configuration
113
+
114
+ ```ruby
115
+ DeviseOneSignal::Configuration.app_id = 'OneSignal APP ID'
116
+ ```
117
+
118
+ | Option | Description | Default |
119
+ | ------------------- | --------------------------------------------------------------------- | ------- |
120
+ | `app_id` (required) | OneSignal application ID | `nil` |
121
+ | `devise_class` | Devise class | `'User'` |
122
+ | `auto_register` | Whether or not the app should automatically try to subscribe the user | `false` |
123
+
124
+ ---
125
+
126
+ ## To Do
127
+
128
+ [Here](https://github.com/jonhue/devise-onesignal/projects/1) is the full list of current projects.
129
+
130
+ To propose your ideas, initiate the discussion by adding a [new issue](https://github.com/jonhue/devise-onesignal/issues/new).
131
+
132
+ ---
133
+
134
+ ## Contributing
135
+
136
+ We hope that you will consider contributing to `devise-onesignal`. Please read this short overview for some information about how to get started:
137
+
138
+ [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)
139
+
140
+ ### Contributors
141
+
142
+ Give the people some :heart: who are working on this project. See them all at:
143
+
144
+ https://github.com/jonhue/devise-onesignal/graphs/contributors
145
+
146
+ ## License
147
+
148
+ MIT License
149
+
150
+ Copyright (c) 2017 Jonas Hübotter
151
+
152
+ Permission is hereby granted, free of charge, to any person obtaining a copy
153
+ of this software and associated documentation files (the "Software"), to deal
154
+ in the Software without restriction, including without limitation the rights
155
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
156
+ copies of the Software, and to permit persons to whom the Software is
157
+ furnished to do so, subject to the following conditions:
158
+
159
+ The above copyright notice and this permission notice shall be included in all
160
+ copies or substantial portions of the Software.
161
+
162
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
163
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
164
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
165
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
166
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
167
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
168
+ SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler/gem_tasks'
2
+ task default: :spec
@@ -0,0 +1,30 @@
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[:id] = cookies[:oneSignalUserId]
12
+ current_onesignal[:permission] = cookies[:oneSignalUserPermission]
13
+ current_onesignal[OneSignalUser::Configuration.devise_class.downcase.to_sym] = OneSignalUser::Configuration.devise_class.constantize&.find_by(onesignal_id: current_onesignal[:id]) if cookies.has_key?(:oneSignalUserId)
14
+ current_onesignal
15
+ end
16
+
17
+ private
18
+
19
+ def set_onesignal_user
20
+ if current_user
21
+ onesignal_user_id = cookies[:oneSignalUserId]
22
+ if onesignal_user_id.nil?
23
+ current_user.update_attributes onesignal_id: nil, onesignal_permission: nil
24
+ else
25
+ current_user.update_attributes onesignal_id: onesignal_user_id, onesignal_permission: cookies[:oneSignalUserPermission]
26
+ end
27
+ end
28
+ end
29
+
30
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path(File.join('..', 'lib', 'devise-onesignal', 'version'), __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = 'devise-onesignal'
6
+ gem.version = DeviseOneSignal::VERSION
7
+ gem.platform = Gem::Platform::RUBY
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.'
10
+ gem.authors = 'Jonas Hübotter'
11
+ gem.email = 'jonas.huebotter@gmail.com'
12
+ gem.homepage = 'https://github.com/jonhue/devise-onesignal'
13
+ gem.license = 'MIT'
14
+
15
+ gem.files = `git ls-files`.split("\n")
16
+ gem.require_paths = ['lib']
17
+
18
+ gem.post_install_message = IO.read('INSTALL.md')
19
+
20
+ gem.required_ruby_version = '>= 2.3'
21
+
22
+ gem.add_development_dependency 'bundler', '~> 1.16'
23
+ gem.add_development_dependency 'rake', '~> 10.0'
24
+ gem.add_dependency 'rails', '>= 4.0'
25
+ gem.add_dependency 'devise', '~> 4.3'
26
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'devise-onesignal'
@@ -0,0 +1,10 @@
1
+ require 'devise-onesignal/version'
2
+
3
+ module DeviseOneSignal
4
+
5
+ autoload :Configuration, 'devise-onesignal/configuration'
6
+
7
+ class Engine < ::Rails::Engine
8
+ end
9
+
10
+ end
@@ -0,0 +1,17 @@
1
+ module DeviseOneSignal
2
+ class Configuration
3
+
4
+ cattr_accessor :app_id, instance_accessor: false
5
+
6
+ def self.auto_register
7
+ @@auto_register || false
8
+ end
9
+ cattr_writer :auto_register, instance_accessor: false
10
+
11
+ def self.devise_class
12
+ @@devise_class || 'User'
13
+ end
14
+ cattr_writer :devise_class, instance_accessor: false
15
+
16
+ end
17
+ end