notifiable-apns-apnotic 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: acc12b3f7e547951316e02ea8a420faf27b1b16ad8baf1a247026afcd5dad1b7
4
+ data.tar.gz: 4f9653212763041adc81a27691047cebcf2fccd882a31ed44db26defc3ee4652
5
+ SHA512:
6
+ metadata.gz: e75084ad01217ae5eefb3a3fa01968efc707a0476c9206b26aec400ccbc4f2a40c6164722f41dd2b6af92c39ded80063e974ad3cad0bc6467ce5aaff7cc60643
7
+ data.tar.gz: 74e9c0f58d5c2bcd4d3b875aec913f5ef55c661d3b485b38402b5bb5fd12127334885d661e8d3fa19e2e708acf3d1d8fa236d3fd4ce50765d8a1e18ad1d43bf8
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in notifiable-apns-apnotic.gemspec
6
+ gemspec
7
+
8
+ gem 'notifiable-rails', path: '../notifiable-rails'
9
+ gem 'sqlite3'
data/Gemfile.lock ADDED
@@ -0,0 +1,169 @@
1
+ PATH
2
+ remote: ../notifiable-rails
3
+ specs:
4
+ notifiable-rails (0.29.0)
5
+ activerecord-postgis-adapter
6
+ pg
7
+ rails
8
+
9
+ PATH
10
+ remote: .
11
+ specs:
12
+ notifiable-apns-apnotic (0.1.0)
13
+ apnotic (~> 1.4.1)
14
+ notifiable-rails (>= 0.29.0)
15
+
16
+ GEM
17
+ remote: https://rubygems.org/
18
+ specs:
19
+ actioncable (5.2.1)
20
+ actionpack (= 5.2.1)
21
+ nio4r (~> 2.0)
22
+ websocket-driver (>= 0.6.1)
23
+ actionmailer (5.2.1)
24
+ actionpack (= 5.2.1)
25
+ actionview (= 5.2.1)
26
+ activejob (= 5.2.1)
27
+ mail (~> 2.5, >= 2.5.4)
28
+ rails-dom-testing (~> 2.0)
29
+ actionpack (5.2.1)
30
+ actionview (= 5.2.1)
31
+ activesupport (= 5.2.1)
32
+ rack (~> 2.0)
33
+ rack-test (>= 0.6.3)
34
+ rails-dom-testing (~> 2.0)
35
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
36
+ actionview (5.2.1)
37
+ activesupport (= 5.2.1)
38
+ builder (~> 3.1)
39
+ erubi (~> 1.4)
40
+ rails-dom-testing (~> 2.0)
41
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
42
+ activejob (5.2.1)
43
+ activesupport (= 5.2.1)
44
+ globalid (>= 0.3.6)
45
+ activemodel (5.2.1)
46
+ activesupport (= 5.2.1)
47
+ activerecord (5.2.1)
48
+ activemodel (= 5.2.1)
49
+ activesupport (= 5.2.1)
50
+ arel (>= 9.0)
51
+ activerecord-postgis-adapter (5.2.1)
52
+ activerecord (~> 5.1)
53
+ rgeo-activerecord (~> 6.0)
54
+ activestorage (5.2.1)
55
+ actionpack (= 5.2.1)
56
+ activerecord (= 5.2.1)
57
+ marcel (~> 0.3.1)
58
+ activesupport (5.2.1)
59
+ concurrent-ruby (~> 1.0, >= 1.0.2)
60
+ i18n (>= 0.7, < 2)
61
+ minitest (~> 5.1)
62
+ tzinfo (~> 1.1)
63
+ apnotic (1.4.1)
64
+ connection_pool (~> 2.0)
65
+ net-http2 (>= 0.18, < 2)
66
+ arel (9.0.0)
67
+ builder (3.2.3)
68
+ concurrent-ruby (1.0.5)
69
+ connection_pool (2.2.2)
70
+ crass (1.0.4)
71
+ diff-lcs (1.3)
72
+ erubi (1.7.1)
73
+ globalid (0.4.1)
74
+ activesupport (>= 4.2.0)
75
+ http-2 (0.9.0)
76
+ i18n (1.1.0)
77
+ concurrent-ruby (~> 1.0)
78
+ loofah (2.2.2)
79
+ crass (~> 1.0.2)
80
+ nokogiri (>= 1.5.9)
81
+ mail (2.7.0)
82
+ mini_mime (>= 0.1.1)
83
+ marcel (0.3.2)
84
+ mimemagic (~> 0.3.2)
85
+ method_source (0.9.0)
86
+ mimemagic (0.3.2)
87
+ mini_mime (1.0.1)
88
+ mini_portile2 (2.3.0)
89
+ minitest (5.11.3)
90
+ net-http2 (0.18.0)
91
+ http-2 (= 0.9.0)
92
+ nio4r (2.3.1)
93
+ nokogiri (1.8.4)
94
+ mini_portile2 (~> 2.3.0)
95
+ pg (1.0.0)
96
+ rack (2.0.5)
97
+ rack-test (1.1.0)
98
+ rack (>= 1.0, < 3)
99
+ rails (5.2.1)
100
+ actioncable (= 5.2.1)
101
+ actionmailer (= 5.2.1)
102
+ actionpack (= 5.2.1)
103
+ actionview (= 5.2.1)
104
+ activejob (= 5.2.1)
105
+ activemodel (= 5.2.1)
106
+ activerecord (= 5.2.1)
107
+ activestorage (= 5.2.1)
108
+ activesupport (= 5.2.1)
109
+ bundler (>= 1.3.0)
110
+ railties (= 5.2.1)
111
+ sprockets-rails (>= 2.0.0)
112
+ rails-dom-testing (2.0.3)
113
+ activesupport (>= 4.2.0)
114
+ nokogiri (>= 1.6)
115
+ rails-html-sanitizer (1.0.4)
116
+ loofah (~> 2.2, >= 2.2.2)
117
+ railties (5.2.1)
118
+ actionpack (= 5.2.1)
119
+ activesupport (= 5.2.1)
120
+ method_source
121
+ rake (>= 0.8.7)
122
+ thor (>= 0.19.0, < 2.0)
123
+ rake (10.5.0)
124
+ rgeo (1.1.1)
125
+ rgeo-activerecord (6.0.0)
126
+ activerecord (~> 5.0)
127
+ rgeo (~> 1.0)
128
+ rspec (3.8.0)
129
+ rspec-core (~> 3.8.0)
130
+ rspec-expectations (~> 3.8.0)
131
+ rspec-mocks (~> 3.8.0)
132
+ rspec-core (3.8.0)
133
+ rspec-support (~> 3.8.0)
134
+ rspec-expectations (3.8.1)
135
+ diff-lcs (>= 1.2.0, < 2.0)
136
+ rspec-support (~> 3.8.0)
137
+ rspec-mocks (3.8.0)
138
+ diff-lcs (>= 1.2.0, < 2.0)
139
+ rspec-support (~> 3.8.0)
140
+ rspec-support (3.8.0)
141
+ sprockets (3.7.2)
142
+ concurrent-ruby (~> 1.0)
143
+ rack (> 1, < 3)
144
+ sprockets-rails (3.2.1)
145
+ actionpack (>= 4.0)
146
+ activesupport (>= 4.0)
147
+ sprockets (>= 3.0.0)
148
+ sqlite3 (1.3.13)
149
+ thor (0.20.0)
150
+ thread_safe (0.3.6)
151
+ tzinfo (1.2.5)
152
+ thread_safe (~> 0.1)
153
+ websocket-driver (0.7.0)
154
+ websocket-extensions (>= 0.1.0)
155
+ websocket-extensions (0.1.3)
156
+
157
+ PLATFORMS
158
+ ruby
159
+
160
+ DEPENDENCIES
161
+ bundler (~> 1.16)
162
+ notifiable-apns-apnotic!
163
+ notifiable-rails!
164
+ rake (~> 10.0)
165
+ rspec (~> 3.0)
166
+ sqlite3
167
+
168
+ BUNDLED WITH
169
+ 1.16.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Matt Brooke-Smith
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Notifiable::Apns::Apnotic
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/notifiable/apns/apnotic`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'notifiable-apns-apnotic'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install notifiable-apns-apnotic
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/notifiable-apns-apnotic.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require 'notifiable'
5
+ require "notifiable/apns/apnotic"
6
+ require 'sqlite3'
7
+
8
+ # setup dummy db connection
9
+ require 'active_record'
10
+ ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => 'db/development.sqlite3')
11
+
12
+ ActiveRecord::Migration.verbose = false
13
+ notifiable_rails_path = Gem.loaded_specs['notifiable-rails'].full_gem_path
14
+ ActiveRecord::MigrationContext.new(File.join(notifiable_rails_path, 'db', 'migrate')).migrate
15
+
16
+ @app = Notifiable::App.create name: 'Test'
17
+ @notification = Notifiable::Notification.new title: 'test', message: 'test', app: @app
18
+ @device = Notifiable::DeviceToken.new token: '8505d004f11feb81afb3fa6dec353be988119d47b157b662313acb70c4b97926', app: @app
19
+ @sender = Notifiable::Apns::Apnotic::Async.new({}, @notification)
20
+ @sender.certificate = '/Users/mattbrooke-smith/Development/notifiable-apns-apnotic/tmp/key.pem'
21
+ @sender.bundle_id = 'com.futureworkshops.notifiable.Sample'
22
+
23
+ require "irb"
24
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
Binary file
@@ -0,0 +1,78 @@
1
+ require 'notifiable'
2
+ require 'apnotic'
3
+
4
+ module Notifiable
5
+ module Apns
6
+ module Apnotic
7
+ class Async < Notifiable::NotifierBase
8
+
9
+ notifier_attribute :certificate, :bundle_id, :passphrase, :sandbox
10
+
11
+ attr_reader :certificate, :passphrase, :bundle_id
12
+
13
+ def sandbox?
14
+ @sandbox == "1"
15
+ end
16
+
17
+ protected
18
+ def enqueue(device, notification)
19
+ raise "certificate missing" if certificate.nil?
20
+ raise "bundle_id missing" if bundle_id.nil?
21
+
22
+ connection = ::Apnotic::Connection.new(cert_path: certificate, cert_pass: passphrase, url: url)
23
+
24
+ apnotic_notification = build_notification(device, notification)
25
+
26
+ push = connection.prepare_push(apnotic_notification)
27
+ push.on(:response) do |response|
28
+ if response.ok?
29
+ processed(device, 0)
30
+ elsif response.status == '410' || (response.status == '400' && response.body['reason'] == 'BadDeviceToken')
31
+ device.destroy
32
+ processed(device, response.status)
33
+ else
34
+ processed(device, response.status)
35
+ end
36
+ end
37
+
38
+ connection.push_async(push)
39
+
40
+ # wait for all requests to be completed
41
+ connection.join
42
+
43
+ # close the connection
44
+ connection.close
45
+ end
46
+
47
+
48
+ private
49
+ def url
50
+ self.sandbox? ? ::Apnotic::APPLE_DEVELOPMENT_SERVER_URL : ::Apnotic::APPLE_PRODUCTION_SERVER_URL
51
+ end
52
+
53
+ attr_accessor :alert, :badge, :sound, :content_available, :category, :custom_payload, :url_args, :mutable_content, :thread_id
54
+
55
+
56
+ def build_notification(device, notification)
57
+ payload = ::Apnotic::Notification.new(device.token)
58
+ payload.alert = {}
59
+ payload.alert[:title] = notification.title if notification.title
60
+ payload.alert[:body] = notification.message if notification.message
61
+ payload.sound = notification.sound || 'default'
62
+ payload.category = notification.category if notification.category
63
+ payload.content_available = notification.content_available if notification.content_available
64
+ payload.badge = notification.badge_count if notification.badge_count
65
+ payload.custom_payload = notification.send_params
66
+ payload.thread_id = notification.thread_id if notification.thread_id
67
+ payload.mutable_content = notification.mutable_content if notification.mutable_content
68
+ payload.category = notification.category if notification.category
69
+ payload.topic = bundle_id
70
+ payload.expiration = 0 || notification.expiry.to_f
71
+ payload.identifier = notification.identifier if notification.identifier
72
+
73
+ payload
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,7 @@
1
+ module Notifiable
2
+ module Apns
3
+ module Apnotic
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ require "notifiable/apns/apnotic/version"
2
+ require "notifiable/apns/apnotic/async"
3
+
4
+ module Notifiable
5
+ module Apns
6
+ module Apnotic
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,29 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "notifiable/apns/apnotic/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "notifiable-apns-apnotic"
8
+ spec.version = Notifiable::Apns::Apnotic::VERSION
9
+ spec.authors = ["Matt Brooke-Smith"]
10
+ spec.email = ["matt@futureworkshops.com"]
11
+
12
+ spec.summary = 'Apnotic APNS connector for Notifiable'
13
+ spec.homepage = "https://github.com/FutureWorkshops/notifiable-apns-apnotic"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
17
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "notifiable-rails", ">= 0.29.0"
24
+ spec.add_dependency 'apnotic', '~> 1.4.1'
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.16"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: notifiable-apns-apnotic
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Matt Brooke-Smith
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-08-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: notifiable-rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.29.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.29.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: apnotic
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.4.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.4.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.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: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description:
84
+ email:
85
+ - matt@futureworkshops.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - Gemfile
93
+ - Gemfile.lock
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - db/development.sqlite3
100
+ - lib/notifiable/apns/apnotic.rb
101
+ - lib/notifiable/apns/apnotic/async.rb
102
+ - lib/notifiable/apns/apnotic/version.rb
103
+ - notifiable-apns-apnotic.gemspec
104
+ homepage: https://github.com/FutureWorkshops/notifiable-apns-apnotic
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.7.3
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Apnotic APNS connector for Notifiable
128
+ test_files: []