resend 0.1.0 → 0.2.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 +40 -0
- data/lib/resend/client.rb +0 -8
- data/lib/resend/mailer.rb +39 -0
- data/lib/resend/railtie.rb +11 -0
- data/lib/resend/version.rb +1 -1
- data/lib/resend.rb +13 -2
- metadata +19 -4
- data/lib/railresend.rb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34d75256450dcc66c26389540c6daa09e35548aa92f597198903625050618ebe
|
4
|
+
data.tar.gz: '08e1a8961434c9cd3ebed403378e01d3ebbd8c592283055a30895d6cb9a0bbd9'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dac58f82c95d6b80f7defe58848c1bc885ad484a93c6290ba1de7ce2351ca72a7bf3ff2b24daf1894c17f2c40cc1ba3c29be2ef81009ece0c0ab30875a2bb077
|
7
|
+
data.tar.gz: 2c34b1cc768b41219ac140c1e87dfc4e10faada1b2afda924ec0eaa458a3a85573fd20d07483ce265c6b6d56db1953c0c1e34e7ea2cfa091a31ba577d83106de
|
data/README.md
CHANGED
@@ -42,4 +42,44 @@ params = {
|
|
42
42
|
}
|
43
43
|
r = client.send_email(params)
|
44
44
|
puts r
|
45
|
+
```
|
46
|
+
|
47
|
+
# Rails and ActiveMailer support
|
48
|
+
|
49
|
+
This gem can be used as an ActionMailer delivery method, add this to your `config/environments/environment.rb` file and replace with your api key.
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
config.action_mailer.delivery_method = :resend
|
53
|
+
config.action_mailer.resend_settings = {
|
54
|
+
api_key: 'resend_api_key',
|
55
|
+
}
|
56
|
+
```
|
57
|
+
|
58
|
+
After that you can deliver_now!, example below:
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
#/app/mailers/user_mailer
|
62
|
+
class UserMailer < ApplicationMailer
|
63
|
+
default from: 'you@yourdomain.io'
|
64
|
+
def welcome_email
|
65
|
+
@user = params[:user]
|
66
|
+
@url = 'http://example.com/login'
|
67
|
+
mail(to: ["example2@mail.com", "example1@mail.com"], subject: 'Hello from Resend')
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# anywhere in the app
|
72
|
+
u = User.new name: "derich"
|
73
|
+
mailer = UserMailer.with(user: u).welcome_email
|
74
|
+
mailer.deliver_now!
|
75
|
+
# => {:id=>"b8f94710-0d84-429c-925a-22d3d8f86916", from: 'you@yourdomain.io', to: ["example2@mail.com", "example1@mail.com"]}
|
76
|
+
```
|
77
|
+
|
78
|
+
This gem can also be initialized with a Rails initializer file, example below:
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
# /app/initializers/mailer.rb
|
82
|
+
Resend.configure do |config|
|
83
|
+
config.api_key = 'resend_api_key'
|
84
|
+
end
|
45
85
|
```
|
data/lib/resend/client.rb
CHANGED
@@ -0,0 +1,39 @@
|
|
1
|
+
require "resend"
|
2
|
+
|
3
|
+
module Resend
|
4
|
+
class Mailer
|
5
|
+
|
6
|
+
attr_accessor :config, :settings
|
7
|
+
|
8
|
+
def initialize(config)
|
9
|
+
@config = config
|
10
|
+
raise Resend::ResendError.new("Config requires api_key", @config) unless @config.has_key?(:api_key)
|
11
|
+
@settings = { return_response: true } # avoids NilError exception
|
12
|
+
@resend_client = Resend::Client.new config[:api_key]
|
13
|
+
end
|
14
|
+
|
15
|
+
def deliver!(mail)
|
16
|
+
params = {
|
17
|
+
from: mail[:from].to_s,
|
18
|
+
to: mail.to,
|
19
|
+
subject: mail.subject,
|
20
|
+
}
|
21
|
+
params[:cc] = mail[:cc] if mail[:cc].present?
|
22
|
+
params[:bcc] = mail[:bcc] if mail[:bcc].present?
|
23
|
+
params[:reply_to] = mail[:reply_to] if mail[:reply_to].present?
|
24
|
+
params[:html] = mail.body.decoded
|
25
|
+
|
26
|
+
resp = @resend_client.send_email(params)
|
27
|
+
|
28
|
+
if resp[:error].nil? then
|
29
|
+
mail.message_id = resp[:id]
|
30
|
+
end
|
31
|
+
|
32
|
+
resp
|
33
|
+
end
|
34
|
+
|
35
|
+
def resend_client
|
36
|
+
@resend_client
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "resend"
|
2
|
+
require "resend/mailer"
|
3
|
+
|
4
|
+
module Resend
|
5
|
+
class Railtie < ::Rails::Railtie
|
6
|
+
ActiveSupport.on_load(:action_mailer) do
|
7
|
+
add_delivery_method :resend, Resend::Mailer
|
8
|
+
ActiveSupport.run_load_hooks(:resend_mailer, Resend::Mailer)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/lib/resend/version.rb
CHANGED
data/lib/resend.rb
CHANGED
@@ -1,6 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require "resend/version"
|
4
4
|
require "resend/client"
|
5
5
|
|
6
|
-
require
|
6
|
+
require 'resend/railtie' if defined?(Rails) && defined?(ActionMailer)
|
7
|
+
|
8
|
+
module Resend
|
9
|
+
class << self
|
10
|
+
attr_accessor :api_key,
|
11
|
+
def configure
|
12
|
+
yield self if block_given?
|
13
|
+
true
|
14
|
+
end
|
15
|
+
alias_method :config, :configure
|
16
|
+
end
|
17
|
+
end
|
metadata
CHANGED
@@ -1,23 +1,37 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resend
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.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: 2022-12-
|
11
|
+
date: 2022-12-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.20.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.20.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
16
30
|
requirements:
|
17
31
|
- - ">="
|
18
32
|
- !ruby/object:Gem::Version
|
19
33
|
version: '0'
|
20
|
-
type: :
|
34
|
+
type: :development
|
21
35
|
prerelease: false
|
22
36
|
version_requirements: !ruby/object:Gem::Requirement
|
23
37
|
requirements:
|
@@ -31,10 +45,11 @@ extensions: []
|
|
31
45
|
extra_rdoc_files: []
|
32
46
|
files:
|
33
47
|
- README.md
|
34
|
-
- lib/railresend.rb
|
35
48
|
- lib/resend.rb
|
36
49
|
- lib/resend/client.rb
|
37
50
|
- lib/resend/errors.rb
|
51
|
+
- lib/resend/mailer.rb
|
52
|
+
- lib/resend/railtie.rb
|
38
53
|
- lib/resend/version.rb
|
39
54
|
homepage: https://github.com/drish/resend-ruby
|
40
55
|
licenses:
|
data/lib/railresend.rb
DELETED