resent 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c4f7acd5d5dae1962175ef7c965b555542a2b42049362b4a9164184e4a19ce13
4
+ data.tar.gz: '04980611b9520269bb6c46a40e74db9a279c06f5399d4d4e510e44019e407770'
5
+ SHA512:
6
+ metadata.gz: 11e60f8e51296234a12940b19d2dbe1aed0bcc076fc4fbee5e9245542ffe7f8459897d7366e9a6e76147736854c13680e3a33b32d35fec47125fa826a6d5847e
7
+ data.tar.gz: 3a698ea03305e16b257e599af745a7ddd5d6bbbca956d56560949883f88723823cb3263d01de8b1408517687e8f6907f0e0bd6be8d2feefaa3427ead1758df75
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Resent
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,82 @@
1
+ <p align="center">
2
+ <img
3
+ alt="Send emails with Ruby — Resent"
4
+ src="https://raw.githubusercontent.com/resentmail/resent-ruby/main/assets/banner.jpg"
5
+ width="100%"
6
+ />
7
+ </p>
8
+
9
+ <p align="center">
10
+ <a href="https://developers.resent.one">Documentation</a>
11
+ ·
12
+ <a href="https://resent.one">Website</a>
13
+ ·
14
+ <a href="https://rubygems.org/gems/resent">RubyGems</a>
15
+ ·
16
+ <a href="https://github.com/resentmail/resent-ruby">GitHub</a>
17
+ </p>
18
+
19
+ # Resent Ruby SDK
20
+
21
+ The official Ruby library for [Resent](https://resent.one) transactional email.
22
+
23
+ ## Install
24
+
25
+ ```bash
26
+ gem install resent
27
+ ```
28
+
29
+ Or in your Gemfile:
30
+
31
+ ```ruby
32
+ gem "resent"
33
+ ```
34
+
35
+ ```bash
36
+ bundle install
37
+ ```
38
+
39
+ ## Setup
40
+
41
+ 1. Verify a sending domain in the [Resent dashboard](https://resent.one/app/settings/domains/)
42
+ 2. Create an API key under [Settings → API keys](https://resent.one/app/settings/api-keys/)
43
+ 3. Store it as `RESENT_API_KEY`
44
+
45
+ ## Usage
46
+
47
+ ```ruby
48
+ require "resent"
49
+
50
+ resent = Resent.new(ENV.fetch("RESENT_API_KEY"))
51
+
52
+ result = resent.emails.send(
53
+ from: "Acme <noreply@yourdomain.com>",
54
+ to: "you@example.com",
55
+ subject: "Hello World",
56
+ html: "<strong>It works!</strong>"
57
+ )
58
+
59
+ puts result["submission_id"]
60
+ ```
61
+
62
+ ## Send email using HTML
63
+
64
+ ```ruby
65
+ result = resent.emails.send(
66
+ from: "Acme <noreply@yourdomain.com>",
67
+ to: ["you@example.com"],
68
+ subject: "Hello World",
69
+ html: "<strong>It works!</strong>"
70
+ )
71
+ ```
72
+
73
+ ## Docs
74
+
75
+ - [Getting started](https://developers.resent.one)
76
+ - [Send transactional email](https://developers.resent.one/guides/send-transactional-email)
77
+ - [Ruby SDK docs](https://developers.resent.one/sdks/ruby)
78
+ - [API overview](https://developers.resent.one)
79
+
80
+ ## License
81
+
82
+ MIT © [Resent](https://resent.one)
data/assets/banner.jpg ADDED
Binary file
@@ -0,0 +1,119 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require "net/http"
5
+ require "uri"
6
+
7
+ module Resent
8
+ class Error < StandardError
9
+ attr_reader :status, :body
10
+
11
+ def initialize(message, status: nil, body: nil)
12
+ super(message)
13
+ @status = status
14
+ @body = body
15
+ end
16
+ end
17
+
18
+ # Official Resent API client.
19
+ #
20
+ # resent = Resent::Client.new(ENV.fetch("RESENT_API_KEY"))
21
+ # result = resent.emails.send(
22
+ # from: "Acme <noreply@yourdomain.com>",
23
+ # to: "you@example.com",
24
+ # subject: "Hello",
25
+ # html: "<strong>It works!</strong>"
26
+ # )
27
+ class Client
28
+ DEFAULT_BASE_URL = "https://resent.one/api/v1"
29
+
30
+ attr_reader :api_key, :base_url
31
+
32
+ def initialize(api_key = nil, base_url: DEFAULT_BASE_URL)
33
+ key = (api_key || ENV["RESENT_API_KEY"]).to_s.strip
34
+ raise Error, "Missing API key. Pass Resent::Client.new(key) or set RESENT_API_KEY." if key.empty?
35
+
36
+ @api_key = key
37
+ @base_url = base_url.to_s.sub(%r{/+\z}, "")
38
+ end
39
+
40
+ def emails
41
+ Emails.new(self)
42
+ end
43
+
44
+ def request(method, path, body: nil)
45
+ uri = URI("#{@base_url}/#{path.sub(%r{\A/}, "")}")
46
+ http = Net::HTTP.new(uri.host, uri.port)
47
+ http.use_ssl = uri.scheme == "https"
48
+ http.open_timeout = 15
49
+ http.read_timeout = 30
50
+
51
+ request = case method.to_s.upcase
52
+ when "POST" then Net::HTTP::Post.new(uri)
53
+ when "GET" then Net::HTTP::Get.new(uri)
54
+ else
55
+ raise Error, "Unsupported HTTP method: #{method}"
56
+ end
57
+
58
+ request["Authorization"] = "Bearer #{api_key}"
59
+ request["Accept"] = "application/json"
60
+ request["Content-Type"] = "application/json"
61
+ request["User-Agent"] = "resent-ruby/#{VERSION}"
62
+ request.body = JSON.generate(body) if body
63
+
64
+ response = http.request(request)
65
+ parsed = parse_json(response.body)
66
+
67
+ unless response.is_a?(Net::HTTPSuccess)
68
+ message = if parsed.is_a?(Hash) && parsed["error"]
69
+ parsed["error"].to_s
70
+ else
71
+ "Resent API error (#{response.code})"
72
+ end
73
+ raise Error.new(message, status: response.code.to_i, body: parsed)
74
+ end
75
+
76
+ parsed
77
+ end
78
+
79
+ private
80
+
81
+ def parse_json(raw)
82
+ return {} if raw.nil? || raw.strip.empty?
83
+
84
+ JSON.parse(raw)
85
+ rescue JSON::ParserError
86
+ { "raw" => raw }
87
+ end
88
+ end
89
+
90
+ class Emails
91
+ def initialize(client)
92
+ @client = client
93
+ end
94
+
95
+ # Send a transactional email.
96
+ #
97
+ # Required: from, to, subject, and html and/or text.
98
+ def send(from:, to:, subject:, html: nil, text: nil, cc: nil, bcc: nil, reply_to: nil)
99
+ to_list = Array(to).map { |v| v.to_s.strip }.reject(&:empty?)
100
+ raise Error, "from is required" if from.to_s.strip.empty?
101
+ raise Error, "to is required" if to_list.empty?
102
+ raise Error, "subject is required" if subject.to_s.strip.empty?
103
+ raise Error, "html or text body is required" if html.to_s.strip.empty? && text.to_s.strip.empty?
104
+
105
+ payload = {
106
+ "from" => from.to_s.strip,
107
+ "to" => to_list,
108
+ "subject" => subject.to_s
109
+ }
110
+ payload["html"] = html if html && !html.to_s.empty?
111
+ payload["text"] = text if text && !text.to_s.empty?
112
+ payload["cc"] = Array(cc) if cc
113
+ payload["bcc"] = Array(bcc) if bcc
114
+ payload["reply_to"] = reply_to if reply_to
115
+
116
+ @client.request("POST", "email/send", body: payload)
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Resent
4
+ VERSION = "0.1.0"
5
+ end
data/lib/resent.rb ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "resent/version"
4
+ require_relative "resent/client"
5
+
6
+ # Convenience alias matching other SDKs:
7
+ # resent = Resent.new(ENV["RESENT_API_KEY"])
8
+ module Resent
9
+ def self.new(api_key = nil, base_url: Client::DEFAULT_BASE_URL)
10
+ Client.new(api_key, base_url: base_url)
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: resent
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Resent
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-07-26 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Send transactional email with the Resent API from Ruby. Verify a domain,
14
+ set RESENT_API_KEY, then call Resent::Client#emails.send.
15
+ email:
16
+ - hello@resent.one
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - LICENSE
22
+ - README.md
23
+ - assets/banner.jpg
24
+ - lib/resent.rb
25
+ - lib/resent/client.rb
26
+ - lib/resent/version.rb
27
+ homepage: https://resent.one
28
+ licenses:
29
+ - MIT
30
+ metadata:
31
+ homepage_uri: https://resent.one
32
+ source_code_uri: https://github.com/resentmail/resent-ruby
33
+ changelog_uri: https://github.com/resentmail/resent-ruby
34
+ documentation_uri: https://developers.resent.one/sdks/ruby
35
+ bug_tracker_uri: https://github.com/resentmail/resent-ruby/issues
36
+ post_install_message:
37
+ rdoc_options: []
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: 2.6.0
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubygems_version: 3.0.3.1
52
+ signing_key:
53
+ specification_version: 4
54
+ summary: Official Ruby SDK for Resent transactional email
55
+ test_files: []