resend 0.5.0 → 0.7.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 +9 -14
- data/lib/resend/errors.rb +4 -1
- data/lib/resend/mailer.rb +16 -2
- data/lib/resend/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 546dd4f52e3f16e399e3d42b6fc5512628ad67249ba9e5a521f97ce428d80682
|
4
|
+
data.tar.gz: 1b291656cdbc4456dddf0aa3444e2ef4b80aef9a1429640a38073395cce99e75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4849accfa344de0ee7db136a06e64ff3111aa73111e68a14ca708c9c5f43af73023a8921d55a436a2a0dfeb2f831dc2572fca01d59014c51adf288c378987e1
|
7
|
+
data.tar.gz: 39dfdac4232712f57d6e884318edc09155bf0bdc67110d49b22de0f88e20d4c2475ca98c91b68a0b2e505b7391884d774dcd75dafb074a3a0c17d113f1edda4f
|
data/README.md
CHANGED
@@ -16,7 +16,7 @@ gem install resend
|
|
16
16
|
|
17
17
|
Via Gemfile:
|
18
18
|
```
|
19
|
-
gem 'resend'
|
19
|
+
gem 'resend'
|
20
20
|
```
|
21
21
|
|
22
22
|
## Setup
|
@@ -59,13 +59,17 @@ You can view all the examples in the [examples folder](https://github.com/drish/
|
|
59
59
|
|
60
60
|
# Rails and ActiveMailer support
|
61
61
|
|
62
|
-
This gem can be used as an ActionMailer delivery method, add this to your `config/environments/environment.rb` file
|
62
|
+
This gem can be used as an ActionMailer delivery method, add this to your `config/environments/environment.rb` file.
|
63
63
|
|
64
64
|
```ruby
|
65
65
|
config.action_mailer.delivery_method = :resend
|
66
|
-
|
67
|
-
|
68
|
-
|
66
|
+
```
|
67
|
+
|
68
|
+
Create or update your mailer initializer file and replace the placeholder with your Resend API Key.
|
69
|
+
|
70
|
+
```rb
|
71
|
+
# /app/initializers/mailer.rb
|
72
|
+
Resend.api_key = "re_123456"
|
69
73
|
```
|
70
74
|
|
71
75
|
After that you can deliver_now!, example below:
|
@@ -87,12 +91,3 @@ mailer = UserMailer.with(user: u).welcome_email
|
|
87
91
|
mailer.deliver_now!
|
88
92
|
# => {:id=>"b8f94710-0d84-429c-925a-22d3d8f86916", from: 'you@yourdomain.io', to: ["example2@mail.com", "example1@mail.com"]}
|
89
93
|
```
|
90
|
-
|
91
|
-
This gem can also be initialized with a Rails initializer file, example below:
|
92
|
-
|
93
|
-
```ruby
|
94
|
-
# /app/initializers/mailer.rb
|
95
|
-
Resend.configure do |config|
|
96
|
-
config.api_key = 'resend_api_key'
|
97
|
-
end
|
98
|
-
```
|
data/lib/resend/errors.rb
CHANGED
@@ -4,7 +4,6 @@ module Resend
|
|
4
4
|
# Errors wrapper class
|
5
5
|
# For more info: https://resend.com/docs/api-reference/error-codes
|
6
6
|
class Error < StandardError
|
7
|
-
|
8
7
|
# 4xx HTTP status code
|
9
8
|
ClientError = Class.new(self)
|
10
9
|
|
@@ -17,6 +16,9 @@ module Resend
|
|
17
16
|
# code 422
|
18
17
|
InvalidRequestError = Class.new(ServerError)
|
19
18
|
|
19
|
+
# code 429
|
20
|
+
RateLimitExceededError = Class.new(ServerError)
|
21
|
+
|
20
22
|
# code 404
|
21
23
|
NotFoundError = Class.new(ServerError)
|
22
24
|
|
@@ -24,6 +26,7 @@ module Resend
|
|
24
26
|
401 => Resend::Error::InvalidRequestError,
|
25
27
|
404 => Resend::Error::InvalidRequestError,
|
26
28
|
422 => Resend::Error::InvalidRequestError,
|
29
|
+
429 => Resend::Error::RateLimitExceededError,
|
27
30
|
400 => Resend::Error::InvalidRequestError,
|
28
31
|
500 => Resend::Error::InternalServerError
|
29
32
|
}.freeze
|
data/lib/resend/mailer.rb
CHANGED
@@ -9,9 +9,10 @@ module Resend
|
|
9
9
|
|
10
10
|
def initialize(config)
|
11
11
|
@config = config
|
12
|
-
raise Resend::
|
12
|
+
raise Resend::Error.new("Make sure your API Key is set", @config) unless Resend.api_key
|
13
13
|
|
14
|
-
|
14
|
+
# avoids NilError exception
|
15
|
+
@settings = { return_response: true }
|
15
16
|
end
|
16
17
|
|
17
18
|
def deliver!(mail)
|
@@ -21,6 +22,7 @@ module Resend
|
|
21
22
|
resp
|
22
23
|
end
|
23
24
|
|
25
|
+
# Builds the payload for sending
|
24
26
|
def build_resend_params(mail)
|
25
27
|
params = {
|
26
28
|
from: get_from(mail.from),
|
@@ -28,11 +30,20 @@ module Resend
|
|
28
30
|
subject: mail.subject
|
29
31
|
}
|
30
32
|
params.merge!(get_addons(mail))
|
33
|
+
params.merge!(get_headers(mail))
|
31
34
|
params[:attachments] = get_attachments(mail) if mail.attachments.present?
|
32
35
|
params.merge!(get_contents(mail))
|
33
36
|
params
|
34
37
|
end
|
35
38
|
|
39
|
+
# Add custom headers fields
|
40
|
+
def get_headers(mail)
|
41
|
+
params = {}
|
42
|
+
params[:headers] = mail[:headers].unparsed_value if mail[:headers].present?
|
43
|
+
params
|
44
|
+
end
|
45
|
+
|
46
|
+
# Add cc, bcc, reply_to fields
|
36
47
|
def get_addons(mail)
|
37
48
|
params = {}
|
38
49
|
params[:cc] = mail.cc if mail.cc.present?
|
@@ -41,6 +52,7 @@ module Resend
|
|
41
52
|
params
|
42
53
|
end
|
43
54
|
|
55
|
+
# Gets the body of the email
|
44
56
|
def get_contents(mail)
|
45
57
|
params = {}
|
46
58
|
case mail.mime_type
|
@@ -55,12 +67,14 @@ module Resend
|
|
55
67
|
params
|
56
68
|
end
|
57
69
|
|
70
|
+
# Gets the `from` field
|
58
71
|
def get_from(input)
|
59
72
|
return input.first if input.is_a? Array
|
60
73
|
|
61
74
|
input
|
62
75
|
end
|
63
76
|
|
77
|
+
# Handle attachments when present
|
64
78
|
def get_attachments(mail)
|
65
79
|
attachments = []
|
66
80
|
mail.attachments.each do |part|
|
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.7.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-07-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -74,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
requirements: []
|
77
|
-
rubygems_version: 3.
|
77
|
+
rubygems_version: 3.3.7
|
78
78
|
signing_key:
|
79
79
|
specification_version: 4
|
80
80
|
summary: The Ruby and Rails SDK for resend.com
|