resend 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/resend/errors.rb +1 -0
- data/lib/resend/mailer.rb +44 -10
- data/lib/resend/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3e46d09490b1ad19c59f04e55fd16b0da3d3c2573ed5c9dcba3297f0f92f5fc
|
4
|
+
data.tar.gz: 6c9dfb7910fd6199bc9c75aa9f3c2e9200677ce9e2ba1e9a29e124908489e714
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58e0cdd7ae1d48654ff33761b1fcb8a4e96061142d154232f85bac348c38956505d11ee3a0cdf6d86592389d2d8c69eba48941d7d97e1c4de904d0c8b5b6d7a6
|
7
|
+
data.tar.gz: 2069dfd99a67245da05ebf8e58658c2771de51cd6999d8d824116174b0aeba38dcc4f4423f05cb73e63388f5497377dba4c4b98eebddba2b2205864530790d3a
|
data/README.md
CHANGED
data/lib/resend/errors.rb
CHANGED
data/lib/resend/mailer.rb
CHANGED
@@ -12,31 +12,65 @@ module Resend
|
|
12
12
|
raise Resend::ResendError.new("Config requires api_key", @config) unless @config.key?(:api_key)
|
13
13
|
|
14
14
|
@settings = { return_response: true } # avoids NilError exception
|
15
|
-
@resend_client = Resend::Client.new config[:api_key]
|
16
15
|
end
|
17
16
|
|
18
17
|
def deliver!(mail)
|
19
18
|
params = build_resend_params(mail)
|
20
|
-
resp =
|
19
|
+
resp = Resend::Emails.send(params)
|
21
20
|
mail.message_id = resp[:id] if resp[:error].nil?
|
22
21
|
resp
|
23
22
|
end
|
24
23
|
|
25
|
-
# rubocop:disable Metrics/AbcSize
|
26
24
|
def build_resend_params(mail)
|
27
25
|
params = {
|
28
|
-
from: mail
|
26
|
+
from: get_from(mail.from),
|
29
27
|
to: mail.to,
|
30
28
|
subject: mail.subject
|
31
29
|
}
|
32
|
-
params
|
33
|
-
params[:
|
34
|
-
params
|
35
|
-
params[:html] = mail.body.decoded
|
30
|
+
params.merge!(get_addons(mail))
|
31
|
+
params[:attachments] = get_attachments(mail) if mail.attachments.present?
|
32
|
+
params.merge!(get_contents(mail))
|
36
33
|
params
|
37
34
|
end
|
38
|
-
# rubocop:enable Metrics/AbcSize
|
39
35
|
|
40
|
-
|
36
|
+
def get_addons(mail)
|
37
|
+
params = {}
|
38
|
+
params[:cc] = mail.cc if mail.cc.present?
|
39
|
+
params[:bcc] = mail.bcc if mail.bcc.present?
|
40
|
+
params[:reply_to] = mail.reply_to if mail.reply_to.present?
|
41
|
+
params
|
42
|
+
end
|
43
|
+
|
44
|
+
def get_contents(mail)
|
45
|
+
params = {}
|
46
|
+
case mail.mime_type
|
47
|
+
when "text/plain"
|
48
|
+
params[:text] = mail.body.decoded
|
49
|
+
when "text/html"
|
50
|
+
params[:html] = mail.body.decoded
|
51
|
+
when "multipart/alternative", "multipart/mixed", "multipart/related"
|
52
|
+
params[:text] = mail.text_part.decoded if mail.text_part
|
53
|
+
params[:html] = mail.html_part.decoded if mail.html_part
|
54
|
+
end
|
55
|
+
params
|
56
|
+
end
|
57
|
+
|
58
|
+
def get_from(input)
|
59
|
+
return input.first if input.is_a? Array
|
60
|
+
|
61
|
+
input
|
62
|
+
end
|
63
|
+
|
64
|
+
def get_attachments(mail)
|
65
|
+
attachments = []
|
66
|
+
mail.attachments.each do |part|
|
67
|
+
attachment = {
|
68
|
+
filename: part.filename,
|
69
|
+
content: part.body.decoded.bytes
|
70
|
+
}
|
71
|
+
attachments.append(attachment)
|
72
|
+
end
|
73
|
+
attachments
|
74
|
+
end
|
41
75
|
end
|
42
76
|
end
|
data/lib/resend/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resend
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Derich Pacheco
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|