laneful-ruby 1.1.0 → 1.2.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.
data/README.md DELETED
@@ -1,343 +0,0 @@
1
- # Laneful Ruby SDK
2
-
3
- A modern Ruby client library for the Laneful email API with support for sending emails, templates, tracking, and webhooks.
4
-
5
- ## Requirements
6
-
7
- - Ruby 3.0 or higher
8
- - Bundler (for dependency management)
9
-
10
- ## Installation
11
-
12
- ### Using Bundler
13
-
14
- Add the following to your `Gemfile`:
15
-
16
- ```ruby
17
- gem 'laneful-ruby'
18
- ```
19
-
20
- Then run:
21
-
22
- ```bash
23
- bundle install
24
- ```
25
-
26
- ### Manual Installation
27
-
28
- ```bash
29
- git clone https://github.com/lanefulhq/laneful-ruby.git
30
- cd laneful-ruby
31
- bundle install
32
- bundle exec rake install
33
- ```
34
-
35
- ## Quick Start
36
-
37
- ```ruby
38
- require 'laneful'
39
-
40
- # Create client
41
- client = Laneful::Client.new(
42
- 'https://your-endpoint.send.laneful.net',
43
- 'your-auth-token'
44
- )
45
-
46
- # Create email
47
- email = Laneful::Email::Builder.new
48
- .from(Laneful::Address.new('sender@example.com', 'Your Name'))
49
- .to(Laneful::Address.new('recipient@example.com', 'Recipient Name'))
50
- .subject('Hello from Laneful Ruby SDK!')
51
- .text_content('This is a simple test email.')
52
- .build
53
-
54
- # Send email
55
- response = client.send_email(email)
56
- puts "Email sent successfully!"
57
- ```
58
-
59
- ## Features
60
-
61
- - Send single or multiple emails
62
- - Plain text and HTML content
63
- - Email templates with dynamic data
64
- - File attachments
65
- - Email tracking (opens, clicks, unsubscribes)
66
- - Custom headers and reply-to addresses
67
- - Scheduled sending
68
- - Webhook signature verification
69
- - Comprehensive error handling
70
- - Modern Ruby 3.0+ features
71
-
72
- ## Examples
73
-
74
- ### Simple Text Email
75
-
76
- ```ruby
77
- email = Laneful::Email::Builder.new
78
- .from(Laneful::Address.new('sender@example.com'))
79
- .to(Laneful::Address.new('user@example.com'))
80
- .subject('Simple Email')
81
- .text_content('This is a simple text email.')
82
- .build
83
-
84
- response = client.send_email(email)
85
- ```
86
-
87
- ### HTML Email with Tracking
88
-
89
- ```ruby
90
- tracking = Laneful::TrackingSettings.new(opens: true, clicks: true, unsubscribes: false)
91
-
92
- email = Laneful::Email::Builder.new
93
- .from(Laneful::Address.new('sender@example.com'))
94
- .to(Laneful::Address.new('user@example.com'))
95
- .subject('HTML Email with Tracking')
96
- .html_content('<h1>Welcome!</h1><p>This is an <strong>HTML email</strong> with tracking enabled.</p>')
97
- .text_content('Welcome! This is an HTML email with tracking enabled.')
98
- .tracking(tracking)
99
- .build
100
-
101
- response = client.send_email(email)
102
- ```
103
-
104
- ### Template Email
105
-
106
- ```ruby
107
- email = Laneful::Email::Builder.new
108
- .from(Laneful::Address.new('sender@example.com'))
109
- .to(Laneful::Address.new('user@example.com'))
110
- .template_id('welcome-template')
111
- .template_data({
112
- 'name' => 'John Doe',
113
- 'company' => 'Acme Corp'
114
- })
115
- .build
116
-
117
- response = client.send_email(email)
118
- ```
119
-
120
- ### Email with Attachments
121
-
122
- ```ruby
123
- # Create attachment from file
124
- attachment = Laneful::Attachment.from_file('/path/to/document.pdf')
125
-
126
- email = Laneful::Email::Builder.new
127
- .from(Laneful::Address.new('sender@example.com'))
128
- .to(Laneful::Address.new('user@example.com'))
129
- .subject('Document Attached')
130
- .text_content('Please find the document attached.')
131
- .attachment(attachment)
132
- .build
133
-
134
- response = client.send_email(email)
135
- ```
136
-
137
- ### Multiple Recipients
138
-
139
- ```ruby
140
- email = Laneful::Email::Builder.new
141
- .from(Laneful::Address.new('sender@example.com'))
142
- .to(Laneful::Address.new('user1@example.com'))
143
- .to(Laneful::Address.new('user2@example.com', 'User Two'))
144
- .cc(Laneful::Address.new('cc@example.com'))
145
- .bcc(Laneful::Address.new('bcc@example.com'))
146
- .subject('Multiple Recipients')
147
- .text_content('This email has multiple recipients.')
148
- .build
149
-
150
- response = client.send_email(email)
151
- ```
152
-
153
- ### Scheduled Email
154
-
155
- ```ruby
156
- # Schedule for 24 hours from now
157
- send_time = Time.now.to_i + (24 * 60 * 60)
158
-
159
- email = Laneful::Email::Builder.new
160
- .from(Laneful::Address.new('sender@example.com'))
161
- .to(Laneful::Address.new('user@example.com'))
162
- .subject('Scheduled Email')
163
- .text_content('This email was scheduled.')
164
- .send_time(send_time)
165
- .build
166
-
167
- response = client.send_email(email)
168
- ```
169
-
170
- ### Multiple Emails
171
-
172
- ```ruby
173
- emails = [
174
- Laneful::Email::Builder.new
175
- .from(Laneful::Address.new('sender@example.com'))
176
- .to(Laneful::Address.new('user1@example.com'))
177
- .subject('Email 1')
178
- .text_content('First email content.')
179
- .build,
180
- Laneful::Email::Builder.new
181
- .from(Laneful::Address.new('sender@example.com'))
182
- .to(Laneful::Address.new('user2@example.com'))
183
- .subject('Email 2')
184
- .text_content('Second email content.')
185
- .build
186
- ]
187
-
188
- response = client.send_emails(emails)
189
- ```
190
-
191
- ### Custom Timeout
192
-
193
- ```ruby
194
- client = Laneful::Client.new(
195
- 'https://your-endpoint.send.laneful.net',
196
- 'your-auth-token',
197
- timeout: 60 # 60 second timeout
198
- )
199
- ```
200
-
201
- ## Webhook Verification
202
-
203
- ```ruby
204
- # In your webhook handler
205
- payload = request.body.read
206
- signature = request.headers['x-webhook-signature']
207
- secret = 'your-webhook-secret'
208
-
209
- if Laneful::WebhookVerifier.verify_signature(secret, payload, signature)
210
- # Process webhook data
211
- data = JSON.parse(payload)
212
- # Handle webhook event
213
- else
214
- # Invalid signature
215
- head :unauthorized
216
- end
217
- ```
218
-
219
- ## Error Handling
220
-
221
- ```ruby
222
- begin
223
- response = client.send_email(email)
224
- puts "Email sent successfully"
225
- rescue Laneful::ValidationException => e
226
- puts "Validation error: #{e.message}"
227
- rescue Laneful::ApiException => e
228
- puts "API error: #{e.message}"
229
- puts "Status code: #{e.status_code}"
230
- puts "Error message: #{e.error_message}"
231
- rescue Laneful::HttpException => e
232
- puts "HTTP error: #{e.message}"
233
- puts "Status code: #{e.status_code}"
234
- rescue StandardError => e
235
- puts "Unexpected error: #{e.message}"
236
- end
237
- ```
238
-
239
- ## API Reference
240
-
241
- ### Laneful::Client
242
-
243
- #### Constructor
244
-
245
- ```ruby
246
- Laneful::Client.new(base_url, auth_token, timeout: 30)
247
- ```
248
-
249
- - `base_url` - The base URL of the Laneful API
250
- - `auth_token` - The authentication token
251
- - `timeout` - Request timeout in seconds (optional, default: 30)
252
-
253
- #### Methods
254
-
255
- - `send_email(email)` - Sends a single email
256
- - `send_emails(emails)` - Sends multiple emails
257
-
258
- ### Laneful::Email::Builder
259
-
260
- #### Required Fields
261
-
262
- - `from(address)` - Sender address
263
-
264
- #### Optional Fields
265
-
266
- - `to(address)` - Recipient addresses
267
- - `cc(address)` - CC addresses
268
- - `bcc(address)` - BCC addresses
269
- - `subject(subject)` - Email subject
270
- - `text_content(content)` - Plain text content
271
- - `html_content(content)` - HTML content
272
- - `template_id(id)` - Template ID
273
- - `template_data(data)` - Template data
274
- - `attachment(attachment)` - File attachments
275
- - `headers(headers)` - Custom headers
276
- - `reply_to(address)` - Reply-to address
277
- - `send_time(time)` - Scheduled send time (Unix timestamp)
278
- - `webhook_data(data)` - Webhook data
279
- - `tag(tag)` - Email tag
280
- - `tracking(tracking)` - Tracking settings
281
-
282
- ### Laneful::Address
283
-
284
- ```ruby
285
- Laneful::Address.new(email, name = nil)
286
- ```
287
-
288
- - `email` - The email address (required)
289
- - `name` - The display name (optional)
290
-
291
- ### Laneful::Attachment
292
-
293
- ```ruby
294
- # From file
295
- Laneful::Attachment.from_file(file_path)
296
-
297
- # From raw data
298
- Laneful::Attachment.new(filename, content_type, content)
299
- ```
300
-
301
- ### Laneful::TrackingSettings
302
-
303
- ```ruby
304
- Laneful::TrackingSettings.new(opens: false, clicks: false, unsubscribes: false)
305
- ```
306
-
307
- ### Laneful::WebhookVerifier
308
-
309
- ```ruby
310
- Laneful::WebhookVerifier.verify_signature(secret, payload, signature)
311
- ```
312
-
313
- ## Exception Types
314
-
315
- - `Laneful::ValidationException` - Thrown when input validation fails
316
- - `Laneful::ApiException` - Thrown when the API returns an error response
317
- - `Laneful::HttpException` - Thrown when HTTP communication fails
318
- - `Laneful::LanefulException` - Base exception class for all SDK exceptions
319
-
320
- ## Development
321
-
322
- ### Running Tests
323
-
324
- ```bash
325
- bundle exec rspec
326
- ```
327
-
328
- ### Code Quality
329
-
330
- ```bash
331
- bundle exec rubocop
332
- ```
333
-
334
- ### Documentation
335
-
336
- ```bash
337
- bundle exec yard doc
338
- ```
339
-
340
- ## License
341
-
342
- This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
343
-
data/Rakefile DELETED
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bundler/gem_tasks'
4
- require 'rspec/core/rake_task'
5
-
6
- RSpec::Core::RakeTask.new(:spec)
7
-
8
- task default: :spec
data/examples/Gemfile DELETED
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
4
-
5
- gem 'laneful-ruby'
@@ -1,123 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require 'laneful'
5
-
6
- # Simple example demonstrating basic usage of the Laneful Ruby SDK
7
- puts '📧 Laneful Ruby SDK - Simple Example'
8
- puts "====================================\n"
9
-
10
- # Configuration - Replace with your actual credentials
11
- base_url = 'https://your-subdomain.z1.send.dev.laneful.net'
12
- auth_token = 'priv-YourAuthTokenHere'
13
-
14
- # Email addresses - Replace with your actual addresses
15
- sender_email = 'sender@yourdomain.com'
16
- sender_name = 'Your Name'
17
- recipient_email = 'recipient@example.com'
18
- recipient_name = 'Recipient Name'
19
- cc_email = 'cc@example.com'
20
- cc_name = 'CC Recipient'
21
-
22
- # Create client
23
- begin
24
- client = Laneful::Client.new(base_url, auth_token)
25
- puts '✅ Client created successfully'
26
- rescue Laneful::ValidationException => e
27
- puts "❌ Failed to create client: #{e.message}"
28
- puts 'Please check your base_url and auth_token configuration.'
29
- exit 1
30
- end
31
-
32
- # Test 1: Send a simple text email
33
- puts "\n📝 Test 1: Sending Simple Text Email"
34
- puts '------------------------------------'
35
-
36
- begin
37
- email = Laneful::Email::Builder.new
38
- .from(Laneful::Address.new(sender_email, sender_name))
39
- .to(Laneful::Address.new(recipient_email, recipient_name))
40
- .subject('Hello from Laneful Ruby SDK! 🚀')
41
- .text_content('Hi! This is a test email sent using the Laneful Ruby SDK. ' \
42
- 'The SDK is working perfectly!')
43
- .tag('ruby-sdk-test')
44
- .build
45
-
46
- response = client.send_email(email)
47
- puts '✅ Simple email sent successfully!'
48
- puts "Response: #{response}"
49
- rescue Laneful::ValidationException => e
50
- puts "❌ Validation error: #{e.message}"
51
- rescue Laneful::ApiException => e
52
- puts "❌ API error: #{e.message} (Status: #{e.status_code})"
53
- puts " Details: #{e.error_message}" if e.error_message
54
- rescue Laneful::HttpException => e
55
- puts "❌ HTTP error: #{e.message} (Status: #{e.status_code})"
56
- end
57
-
58
- # Test 2: Send an HTML email with CC
59
- puts "\n🎨 Test 2: Sending HTML Email with CC"
60
- puts '-------------------------------------'
61
-
62
- begin
63
- tracking = Laneful::TrackingSettings.new(opens: true, clicks: true, unsubscribes: false)
64
-
65
- email = Laneful::Email::Builder.new
66
- .from(Laneful::Address.new(sender_email, sender_name))
67
- .to(Laneful::Address.new(recipient_email, recipient_name))
68
- .cc(Laneful::Address.new(cc_email, cc_name))
69
- .subject('Ruby SDK Test - HTML Email with Tracking 📧')
70
- .html_content(<<~HTML)
71
- <!DOCTYPE html>
72
- <html>
73
- <head>
74
- <title>Ruby SDK Test</title>
75
- </head>
76
- <body style="font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto; padding: 20px;">
77
- <h1 style="color: #2c3e50;">🎉 Ruby SDK Test Successful!</h1>
78
- <p>Hello! This email was sent using the <strong>Laneful Ruby SDK</strong> with modern Ruby features:</p>
79
- <ul style="background-color: #f8f9fa; padding: 15px; border-radius: 5px;">
80
- <li>✅ Frozen string literals for immutability</li>
81
- <li>✅ Keyword arguments for clean APIs</li>
82
- <li>✅ Safe navigation operator (&.)</li>
83
- <li>✅ Enhanced exception handling</li>
84
- <li>✅ Modern Ruby syntax throughout</li>
85
- </ul>
86
- <p style="color: #7f8c8d;">This email has tracking enabled for opens and clicks.</p>
87
- <hr style="border: none; border-top: 1px solid #eee; margin: 20px 0;">
88
- <p style="font-size: 12px; color: #95a5a6;">
89
- Sent from: #{sender_email}<br>
90
- To: #{recipient_email}<br>
91
- CC: #{cc_email}
92
- </p>
93
- </body>
94
- </html>
95
- HTML
96
- .text_content('Ruby SDK Test Successful! Hello! This email was sent using ' \
97
- 'the Laneful Ruby SDK with modern Ruby features including ' \
98
- 'frozen string literals, keyword arguments, safe navigation ' \
99
- 'operator, and enhanced exception handling. This email has ' \
100
- 'tracking enabled for opens and clicks.')
101
- .tracking(tracking)
102
- .tag('html-cc-test')
103
- .build
104
-
105
- response = client.send_email(email)
106
- puts '✅ HTML email with CC sent successfully!'
107
- puts "Response: #{response}"
108
- rescue Laneful::ValidationException => e
109
- puts "❌ Validation error: #{e.message}"
110
- rescue Laneful::ApiException => e
111
- puts "❌ API error: #{e.message} (Status: #{e.status_code})"
112
- puts " Details: #{e.error_message}" if e.error_message
113
- rescue Laneful::HttpException => e
114
- puts "❌ HTTP error: #{e.message} (Status: #{e.status_code})"
115
- end
116
-
117
- puts "\n🎉 Tests completed!"
118
- puts "\n📋 Summary:"
119
- puts ' • Ruby SDK is working correctly'
120
- puts ' • Real API endpoint is accessible'
121
- puts ' • Email building and sending functionality is operational'
122
- puts ' • Error handling is working properly'
123
- puts "\n💡 Check your email inboxes for the test emails!"
data/laneful-ruby.gemspec DELETED
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'lib/laneful/version'
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = 'laneful-ruby'
7
- spec.version = Laneful::VERSION
8
- spec.authors = ['Laneful Team']
9
- spec.email = ['support@laneful.com']
10
-
11
- spec.summary = 'Ruby SDK for the Laneful email API'
12
- spec.description = 'A modern Ruby client library for the Laneful email API, ' \
13
- 'providing easy integration for email sending, webhooks, and analytics.'
14
- spec.homepage = 'https://github.com/laneful/laneful-ruby'
15
- spec.license = 'MIT'
16
- spec.required_ruby_version = '>= 3.0.0'
17
-
18
- spec.metadata['homepage_uri'] = spec.homepage
19
- spec.metadata['source_code_uri'] = 'https://github.com/laneful/laneful-ruby'
20
- spec.metadata['changelog_uri'] = 'https://github.com/laneful/laneful-ruby/blob/main/CHANGELOG.md'
21
- spec.metadata['documentation_uri'] = 'https://docs.laneful.com/ruby'
22
- spec.metadata['rubygems_mfa_required'] = 'true'
23
-
24
- # Specify which files should be added to the gem when it is released.
25
- spec.files = Dir.chdir(__dir__) do
26
- `git ls-files -z`.split("\x0").reject do |f|
27
- (File.expand_path(f) == __FILE__) ||
28
- f.start_with?(*%w[bin/ test/ spec/ features/ .git appveyor Gemfile])
29
- end
30
- end
31
- spec.bindir = 'exe'
32
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
33
- spec.require_paths = ['lib']
34
-
35
- # Dependencies
36
- spec.add_dependency 'httparty', '~> 0.21'
37
- spec.add_dependency 'json', '~> 2.6'
38
- end
data/scripts/publish.sh DELETED
@@ -1,169 +0,0 @@
1
- #!/bin/bash
2
-
3
- # Laneful Ruby SDK Publishing Script
4
- # This script handles the complete publishing workflow to RubyGems
5
-
6
- set -e
7
-
8
- # Colors for output
9
- RED='\033[0;31m'
10
- GREEN='\033[0;32m'
11
- YELLOW='\033[1;33m'
12
- BLUE='\033[0;34m'
13
- NC='\033[0m' # No Color
14
-
15
- # Function to print colored output
16
- print_status() {
17
- echo -e "${BLUE}[INFO]${NC} $1"
18
- }
19
-
20
- print_success() {
21
- echo -e "${GREEN}[SUCCESS]${NC} $1"
22
- }
23
-
24
- print_warning() {
25
- echo -e "${YELLOW}[WARNING]${NC} $1"
26
- }
27
-
28
- print_error() {
29
- echo -e "${RED}[ERROR]${NC} $1"
30
- }
31
-
32
- # Check if required environment variables are set
33
- check_environment() {
34
- print_status "Checking environment variables..."
35
-
36
- if [ -z "$GEM_HOST_API_KEY" ]; then
37
- print_error "GEM_HOST_API_KEY environment variable is not set"
38
- print_status "Please set your RubyGems API key:"
39
- print_status "export GEM_HOST_API_KEY=your_api_key_here"
40
- exit 1
41
- fi
42
-
43
- print_success "Environment variables are set"
44
- }
45
-
46
- # Check if we're in the right directory
47
- check_directory() {
48
- if [ ! -f "laneful-ruby.gemspec" ]; then
49
- print_error "laneful-ruby.gemspec not found. Please run this script from the project root."
50
- exit 1
51
- fi
52
- print_success "Found gemspec file"
53
- }
54
-
55
- # Check Ruby version
56
- check_ruby_version() {
57
- print_status "Checking Ruby version..."
58
- ruby_version=$(ruby -v | cut -d' ' -f2)
59
- required_version="3.0.0"
60
-
61
- if [ "$(printf '%s\n' "$required_version" "$ruby_version" | sort -V | head -n1)" = "$required_version" ]; then
62
- print_success "Ruby version $ruby_version is compatible"
63
- else
64
- print_error "Ruby version $ruby_version is not compatible. Required: $required_version or higher"
65
- exit 1
66
- fi
67
- }
68
-
69
- # Install dependencies
70
- install_dependencies() {
71
- print_status "Installing dependencies..."
72
- bundle install
73
- if [ $? -eq 0 ]; then
74
- print_success "Dependencies installed successfully"
75
- else
76
- print_error "Failed to install dependencies. Aborting publish."
77
- exit 1
78
- fi
79
- }
80
-
81
- # Run tests
82
- run_tests() {
83
- print_status "Running tests..."
84
- bundle exec rspec
85
- if [ $? -eq 0 ]; then
86
- print_success "All tests passed"
87
- else
88
- print_error "Tests failed. Aborting publish."
89
- exit 1
90
- fi
91
- }
92
-
93
- # Run linting
94
- run_lint() {
95
- print_status "Running linter..."
96
- bundle exec rubocop
97
- if [ $? -eq 0 ]; then
98
- print_success "Linting passed"
99
- else
100
- print_error "Linting failed. Aborting publish."
101
- exit 1
102
- fi
103
- }
104
-
105
- # Build the gem
106
- build_gem() {
107
- print_status "Building gem..."
108
- gem build laneful-ruby.gemspec
109
- if [ $? -eq 0 ]; then
110
- print_success "Gem built successfully"
111
- else
112
- print_error "Gem build failed. Aborting publish."
113
- exit 1
114
- fi
115
- }
116
-
117
- # Publish to RubyGems
118
- publish_gem() {
119
- print_status "Publishing to RubyGems..."
120
- gem push laneful-ruby-*.gem
121
- if [ $? -eq 0 ]; then
122
- print_success "Gem published successfully to RubyGems!"
123
- else
124
- print_error "Failed to publish gem to RubyGems."
125
- exit 1
126
- fi
127
- }
128
-
129
- # Clean up
130
- cleanup() {
131
- print_status "Cleaning up..."
132
- rm -f laneful-ruby-*.gem
133
- print_success "Cleanup completed"
134
- }
135
-
136
- # Main execution
137
- main() {
138
- print_status "Starting Laneful Ruby SDK publishing process..."
139
-
140
- check_environment
141
- check_directory
142
- check_ruby_version
143
- install_dependencies
144
-
145
- # Ask for confirmation
146
- echo
147
- print_warning "This will publish the gem to RubyGems. Are you sure? (y/N)"
148
- read -r response
149
- if [[ ! "$response" =~ ^[Yy]$ ]]; then
150
- print_status "Publishing cancelled."
151
- exit 0
152
- fi
153
-
154
- run_tests
155
- run_lint
156
- build_gem
157
- publish_gem
158
- cleanup
159
-
160
- print_success "Publishing process completed successfully!"
161
- print_status "Your gem is now available on RubyGems: https://rubygems.org/gems/laneful-ruby"
162
- }
163
-
164
- # Handle script interruption
165
- trap cleanup EXIT
166
-
167
- # Run main function
168
- main "$@"
169
-