resend 0.3.0 → 0.5.0
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 +4 -4
- data/README.md +1 -1
- data/lib/resend/api_keys.rb +3 -3
- data/lib/resend/domains.rb +10 -4
- data/lib/resend/errors.rb +1 -0
- data/lib/resend/mailer.rb +44 -10
- data/lib/resend/request.rb +2 -1
- 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: d3e4d80d6041ac5d061ec2eafce26da90a106d14be6ae2b23dc66741b29a7d55
|
4
|
+
data.tar.gz: 3d486cd3522bda376cc61ee41c0ef1bdc91b6af2db07b4f05530d01d5a74f616
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 548f3a9603ecba1a0d44f7846d08e2194bd29d5baae28c6df8bdd3c1d5f3827210dacddad009556ff4d33c9eb1c567be60d522f3eda6f240fe7b1a3e0b3e6e49
|
7
|
+
data.tar.gz: a775247f3a2c7ab2a17e277d30f1b44700a5b9a17082de247aeff0a781e17c728bd67aa9bf1ad7e7807d78f43be43bd717c6c77ed464e333540a70efb325afd8
|
data/README.md
CHANGED
data/lib/resend/api_keys.rb
CHANGED
@@ -9,19 +9,19 @@ module Resend
|
|
9
9
|
class << self
|
10
10
|
# https://resend.com/docs/api-reference/api-keys/create-api-key
|
11
11
|
def create(params)
|
12
|
-
path = "
|
12
|
+
path = "api-keys"
|
13
13
|
Resend::Request.new(path, params, "post").perform
|
14
14
|
end
|
15
15
|
|
16
16
|
# https://resend.com/docs/api-reference/api-keys/list-api-keys
|
17
17
|
def list
|
18
|
-
path = "
|
18
|
+
path = "api-keys"
|
19
19
|
Resend::Request.new(path, {}, "get").perform
|
20
20
|
end
|
21
21
|
|
22
22
|
# https://resend.com/docs/api-reference/api-keys/delete-api-key
|
23
23
|
def remove(api_key_id = "")
|
24
|
-
path = "
|
24
|
+
path = "api-keys/#{api_key_id}"
|
25
25
|
Resend::Request.new(path, {}, "delete").perform
|
26
26
|
end
|
27
27
|
end
|
data/lib/resend/domains.rb
CHANGED
@@ -9,25 +9,31 @@ module Resend
|
|
9
9
|
class << self
|
10
10
|
# https://resend.com/docs/api-reference/domains/create-domain
|
11
11
|
def create(params)
|
12
|
-
path = "
|
12
|
+
path = "domains"
|
13
13
|
Resend::Request.new(path, params, "post").perform
|
14
14
|
end
|
15
15
|
|
16
|
+
# https://resend.com/docs/api-reference/domains/get-domain
|
17
|
+
def get(domain_id = "")
|
18
|
+
path = "domains/#{domain_id}"
|
19
|
+
Resend::Request.new(path, {}, "get").perform
|
20
|
+
end
|
21
|
+
|
16
22
|
# https://resend.com/docs/api-reference/api-keys/list-api-keys
|
17
23
|
def list
|
18
|
-
path = "
|
24
|
+
path = "domains"
|
19
25
|
Resend::Request.new(path, {}, "get").perform
|
20
26
|
end
|
21
27
|
|
22
28
|
# https://resend.com/docs/api-reference/domains/delete-domain
|
23
29
|
def remove(domain_id = "")
|
24
|
-
path = "
|
30
|
+
path = "domains/#{domain_id}"
|
25
31
|
Resend::Request.new(path, {}, "delete").perform
|
26
32
|
end
|
27
33
|
|
28
34
|
# https://resend.com/docs/api-reference/domains/verify-domain
|
29
35
|
def verify(domain_id = "")
|
30
|
-
path = "
|
36
|
+
path = "domains/#{domain_id}/verify"
|
31
37
|
Resend::Request.new(path, {}, "post").perform
|
32
38
|
end
|
33
39
|
end
|
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/request.rb
CHANGED
@@ -31,10 +31,11 @@ module Resend
|
|
31
31
|
options = {
|
32
32
|
headers: @headers
|
33
33
|
}
|
34
|
+
|
34
35
|
options[:body] = @body.to_json unless @body.empty?
|
35
36
|
resp = HTTParty.send(@verb.to_sym, "#{BASE_URL}#{@path}", options)
|
36
37
|
resp.transform_keys!(&:to_sym) unless resp.body.empty?
|
37
|
-
handle_error!(resp) if resp[:statusCode] && resp[:statusCode] != 200
|
38
|
+
handle_error!(resp) if resp[:statusCode] && (resp[:statusCode] != 200 || resp[:statusCode] != 201)
|
38
39
|
resp
|
39
40
|
end
|
40
41
|
|
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.5.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-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|