resend 0.1.1 → 0.2.1

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: aab8a1f078990a6a2c6e40c01f4b72771915d74e5ad8fa19fec67d9e0d00dc7e
4
+ data.tar.gz: c440488de4a502b5abf3fbe79a83cd3535039fab30533308176f7b39b24477df
5
5
  SHA512:
6
- metadata.gz: 05bc0f823550ff12d558dc49fe216a1ef03c93cb3a14cf6633a625233c7041cda6564dc25bd1eee8f74b15b179749eef94b1f2c0afa76239e2a20e53adc4138c
7
- data.tar.gz: 41e8d96e7560f4efda6a46ec1b2bd350c63e7680cc487f31e41b57639dd9bd8fb5fb8b614ced2834a963d9f4c825abfc6e254f7e77a3b6152badf7f1ce370364
6
+ metadata.gz: 577cb058bcada5f1cb56820c7ae1a6ba0f93da4035b1ac82d487fc3768a3c9b77a091a76b9cb5a91d5cb4a0331c8d6294f1b629ac40e86e6452e2d99c237b765
7
+ data.tar.gz: 037aa163eea257ab8c8a779d58dad4bbc166d69d979d258a578843d3229a35d5a90b337d4dd0d4d8680d27707c2ead0be5b8142fa7cf190ab4bbc0674a4149ca
data/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
4
4
  ![Build](https://github.com/drish/resend-ruby/actions/workflows/build.yml/badge.svg)
5
+ [![Gem Version](https://badge.fury.io/rb/resend.svg)](https://badge.fury.io/rb/resend)
5
6
  ---
6
7
 
7
8
  ## Installation
@@ -15,7 +16,7 @@ gem install resend
15
16
 
16
17
  Via Gemfile:
17
18
  ```
18
- gem 'resend', '~>0.1.0'
19
+ gem 'resend', '~>0.2.1'
19
20
  ```
20
21
 
21
22
  ## Setup
@@ -42,4 +43,44 @@ params = {
42
43
  }
43
44
  r = client.send_email(params)
44
45
  puts r
45
- ```
46
+ ```
47
+
48
+ # Rails and ActiveMailer support
49
+
50
+ 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.
51
+
52
+ ```ruby
53
+ config.action_mailer.delivery_method = :resend
54
+ config.action_mailer.resend_settings = {
55
+ api_key: 'resend_api_key',
56
+ }
57
+ ```
58
+
59
+ After that you can deliver_now!, example below:
60
+
61
+ ```ruby
62
+ #/app/mailers/user_mailer
63
+ class UserMailer < ApplicationMailer
64
+ default from: 'you@yourdomain.io'
65
+ def welcome_email
66
+ @user = params[:user]
67
+ @url = 'http://example.com/login'
68
+ mail(to: ["example2@mail.com", "example1@mail.com"], subject: 'Hello from Resend')
69
+ end
70
+ end
71
+
72
+ # anywhere in the app
73
+ u = User.new name: "derich"
74
+ mailer = UserMailer.with(user: u).welcome_email
75
+ mailer.deliver_now!
76
+ # => {:id=>"b8f94710-0d84-429c-925a-22d3d8f86916", from: 'you@yourdomain.io', to: ["example2@mail.com", "example1@mail.com"]}
77
+ ```
78
+
79
+ This gem can also be initialized with a Rails initializer file, example below:
80
+
81
+ ```ruby
82
+ # /app/initializers/mailer.rb
83
+ Resend.configure do |config|
84
+ config.api_key = 'resend_api_key'
85
+ end
86
+ ```
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].to_s if mail[:cc].present?
22
+ params[:bcc] = mail[:bcc].to_s if mail[:bcc].present?
23
+ params[:reply_to] = mail[:reply_to].to_s 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.1"
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.1
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: 2023-03-02 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:
@@ -55,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
70
  - !ruby/object:Gem::Version
56
71
  version: '0'
57
72
  requirements: []
58
- rubygems_version: 3.3.11
73
+ rubygems_version: 3.4.6
59
74
  signing_key:
60
75
  specification_version: 4
61
76
  summary: The Ruby and Rails SDK for resend.com
data/lib/railresend.rb DELETED
@@ -1,4 +0,0 @@
1
- require_relative "resend/version"
2
- require "resend/client"
3
-
4
- module Resend;end