mslm 1.1.1 → 2.2.1
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 +4 -4
- data/README.md +1 -1
- data/lib/mslm/email_verify.rb +80 -0
- data/lib/mslm/lib.rb +80 -0
- data/lib/mslm/mslm_errors.rb +25 -0
- data/lib/mslm/otp.rb +92 -33
- data/lib/mslm/otp_resp.rb +30 -0
- data/lib/mslm/otp_send_req.rb +11 -0
- data/lib/mslm/otp_token_verify_req.rb +10 -0
- data/lib/mslm/req_opts.rb +57 -0
- data/lib/mslm/single_verify_resp.rb +33 -0
- data/lib/mslm/single_verify_resp_mx.rb +26 -0
- data/lib/mslm/version.rb +1 -1
- data/lib/mslm.rb +6 -6
- data/mslm.gemspec +1 -1
- metadata +11 -6
- data/CODE_OF_CONDUCT.md +0 -84
- data/lib/mslm/constants/constants.rb +0 -48
- data/lib/mslm/email_verification.rb +0 -36
- data/sig/mslm.rbs +0 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2d94f857bd5851ae64057c5bbec4cbc08c3d0a6fc8d2604e81f6a060be3d6048
|
|
4
|
+
data.tar.gz: bd315b955fef052d9d9f07f08afc41443fe7dd62b76e3cea0b7e874b947938fd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a8103350a873165f4a36d2a2b637e732188bb5ac773619f8550e0664d25201f691af650fd79c0bf7482f8c30a55c33a72b2d27ce83f65dc6ccf928f1c06cb373
|
|
7
|
+
data.tar.gz: '06628bbf04c38b2a15838a02cfde5ad0bfd7fb01de8e69801f9e19bb6742eefd38678c7a20af16a781d717dca6f62ff6df3e849b86689f47abdebc235a06d071'
|
data/README.md
CHANGED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
require 'json'
|
|
4
|
+
require_relative 'lib'
|
|
5
|
+
require_relative 'req_opts'
|
|
6
|
+
require_relative 'mslm_errors'
|
|
7
|
+
require_relative 'single_verify_resp'
|
|
8
|
+
|
|
9
|
+
module Mslm
|
|
10
|
+
class EmailVerify
|
|
11
|
+
|
|
12
|
+
# Class for performing email verification using an API.
|
|
13
|
+
attr_reader :lib
|
|
14
|
+
|
|
15
|
+
# Initializes an EmailVerify object with an API key.
|
|
16
|
+
def initialize(api_key)
|
|
17
|
+
@lib = Lib.new(api_key)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Sets the HTTP client to be used for making requests.
|
|
21
|
+
def set_http_client(http_client)
|
|
22
|
+
@lib.set_http_client(http_client)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Sets the user agent to be used in HTTP requests.
|
|
26
|
+
def set_user_agent(user_agent)
|
|
27
|
+
@lib.set_user_agent(user_agent)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Sets the API key for authentication.
|
|
31
|
+
def set_api_key(api_key)
|
|
32
|
+
@lib.set_api_key(api_key)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Performs a single email verification with optional request options.
|
|
36
|
+
def single_verify(email, opts = nil)
|
|
37
|
+
opt = ReqOpts::Builder.new
|
|
38
|
+
.with_api_key(@lib.api_key)
|
|
39
|
+
.with_base_url(@lib.base_url)
|
|
40
|
+
.with_http_client(@lib.http)
|
|
41
|
+
.with_user_agent(@lib.user_agent)
|
|
42
|
+
.build
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
opt = opts if opts
|
|
46
|
+
qp = { 'email' => email }
|
|
47
|
+
|
|
48
|
+
t_url = @lib.prepare_url('/api/sv/v1', qp, opt)
|
|
49
|
+
|
|
50
|
+
resp = @lib.req_and_resp(t_url, opt)
|
|
51
|
+
resp_data = JSON.parse(resp.body)
|
|
52
|
+
|
|
53
|
+
email = resp_data['email']
|
|
54
|
+
username = resp_data['username']
|
|
55
|
+
domain = resp_data['domain']
|
|
56
|
+
malformed = resp_data['malformed']
|
|
57
|
+
suggestion = resp_data['suggestion']
|
|
58
|
+
status = resp_data['status']
|
|
59
|
+
has_mailbox = resp_data['has_mailbox']
|
|
60
|
+
accept_all = resp_data['accept_all']
|
|
61
|
+
disposable = resp_data['disposable']
|
|
62
|
+
free = resp_data['free']
|
|
63
|
+
role = resp_data['role']
|
|
64
|
+
mx = resp_data['mx']
|
|
65
|
+
|
|
66
|
+
status_code = resp.code.to_i
|
|
67
|
+
|
|
68
|
+
if status_code == 429
|
|
69
|
+
return nil, RequestQuotaExceededError.new
|
|
70
|
+
elsif status_code != 200
|
|
71
|
+
return nil, MslmError.new(status_code, 'API request failed')
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
single_verify_resp = SingleVerifyResp.new(email, username, domain, malformed, suggestion, status,
|
|
75
|
+
has_mailbox, accept_all, disposable, free, role, mx)
|
|
76
|
+
|
|
77
|
+
single_verify_resp
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
data/lib/mslm/lib.rb
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
require 'uri'
|
|
3
|
+
require 'net/http'
|
|
4
|
+
|
|
5
|
+
class Lib
|
|
6
|
+
|
|
7
|
+
# Generic utility class for handling HTTP requests and responses.
|
|
8
|
+
attr_accessor :api_key, :http, :base_url, :user_agent
|
|
9
|
+
|
|
10
|
+
# Initializes a Lib object with an optional API key.
|
|
11
|
+
def initialize(api_key = "")
|
|
12
|
+
@api_key = api_key
|
|
13
|
+
@http = nil
|
|
14
|
+
@base_url = URI.parse('https://mslm.io')
|
|
15
|
+
@user_agent = self.class.get_user_agent('mslm')
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Sets the HTTP client for making requests.
|
|
19
|
+
def set_http_client(http_client)
|
|
20
|
+
@http = http_client
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Sets the base URL for API requests.
|
|
24
|
+
def set_base_url(base_url_str)
|
|
25
|
+
@base_url = URI.parse(base_url_str)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Sets the user agent for HTTP requests.
|
|
29
|
+
def set_user_agent(user_agent)
|
|
30
|
+
@user_agent = user_agent
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Sets the API key for authentication.
|
|
34
|
+
def set_api_key(api_key)
|
|
35
|
+
@api_key = api_key
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Static method to generate a user agent string.
|
|
39
|
+
def self.get_user_agent(pkg)
|
|
40
|
+
"#{pkg}/ruby/2.2.1"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Prepares the URL for making a request.
|
|
44
|
+
def prepare_url(url_path, qp, opt)
|
|
45
|
+
|
|
46
|
+
qp['apikey'] = opt.api_key
|
|
47
|
+
|
|
48
|
+
t_url = @base_url.dup
|
|
49
|
+
t_url.path = url_path
|
|
50
|
+
|
|
51
|
+
qp_str = URI.encode_www_form(qp)
|
|
52
|
+
t_url.query = if t_url.query
|
|
53
|
+
"#{t_url.query}&#{qp_str}"
|
|
54
|
+
else
|
|
55
|
+
qp_str
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
t_url
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Makes an HTTP request and returns the response.
|
|
62
|
+
def req_and_resp(t_url, opt, method = 'GET', data = nil)
|
|
63
|
+
|
|
64
|
+
uri = URI.parse(t_url)
|
|
65
|
+
@http = Net::HTTP.new(uri.host, uri.port)
|
|
66
|
+
http.use_ssl = true if uri.scheme == 'https'
|
|
67
|
+
headers = {}
|
|
68
|
+
|
|
69
|
+
if method.upcase == 'GET'
|
|
70
|
+
response = @http.get(uri.request_uri)
|
|
71
|
+
elsif method.upcase == 'POST'
|
|
72
|
+
headers['Content-Type'] = 'application/json'
|
|
73
|
+
response = @http.post(uri.request_uri,data,headers)
|
|
74
|
+
else
|
|
75
|
+
raise ArgumentError, 'Invalid HTTP method. Supported methods are GET and POST.'
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
response
|
|
79
|
+
end
|
|
80
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
|
|
2
|
+
# Base class for errors
|
|
3
|
+
class MslmError < StandardError
|
|
4
|
+
attr_reader :code, :message
|
|
5
|
+
|
|
6
|
+
# Initializes a new MslmError object with a code and a message
|
|
7
|
+
def initialize(code, message)
|
|
8
|
+
@code = code
|
|
9
|
+
@message = message
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# Returns a string representation of the error
|
|
13
|
+
def to_s
|
|
14
|
+
"Error: code: #{@code}, message: #{@message}"
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Error raised when the request quota for the API key has been exceeded
|
|
19
|
+
class RequestQuotaExceededError < MslmError
|
|
20
|
+
|
|
21
|
+
# Initializes a new RequestQuotaExceededError object with a default message and code
|
|
22
|
+
def initialize(message = "Request quota for API key has been exceeded.")
|
|
23
|
+
super(429, message)
|
|
24
|
+
end
|
|
25
|
+
end
|
data/lib/mslm/otp.rb
CHANGED
|
@@ -1,52 +1,111 @@
|
|
|
1
|
-
|
|
2
|
-
require_relative '
|
|
3
|
-
require_relative '
|
|
1
|
+
require 'json'
|
|
2
|
+
require_relative 'lib'
|
|
3
|
+
require_relative 'req_opts'
|
|
4
|
+
require_relative 'mslm_errors'
|
|
5
|
+
require_relative 'otp_send_req'
|
|
6
|
+
require_relative 'otp_resp'
|
|
7
|
+
require_relative 'otp_token_verify_req'
|
|
4
8
|
|
|
5
9
|
module Mslm
|
|
6
|
-
module Otp
|
|
7
|
-
include Constants
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
class Otp
|
|
12
|
+
|
|
13
|
+
# Class for performing otp using an API.
|
|
14
|
+
attr_reader :lib
|
|
15
|
+
|
|
16
|
+
# Initializes an object with an API key.
|
|
17
|
+
def initialize(api_key)
|
|
18
|
+
@lib = Lib.new(api_key)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Sets the HTTP client to be used for making requests.
|
|
22
|
+
def set_http_client(http_client)
|
|
23
|
+
@lib.set_http_client(http_client)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Sets the user agent to be used in HTTP requests.
|
|
27
|
+
def set_user_agent(user_agent)
|
|
28
|
+
@lib.set_user_agent(user_agent)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Sets the API key for authentication.
|
|
32
|
+
def set_api_key(api_key)
|
|
33
|
+
@lib.set_api_key(api_key)
|
|
12
34
|
end
|
|
13
35
|
|
|
14
|
-
|
|
36
|
+
# Sends an OTP to the specified phone number with the provided options.
|
|
37
|
+
def send(otp_req, opts = nil)
|
|
38
|
+
opt = ReqOpts::Builder.new
|
|
39
|
+
.with_api_key(@lib.api_key)
|
|
40
|
+
.with_base_url(@lib.base_url)
|
|
41
|
+
.with_http_client(@lib.http)
|
|
42
|
+
.with_user_agent(@lib.user_agent)
|
|
43
|
+
.build
|
|
15
44
|
|
|
16
|
-
|
|
45
|
+
opt = opts if opts
|
|
46
|
+
qp = {
|
|
47
|
+
'phone' => otp_req['phone'],
|
|
48
|
+
'tmpl_sms' => otp_req['tmpl_sms'],
|
|
49
|
+
'token_len' => otp_req['token_len'],
|
|
50
|
+
'expire_seconds' => otp_req['expire_seconds']
|
|
51
|
+
}
|
|
17
52
|
|
|
18
|
-
opt = SingleVerifyReqOpts.new
|
|
19
|
-
opt = opts.last unless opts.nil? || opts.empty?
|
|
20
|
-
qp ={}
|
|
21
|
-
if Mslm.api_key || opt.api_key
|
|
22
|
-
api_key = opt.api_key || Mslm.api_key
|
|
23
|
-
qp['apikey'] = api_key
|
|
24
|
-
end
|
|
25
53
|
|
|
26
|
-
|
|
54
|
+
t_url = @lib.prepare_url('/api/otp/v1/send', {}, opt)
|
|
55
|
+
resp = @lib.req_and_resp(t_url, opt, 'POST', qp.to_json)
|
|
56
|
+
resp_data = JSON.parse(resp.body)
|
|
27
57
|
|
|
58
|
+
code = resp_data['code']
|
|
59
|
+
msg = resp_data['msg']
|
|
28
60
|
|
|
29
|
-
|
|
30
|
-
|
|
61
|
+
status_code = resp.code.to_i
|
|
62
|
+
|
|
63
|
+
if status_code == 429
|
|
64
|
+
return nil, RequestQuotaExceededError.new
|
|
65
|
+
elsif status_code != 200
|
|
66
|
+
return nil, MslmError.new(status_code, resp_data['msg'] || 'API request failed')
|
|
31
67
|
end
|
|
32
68
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
69
|
+
otp_send_resp = OtpSendResp.new(code,msg)
|
|
70
|
+
otp_send_resp
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Verifies an OTP token for the specified phone number with the provided options.
|
|
74
|
+
def verify(otp_token_req, opts = nil)
|
|
75
|
+
opt = ReqOpts::Builder.new
|
|
76
|
+
.with_api_key(@lib.api_key)
|
|
77
|
+
.with_base_url(@lib.base_url)
|
|
78
|
+
.with_http_client(@lib.http)
|
|
79
|
+
.with_user_agent(@lib.user_agent)
|
|
80
|
+
.build
|
|
81
|
+
|
|
82
|
+
opt = opts if opts
|
|
83
|
+
qp = {
|
|
84
|
+
'phone' => otp_token_req["phone"],
|
|
85
|
+
'token' => otp_token_req["token"],
|
|
86
|
+
'consume' => otp_token_req["consume"]
|
|
87
|
+
}
|
|
37
88
|
|
|
38
|
-
|
|
39
|
-
if Mslm.api_key || opt.api_key
|
|
40
|
-
api_key = opt.api_key || Mslm.api_key
|
|
41
|
-
qp['apikey'] = api_key
|
|
42
|
-
end
|
|
89
|
+
t_url = @lib.prepare_url('/api/otp/v1/token_verify', {}, opt)
|
|
43
90
|
|
|
44
|
-
|
|
91
|
+
resp = @lib.req_and_resp(t_url, opt, 'POST', qp.to_json)
|
|
92
|
+
resp_data = JSON.parse(resp.body)
|
|
45
93
|
|
|
94
|
+
code = resp_data['code']
|
|
95
|
+
msg = resp_data['msg']
|
|
46
96
|
|
|
47
|
-
|
|
48
|
-
|
|
97
|
+
status_code = resp.code.to_i
|
|
98
|
+
|
|
99
|
+
if status_code == 429
|
|
100
|
+
return nil, RequestQuotaExceededError.new
|
|
101
|
+
elsif status_code != 200
|
|
102
|
+
return nil, MslmError.new(status_code, resp_data['msg'] || 'API request failed')
|
|
49
103
|
end
|
|
104
|
+
|
|
105
|
+
otp_verify_resp = OtpTokenVerifyResp.new(code,msg)
|
|
106
|
+
otp_verify_resp
|
|
50
107
|
end
|
|
51
108
|
end
|
|
52
|
-
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
class OtpResp
|
|
2
|
+
attr_reader :code, :msg
|
|
3
|
+
|
|
4
|
+
# Constructor method to initialize OtpResp object.
|
|
5
|
+
def initialize(code, msg)
|
|
6
|
+
@code = code
|
|
7
|
+
@msg = msg
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
# String representation of OtpResp object.
|
|
11
|
+
def to_s
|
|
12
|
+
"{code='#{@code}', message='#{@msg}'}"
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
class OtpSendResp < OtpResp
|
|
17
|
+
|
|
18
|
+
# String representation of OtpSendResp object.
|
|
19
|
+
def to_s
|
|
20
|
+
"{code='#{@code}', message='#{@msg}'}"
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
class OtpTokenVerifyResp < OtpResp
|
|
25
|
+
|
|
26
|
+
# String representation of OtpTokenVerifyResp object.
|
|
27
|
+
def to_s
|
|
28
|
+
"{code='#{@code}', message='#{@msg}'}"
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
class OtpSendReq
|
|
2
|
+
attr_reader :phone, :tmpl_sms, :token_len, :expire_seconds
|
|
3
|
+
|
|
4
|
+
# Constructor method to initialize OtpSendReq object.
|
|
5
|
+
def initialize(phone, tmpl_sms, token_len, expire_seconds)
|
|
6
|
+
@phone = phone
|
|
7
|
+
@tmpl_sms = tmpl_sms
|
|
8
|
+
@token_len = token_len
|
|
9
|
+
@expire_seconds = expire_seconds
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
require 'uri'
|
|
2
|
+
require 'net/http'
|
|
3
|
+
|
|
4
|
+
class ReqOpts
|
|
5
|
+
|
|
6
|
+
# Request options class for configuring HTTP requests.
|
|
7
|
+
attr_accessor :api_key, :http, :base_url, :user_agent
|
|
8
|
+
|
|
9
|
+
# Initializes a ReqOpts object with default or provided values.
|
|
10
|
+
def initialize(api_key: "", http: nil, base_url: "https://mslm.io", user_agent: "mslm")
|
|
11
|
+
|
|
12
|
+
@api_key = api_key
|
|
13
|
+
@http = http
|
|
14
|
+
@base_url = URI.parse(base_url)
|
|
15
|
+
@user_agent = user_agent
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Nested builder class for constructing instances of ReqOpts.
|
|
19
|
+
class Builder
|
|
20
|
+
|
|
21
|
+
# Builder class for constructing instances of ReqOpts.
|
|
22
|
+
attr_reader :opts
|
|
23
|
+
|
|
24
|
+
def initialize
|
|
25
|
+
@opts = ReqOpts.new
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Sets the API key.
|
|
29
|
+
def with_api_key(api_key)
|
|
30
|
+
@opts.api_key = api_key
|
|
31
|
+
self
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Sets the HTTP client.
|
|
35
|
+
def with_http_client(http)
|
|
36
|
+
@opts.http = http
|
|
37
|
+
self
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Sets the base URL.
|
|
41
|
+
def with_base_url(base_url)
|
|
42
|
+
@opts.base_url = URI.parse(base_url)
|
|
43
|
+
self
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Sets the user agent.
|
|
47
|
+
def with_user_agent(user_agent)
|
|
48
|
+
@opts.user_agent = user_agent
|
|
49
|
+
self
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Builds and returns an instance of ReqOpts.
|
|
53
|
+
def build
|
|
54
|
+
@opts
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require_relative 'single_verify_resp_mx'
|
|
2
|
+
|
|
3
|
+
class SingleVerifyResp
|
|
4
|
+
# Data class representing the response of a single email verification.
|
|
5
|
+
|
|
6
|
+
attr_reader :email, :username, :domain, :malformed, :suggestion, :status,
|
|
7
|
+
:has_mailbox, :accept_all, :disposable, :free, :role, :mx
|
|
8
|
+
|
|
9
|
+
# Initializes a SingleVerifyResp object with provided attributes.
|
|
10
|
+
def initialize(email, username, domain, malformed, suggestion, status, has_mailbox,
|
|
11
|
+
accept_all, disposable, free, role, mx)
|
|
12
|
+
@email = email
|
|
13
|
+
@username = username
|
|
14
|
+
@domain = domain
|
|
15
|
+
@malformed = malformed
|
|
16
|
+
@suggestion = suggestion
|
|
17
|
+
@status = status
|
|
18
|
+
@has_mailbox = has_mailbox
|
|
19
|
+
@accept_all = accept_all
|
|
20
|
+
@disposable = disposable
|
|
21
|
+
@free = free
|
|
22
|
+
@role = role
|
|
23
|
+
@mx = mx
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Returns a string representation of the SingleVerifyResp object.
|
|
27
|
+
def to_s
|
|
28
|
+
"SingleVerifyResp{email='#{@email}', username='#{@username}', domain='#{@domain}', " \
|
|
29
|
+
"malformed=#{@malformed}, suggestion='#{@suggestion}', status='#{@status}', " \
|
|
30
|
+
"has_mailbox=#{@has_mailbox}, accept_all=#{@accept_all}, disposable=#{@disposable}, " \
|
|
31
|
+
"free=#{@free}, role=#{@role}, mx=#{@mx}}"
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
class SingleVerifyRespMx
|
|
2
|
+
# Data class representing Mail Exchange (MX) records in the response of a single email verification.
|
|
3
|
+
|
|
4
|
+
attr_reader :host, :pref
|
|
5
|
+
|
|
6
|
+
# Initializes a SingleVerifyRespMx object with host and preference values.
|
|
7
|
+
def initialize(host, pref)
|
|
8
|
+
@host = host
|
|
9
|
+
@pref = pref
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# Returns a string representation of the SingleVerifyRespMx object.
|
|
13
|
+
def to_s
|
|
14
|
+
"{host='#{@host}', pref=#{@pref}}"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Returns the host or domain name of the mail server.
|
|
18
|
+
def get_host
|
|
19
|
+
@host
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Returns the preference value indicating the priority of the mail server.
|
|
23
|
+
def get_pref
|
|
24
|
+
@pref
|
|
25
|
+
end
|
|
26
|
+
end
|
data/lib/mslm/version.rb
CHANGED
data/lib/mslm.rb
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
+
require_relative './mslm/otp'
|
|
2
|
+
require_relative './mslm/email_verify'
|
|
1
3
|
|
|
2
|
-
require_relative "mslm/email_verification"
|
|
3
|
-
require_relative "mslm/otp"
|
|
4
|
-
require_relative "mslm/version"
|
|
5
4
|
|
|
6
5
|
module Mslm
|
|
7
6
|
class << self
|
|
8
|
-
attr_accessor :
|
|
7
|
+
attr_accessor :email_verify, :otp
|
|
9
8
|
|
|
10
|
-
def
|
|
11
|
-
@
|
|
9
|
+
def initialize(api_key)
|
|
10
|
+
@email_verify = EmailVerify.new(api_key)
|
|
11
|
+
@otp = Otp.new(api_key)
|
|
12
12
|
end
|
|
13
13
|
end
|
|
14
14
|
end
|
data/mslm.gemspec
CHANGED
|
@@ -19,11 +19,11 @@ Gem::Specification.new do |spec|
|
|
|
19
19
|
spec.metadata["source_code_uri"] = "https://github.com/mslmio/sdk-ruby"
|
|
20
20
|
spec.metadata["changelog_uri"] = "https://github.com/mslmio/sdk-ruby/blob/main/CHANGELOG.md"
|
|
21
21
|
|
|
22
|
-
|
|
23
22
|
spec.files = Dir.chdir(__dir__) do
|
|
24
23
|
`git ls-files -z`.split("\x0").reject do |f|
|
|
25
24
|
(File.expand_path(f) == __FILE__) ||
|
|
26
25
|
f.start_with?(*%w[bin/ test/ spec/ features/ .git appveyor Gemfile])
|
|
26
|
+
# excluded_files.include?(f)
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
spec.bindir = "exe"
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mslm
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sahal Abdullah
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2024-
|
|
11
|
+
date: 2024-04-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: RubyGem offering email verification and OTP (One-Time Password) generation
|
|
14
14
|
and verification capabilities. Seamlessly integrate email verification and OTP functionality
|
|
@@ -20,18 +20,23 @@ extensions: []
|
|
|
20
20
|
extra_rdoc_files: []
|
|
21
21
|
files:
|
|
22
22
|
- CHANGELOG.md
|
|
23
|
-
- CODE_OF_CONDUCT.md
|
|
24
23
|
- CONTRIBUTING.md
|
|
25
24
|
- LICENSE
|
|
26
25
|
- README.md
|
|
27
26
|
- Rakefile
|
|
28
27
|
- lib/mslm.rb
|
|
29
|
-
- lib/mslm/
|
|
30
|
-
- lib/mslm/
|
|
28
|
+
- lib/mslm/email_verify.rb
|
|
29
|
+
- lib/mslm/lib.rb
|
|
30
|
+
- lib/mslm/mslm_errors.rb
|
|
31
31
|
- lib/mslm/otp.rb
|
|
32
|
+
- lib/mslm/otp_resp.rb
|
|
33
|
+
- lib/mslm/otp_send_req.rb
|
|
34
|
+
- lib/mslm/otp_token_verify_req.rb
|
|
35
|
+
- lib/mslm/req_opts.rb
|
|
36
|
+
- lib/mslm/single_verify_resp.rb
|
|
37
|
+
- lib/mslm/single_verify_resp_mx.rb
|
|
32
38
|
- lib/mslm/version.rb
|
|
33
39
|
- mslm.gemspec
|
|
34
|
-
- sig/mslm.rbs
|
|
35
40
|
homepage: https://github.com/mslmio/sdk-ruby
|
|
36
41
|
licenses:
|
|
37
42
|
- MIT
|
data/CODE_OF_CONDUCT.md
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
# Contributor Covenant Code of Conduct
|
|
2
|
-
|
|
3
|
-
## Our Pledge
|
|
4
|
-
|
|
5
|
-
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
|
6
|
-
|
|
7
|
-
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
|
8
|
-
|
|
9
|
-
## Our Standards
|
|
10
|
-
|
|
11
|
-
Examples of behavior that contributes to a positive environment for our community include:
|
|
12
|
-
|
|
13
|
-
* Demonstrating empathy and kindness toward other people
|
|
14
|
-
* Being respectful of differing opinions, viewpoints, and experiences
|
|
15
|
-
* Giving and gracefully accepting constructive feedback
|
|
16
|
-
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
|
17
|
-
* Focusing on what is best not just for us as individuals, but for the overall community
|
|
18
|
-
|
|
19
|
-
Examples of unacceptable behavior include:
|
|
20
|
-
|
|
21
|
-
* The use of sexualized language or imagery, and sexual attention or
|
|
22
|
-
advances of any kind
|
|
23
|
-
* Trolling, insulting or derogatory comments, and personal or political attacks
|
|
24
|
-
* Public or private harassment
|
|
25
|
-
* Publishing others' private information, such as a physical or email
|
|
26
|
-
address, without their explicit permission
|
|
27
|
-
* Other conduct which could reasonably be considered inappropriate in a
|
|
28
|
-
professional setting
|
|
29
|
-
|
|
30
|
-
## Enforcement Responsibilities
|
|
31
|
-
|
|
32
|
-
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
|
33
|
-
|
|
34
|
-
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
|
35
|
-
|
|
36
|
-
## Scope
|
|
37
|
-
|
|
38
|
-
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
|
39
|
-
|
|
40
|
-
## Enforcement
|
|
41
|
-
|
|
42
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at sahalzai111@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
|
|
43
|
-
|
|
44
|
-
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
|
45
|
-
|
|
46
|
-
## Enforcement Guidelines
|
|
47
|
-
|
|
48
|
-
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
|
49
|
-
|
|
50
|
-
### 1. Correction
|
|
51
|
-
|
|
52
|
-
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
|
53
|
-
|
|
54
|
-
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
|
55
|
-
|
|
56
|
-
### 2. Warning
|
|
57
|
-
|
|
58
|
-
**Community Impact**: A violation through a single incident or series of actions.
|
|
59
|
-
|
|
60
|
-
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
|
61
|
-
|
|
62
|
-
### 3. Temporary Ban
|
|
63
|
-
|
|
64
|
-
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
|
65
|
-
|
|
66
|
-
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
|
67
|
-
|
|
68
|
-
### 4. Permanent Ban
|
|
69
|
-
|
|
70
|
-
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
|
71
|
-
|
|
72
|
-
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
|
73
|
-
|
|
74
|
-
## Attribution
|
|
75
|
-
|
|
76
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
|
77
|
-
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
|
78
|
-
|
|
79
|
-
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
|
80
|
-
|
|
81
|
-
[homepage]: https://www.contributor-covenant.org
|
|
82
|
-
|
|
83
|
-
For answers to common questions about this code of conduct, see the FAQ at
|
|
84
|
-
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
require 'uri'
|
|
3
|
-
require 'net/http'
|
|
4
|
-
require 'json'
|
|
5
|
-
|
|
6
|
-
module Mslm
|
|
7
|
-
module Constants
|
|
8
|
-
BASE_URL = 'https://mslm.io/'.freeze
|
|
9
|
-
|
|
10
|
-
def self.prepare_url(path, query_params, opts)
|
|
11
|
-
url = path.dup
|
|
12
|
-
url << '?' << URI.encode_www_form(query_params) unless query_params.empty?
|
|
13
|
-
url
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def self.req_and_resp(_method, _url, _data, _opts)
|
|
17
|
-
uri = URI.parse(_url)
|
|
18
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
|
19
|
-
http.use_ssl = true if uri.scheme == 'https'
|
|
20
|
-
|
|
21
|
-
if _method == 'POST'
|
|
22
|
-
request = Net::HTTP::Post.new(uri.request_uri)
|
|
23
|
-
request.body = _data.to_json
|
|
24
|
-
request.content_type = 'application/json'
|
|
25
|
-
elsif _method == 'GET'
|
|
26
|
-
request = Net::HTTP::Get.new(uri.request_uri)
|
|
27
|
-
|
|
28
|
-
else
|
|
29
|
-
return "Unsupported HTTP method: #{_method}"
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
response_data = http.request(request)
|
|
33
|
-
|
|
34
|
-
if _method == 'POST' and response_data.code.to_i == 200
|
|
35
|
-
json_response = JSON.parse(response_data.body)
|
|
36
|
-
return json_response
|
|
37
|
-
|
|
38
|
-
elsif response_data.code.to_i == 200
|
|
39
|
-
json_response = JSON.parse(response_data.body)
|
|
40
|
-
response = [json_response["email"],json_response["username"],json_response["domain"],json_response["malformed"],json_response["suggestion"],json_response["status"],json_response["has_mailbox"],json_response["accept_all"],json_response["disposable"],json_response["free"],json_response["role"],json_response['mx']]
|
|
41
|
-
|
|
42
|
-
return response
|
|
43
|
-
else
|
|
44
|
-
return "HTTP #{response_data.code}: #{response_data.message}"
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
require_relative '../mslm'
|
|
3
|
-
require_relative './constants/constants'
|
|
4
|
-
|
|
5
|
-
module Mslm
|
|
6
|
-
module EmailVerification
|
|
7
|
-
include Constants
|
|
8
|
-
|
|
9
|
-
class SingleVerifyReqOpts
|
|
10
|
-
attr_accessor :disable_url_encode
|
|
11
|
-
attr_accessor :api_key
|
|
12
|
-
end
|
|
13
|
-
class SingleVerifyEmail
|
|
14
|
-
|
|
15
|
-
def single_verify(email_addr, opts = nil)
|
|
16
|
-
opt = SingleVerifyReqOpts.new
|
|
17
|
-
opt = opts.last unless opts.nil? || opts.empty?
|
|
18
|
-
opt.disable_url_encode = true if opt.disable_url_encode.nil?
|
|
19
|
-
|
|
20
|
-
email_addr = URI.encode_www_form_component(email_addr) unless opt.disable_url_encode
|
|
21
|
-
|
|
22
|
-
qp = { 'email' => email_addr }
|
|
23
|
-
if Mslm.api_key || opt.api_key
|
|
24
|
-
api_key = opt.api_key || Mslm.api_key
|
|
25
|
-
qp['apikey'] = api_key
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
t_url = Mslm::Constants.prepare_url(Mslm::EmailVerification::BASE_URL + 'api/sv/v1', qp, opt)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
sv_resp = Mslm::Constants.req_and_resp('GET', t_url, nil, opt)
|
|
32
|
-
return sv_resp
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
data/sig/mslm.rbs
DELETED