web-push-notification-rails 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 001c84b8de90c50929b1e7c88be6c946e8416ee7
4
+ data.tar.gz: 65a2c2e57b4c731a9e7161ad3eecdbb121c5d44e
5
+ SHA512:
6
+ metadata.gz: 2d1d148be8d0bde382ef93ed82dcac620d89434a8906c626f9bc2c284ebae2125d9473f8203e6d08eefc172d5e50b95c9b31fe4d9a3939d04dcef1a7b3a92700
7
+ data.tar.gz: 7f70818404b98c9fdae82245a3d9c7dd806d5b5873fc2190bde66ebe0497365e6fcafefec6127bcd9f706799dd5003ff25177c2fabc2b5a227f209a5d5716888
@@ -0,0 +1,27 @@
1
+ module WebNotification
2
+ module Generators
3
+ class NotificationPackageGenerator < Rails::Generators::Base
4
+ source_root File.expand_path('../templates', __FILE__)
5
+ argument :website_name, type: :string, optional: false, banner: ""
6
+ argument :website_service_url, type: :string, optional: false, banner: ""
7
+ argument :website_push_id, type: :string, optional: false, banner: ""
8
+ argument :website_allowed_domain, type: :string, optional: false, banner: ""
9
+ argument :website_url_formatted_string, type: :string, optional: false, banner: ""
10
+ argument :wwdr_certificate_path, type: :string, optional: false, banner: "Absolute path to your WWDR certification file"
11
+ argument :key_path, type: :string, optional: false, banner: "Absolute path to your p12 file"
12
+ argument :cert_password, type: :string, default: '', optional: true, banner: "Password for your P12 certificate"
13
+
14
+ desc 'Creating controller, routes and package generator files'
15
+ def create_initializer_file
16
+ template 'web_notification_package_initializer.rb', File.join('config', 'initializers', "web_notification_package_initializer.rb")
17
+ template 'apple_web_notifications_controller.rb', File.join('app', 'controllers', "apple_web_notifications_controller.rb")
18
+ route "delete '/v1/devices/:device_token/registrations/:web_push_id', :controller => :apple_web_notifications, :action => :add_device, :constraints => { :web_push_id => /[^\/]+/ }"
19
+ route "post '/v1/devices/:device_token/registrations/:web_push_id', :controller => :apple_web_notifications, :action => :delete_device, :constraints => { :web_push_id => /[^\/]+/ }"
20
+ route "post '/v1/pushPackages/:web_push_id', :controller => :apple_web_notifications, :action => :package, :constraints => { :web_push_id => /[^\/]+/ }"
21
+ route "post '/v1/log', :controller => :apple_web_notifications, :action => :log"
22
+ template 'website.json', File.join('notification', 'web_package', "website.json")
23
+ directory 'icon.iconset', File.join('notification', 'web_package', 'icon.iconset')
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ class AppleWebNotificationsController < ApplicationController
2
+
3
+ def add_device
4
+ puts params
5
+ # add your code to add device
6
+ render json: {}
7
+ end
8
+
9
+ def delete_device
10
+ puts params
11
+ # add your code to add device
12
+ render json: {}
13
+ end
14
+
15
+ def package
16
+ packaged_data = WebNotification::NotificationPackage.instance.generate_with_auth_token(SecureRandom.base64)
17
+ response.headers["last-modified"] = Time.zone.now.strftime("%Y-%m-%d %H:%M:%S")
18
+ send_data(packaged_data.sysread, :type => 'application/zip', :disposition => 'inline', :filename => "package.zip") and return
19
+ end
20
+
21
+ def log
22
+ puts params
23
+ # errors are sent here
24
+ render json: {}
25
+ end
26
+
27
+ end
@@ -0,0 +1,6 @@
1
+ require 'openssl'
2
+
3
+ WebNotification::NotificationPackage.instance.configure do |package|
4
+ package.wwdr_intermediate_certificate = OpenSSL::X509::Certificate.new(File.read("<%= wwdr_certificate_path %>"))
5
+ package.p12 = OpenSSL::PKCS12::new(File.read("<%= key_path %>"), "<%= cert_password %>")
6
+ end
@@ -0,0 +1,8 @@
1
+ {
2
+ "websiteName": "<%= website_name %>",
3
+ "websitePushID": "<%= website_push_id %>",
4
+ "allowedDomains": ["<%= website_allowed_domain %>"],
5
+ "urlFormatString": "<%= website_url_formatted_string %>",
6
+ "authenticationToken": "",
7
+ "webServiceURL": "<%= website_service_url %>"
8
+ }
@@ -0,0 +1 @@
1
+ require "web_notification/notification_package"
@@ -0,0 +1,55 @@
1
+ require 'digest/sha1'
2
+ require 'json'
3
+ require 'openssl'
4
+ require 'zip/zip'
5
+ require 'zip/zipfilesystem'
6
+
7
+ module WebNotification
8
+
9
+ class NotificationPackage
10
+ include Singleton
11
+
12
+ attr_accessor :files, :json, :wwdr_intermediate_certificate_path, :cert_path, :wwdr_intermediate_certificate, :p12
13
+
14
+ def configure
15
+ yield self
16
+ end
17
+
18
+ def generate_with_auth_token(authentication_token)
19
+ files = {}
20
+ path = "notification/web_package"
21
+ Dir.glob(path+"/**/**").each do |file_path|
22
+ next if File.directory? file_path
23
+ filename = Pathname.new(file_path).relative_path_from(Pathname.new(path))
24
+ file = File.open(file_path, "rb")
25
+ files[filename.to_s] = File.read(file)
26
+ end
27
+
28
+ json = JSON.parse(files['website.json'])
29
+ json['authenticationToken'] = authentication_token
30
+ files['website.json'] = JSON.pretty_generate(json)
31
+
32
+ manifest = {}
33
+ files.each do |filename, content|
34
+ manifest[filename] = Digest::SHA1.hexdigest(content)
35
+ end
36
+ files['manifest.json'] = JSON.pretty_generate(manifest)
37
+
38
+
39
+ flag = OpenSSL::PKCS7::BINARY|OpenSSL::PKCS7::DETACHED
40
+ signed = OpenSSL::PKCS7::sign(p12.certificate, p12.key, files['manifest.json'], [wwdr_intermediate_certificate], flag)
41
+ files['signature'] = signed.to_der.force_encoding('UTF-8')
42
+
43
+
44
+ stringio = Zip::ZipOutputStream::write_buffer do |z|
45
+ files.each do |filename, content|
46
+ z.put_next_entry filename
47
+ z.print content
48
+ end
49
+ end
50
+ stringio.set_encoding "binary"
51
+ stringio.rewind
52
+ stringio
53
+ end
54
+ end
55
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: web-push-notification-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ankur Patel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 3.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 3.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubyzip
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - <
46
+ - !ruby/object:Gem::Version
47
+ version: 1.0.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - <
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>'
74
+ - !ruby/object:Gem::Version
75
+ version: '2.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>'
81
+ - !ruby/object:Gem::Version
82
+ version: '2.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Apple Web Push Notifications Package Generator
98
+ email: ankur.patel@ymail.com
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - lib/rails/generators/web_notification/notification_package/notification_package_generator.rb
104
+ - lib/rails/generators/web_notification/notification_package/templates/apple_web_notifications_controller.rb
105
+ - lib/rails/generators/web_notification/notification_package/templates/icon.iconset/icon_128x128.png
106
+ - lib/rails/generators/web_notification/notification_package/templates/icon.iconset/icon_128x128@2x.png
107
+ - lib/rails/generators/web_notification/notification_package/templates/icon.iconset/icon_16x16.png
108
+ - lib/rails/generators/web_notification/notification_package/templates/icon.iconset/icon_16x16@2x.png
109
+ - lib/rails/generators/web_notification/notification_package/templates/icon.iconset/icon_32x32.png
110
+ - lib/rails/generators/web_notification/notification_package/templates/icon.iconset/icon_32x32@2x.png
111
+ - lib/rails/generators/web_notification/notification_package/templates/web_notification_package_initializer.rb
112
+ - lib/rails/generators/web_notification/notification_package/templates/website.json
113
+ - lib/web-push-notification-rails.rb
114
+ - lib/web_notification/notification_package.rb
115
+ homepage: https://github.com/ankurp/apple-web-push-notification-rails
116
+ licenses:
117
+ - MIT
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - '>='
126
+ - !ruby/object:Gem::Version
127
+ version: 2.0.0
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project: web-push-notification-rails
135
+ rubygems_version: 2.0.6
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: Apple Web Push Notifications Package Generator
139
+ test_files: []