notifiable-email-ses 0.1.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: b55b26ea0a66f50f341dc968d5e22c03133fa41e4b71df99209e6a4d6588b7ed
4
+ data.tar.gz: 4a5d92ee0c79167823abf145a758713e891cce4001bfb21bcd150fd8f794819d
5
+ SHA512:
6
+ metadata.gz: dfe39ad18e52b767b983ac9251a3ec7d4d541675d729b89b484cbfd95a4ebd67f18203d765ebfafca5a93fd175737fdbc1e37c1bc7b41d5c84d806fa56f58816
7
+ data.tar.gz: 39486c1278199f9e87315c19fffa2d03e9e5180bf9b0bf149351b83d37b4efd5d473f1b2242d3eb6486e764d3543658968e086728b59635f4c90ca7026c2e85c
data/.gitignore ADDED
@@ -0,0 +1,13 @@
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
12
+ /db
13
+ /.byebug_history
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,6 @@
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-sms-sns.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,85 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ notifiable-email-ses (0.1.0)
5
+ aws-sdk-ses (~> 1.5)
6
+ notifiable-core (>= 0.1.3)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activemodel (5.2.1)
12
+ activesupport (= 5.2.1)
13
+ activerecord (5.2.1)
14
+ activemodel (= 5.2.1)
15
+ activesupport (= 5.2.1)
16
+ arel (>= 9.0)
17
+ activerecord-import (0.26.0)
18
+ activerecord (>= 3.2)
19
+ activesupport (5.2.1)
20
+ concurrent-ruby (~> 1.0, >= 1.0.2)
21
+ i18n (>= 0.7, < 2)
22
+ minitest (~> 5.1)
23
+ tzinfo (~> 1.1)
24
+ arel (9.0.0)
25
+ aws-eventstream (1.0.1)
26
+ aws-partitions (1.105.0)
27
+ aws-sdk-core (3.30.0)
28
+ aws-eventstream (~> 1.0)
29
+ aws-partitions (~> 1.0)
30
+ aws-sigv4 (~> 1.0)
31
+ jmespath (~> 1.0)
32
+ aws-sdk-ses (1.11.0)
33
+ aws-sdk-core (~> 3, >= 3.26.0)
34
+ aws-sigv4 (~> 1.0)
35
+ aws-sigv4 (1.0.3)
36
+ byebug (10.0.2)
37
+ concurrent-ruby (1.0.5)
38
+ database_cleaner (1.7.0)
39
+ diff-lcs (1.3)
40
+ factory_bot (4.11.0)
41
+ activesupport (>= 3.0.0)
42
+ i18n (1.1.0)
43
+ concurrent-ruby (~> 1.0)
44
+ jmespath (1.4.0)
45
+ minitest (5.11.3)
46
+ notifiable-core (0.2.0)
47
+ activerecord
48
+ activerecord-import
49
+ pg (1.1.2)
50
+ rake (10.5.0)
51
+ rspec (3.8.0)
52
+ rspec-core (~> 3.8.0)
53
+ rspec-expectations (~> 3.8.0)
54
+ rspec-mocks (~> 3.8.0)
55
+ rspec-core (3.8.0)
56
+ rspec-support (~> 3.8.0)
57
+ rspec-expectations (3.8.1)
58
+ diff-lcs (>= 1.2.0, < 2.0)
59
+ rspec-support (~> 3.8.0)
60
+ rspec-mocks (3.8.0)
61
+ diff-lcs (>= 1.2.0, < 2.0)
62
+ rspec-support (~> 3.8.0)
63
+ rspec-support (3.8.0)
64
+ sqlite3 (1.3.13)
65
+ thread_safe (0.3.6)
66
+ tzinfo (1.2.5)
67
+ thread_safe (~> 0.1)
68
+
69
+ PLATFORMS
70
+ ruby
71
+
72
+ DEPENDENCIES
73
+ bundler (~> 1.16)
74
+ byebug
75
+ database_cleaner
76
+ factory_bot
77
+ notifiable-email-ses!
78
+ pg
79
+ rake (~> 10.0)
80
+ rspec (~> 3.0)
81
+ rspec-mocks
82
+ sqlite3
83
+
84
+ BUNDLED WITH
85
+ 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::Sms::Sns
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/email/sns`. 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-email-sns'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install notifiable-email-sns
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-email-sns.
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,9 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ notifiable_path = Gem::Specification.find_by_name 'notifiable-core'
5
+ load "#{notifiable_path.gem_dir}/lib/tasks/db.rake"
6
+
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require 'notifiable'
5
+ require "notifiable/email/ses"
6
+ require 'sqlite3'
7
+ require 'byebug'
8
+
9
+ # setup dummy db connection
10
+ require 'active_record'
11
+ ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => 'db/development.sqlite3')
12
+
13
+ ActiveRecord::Migration.verbose = false
14
+ notifiable_rails_path = Gem.loaded_specs['notifiable-core'].full_gem_path
15
+ ActiveRecord::MigrationContext.new(File.join(notifiable_rails_path, 'db', 'migrate')).migrate
16
+
17
+ @app = Notifiable::App.create name: 'Test'
18
+ @notification = Notifiable::Notification.new title: 'subject test', message: 'message test', app: @app
19
+ @device = Notifiable::DeviceToken.new token: 'matt@futureworkshops.com', app: @app
20
+ @sender = Notifiable::Email::Ses::Sender.new(@notification)
21
+ @sender.access_id = ENV['ACCESS_ID']
22
+ @sender.secret_key = ENV['SECRET_KEY']
23
+
24
+ require "irb"
25
+ 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
@@ -0,0 +1,12 @@
1
+ postgres: &postgres
2
+ adapter: postgresql
3
+ host: localhost
4
+ port: 5432
5
+
6
+ development:
7
+ <<: *postgres
8
+ database: notifiable-email-ses-development
9
+
10
+ test:
11
+ <<: *postgres
12
+ database: notifiable-email-ses-development
@@ -0,0 +1,10 @@
1
+ require "notifiable/email/ses/version"
2
+ require "notifiable/email/ses/sender"
3
+ require "notifiable/email/ses/listener"
4
+
5
+ module Notifiable
6
+ module Email
7
+ module Ses
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,27 @@
1
+ require 'json'
2
+
3
+ # Class which will listen for JSON events from an SNS queue
4
+ module Notifiable
5
+ module Email
6
+ module Ses
7
+ class Listener
8
+ def event_recieved(json)
9
+ json_event = JSON.parse(json)
10
+ event_type = json_event["notificationType"]
11
+ case event_type
12
+ when "Delivery"
13
+ recipients = json_event["delivery"]["recipients"]
14
+ logger.info("Recipients #{recipients} recieved email.")
15
+ else
16
+ logger.info("Event #{event_type}.")
17
+ end
18
+ end
19
+
20
+ private
21
+ def logger
22
+ @logger ||= Logger.new(STDOUT)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,62 @@
1
+ require 'notifiable'
2
+ require 'aws-sdk-ses'
3
+
4
+ # https://docs.aws.amazon.com/ses/latest/DeveloperGuide/deliverability-and-ses.html
5
+
6
+ module Notifiable
7
+ module Email
8
+ module Ses
9
+ class Sender < Notifiable::NotifierBase
10
+
11
+ notifier_attribute :access_id, :secret_key
12
+
13
+ protected
14
+ def enqueue(device, notification)
15
+ raise "access_id missing" if @access_id.nil?
16
+ raise "secret_key missing" if @secret_key.nil?
17
+
18
+ sender = 'info@futureworkshops.com'
19
+ recipient = device.token
20
+ htmlbody = "<p>#{notification.message}</p>"
21
+ textbody = notification.message
22
+ encoding = 'UTF-8'
23
+
24
+ client.send_email(
25
+ destination: {
26
+ to_addresses: [
27
+ recipient
28
+ ]
29
+ },
30
+ message: {
31
+ body: {
32
+ html: {
33
+ charset: encoding,
34
+ data: htmlbody
35
+ },
36
+ text: {
37
+ charset: encoding,
38
+ data: textbody
39
+ }
40
+ },
41
+ subject: {
42
+ charset: encoding,
43
+ data: notification.title
44
+ }
45
+ },
46
+ source: sender,
47
+ )
48
+
49
+ processed(device)
50
+
51
+ rescue Aws::SES::Errors::ServiceError => error
52
+ processed(device, NotificationStatus::REJECTED_STATUS, nil, error.message)
53
+ end
54
+
55
+ private
56
+ def client
57
+ @client ||= Aws::SES::Client.new(region: 'us-east-1', access_key_id: @access_id, secret_access_key: @secret_key)
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,7 @@
1
+ module Notifiable
2
+ module Email
3
+ module Ses
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,37 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "notifiable/email/ses/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "notifiable-email-ses"
8
+ spec.version = Notifiable::Email::Ses::VERSION
9
+ spec.authors = ["Matt Brooke-Smith"]
10
+ spec.email = ["matt@futureworkshops.com"]
11
+
12
+ spec.summary = 'AWS SNS Email connector for Notifiable'
13
+ spec.homepage = "https://github.com/FutureWorkshops/notifiable-email-ses"
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-core', '>= 0.1.3'
24
+ spec.add_dependency 'aws-sdk-ses', '~> 1.5'
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
+ spec.add_development_dependency "rspec-mocks"
30
+ spec.add_development_dependency "pg"
31
+ spec.add_development_dependency "sqlite3"
32
+ spec.add_development_dependency "factory_bot"
33
+ spec.add_development_dependency "byebug"
34
+ spec.add_development_dependency "database_cleaner"
35
+
36
+
37
+ end
metadata ADDED
@@ -0,0 +1,213 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: notifiable-email-ses
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-10-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: notifiable-core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: aws-sdk-ses
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
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
+ - !ruby/object:Gem::Dependency
84
+ name: rspec-mocks
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
+ - !ruby/object:Gem::Dependency
98
+ name: pg
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: sqlite3
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: factory_bot
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: byebug
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: database_cleaner
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ description:
168
+ email:
169
+ - matt@futureworkshops.com
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - ".gitignore"
175
+ - ".rspec"
176
+ - Gemfile
177
+ - Gemfile.lock
178
+ - LICENSE.txt
179
+ - README.md
180
+ - Rakefile
181
+ - bin/console
182
+ - bin/setup
183
+ - config/database.yml
184
+ - lib/notifiable/email/ses.rb
185
+ - lib/notifiable/email/ses/listener.rb
186
+ - lib/notifiable/email/ses/sender.rb
187
+ - lib/notifiable/email/ses/version.rb
188
+ - notifiable-email-ses.gemspec
189
+ homepage: https://github.com/FutureWorkshops/notifiable-email-ses
190
+ licenses:
191
+ - MIT
192
+ metadata: {}
193
+ post_install_message:
194
+ rdoc_options: []
195
+ require_paths:
196
+ - lib
197
+ required_ruby_version: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ required_rubygems_version: !ruby/object:Gem::Requirement
203
+ requirements:
204
+ - - ">="
205
+ - !ruby/object:Gem::Version
206
+ version: '0'
207
+ requirements: []
208
+ rubyforge_project:
209
+ rubygems_version: 2.7.3
210
+ signing_key:
211
+ specification_version: 4
212
+ summary: AWS SNS Email connector for Notifiable
213
+ test_files: []