resend 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: 0edb877306c27569fda6e455102f59ae368de55b2a95e884b0c9608353488d9c
4
+ data.tar.gz: ee95e08639e0dd1d145ff8d84c50b163719f381d11295f384775b1cdafe4c5e3
5
+ SHA512:
6
+ metadata.gz: 2f1ce217a7529c5fbf27b6d84bf61036e705d57a11624f08cf6ec1683c56ce7bbad37e3013dc67fd4a607af9c3e597f1aab83121fd2b56a1c9edcc33a4bc06a6
7
+ data.tar.gz: 8fb0e506d83d1ef9ab19add603bf441508fda81dfe609e1e841ca5ba0bde812962341069ed850d7914ff7bbccddf2507961a5bb440fec5843b46e82572d13f98
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # Resend Ruby and Rails SDK
2
+
3
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
4
+ ![Build](https://github.com/drish/resend-ruby/actions/workflows/build.yml/badge.svg)
5
+ ---
6
+
7
+ ## Installation
8
+
9
+ To install Resend Ruby and Rails SDK, simply execute the following command in a terminal:
10
+
11
+ Via RubyGems:
12
+ ```
13
+ gem install resend
14
+ ```
15
+
16
+ Via Gemfile:
17
+ ```
18
+ gem 'resend', '~>0.1.0'
19
+ ```
20
+
21
+ ## Setup
22
+
23
+ First, you need to get an API key, which is available in the [Resend Dashboard](https://resend.com).
24
+
25
+ ```ruby
26
+ require "resend"
27
+ client = Resend::Client.new "re_YOUR_API_KEY"
28
+ ```
29
+
30
+ ## Example
31
+
32
+ ```rb
33
+ require "resend"
34
+
35
+ client = Resend::Client.new "re_YOUR_API_KEY"
36
+
37
+ params = {
38
+ "from": "team@recomendo.io",
39
+ "to": "carlosderich@gmail.com",
40
+ "html": "<h1>Hello World</h1>",
41
+ "subject": "Hey"
42
+ }
43
+ r = client.send_email(params)
44
+ puts r
45
+ ```
data/lib/railresend.rb ADDED
@@ -0,0 +1,4 @@
1
+ require_relative "resend/version"
2
+ require "resend/client"
3
+
4
+ module Resend;end
@@ -0,0 +1,70 @@
1
+ require_relative "./version"
2
+ require_relative "./errors"
3
+ require "httparty"
4
+
5
+ module Resend
6
+
7
+ class Client
8
+ BASE_URL = "https://api.klotty.com/".freeze
9
+
10
+ attr_reader :api_key, :base_url, :timeout
11
+
12
+ def initialize(api_key)
13
+ raise ArgumentError.new("API Key is not a string") unless api_key.is_a?(String)
14
+ @api_key = api_key
15
+ @timeout = nil
16
+ end
17
+
18
+ def send_email(params)
19
+ validate!(params)
20
+
21
+ options = {
22
+ headers: {
23
+ 'Content-Type' => 'application/json',
24
+ "Accept" => "application/json",
25
+ "User-Agent" => "ruby:#{Resend::VERSION}",
26
+ "Authorization" => "Bearer #{@api_key}",
27
+ },
28
+ body: params.to_json
29
+ }
30
+
31
+ resp = HTTParty.post("#{BASE_URL}/email", options)
32
+ resp.transform_keys!(&:to_sym)
33
+ if not resp[:error].nil?
34
+ handle_error!(resp[:error])
35
+ end
36
+ resp
37
+ end
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
+ private
48
+
49
+ def validate!(params)
50
+ raise ArgumentError.new("'to' should be an Array or String") unless params[:to].is_a?(String) or params[:to].is_a?(Array)
51
+ raise ArgumentError.new("Argument 'to' is missing") if params[:to].nil?
52
+ raise ArgumentError.new("'to' can not be empty") if params[:to].empty?
53
+
54
+ raise ArgumentError.new("'from' should be a String") unless params[:from].is_a?(String)
55
+ raise ArgumentError.new("Argument 'from' is missing") if params[:from].nil?
56
+ raise ArgumentError.new("'from' can not be empty") if params[:from].empty?
57
+
58
+ raise ArgumentError.new("'from' should be a String") unless params[:from].is_a?(String)
59
+ raise ArgumentError.new("Argument 'subject' is missing") if params[:subject].nil?
60
+ raise ArgumentError.new("'subject' can not be empty") if params[:subject].empty?
61
+
62
+ raise ArgumentError.new("Argument 'text' and 'html' are missing") if params[:text].nil? and params[:html].nil?
63
+ end
64
+
65
+ def handle_error!(error)
66
+ err = error.transform_keys(&:to_sym)
67
+ raise Resend::ResendError.new(err[:message])
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,5 @@
1
+ module Resend
2
+ class ResendError < StandardError
3
+ end
4
+ end
5
+
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Resend
4
+ VERSION = "0.1.0"
5
+ end
data/lib/resend.rb ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "resend/version"
4
+ require "resend/client"
5
+
6
+ require "./railsend" if defined?(Rails) && defined?(ActionMailer)
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: resend
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Derich Pacheco
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-12-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description:
28
+ email: carlosderich@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - README.md
34
+ - lib/railresend.rb
35
+ - lib/resend.rb
36
+ - lib/resend/client.rb
37
+ - lib/resend/errors.rb
38
+ - lib/resend/version.rb
39
+ homepage: https://github.com/drish/resend-ruby
40
+ licenses:
41
+ - MIT
42
+ metadata: {}
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '2.6'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubygems_version: 3.3.11
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: The Ruby and Rails SDK for resend.com
62
+ test_files: []