resend 0.1.1 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b883c0e0caedcf14be29d0eca5a0d708cef655d1847647648014a68f9a045db8
4
- data.tar.gz: 18144a137e2f5536496d2bde9000edc0dcf5a4ae1851cad4d8970b293189b754
3
+ metadata.gz: 34d75256450dcc66c26389540c6daa09e35548aa92f597198903625050618ebe
4
+ data.tar.gz: '08e1a8961434c9cd3ebed403378e01d3ebbd8c592283055a30895d6cb9a0bbd9'
5
5
  SHA512:
6
- metadata.gz: 05bc0f823550ff12d558dc49fe216a1ef03c93cb3a14cf6633a625233c7041cda6564dc25bd1eee8f74b15b179749eef94b1f2c0afa76239e2a20e53adc4138c
7
- data.tar.gz: 41e8d96e7560f4efda6a46ec1b2bd350c63e7680cc487f31e41b57639dd9bd8fb5fb8b614ced2834a963d9f4c825abfc6e254f7e77a3b6152badf7f1ce370364
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
@@ -36,14 +36,6 @@ module Resend
36
36
  resp
37
37
  end
38
38
 
39
- # Rails #configure
40
- def configure(options)
41
- options.each do |key, value|
42
- instance_variable_set("@#{key}", value)
43
- end
44
- yield(self) if block_given?
45
- end
46
-
47
39
  private
48
40
 
49
41
  def validate!(params)
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Resend
4
- VERSION = "0.1.1"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/resend.rb CHANGED
@@ -1,6 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "resend/version"
3
+ require "resend/version"
4
4
  require "resend/client"
5
5
 
6
- require "./railsend" if defined?(Rails) && defined?(ActionMailer)
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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resend
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
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-27 00:00:00.000000000 Z
11
+ date: 2022-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.20.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  description:
28
42
  email: carlosderich@gmail.com
29
43
  executables: []
@@ -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
@@ -1,4 +0,0 @@
1
- require_relative "resend/version"
2
- require "resend/client"
3
-
4
- module Resend;end