resend 0.14.0 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f0e67dbad71b9cb9f973da1f6502eb56200d7f1b14c04d61e54a2667c9fa6256
4
- data.tar.gz: 7e451c94a32672e28c01ee30fcb21c1a03fdedc714b7ea89ef1e37af8bc8633c
3
+ metadata.gz: 67fb549176718ac10025dad2b41cba2519de04a0890631950c4f2d022e6106f8
4
+ data.tar.gz: de3d5e59326e9ae9fdd1e5d4d0b507a147ecc95aa3ed6db918e4a5f40894d782
5
5
  SHA512:
6
- metadata.gz: 9fdb85310827bfde2e36ac65c5715ec45e503d151ec49ea56f6395fbccf1b967916b59039e9bd80566b8ec1babe706e7737130ef68f976b31693049b708ab0c6
7
- data.tar.gz: f5cab30d484e6dd386da48f16b7ac03c207c8a975a3d7550e84642e0872222c5510d399f38b44746546b04d1a78ee8da07bed6af5347bf2566f05599c94acbc8
6
+ metadata.gz: 77ae6d4b92169173fef0d18661de7e873fdb6c2e33291a0676a5a2ef622845bec3bfff815e63fda76ec6c5f8fb5f267df60b64fa62812544e100ceaa79bd916b
7
+ data.tar.gz: a2dbe3619bf9958234a96299909937de98a752fe61678fb8d0082d83ba845828ca12fdc593b92c52fffbf98dd9139db9283957a45659aa8b4aba2d4ae5582c9b
data/README.md CHANGED
@@ -3,6 +3,7 @@
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
5
  [![Gem Version](https://badge.fury.io/rb/resend.svg)](https://badge.fury.io/rb/resend)
6
+
6
7
  ---
7
8
 
8
9
  ## Installation
@@ -10,11 +11,13 @@
10
11
  To install Resend Ruby and Rails SDK, simply execute the following command in a terminal:
11
12
 
12
13
  Via RubyGems:
14
+
13
15
  ```
14
16
  gem install resend
15
17
  ```
16
18
 
17
19
  Via Gemfile:
20
+
18
21
  ```
19
22
  gem 'resend'
20
23
  ```
@@ -37,6 +40,19 @@ Resend.configure do |config|
37
40
  end
38
41
  ```
39
42
 
43
+ The `#api_key` method also accepts a block without arguments, which can be useful for lazy or dynamic loading of API keys.
44
+
45
+ ```ruby
46
+ require "resend"
47
+ Resend.api_key = -> { ENV["RESEND_API_KEY"] }
48
+ ```
49
+
50
+ ```ruby
51
+ Resend.configure do |config|
52
+ config.api_key = -> { Current.user.resend_api_key } # Assumes the user has a `resend_api_key` attribute.
53
+ end
54
+ ```
55
+
40
56
  ## Example
41
57
 
42
58
  ```rb
@@ -56,7 +72,6 @@ puts r
56
72
 
57
73
  You can view all the examples in the [examples folder](https://github.com/drish/resend-ruby/tree/main/examples)
58
74
 
59
-
60
75
  # Rails and ActiveMailer support
61
76
 
62
77
  This gem can be used as an ActionMailer delivery method, add this to your `config/environments/environment.rb` file.
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "resend/request"
4
+ require "resend/errors"
5
+
6
+ module Resend
7
+ # broadcasts api wrapper
8
+ module Broadcasts
9
+ class << self
10
+ # https://resend.com/docs/api-reference/broadcasts/create-broadcast
11
+ def create(params = {})
12
+ path = "broadcasts"
13
+ Resend::Request.new(path, params, "post").perform
14
+ end
15
+
16
+ # https://resend.com/docs/api-reference/broadcasts/send-broadcast
17
+ def send(params = {})
18
+ path = "broadcasts/#{params[:broadcast_id]}/send"
19
+ Resend::Request.new(path, params, "post").perform
20
+ end
21
+
22
+ # https://resend.com/docs/api-reference/broadcasts/list-broadcasts
23
+ def list
24
+ path = "broadcasts"
25
+ Resend::Request.new(path, {}, "get").perform
26
+ end
27
+
28
+ # https://resend.com/docs/api-reference/broadcasts/delete-broadcast
29
+ def remove(broadcast_id = "")
30
+ path = "broadcasts/#{broadcast_id}"
31
+ Resend::Request.new(path, {}, "delete").perform
32
+ end
33
+
34
+ # https://resend.com/docs/api-reference/broadcasts/get-broadcast
35
+ def get(broadcast_id = "")
36
+ path = "broadcasts/#{broadcast_id}"
37
+ Resend::Request.new(path, {}, "get").perform
38
+ end
39
+ end
40
+ end
41
+ end
data/lib/resend/client.rb CHANGED
@@ -1,11 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "resend/audiences"
3
4
  require "resend/api_keys"
4
- require "resend/domains"
5
- require "resend/emails"
5
+ require "resend/broadcasts"
6
6
  require "resend/batch"
7
- require "resend/audiences"
8
7
  require "resend/contacts"
8
+ require "resend/domains"
9
+ require "resend/emails"
9
10
  require "httparty"
10
11
 
11
12
  module Resend
data/lib/resend/mailer.rb CHANGED
@@ -44,6 +44,7 @@ module Resend
44
44
  }
45
45
  params.merge!(get_addons(mail))
46
46
  params.merge!(get_headers(mail))
47
+ params.merge!(get_tags(mail))
47
48
  params[:attachments] = get_attachments(mail) if mail.attachments.present?
48
49
  params.merge!(get_contents(mail))
49
50
  params
@@ -62,6 +63,19 @@ module Resend
62
63
  params
63
64
  end
64
65
 
66
+ #
67
+ # Add tags fields
68
+ #
69
+ # @param Mail mail Rails Mail object
70
+ #
71
+ # @return Hash hash with tags param
72
+ #
73
+ def get_tags(mail)
74
+ params = {}
75
+ params[:tags] = mail[:tags].unparsed_value if mail[:tags].present?
76
+ params
77
+ end
78
+
65
79
  #
66
80
  # Add cc, bcc, reply_to fields
67
81
  #
@@ -13,7 +13,9 @@ module Resend
13
13
  attr_accessor :body, :verb
14
14
 
15
15
  def initialize(path = "", body = {}, verb = "POST")
16
- raise if Resend.api_key.nil?
16
+ raise if (api_key = Resend.api_key).nil?
17
+
18
+ api_key = api_key.call if api_key.is_a?(Proc)
17
19
 
18
20
  @path = path
19
21
  @body = body
@@ -22,7 +24,7 @@ module Resend
22
24
  "Content-Type" => "application/json",
23
25
  "Accept" => "application/json",
24
26
  "User-Agent" => "resend-ruby:#{Resend::VERSION}",
25
- "Authorization" => "Bearer #{Resend.api_key}"
27
+ "Authorization" => "Bearer #{api_key}"
26
28
  }
27
29
  end
28
30
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Resend
4
- VERSION = "0.14.0"
4
+ VERSION = "0.16.0"
5
5
  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.14.0
4
+ version: 0.16.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: 2024-11-08 00:00:00.000000000 Z
11
+ date: 2024-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -49,6 +49,7 @@ files:
49
49
  - lib/resend/api_keys.rb
50
50
  - lib/resend/audiences.rb
51
51
  - lib/resend/batch.rb
52
+ - lib/resend/broadcasts.rb
52
53
  - lib/resend/client.rb
53
54
  - lib/resend/contacts.rb
54
55
  - lib/resend/domains.rb