dcidev_mailer 0.0.2 → 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: 4956bc5bb816bedd327ed4807d1e904e57b19a95d684cb3a21fd0ab35bfd9351
4
- data.tar.gz: 5347015c28d96ed779c5c50e47ab24afa6b6a488550c580dcb46d846297e83c7
3
+ metadata.gz: 99da00135ff089f563f8843ac8eed71aff180563e8257c0c3ad50a5fea4627e1
4
+ data.tar.gz: 9c07e164bde039359ef9ec2ab2102d0277d733970218f64ac6033e0639f838b2
5
5
  SHA512:
6
- metadata.gz: 0aee6dfe65decc88a005b0bc0baf1387a3e0655927d8f24e07f9eb08aaa2b5e3a9d9a2ef430c25ca741477b0d6423a30b1e814db25513af656e786a108e9a220
7
- data.tar.gz: 59282a2ae0a9d575eaf0222c8560f30b12a39745add570d9ade923fc3d4b4476df4de72428e60fb78128b9e2ec0108a3653ed5ecfb867add858ec16bbf5185ee
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
@@ -0,0 +1,79 @@
1
+ # require 'mail'
2
+ require 'action_mailer'
3
+ require 'action_view'
4
+ require 'mail'
5
+ require 'dcidev_mailer/errors/invalid_recipients'
6
+ require 'dcidev_mailer/errors/invalid_body'
7
+ require 'dcidev_mailer/errors/invalid_template'
8
+ module DcidevMailer
9
+ class RailsMailer < ActionMailer::Base
10
+
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?
23
+ end
24
+ end
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
+ }
43
+ end
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
+
78
+ end
79
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dcidev_mailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Punto Damar P
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-07 00:00:00.000000000 Z
11
+ date: 2022-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mimemagic
@@ -47,8 +47,11 @@ 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
53
+ - lib/dcidev_mailer/mail.rb
50
54
  - lib/dcidev_mailer/mandrill.rb
51
- - lib/dcidev_mailer/rails.rb
52
55
  homepage:
53
56
  licenses: []
54
57
  metadata: {}
@@ -67,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
70
  - !ruby/object:Gem::Version
68
71
  version: '0'
69
72
  requirements: []
70
- rubygems_version: 3.2.3
73
+ rubygems_version: 3.0.6
71
74
  signing_key:
72
75
  specification_version: 4
73
76
  summary: Commonly used email codes
@@ -1,29 +0,0 @@
1
- require 'mail'
2
-
3
- module DcidevMailer
4
- class Rails < ActionMailer::Base
5
- default from: ENV['DEFAULT_EMAIL_SENDER']
6
-
7
- class << self
8
- def email(html_body: "", header_url: "", footer_url: "", file_attachments: nil, to: "", from: nil, subject: "")
9
- wording, images = DcidevMailer.format_image_from_html(html_body)
10
- locals = {wording: wording, header: nil, footer: nil}
11
- 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?
12
-
13
- if file_attachments.present?
14
- file_attachments.each do |a|
15
- attachments[a[:name].to_s] = a[:content] unless a[:content].nil?
16
- end
17
- end
18
-
19
- attachments.inline['header'] = File.read(Utility.download_to_file(header_url)) rescue nil if header_url.present?
20
- attachments.inline['footer'] = File.read(Utility.download_to_file(footer_url)) rescue nil if footer_url.present?
21
-
22
- mail(to: to, subject: subject, format: "text/html", from: from) do |format|
23
- format.html {
24
- render locals: locals
25
- }
26
- end
27
- end
28
- end
29
- end