resend 0.12.0 → 0.14.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: 5bd8ec3527247e6ccc2315a7f3f6883ea45f769a9a6576d6a0a4c9e941c85885
4
- data.tar.gz: 25eac271e0761626a3acfdb9f5081bf7beee4c78cfe4c12fd09e3ca029fbafdb
3
+ metadata.gz: f0e67dbad71b9cb9f973da1f6502eb56200d7f1b14c04d61e54a2667c9fa6256
4
+ data.tar.gz: 7e451c94a32672e28c01ee30fcb21c1a03fdedc714b7ea89ef1e37af8bc8633c
5
5
  SHA512:
6
- metadata.gz: 2a457f66b1430ce5c5fcc229f8af3a4fec83b6463dc6f2eb4ba1800c307c6073ea35fe52f0e0ceb259329ada364d6ab2b8a3886fc570edbdac0aba1f1bbf0187
7
- data.tar.gz: c6555f83fa665267e7e37367bd67d0af50a3f1dd26b1c73be1b60a554c43ced15bdf104fd4be89168510c6ec7d4598f17175c5c9e5e65415abcbeeb45031ba04
6
+ metadata.gz: 9fdb85310827bfde2e36ac65c5715ec45e503d151ec49ea56f6395fbccf1b967916b59039e9bd80566b8ec1babe706e7737130ef68f976b31693049b708ab0c6
7
+ data.tar.gz: f5cab30d484e6dd386da48f16b7ac03c207c8a975a3d7550e84642e0872222c5510d399f38b44746546b04d1a78ee8da07bed6af5347bf2566f05599c94acbc8
data/lib/resend/emails.rb CHANGED
@@ -6,17 +6,33 @@ module Resend
6
6
  # Module responsible for wrapping email sending API
7
7
  module Emails
8
8
  class << self
9
- # send email functionality
10
- # https://resend.com/docs/api-reference/send-email
9
+ # Sends or schedules an email.
10
+ # see more: https://resend.com/docs/api-reference/send-email
11
11
  def send(params)
12
12
  path = "emails"
13
13
  Resend::Request.new(path, params, "post").perform
14
14
  end
15
15
 
16
+ # Retrieve a single email.
17
+ # see more: https://resend.com/docs/api-reference/emails/retrieve-email
16
18
  def get(email_id = "")
17
19
  path = "emails/#{email_id}"
18
20
  Resend::Request.new(path, {}, "get").perform
19
21
  end
22
+
23
+ # Update a scheduled email.
24
+ # see more: https://resend.com/docs/api-reference/emails/update-email
25
+ def update(params)
26
+ path = "emails/#{params[:email_id]}"
27
+ Resend::Request.new(path, params, "patch").perform
28
+ end
29
+
30
+ # Cancel a scheduled email.
31
+ # see more: https://resend.com/docs/api-reference/emails/cancel-email
32
+ def cancel(email_id = "")
33
+ path = "emails/#{email_id}/cancel"
34
+ Resend::Request.new(path, {}, "post").perform
35
+ end
20
36
  end
21
37
 
22
38
  # This method is kept here for backwards compatibility
@@ -34,6 +34,9 @@ module Resend
34
34
 
35
35
  options[:body] = @body.to_json unless @body.empty?
36
36
  resp = HTTParty.send(@verb.to_sym, "#{BASE_URL}#{@path}", options)
37
+
38
+ check_json!(resp)
39
+
37
40
  resp.transform_keys!(&:to_sym) unless resp.body.empty?
38
41
  handle_error!(resp) if resp[:statusCode] && (resp[:statusCode] != 200 || resp[:statusCode] != 201)
39
42
  resp
@@ -45,5 +48,17 @@ module Resend
45
48
  error = Resend::Error::ERRORS[code]
46
49
  raise(error.new(body, code)) if error
47
50
  end
51
+
52
+ private
53
+
54
+ def check_json!(resp)
55
+ if resp.body.is_a?(Hash)
56
+ JSON.parse(resp.body.to_json)
57
+ else
58
+ JSON.parse(resp.body)
59
+ end
60
+ rescue JSON::ParserError, TypeError
61
+ raise Resend::Error::InternalServerError.new("Resend API returned an unexpected response", nil)
62
+ end
48
63
  end
49
64
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Resend
4
- VERSION = "0.12.0"
4
+ VERSION = "0.14.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.12.0
4
+ version: 0.14.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-06-10 00:00:00.000000000 Z
11
+ date: 2024-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty