mailsentry 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: 4410aa49c2518ebc3b27ead59b2db6c5f49416f4ddfc16f27bd619c3528d8d7c
4
+ data.tar.gz: 28712ba826de1c82911569b3d77ef2b09fe30c6c5b74e61a91232ff4da55b098
5
+ SHA512:
6
+ metadata.gz: d75098031f33199fd14c7ee489217b0fea9c16fb86c9fb0e0b4ad6691dc03a7c84312e37c0c24865b93c0fe1fd594a512be9aef3cc75c370ce9a3cbfd6a860e1
7
+ data.tar.gz: f7c70e5fff2060a91229a881254cd37328372f061045f7f6ca9b4d45241cfd8480eb0557612eb23ef08ab9bf477bf9755df03462067d9fa35bfde5f1bac0c039
data/README.md ADDED
@@ -0,0 +1,151 @@
1
+ # MailSentry Ruby SDK
2
+
3
+ Official Ruby SDK for the [MailSentry](https://mailsentry.dev) email-validation API.
4
+
5
+ Validate emails in real time with 8 layers of checks — syntax, MX records, disposable detection, role-based detection, typo suggestions, SMTP verification, gibberish scoring, and spam-trap detection.
6
+
7
+ ## Requirements
8
+
9
+ - Ruby 3.0+
10
+ - No external dependencies (uses `net/http` and `json` from the standard library)
11
+
12
+ ## Installation
13
+
14
+ Add to your Gemfile:
15
+
16
+ ```ruby
17
+ gem "mailsentry"
18
+ ```
19
+
20
+ Then run:
21
+
22
+ ```
23
+ bundle install
24
+ ```
25
+
26
+ Or install directly:
27
+
28
+ ```
29
+ gem install mailsentry
30
+ ```
31
+
32
+ ## Quick Start
33
+
34
+ ```ruby
35
+ require "mailsentry"
36
+
37
+ client = MailSentry::Client.new(api_key: "ms_live_your_key_here")
38
+
39
+ # Validate a single email
40
+ result = client.verify("user@example.com")
41
+
42
+ puts result["verdict"] # => "valid", "caution", "risky", or "invalid"
43
+ puts result["score"] # => 0-100
44
+ puts result["checks"]["disposable"]["is_disposable"]
45
+ ```
46
+
47
+ ## Usage
48
+
49
+ ### Initialize the client
50
+
51
+ ```ruby
52
+ client = MailSentry::Client.new(
53
+ api_key: "ms_live_your_key_here",
54
+ base_url: "https://mailsentry.dev", # optional, default shown
55
+ timeout: 30 # optional, seconds
56
+ )
57
+ ```
58
+
59
+ ### Single email validation
60
+
61
+ ```ruby
62
+ result = client.verify("user@example.com")
63
+
64
+ # result is a Hash with these keys:
65
+ # "email", "score", "verdict", "recommendation", "verification_level",
66
+ # "warning", "checks", "response_time_ms"
67
+
68
+ puts result["score"] # => 92
69
+ puts result["verdict"] # => "valid"
70
+ puts result["recommendation"] # => "Safe to send"
71
+
72
+ # Inspect individual checks
73
+ checks = result["checks"]
74
+ puts checks["mx_records"]["valid"] # => true
75
+ puts checks["disposable"]["is_disposable"] # => false
76
+ puts checks["typo"]["has_typo"] # => false
77
+ puts checks["smtp"]["valid"] # => true
78
+ ```
79
+
80
+ ### Bulk email validation
81
+
82
+ ```ruby
83
+ # Submit a batch (plan limits apply: free 100, starter 500, pro 1000, etc.)
84
+ job = client.bulk_verify(["a@example.com", "b@example.com", "c@test.com"])
85
+
86
+ puts job["id"] # => "bulk_abc123"
87
+ puts job["status"] # => "processing" or "completed"
88
+ puts job["total"] # => 3
89
+
90
+ # Each result in the array:
91
+ job["results"].each do |r|
92
+ puts "#{r["email"]} — #{r["verdict"]} (score: #{r["score"]})"
93
+ end
94
+ ```
95
+
96
+ ### Retrieve a bulk job
97
+
98
+ ```ruby
99
+ detail = client.get_bulk_job("bulk_abc123")
100
+
101
+ puts detail["status"] # => "completed"
102
+ puts detail["total_emails"] # => 3
103
+ puts detail["results"].length
104
+ ```
105
+
106
+ ### List recent bulk jobs
107
+
108
+ ```ruby
109
+ jobs = client.list_bulk_jobs
110
+
111
+ jobs.each do |j|
112
+ puts "#{j["id"]} — #{j["status"]} (#{j["processed"]}/#{j["total_emails"]})"
113
+ end
114
+ ```
115
+
116
+ ## Error Handling
117
+
118
+ All API errors raise `MailSentry::Error`, which includes the HTTP status code:
119
+
120
+ ```ruby
121
+ begin
122
+ client.verify("bad-input")
123
+ rescue MailSentry::Error => e
124
+ puts e.message # => "Invalid email format"
125
+ puts e.status_code # => 422
126
+ end
127
+ ```
128
+
129
+ Common status codes:
130
+
131
+ | Code | Meaning |
132
+ |------|---------|
133
+ | 401 | Invalid or missing API key |
134
+ | 422 | Validation error (bad input) |
135
+ | 429 | Rate limit exceeded |
136
+ | 500 | Server error |
137
+
138
+ ## API Reference
139
+
140
+ | Method | HTTP | Path | Returns |
141
+ |--------|------|------|---------|
142
+ | `verify(email)` | POST | `/api/v1/verify` | `Hash` |
143
+ | `bulk_verify(emails, filename:)` | POST | `/api/v1/bulk` | `Hash` |
144
+ | `get_bulk_job(id)` | GET | `/api/v1/bulk/{id}` | `Hash` |
145
+ | `list_bulk_jobs` | GET | `/api/v1/bulk` | `Array<Hash>` |
146
+
147
+ ## Links
148
+
149
+ - [Documentation](https://mailsentry.dev/docs)
150
+ - [Dashboard & API keys](https://mailsentry.dev/dashboard)
151
+ - [Sign up (free, no credit card)](https://mailsentry.dev/signup)
@@ -0,0 +1,108 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "net/http"
4
+ require "json"
5
+ require "uri"
6
+
7
+ module MailSentry
8
+ # HTTP client for the MailSentry email-validation API.
9
+ #
10
+ # client = MailSentry::Client.new(api_key: "ms_live_...")
11
+ # result = client.verify("user@example.com")
12
+ #
13
+ class Client
14
+ DEFAULT_BASE_URL = "https://mailsentry.dev"
15
+ DEFAULT_TIMEOUT = 30 # seconds
16
+
17
+ # @param api_key [String] your MailSentry API key.
18
+ # @param base_url [String] API base URL (override for testing / self-hosted).
19
+ # @param timeout [Integer] request timeout in seconds.
20
+ def initialize(api_key:, base_url: DEFAULT_BASE_URL, timeout: DEFAULT_TIMEOUT)
21
+ raise ArgumentError, "API key is required" if api_key.nil? || api_key.strip.empty?
22
+
23
+ @api_key = api_key
24
+ @base_url = base_url.chomp("/")
25
+ @timeout = timeout
26
+ end
27
+
28
+ # Validate a single email address.
29
+ #
30
+ # @param email [String] the email address to validate.
31
+ # @return [Hash] validation result with score, verdict, checks, etc.
32
+ # @raise [MailSentry::Error] on non-2xx responses.
33
+ def verify(email)
34
+ post("/api/v1/verify", { email: email })
35
+ end
36
+
37
+ # Submit a batch of emails for bulk validation.
38
+ #
39
+ # @param emails [Array<String>] list of email addresses.
40
+ # @param filename [String, nil] optional label for the job.
41
+ # @return [Hash] bulk job response with id, status, total, and results.
42
+ # @raise [MailSentry::Error] on non-2xx responses.
43
+ def bulk_verify(emails, filename: nil)
44
+ body = { emails: emails }
45
+ body[:filename] = filename if filename
46
+ post("/api/v1/bulk", body)
47
+ end
48
+
49
+ # Retrieve details and results of a bulk validation job.
50
+ #
51
+ # @param id [String] the bulk job ID.
52
+ # @return [Hash] job details including results array.
53
+ # @raise [MailSentry::Error] on non-2xx responses.
54
+ def get_bulk_job(id)
55
+ get("/api/v1/bulk/#{id}")
56
+ end
57
+
58
+ # List recent bulk validation jobs (up to 20).
59
+ #
60
+ # @return [Array<Hash>] list of bulk job summaries.
61
+ # @raise [MailSentry::Error] on non-2xx responses.
62
+ def list_bulk_jobs
63
+ data = get("/api/v1/bulk")
64
+ data["jobs"]
65
+ end
66
+
67
+ private
68
+
69
+ # ---- HTTP helpers -------------------------------------------------------
70
+
71
+ def get(path)
72
+ request(Net::HTTP::Get, path)
73
+ end
74
+
75
+ def post(path, body)
76
+ request(Net::HTTP::Post, path, body)
77
+ end
78
+
79
+ def request(verb_class, path, body = nil)
80
+ uri = URI("#{@base_url}#{path}")
81
+
82
+ http = Net::HTTP.new(uri.host, uri.port)
83
+ http.use_ssl = uri.scheme == "https"
84
+ http.open_timeout = @timeout
85
+ http.read_timeout = @timeout
86
+
87
+ req = verb_class.new(uri)
88
+ req["Content-Type"] = "application/json"
89
+ req["X-API-Key"] = @api_key
90
+ req.body = JSON.generate(body) if body
91
+
92
+ res = http.request(req)
93
+
94
+ parsed = begin
95
+ JSON.parse(res.body)
96
+ rescue JSON::ParserError
97
+ nil
98
+ end
99
+
100
+ unless res.is_a?(Net::HTTPSuccess)
101
+ message = parsed&.dig("error") || "Request failed: #{res.code}"
102
+ raise MailSentry::Error.new(message, res.code.to_i)
103
+ end
104
+
105
+ parsed
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MailSentry
4
+ # Raised when the MailSentry API returns a non-2xx response.
5
+ class Error < StandardError
6
+ # @return [Integer] HTTP status code from the API response.
7
+ attr_reader :status_code
8
+
9
+ # @param message [String] human-readable error description.
10
+ # @param status_code [Integer] HTTP status code.
11
+ def initialize(message, status_code)
12
+ @status_code = status_code
13
+ super(message)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MailSentry
4
+ VERSION = "1.0.0"
5
+ end
data/lib/mailsentry.rb ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "mailsentry/version"
4
+ require_relative "mailsentry/error"
5
+ require_relative "mailsentry/client"
6
+
7
+ module MailSentry
8
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mailsentry
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - MailSentry
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-04-09 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Validate emails in real time with 8 layers of checks including syntax,
14
+ MX, disposable, role-based, typo, SMTP, gibberish, and spam-trap detection.
15
+ email:
16
+ - support@mailsentry.dev
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - README.md
22
+ - lib/mailsentry.rb
23
+ - lib/mailsentry/client.rb
24
+ - lib/mailsentry/error.rb
25
+ - lib/mailsentry/version.rb
26
+ homepage: https://mailsentry.dev
27
+ licenses:
28
+ - MIT
29
+ metadata:
30
+ homepage_uri: https://mailsentry.dev
31
+ source_code_uri: https://github.com/mailsentry/mailsentry-ruby
32
+ documentation_uri: https://mailsentry.dev/docs
33
+ changelog_uri: https://github.com/mailsentry/mailsentry-ruby/blob/main/CHANGELOG.md
34
+ rubygems_mfa_required: 'true'
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '3.0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubygems_version: 3.0.3.1
51
+ signing_key:
52
+ specification_version: 4
53
+ summary: Ruby SDK for the MailSentry email-validation API
54
+ test_files: []