sendgrid_notification 0.1.0 → 0.1.2

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: 90775898ca7fc2946047128eedcdddce10254fdf
4
- data.tar.gz: f1ac7c958212d54a465c8f22af4cda0dcd587e1f
3
+ metadata.gz: 5a6289282bff591ae77653ea3172ce498e80c001
4
+ data.tar.gz: ff5e384e4a9c50789108192cbb043db1833dd584
5
5
  SHA512:
6
- metadata.gz: 900f013823a5951052e7c113080d84b03a7381ddf61362fff59227543631c2a222e4e49d2db9f91bb21798368cf427679d5c15240284319cbd962d79b647ef29
7
- data.tar.gz: 9b91afb7880024fc55f2edf5cdf65d0520441a5cba56af5733507b7de3b3e8c3673b58d77fd600a42bc3af6c503d0a0cf37c4a684d8c8157dbe64a6cc9694a30
6
+ metadata.gz: abf8bdbfba44a15bf27270f45a2dfc888f08ba41d3ffdd25fe0417885b2ed474df233aacb5d1692258103d585eaef631300a6d4a2a17a713217283781a077d53
7
+ data.tar.gz: daa00bc9ebff0b4dd783d0d3e8e8e181ed0278978429268729f224af6eea998612fa7abf345de08e1cb85317e48b5d773ac2db292cc4237a458d189d4acb23c4
@@ -1,11 +1,11 @@
1
1
  module SendgridNotification
2
- class SendmailJob < ActiveJob::Base
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(@from, to, notification_mail.subject, body, Time.now)
11
+ results << Result.new(from, to, notification_mail.subject, body, Time.now)
19
12
  end
20
13
 
21
14
  def last_result
@@ -28,7 +28,7 @@ module SendgridNotification
28
28
  end
29
29
 
30
30
  def body
31
- raw.try(:body) ? JSON.parse(raw.body) : ''
31
+ JSON.parse(raw.body) rescue {}
32
32
  end
33
33
 
34
34
  delegate :headers, to: :raw
@@ -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: @from,
38
- from_name: @from_name,
29
+ from: from,
30
+ from_name: from_name,
39
31
  to: to,
40
32
  subject: notification_mail.subject,
41
33
  body: body
@@ -1,3 +1,3 @@
1
1
  module SendgridNotification
2
- VERSION = "0.1.0".freeze
2
+ VERSION = "0.1.2".freeze
3
3
  end
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.0
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-08-03 00:00:00.000000000 Z
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: factory_girl_rails
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.11
183
+ rubygems_version: 2.6.13
183
184
  signing_key:
184
185
  specification_version: 4
185
186
  summary: notification mail sender via sendgrid API