web-push-notification-rails 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 001c84b8de90c50929b1e7c88be6c946e8416ee7
4
- data.tar.gz: 65a2c2e57b4c731a9e7161ad3eecdbb121c5d44e
3
+ metadata.gz: 3674d99bcbce732c62bdc23eac4194b171e1186f
4
+ data.tar.gz: 0a2b6f64e67bde66a756ecfdd7c4276b8d847ca9
5
5
  SHA512:
6
- metadata.gz: 2d1d148be8d0bde382ef93ed82dcac620d89434a8906c626f9bc2c284ebae2125d9473f8203e6d08eefc172d5e50b95c9b31fe4d9a3939d04dcef1a7b3a92700
7
- data.tar.gz: 7f70818404b98c9fdae82245a3d9c7dd806d5b5873fc2190bde66ebe0497365e6fcafefec6127bcd9f706799dd5003ff25177c2fabc2b5a227f209a5d5716888
6
+ metadata.gz: c5ce1ed0e453119c1eb6d6db987db4c69ec4c0202db698c1222bdb1469f630eba911370917c5e30ca215e8b28f4e7e4c2d87912ab3ad1016dda80f8fa42d6dce
7
+ data.tar.gz: 6968ff49922e1f8265237d32bf393bff95a7c98a23d800317f784d831a3d4421d1e597f0c5d1317a4451f39f3cd61a0a10c23da4b079da5dc718319df7fa93f2
@@ -15,10 +15,12 @@ module WebNotification
15
15
  def create_initializer_file
16
16
  template 'web_notification_package_initializer.rb', File.join('config', 'initializers', "web_notification_package_initializer.rb")
17
17
  template 'apple_web_notifications_controller.rb', File.join('app', 'controllers', "apple_web_notifications_controller.rb")
18
+ template 'index.html.erb', File.join('app', 'views', 'apple_web_notifications', 'index.html.erb')
18
19
  route "delete '/v1/devices/:device_token/registrations/:web_push_id', :controller => :apple_web_notifications, :action => :add_device, :constraints => { :web_push_id => /[^\/]+/ }"
19
20
  route "post '/v1/devices/:device_token/registrations/:web_push_id', :controller => :apple_web_notifications, :action => :delete_device, :constraints => { :web_push_id => /[^\/]+/ }"
20
21
  route "post '/v1/pushPackages/:web_push_id', :controller => :apple_web_notifications, :action => :package, :constraints => { :web_push_id => /[^\/]+/ }"
21
22
  route "post '/v1/log', :controller => :apple_web_notifications, :action => :log"
23
+ route "get '/apple_web_notifications', :controller => :apple_web_notifications, :action => :index"
22
24
  template 'website.json', File.join('notification', 'web_package', "website.json")
23
25
  directory 'icon.iconset', File.join('notification', 'web_package', 'icon.iconset')
24
26
  end
@@ -1,4 +1,7 @@
1
1
  class AppleWebNotificationsController < ApplicationController
2
+
3
+ def index
4
+ end
2
5
 
3
6
  def add_device
4
7
  puts params
@@ -0,0 +1,35 @@
1
+ <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
2
+ <script type="text/javascript">
3
+ var token = "";
4
+ var id = "1"; // Replace this with a user id or unique id of the client
5
+ window.onload = function() {
6
+ if(window.navigator.userAgent.indexOf('7.0 Safari') > -1) {
7
+ checkPerms();
8
+ } else {
9
+ alert("Browser not supported for web push notification subscription");
10
+ }
11
+ };
12
+
13
+ function checkPerms() {
14
+ var result = window.safari.pushNotification.permission("<%= website_push_id %>");
15
+ if(result.permission === 'default') {
16
+ alert("Requesting Permission");
17
+ requestPermissions();
18
+ } else if(result.permission === 'granted') {
19
+ token = result.deviceToken;
20
+ } else if(result.permission === 'denied') {
21
+ alert("Permission Denied");
22
+ }
23
+ }
24
+
25
+ function requestPermissions() {
26
+ window.safari.pushNotification.requestPermission("<%= website_service_url %>", "<%= website_push_id %>", {"id": id}, function(c) {
27
+ if(c.permission === 'granted') {
28
+ token = result.deviceToken;
29
+ alert("Token received for your device and sent to your server: " + token);
30
+ } else if(c.permission === 'denied') {
31
+ alert("Permission denied by Apple. Please check the log of your server for error.");
32
+ }
33
+ });
34
+ }
35
+ </script>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: web-push-notification-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ankur Patel
@@ -108,6 +108,7 @@ files:
108
108
  - lib/rails/generators/web_notification/notification_package/templates/icon.iconset/icon_16x16@2x.png
109
109
  - lib/rails/generators/web_notification/notification_package/templates/icon.iconset/icon_32x32.png
110
110
  - lib/rails/generators/web_notification/notification_package/templates/icon.iconset/icon_32x32@2x.png
111
+ - lib/rails/generators/web_notification/notification_package/templates/index.html.erb
111
112
  - lib/rails/generators/web_notification/notification_package/templates/web_notification_package_initializer.rb
112
113
  - lib/rails/generators/web_notification/notification_package/templates/website.json
113
114
  - lib/web-push-notification-rails.rb