sendgrid_notification 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/jobs/sendgrid_notification/sendmail_job.rb +2 -2
- data/app/models/sendgrid_notification/base_mailer.rb +23 -0
- data/app/models/sendgrid_notification/null_mailer.rb +2 -9
- data/app/models/sendgrid_notification/sendgrid_client.rb +1 -1
- data/app/models/sendgrid_notification/sendgrid_mailer.rb +3 -11
- data/lib/sendgrid_notification/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a6289282bff591ae77653ea3172ce498e80c001
|
4
|
+
data.tar.gz: ff5e384e4a9c50789108192cbb043db1833dd584
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: abf8bdbfba44a15bf27270f45a2dfc888f08ba41d3ffdd25fe0417885b2ed474df233aacb5d1692258103d585eaef631300a6d4a2a17a713217283781a077d53
|
7
|
+
data.tar.gz: daa00bc9ebff0b4dd783d0d3e8e8e181ed0278978429268729f224af6eea998612fa7abf345de08e1cb85317e48b5d773ac2db292cc4237a458d189d4acb23c4
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module SendgridNotification
|
2
|
-
class SendmailJob <
|
2
|
+
class SendmailJob < ApplicationJob
|
3
3
|
queue_as :sendmail
|
4
4
|
|
5
5
|
MailerClass = Rails.application.config.sendgrid_notification.mailer.constantize
|
6
6
|
|
7
7
|
def perform(to, notification_mail, params)
|
8
|
-
MailerClass.new.sendmail(to, notification_mail, params)
|
8
|
+
MailerClass.new(params).sendmail(to, notification_mail, params)
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module SendgridNotification
|
2
|
+
class BaseMailer
|
3
|
+
attr_reader :from, :from_name
|
4
|
+
|
5
|
+
def initialize(params = {})
|
6
|
+
_params = params.with_indifferent_access
|
7
|
+
@from = _params.fetch(:mail_from) { Rails.application.config.sendgrid_notification.mail_from }
|
8
|
+
@from_name = _params.fetch(:mail_from_name) { Rails.application.config.sendgrid_notification.mail_from_name }
|
9
|
+
end
|
10
|
+
|
11
|
+
def sendmail(to, notification_mail, params = {})
|
12
|
+
raise NotImplementedError, "you should implement #{self.class}##{__method__}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def last_result
|
16
|
+
raise NotImplementedError, "you should implement #{self.class}##{__method__}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def last_result_success?
|
20
|
+
raise NotImplementedError, "you should implement #{self.class}##{__method__}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,21 +1,14 @@
|
|
1
|
-
require 'sendgrid-ruby'
|
2
|
-
|
3
1
|
module SendgridNotification
|
4
|
-
class NullMailer
|
2
|
+
class NullMailer < BaseMailer
|
5
3
|
prepend MailRecordable
|
6
|
-
|
7
4
|
Result = Struct.new(:from, :to, :subject, :body, :sent_at)
|
8
5
|
|
9
6
|
@@results = []
|
10
7
|
cattr_reader :results
|
11
8
|
|
12
|
-
def initialize
|
13
|
-
@from = Rails.application.config.sendgrid_notification.mail_from
|
14
|
-
end
|
15
|
-
|
16
9
|
def sendmail(to, notification_mail, params = {})
|
17
10
|
body = notification_mail.apply(params)
|
18
|
-
results << Result.new(
|
11
|
+
results << Result.new(from, to, notification_mail.subject, body, Time.now)
|
19
12
|
end
|
20
13
|
|
21
14
|
def last_result
|
@@ -1,16 +1,8 @@
|
|
1
|
-
require 'sendgrid-ruby'
|
2
|
-
|
3
1
|
module SendgridNotification
|
4
|
-
class SendgridMailer
|
2
|
+
class SendgridMailer < BaseMailer
|
5
3
|
prepend MailRecordable
|
6
|
-
|
7
4
|
class Error < StandardError; end
|
8
5
|
|
9
|
-
def initialize
|
10
|
-
@from = Rails.application.config.sendgrid_notification.mail_from
|
11
|
-
@from_name = Rails.application.config.sendgrid_notification.mail_from_name
|
12
|
-
end
|
13
|
-
|
14
6
|
def sendmail(to, notification_mail, params = {})
|
15
7
|
body = notification_mail.apply(params)
|
16
8
|
_sendmail(to, notification_mail, body)
|
@@ -34,8 +26,8 @@ module SendgridNotification
|
|
34
26
|
|
35
27
|
def _sendmail(to, notification_mail, body)
|
36
28
|
sendgrid_client.mail_send(
|
37
|
-
from:
|
38
|
-
from_name:
|
29
|
+
from: from,
|
30
|
+
from_name: from_name,
|
39
31
|
to: to,
|
40
32
|
subject: notification_mail.subject,
|
41
33
|
body: body
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sendgrid_notification
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- HORII Keima
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: factory_bot_rails
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
@@ -141,6 +141,7 @@ files:
|
|
141
141
|
- app/jobs/sendgrid_notification/sendmail_job.rb
|
142
142
|
- app/mailers/sendgrid_notification/application_mailer.rb
|
143
143
|
- app/models/sendgrid_notification/application_record.rb
|
144
|
+
- app/models/sendgrid_notification/base_mailer.rb
|
144
145
|
- app/models/sendgrid_notification/mail_history.rb
|
145
146
|
- app/models/sendgrid_notification/mail_recordable.rb
|
146
147
|
- app/models/sendgrid_notification/notification_mail.rb
|
@@ -179,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
179
180
|
version: '0'
|
180
181
|
requirements: []
|
181
182
|
rubyforge_project:
|
182
|
-
rubygems_version: 2.6.
|
183
|
+
rubygems_version: 2.6.13
|
183
184
|
signing_key:
|
184
185
|
specification_version: 4
|
185
186
|
summary: notification mail sender via sendgrid API
|