isend 1.0.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: b77ca55ae43e1aa40d4dfa688b159ac63061d4c5e448e9905a6fcb39e74dc1ae
4
+ data.tar.gz: 70cd3a62700318fb01464050153e4cf6f774ed84796d54300e51b7c8bcccb4af
5
+ SHA512:
6
+ metadata.gz: bfa0d7d258258a0c7b6d82f3e16d4d2b13094f2bfce38767831bb300c89df70d404097b13ed26f8fe6fb400a4b96536065441ad79a899a49e5baf58cd0f360c5
7
+ data.tar.gz: 9855d39bf75487512affd620d6d7556fffb803b668c1b5d80b82f3387793ee3be86e5f0f2df5e83a577bf1e101f72b3ab9d611d7bf5c008e610216ad831789dd
data/CHANGELOG.md ADDED
@@ -0,0 +1,25 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [1.0.0] - 2024-01-01
9
+
10
+ ### Added
11
+ - Initial release of the Ruby SDK
12
+ - `ISend::Client` class for sending emails via isend.ai API
13
+ - Support for template-based email sending
14
+ - Custom exception classes for error handling
15
+ - Rails integration examples
16
+ - Comprehensive documentation and examples
17
+ - HTTParty integration for HTTP requests
18
+ - Configuration options including timeout settings
19
+
20
+ ### Features
21
+ - Send emails using template IDs
22
+ - Data mapping for template variables
23
+ - Proper error handling with custom exceptions
24
+ - Easy integration with Rails applications
25
+ - Background job support examples
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 isend.ai
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,213 @@
1
+ # isend.ai Ruby SDK
2
+
3
+ A simple Ruby SDK for sending emails through isend.ai using various email connectors like AWS SES, SendGrid, Mailgun, and more.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'isend'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```bash
16
+ $ bundle install
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```bash
22
+ $ gem install isend
23
+ ```
24
+
25
+ ## Quick Start
26
+
27
+ ```ruby
28
+ require 'isend'
29
+
30
+ # Initialize the client
31
+ client = ISend::Client.new('your-api-key-here')
32
+
33
+ # Send email using template
34
+ email_data = {
35
+ template_id: 124,
36
+ to: 'hi@isend.ai',
37
+ dataMapping: {
38
+ name: 'ISend'
39
+ }
40
+ }
41
+
42
+ response = client.send_email(email_data)
43
+ puts response
44
+ ```
45
+
46
+ ## Usage
47
+
48
+ ### Send Email Using Template
49
+
50
+ ```ruby
51
+ email_data = {
52
+ template_id: 124,
53
+ to: 'hi@isend.ai',
54
+ dataMapping: {
55
+ name: 'ISend'
56
+ }
57
+ }
58
+
59
+ response = client.send_email(email_data)
60
+ ```
61
+
62
+ ### With Configuration Options
63
+
64
+ ```ruby
65
+ client = ISend::Client.new('your-api-key-here', timeout: 60)
66
+
67
+ email_data = {
68
+ template_id: 124,
69
+ to: 'hi@isend.ai',
70
+ dataMapping: {
71
+ name: 'ISend',
72
+ company: 'Your Company'
73
+ }
74
+ }
75
+
76
+ response = client.send_email(email_data)
77
+ ```
78
+
79
+ ## API Reference
80
+
81
+ ### ISend::Client
82
+
83
+ #### Constructor
84
+ ```ruby
85
+ ISend::Client.new(api_key, config = {})
86
+ ```
87
+
88
+ **Parameters:**
89
+ - `api_key` (String): Your isend.ai API key
90
+ - `config` (Hash): Additional configuration options
91
+ - `timeout` (Integer): Request timeout in seconds (default: 30)
92
+
93
+ #### Methods
94
+
95
+ ##### send_email(email_data)
96
+ Sends an email using the provided template and data.
97
+
98
+ **Parameters:**
99
+ - `email_data` (Hash): Email data including:
100
+ - `template_id` (Integer): The template ID to use
101
+ - `to` (String): Recipient email address
102
+ - `dataMapping` (Hash): Data mapping for template variables
103
+
104
+ **Returns:**
105
+ - `Hash`: Response from the API
106
+
107
+ ## Error Handling
108
+
109
+ The SDK raises custom exceptions for different error types:
110
+
111
+ ```ruby
112
+ begin
113
+ response = client.send_email({
114
+ template_id: 124,
115
+ to: 'hi@isend.ai',
116
+ dataMapping: {
117
+ name: 'ISend'
118
+ }
119
+ })
120
+ rescue ISend::InvalidArgumentError => e
121
+ puts "Invalid argument: #{e.message}"
122
+ rescue ISend::ApiError => e
123
+ puts "API error: #{e.message}"
124
+ rescue ISend::Error => e
125
+ puts "General error: #{e.message}"
126
+ end
127
+ ```
128
+
129
+ ### Exception Types
130
+
131
+ - `ISend::InvalidArgumentError`: Raised when invalid arguments are provided
132
+ - `ISend::ApiError`: Raised when the API request fails
133
+ - `ISend::Error`: Base exception class for all SDK errors
134
+
135
+ ## Rails Integration
136
+
137
+ ### In Rails Application
138
+
139
+ Add to your Gemfile:
140
+
141
+ ```ruby
142
+ gem 'isend'
143
+ ```
144
+
145
+ Create an initializer (`config/initializers/isend.rb`):
146
+
147
+ ```ruby
148
+ ISEND_CLIENT = ISend::Client.new(ENV['ISEND_API_KEY'])
149
+ ```
150
+
151
+ Use in your controllers or models:
152
+
153
+ ```ruby
154
+ class UserMailer
155
+ def self.send_welcome_email(user)
156
+ email_data = {
157
+ template_id: 124,
158
+ to: user.email,
159
+ dataMapping: {
160
+ name: user.name,
161
+ company: user.company
162
+ }
163
+ }
164
+
165
+ ISEND_CLIENT.send_email(email_data)
166
+ end
167
+ end
168
+ ```
169
+
170
+ ### Background Job Example
171
+
172
+ ```ruby
173
+ class EmailJob < ApplicationJob
174
+ queue_as :default
175
+
176
+ def perform(user_id, template_id)
177
+ user = User.find(user_id)
178
+
179
+ email_data = {
180
+ template_id: template_id,
181
+ to: user.email,
182
+ dataMapping: {
183
+ name: user.name
184
+ }
185
+ }
186
+
187
+ ISEND_CLIENT.send_email(email_data)
188
+ end
189
+ end
190
+ ```
191
+
192
+ ## Examples
193
+
194
+ See the `examples/` directory for complete usage examples.
195
+
196
+ ## Requirements
197
+
198
+ - Ruby 2.0 or higher
199
+ - HTTParty gem for HTTP requests
200
+
201
+ ## Development
202
+
203
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
204
+
205
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
206
+
207
+ ## Contributing
208
+
209
+ Bug reports and pull requests are welcome on GitHub at https://github.com/isend-ai/ruby-sdk. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](CODE_OF_CONDUCT.md).
210
+
211
+ ## License
212
+
213
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,73 @@
1
+ # Rails Integration Example
2
+ # This file shows how to integrate the ISend SDK with a Rails application
3
+
4
+ # In config/initializers/isend.rb
5
+ ISEND_CLIENT = ISend::Client.new(ENV['ISEND_API_KEY'])
6
+
7
+ # In app/models/user_mailer.rb
8
+ class UserMailer
9
+ def self.send_welcome_email(user)
10
+ email_data = {
11
+ template_id: 124,
12
+ to: user.email,
13
+ dataMapping: {
14
+ name: user.name,
15
+ company: user.company || 'Your Company'
16
+ }
17
+ }
18
+
19
+ ISEND_CLIENT.send_email(email_data)
20
+ end
21
+
22
+ def self.send_password_reset(user, reset_token)
23
+ email_data = {
24
+ template_id: 125,
25
+ to: user.email,
26
+ dataMapping: {
27
+ name: user.name,
28
+ reset_url: "#{ENV['APP_URL']}/reset-password?token=#{reset_token}"
29
+ }
30
+ }
31
+
32
+ ISEND_CLIENT.send_email(email_data)
33
+ end
34
+ end
35
+
36
+ # In app/jobs/email_job.rb
37
+ class EmailJob < ApplicationJob
38
+ queue_as :default
39
+
40
+ def perform(user_id, template_id, data_mapping = {})
41
+ user = User.find(user_id)
42
+
43
+ email_data = {
44
+ template_id: template_id,
45
+ to: user.email,
46
+ dataMapping: data_mapping.merge({
47
+ name: user.name,
48
+ email: user.email
49
+ })
50
+ }
51
+
52
+ ISEND_CLIENT.send_email(email_data)
53
+ end
54
+ end
55
+
56
+ # Usage in controllers
57
+ class UsersController < ApplicationController
58
+ def create
59
+ @user = User.new(user_params)
60
+
61
+ if @user.save
62
+ # Send welcome email
63
+ UserMailer.send_welcome_email(@user)
64
+
65
+ # Or use background job
66
+ EmailJob.perform_later(@user.id, 124, { company: 'Your Company' })
67
+
68
+ redirect_to @user, notice: 'User created successfully!'
69
+ else
70
+ render :new
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/isend'
4
+
5
+ # Initialize the client with your API key
6
+ client = ISend::Client.new('your-api-key-here')
7
+
8
+ # Example: Send email using template
9
+ begin
10
+ email_data = {
11
+ template_id: 124,
12
+ to: 'hi@isend.ai',
13
+ dataMapping: {
14
+ name: 'ISend'
15
+ }
16
+ }
17
+
18
+ response = client.send_email(email_data)
19
+
20
+ puts "Email sent successfully!"
21
+ puts response
22
+ rescue ISend::InvalidArgumentError => e
23
+ puts "Invalid argument: #{e.message}"
24
+ rescue ISend::ApiError => e
25
+ puts "API error: #{e.message}"
26
+ rescue ISend::Error => e
27
+ puts "General error: #{e.message}"
28
+ end
@@ -0,0 +1,84 @@
1
+ require 'httparty'
2
+ require 'json'
3
+
4
+ module ISend
5
+ class Client
6
+ include HTTParty
7
+
8
+ API_BASE_URL = 'https://www.isend.ai/api'
9
+
10
+ attr_reader :api_key, :timeout
11
+
12
+ # Create a new ISend::Client instance
13
+ #
14
+ # @param api_key [String] Your isend.ai API key
15
+ # @param config [Hash] Additional configuration options
16
+ # @option config [Integer] :timeout (30) Request timeout in seconds
17
+ # @raise [ISend::InvalidArgumentError] if API key is empty
18
+ def initialize(api_key, config = {})
19
+ if api_key.nil? || api_key.strip.empty?
20
+ raise ISend::InvalidArgumentError, 'API key is required'
21
+ end
22
+
23
+ @api_key = api_key.strip
24
+ @timeout = config[:timeout] || 30
25
+
26
+ # Configure HTTParty
27
+ self.class.base_uri API_BASE_URL
28
+ self.class.default_timeout @timeout
29
+ self.class.headers({
30
+ 'Authorization' => "Bearer #{@api_key}",
31
+ 'Content-Type' => 'application/json',
32
+ 'User-Agent' => "isend-ai-ruby-sdk/#{ISend::VERSION}"
33
+ })
34
+ end
35
+
36
+ # Send an email using isend.ai
37
+ #
38
+ # @param email_data [Hash] Email data including template_id, to, dataMapping, etc.
39
+ # @option email_data [Integer] :template_id The template ID to use
40
+ # @option email_data [String] :to Recipient email address
41
+ # @option email_data [Hash] :dataMapping Data mapping for template variables
42
+ # @return [Hash] Response from the API
43
+ # @raise [ISend::ApiError] if the API request fails
44
+ def send_email(email_data)
45
+ validate_email_data(email_data)
46
+
47
+ response = self.class.post('/send-email', {
48
+ body: email_data.to_json,
49
+ headers: { 'Content-Type' => 'application/json' }
50
+ })
51
+
52
+ handle_response(response)
53
+ end
54
+
55
+ private
56
+
57
+ def validate_email_data(email_data)
58
+ unless email_data.is_a?(Hash)
59
+ raise ISend::InvalidArgumentError, 'Email data must be a hash'
60
+ end
61
+
62
+ unless email_data[:template_id]
63
+ raise ISend::InvalidArgumentError, 'template_id is required'
64
+ end
65
+
66
+ unless email_data[:to]
67
+ raise ISend::InvalidArgumentError, 'to email address is required'
68
+ end
69
+ end
70
+
71
+ def handle_response(response)
72
+ case response.code
73
+ when 200..299
74
+ begin
75
+ JSON.parse(response.body)
76
+ rescue JSON::ParserError => e
77
+ raise ISend::ApiError, "Invalid JSON response: #{e.message}"
78
+ end
79
+ else
80
+ raise ISend::ApiError, "HTTP error #{response.code}: #{response.body}"
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,3 @@
1
+ module ISend
2
+ VERSION = "1.0.0"
3
+ end
data/lib/isend.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'httparty'
2
+ require 'json'
3
+
4
+ require_relative 'isend/client'
5
+ require_relative 'isend/version'
6
+
7
+ module ISend
8
+ class Error < StandardError; end
9
+ class InvalidArgumentError < Error; end
10
+ class ApiError < Error; end
11
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: isend
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - isend.ai
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-07-06 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.21'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.21'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.12'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.12'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.18'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.18'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '13.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '13.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.50'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.50'
97
+ description: A simple Ruby SDK for sending emails through isend.ai using various email
98
+ connectors like AWS SES, SendGrid, Mailgun, and more.
99
+ email:
100
+ - support@isend.ai
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - CHANGELOG.md
106
+ - LICENSE
107
+ - README.md
108
+ - examples/rails_integration.rb
109
+ - examples/send_email.rb
110
+ - lib/isend.rb
111
+ - lib/isend/client.rb
112
+ - lib/isend/version.rb
113
+ homepage: https://github.com/isend-ai/ruby-sdk
114
+ licenses:
115
+ - MIT
116
+ metadata:
117
+ homepage_uri: https://github.com/isend-ai/ruby-sdk
118
+ source_code_uri: https://github.com/isend-ai/ruby-sdk
119
+ changelog_uri: https://github.com/isend-ai/ruby-sdk/blob/main/CHANGELOG.md
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: 2.0.0
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubygems_version: 3.0.3.1
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: Ruby SDK for isend.ai - Send emails easily using email connectors like SES,
139
+ SendGrid, and more
140
+ test_files: []