dcidev_mailer 0.0.5 → 0.0.6

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
  SHA256:
3
- metadata.gz: 63527600458fafe442b04ad42cc9afe6ce814587d6c7d3ca1df0a9c8ee2cfbf3
4
- data.tar.gz: 134af01794ea7b23d6075959f87b09e6952362059ddec4f3f5b64dabdd690771
3
+ metadata.gz: 99da00135ff089f563f8843ac8eed71aff180563e8257c0c3ad50a5fea4627e1
4
+ data.tar.gz: 9c07e164bde039359ef9ec2ab2102d0277d733970218f64ac6033e0639f838b2
5
5
  SHA512:
6
- metadata.gz: 2359b8a5f941a4b2ee802386b2b27c8e1167a7543d7fadfd3615826368601c8e6e36a0f39264c180ff01e548f04b0582fd3852843ba3e134d5f641203f142a81
7
- data.tar.gz: b29ffd3b8554b5cd8767edff42e5cea95fc11c14f0e684f30957f8743c05019957954a01f3b9a994c35561a5782bbb8f06907c41bacd7bd7354228bad1bec791
6
+ metadata.gz: defa57723a34010ec7fb48f680fd331dfa063c15b3790d976e8612718b9ee9550a260400d729a410bd79fad7bcc16de7aa41d4f326c3fa340d1a939eb04ddb51
7
+ data.tar.gz: 60066e1f871cf6b8d56ea407ca01472e3fd8ee9848f34bd063852cca20e2d1ecdb99e8d2d964bd18eb67f9bfc1db724a241736bc4a7c10ad96f812993eb2d092
@@ -0,0 +1,9 @@
1
+ module DcidevMailer
2
+ module Errors
3
+ class InvalidBody < StandardError
4
+ def to_s
5
+ "Email body must be HTML string"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module DcidevMailer
2
+ module Errors
3
+ class InvalidRecipients < StandardError
4
+ def to_s
5
+ "Must have at lease one recipient"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module DcidevMailer
2
+ module Errors
3
+ class InvalidTemplate < StandardError
4
+ def to_s
5
+ "Missing email template"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,48 +1,79 @@
1
-
2
-
3
1
  # require 'mail'
4
- require 'action_mailer/base'
2
+ require 'action_mailer'
5
3
  require 'action_view'
6
4
  require 'mail'
5
+ require 'dcidev_mailer/errors/invalid_recipients'
6
+ require 'dcidev_mailer/errors/invalid_body'
7
+ require 'dcidev_mailer/errors/invalid_template'
7
8
  module DcidevMailer
8
- class Mail < ActionMailer::Base
9
- default from: ENV['DEFAULT_EMAIL_SENDER']
10
- class << self
11
-
12
- def email(html_body: "", header_url: "", footer_url: "", file_attachments: nil, to: "", from: nil, subject: "", template_path: "", template_name: "")
13
- wording, images = DcidevMailer.format_image_from_html(html_body)
14
-
15
- @wording = "wording"
16
- locals = { wording: wording, header: nil, footer: nil }
17
- locals, images = DcidevMailer.format_header_footer(header_url: header_url, footer_url: footer_url, locals: locals, images: images) if header_url.present? && footer_url.present?
18
-
19
- att = ActionMailer::Base.new
20
- if file_attachments.present?
21
- file_attachments.each do |a|
22
- att.attachments[a[:name].to_s] = a[:content] unless a[:content].nil?
23
- end
24
- end
9
+ class RailsMailer < ActionMailer::Base
25
10
 
26
- # self.attachments.inline['header'] = File.read(Utility.download_to_file(header_url)) rescue nil if header_url.present?
27
- # self.attachments.inline['footer'] = File.read(Utility.download_to_file(footer_url)) rescue nil if footer_url.present?
28
-
29
- att.attachments.inline['header'] = File.read(Utility.download_to_file(header_url)) rescue nil if header_url.present?
30
- att.attachments.inline['footer'] = File.read(Utility.download_to_file(footer_url)) rescue nil if footer_url.present?
31
-
32
- ActionMailer::Base.mail(
33
- to: to,
34
- subject: subject,
35
- format: "text/html",
36
- from: from,
37
- template_path: template_path,
38
- template_name: template_name
39
- ) do |format|
40
- format.html {
41
- ActionView::Base.new.render locals: locals
42
- }
11
+ def email(html_body: "", header_url: "", footer_url: "", file_attachments: nil, to: nil, cc: nil, bcc: nil, from: nil, subject: "", template_path: "")
12
+ raise DcidevMailer::Errors::InvalidRecipients unless to.present?
13
+ raise DcidevMailer::Errors::InvalidBody unless html_body.present? && html_body.is_a?(String)
14
+ raise DcidevMailer::Errors::InvalidTemplate unless template_path.present?
15
+ wording, images = DcidevMailer.format_image_from_html(html_body)
16
+
17
+ locals = { wording: wording, header: nil, footer: nil }
18
+ locals, images = DcidevMailer.format_header_footer(header_url: header_url, footer_url: footer_url, locals: locals, images: images) if header_url.present? && footer_url.present?
19
+
20
+ if file_attachments.present?
21
+ file_attachments.each do |a|
22
+ am.attachments[a[:name].to_s] = a[:content] unless a[:content].nil?
43
23
  end
24
+ end
44
25
 
26
+ attachments.inline['header'] = File.read(Utility.download_to_file(header_url)) rescue nil if header_url.present?
27
+ attachments.inline['footer'] = File.read(Utility.download_to_file(footer_url)) rescue nil if footer_url.present?
28
+
29
+ mail(
30
+ to: to,
31
+ cc: cc,
32
+ bcc: bcc,
33
+ subject: subject,
34
+ format: "text/html",
35
+ from: from,
36
+ # template_path: "dcidev_mailer/rails_mailer",
37
+ # template_name: 'a',
38
+ ) do |format|
39
+ format.html {
40
+ render locals: locals, html: ActionController::Base.new.render_to_string(template: template_path, locals: locals)
41
+
42
+ }
45
43
  end
46
44
  end
45
+
46
+
47
+ # def self.method_missing(method_name, html_body: "", header_url: "", footer_url: "", file_attachments: nil, to: nil, cc: nil, bcc: nil, from: nil, subject: "")
48
+ # raise DcidevMailer::Errors::InvalidRecipients unless to.present?
49
+ # raise DcidevMailer::Errors::InvalidBody unless html_body.present? && html_body.is_a?(String)
50
+ # wording, images = DcidevMailer.format_image_from_html(html_body)
51
+ #
52
+ # locals = { wording: wording, header: nil, footer: nil }
53
+ # locals, images = DcidevMailer.format_header_footer(header_url: header_url, footer_url: footer_url, locals: locals, images: images) if header_url.present? && footer_url.present?
54
+ #
55
+ # if file_attachments.present?
56
+ # file_attachments.each do |a|
57
+ # am.attachments[a[:name].to_s] = a[:content] unless a[:content].nil?
58
+ # end
59
+ # end
60
+ #
61
+ # attachments.inline['header'] = File.read(Utility.download_to_file(header_url)) rescue nil if header_url.present?
62
+ # attachments.inline['footer'] = File.read(Utility.download_to_file(footer_url)) rescue nil if footer_url.present?
63
+ #
64
+ # mail(
65
+ # to: to,
66
+ # cc: cc,
67
+ # bcc: bcc,
68
+ # subject: subject,
69
+ # format: "text/html",
70
+ # from: from,
71
+ # ) do |format|
72
+ # format.html {
73
+ # render locals: locals
74
+ # }
75
+ # end
76
+ # end
77
+
47
78
  end
48
79
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dcidev_mailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Punto Damar P
@@ -47,6 +47,9 @@ extra_rdoc_files: []
47
47
  files:
48
48
  - README.md
49
49
  - lib/dcidev_mailer.rb
50
+ - lib/dcidev_mailer/errors/invalid_body.rb
51
+ - lib/dcidev_mailer/errors/invalid_recipients.rb
52
+ - lib/dcidev_mailer/errors/invalid_template.rb
50
53
  - lib/dcidev_mailer/mail.rb
51
54
  - lib/dcidev_mailer/mandrill.rb
52
55
  homepage: