resend 0.4.0 → 0.6.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: e3e46d09490b1ad19c59f04e55fd16b0da3d3c2573ed5c9dcba3297f0f92f5fc
4
- data.tar.gz: 6c9dfb7910fd6199bc9c75aa9f3c2e9200677ce9e2ba1e9a29e124908489e714
3
+ metadata.gz: 154948a83edaf33d2c541d663519984ce81c88de1dfdce855d6a57b495841e19
4
+ data.tar.gz: 77ff14940114642d5099134f4c9ea7eb6a504f9c2f088f208b3492df0238d481
5
5
  SHA512:
6
- metadata.gz: 58e0cdd7ae1d48654ff33761b1fcb8a4e96061142d154232f85bac348c38956505d11ee3a0cdf6d86592389d2d8c69eba48941d7d97e1c4de904d0c8b5b6d7a6
7
- data.tar.gz: 2069dfd99a67245da05ebf8e58658c2771de51cd6999d8d824116174b0aeba38dcc4f4423f05cb73e63388f5497377dba4c4b98eebddba2b2205864530790d3a
6
+ metadata.gz: 1e4b18829fce8858425ed271eb6608e72ee00e66391d2530e868503389c66e05acb4f65d92f0ca0454abb01c40e2d58742907d628d230bc47d37f0da863290cf
7
+ data.tar.gz: ddc74f6a84b63ffc26914d1230b697d04759cea952c14d3e7ec6a8743267850532303eb8260fa7db19e215bc8253b1dfa93f57a8e693e4d8121953721e8e7734
data/README.md CHANGED
@@ -16,7 +16,7 @@ gem install resend
16
16
 
17
17
  Via Gemfile:
18
18
  ```
19
- gem 'resend', '~>0.3.0'
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 and replace with your api key.
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
- config.action_mailer.resend_settings = {
67
- api_key: 'resend_api_key',
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
- ```
@@ -9,19 +9,19 @@ module Resend
9
9
  class << self
10
10
  # https://resend.com/docs/api-reference/api-keys/create-api-key
11
11
  def create(params)
12
- path = "/api-keys"
12
+ path = "api-keys"
13
13
  Resend::Request.new(path, params, "post").perform
14
14
  end
15
15
 
16
16
  # https://resend.com/docs/api-reference/api-keys/list-api-keys
17
17
  def list
18
- path = "/api-keys"
18
+ path = "api-keys"
19
19
  Resend::Request.new(path, {}, "get").perform
20
20
  end
21
21
 
22
22
  # https://resend.com/docs/api-reference/api-keys/delete-api-key
23
23
  def remove(api_key_id = "")
24
- path = "/api-keys/#{api_key_id}"
24
+ path = "api-keys/#{api_key_id}"
25
25
  Resend::Request.new(path, {}, "delete").perform
26
26
  end
27
27
  end
@@ -9,25 +9,31 @@ module Resend
9
9
  class << self
10
10
  # https://resend.com/docs/api-reference/domains/create-domain
11
11
  def create(params)
12
- path = "/domains"
12
+ path = "domains"
13
13
  Resend::Request.new(path, params, "post").perform
14
14
  end
15
15
 
16
+ # https://resend.com/docs/api-reference/domains/get-domain
17
+ def get(domain_id = "")
18
+ path = "domains/#{domain_id}"
19
+ Resend::Request.new(path, {}, "get").perform
20
+ end
21
+
16
22
  # https://resend.com/docs/api-reference/api-keys/list-api-keys
17
23
  def list
18
- path = "/domains"
24
+ path = "domains"
19
25
  Resend::Request.new(path, {}, "get").perform
20
26
  end
21
27
 
22
28
  # https://resend.com/docs/api-reference/domains/delete-domain
23
29
  def remove(domain_id = "")
24
- path = "/domains/#{domain_id}"
30
+ path = "domains/#{domain_id}"
25
31
  Resend::Request.new(path, {}, "delete").perform
26
32
  end
27
33
 
28
34
  # https://resend.com/docs/api-reference/domains/verify-domain
29
35
  def verify(domain_id = "")
30
- path = "/domains/#{domain_id}/verify"
36
+ path = "domains/#{domain_id}/verify"
31
37
  Resend::Request.new(path, {}, "post").perform
32
38
  end
33
39
  end
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
@@ -5,13 +5,11 @@ require "resend"
5
5
  module Resend
6
6
  # Mailer class used by railtie
7
7
  class Mailer
8
- attr_accessor :config, :settings
8
+ attr_accessor :config
9
9
 
10
10
  def initialize(config)
11
11
  @config = config
12
- raise Resend::ResendError.new("Config requires api_key", @config) unless @config.key?(:api_key)
13
-
14
- @settings = { return_response: true } # avoids NilError exception
12
+ raise Resend::Error.new("Make sure your api is set", @config) unless Resend.api_key
15
13
  end
16
14
 
17
15
  def deliver!(mail)
@@ -31,10 +31,11 @@ module Resend
31
31
  options = {
32
32
  headers: @headers
33
33
  }
34
+
34
35
  options[:body] = @body.to_json unless @body.empty?
35
36
  resp = HTTParty.send(@verb.to_sym, "#{BASE_URL}#{@path}", options)
36
37
  resp.transform_keys!(&:to_sym) unless resp.body.empty?
37
- handle_error!(resp) if resp[:statusCode] && resp[:statusCode] != 200
38
+ handle_error!(resp) if resp[:statusCode] && (resp[:statusCode] != 200 || resp[:statusCode] != 201)
38
39
  resp
39
40
  end
40
41
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Resend
4
- VERSION = "0.4.0"
4
+ VERSION = "0.6.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.4.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derich Pacheco
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-20 00:00:00.000000000 Z
11
+ date: 2023-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -38,7 +38,7 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description:
41
+ description:
42
42
  email: carlosderich@gmail.com
43
43
  executables: []
44
44
  extensions: []
@@ -59,7 +59,7 @@ homepage: https://github.com/resendlabs/resend-ruby
59
59
  licenses:
60
60
  - MIT
61
61
  metadata: {}
62
- post_install_message:
62
+ post_install_message:
63
63
  rdoc_options: []
64
64
  require_paths:
65
65
  - lib
@@ -74,8 +74,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  requirements: []
77
- rubygems_version: 3.4.6
78
- signing_key:
77
+ rubygems_version: 3.0.3.1
78
+ signing_key:
79
79
  specification_version: 4
80
80
  summary: The Ruby and Rails SDK for resend.com
81
81
  test_files: []