mslm 2.2.2 → 2.2.4
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/.gitignore +0 -0
- data/Gemfile +8 -0
- data/README.md +60 -41
- data/bin/console +11 -0
- data/bin/setup +8 -0
- data/lib/mslm/email_verify.rb +11 -47
- data/lib/mslm/lib.rb +64 -65
- data/lib/mslm/mslm_errors.rb +15 -18
- data/lib/mslm/otp.rb +69 -105
- data/lib/mslm/req_opts.rb +47 -50
- data/lib/mslm/version.rb +1 -3
- data/lib/mslm.rb +42 -8
- data/mslm.gemspec +12 -7
- data/test/email_verify_test.rb +82 -0
- data/test/otp_send_test.rb +25 -0
- data/test/otp_verify_test.rb +27 -0
- metadata +9 -7
- data/lib/mslm/otp_resp.rb +0 -30
- data/lib/mslm/otp_send_req.rb +0 -11
- data/lib/mslm/otp_token_verify_req.rb +0 -10
- data/lib/mslm/single_verify_resp.rb +0 -33
- data/lib/mslm/single_verify_resp_mx.rb +0 -26
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f4c36e8dda6b4d3606e0108e0c87b5dbba260a9a032daf246b6d4468d9ef3a12
|
|
4
|
+
data.tar.gz: 150a1b6af2365d14b05d4a5e7eb7d76a9b3d6cdb36becfa8172019ba3964b982
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8b56b440b888ac432d67a555f328f7453f831c2974df0ed8178c8aac9fded1cd047d47c755f40357fe58c7704950107404da6af1a07aac160d94d460da04c42d
|
|
7
|
+
data.tar.gz: e4ff21bcda23fdeadff7fa3da75b187024e5d9675d8273687dcc6d5f1f9344d2f942f572283b20e67a977821dfae5f7141b6e036dacfa6816773ac563d7a52a6
|
data/.gitignore
ADDED
|
File without changes
|
data/Gemfile
ADDED
data/README.md
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
# Mslm Ruby SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# [<img src="https://avatars.githubusercontent.com/u/50307970?s=200&v=4" alt="Mslm" width="24"/>](https://mslm.io/) IPinfo Ruby Client Library
|
|
4
|
+
|
|
5
|
+
The official Ruby SDK for Mslm APIs [Mslm.io](https://mslm.io) that enables you to verify email addresses and perform other actions related to email verification, sending and verifying otp.
|
|
4
6
|
|
|
5
7
|
## Requirements
|
|
6
8
|
|
|
9
|
+
Before you start using the Mslm Ruby SDK, ensure that you have the following:
|
|
10
|
+
|
|
11
|
+
- **Ruby:** The SDK is compatible with Ruby version >= 3.0.0.
|
|
12
|
+
|
|
7
13
|
## Authentication
|
|
8
14
|
|
|
9
15
|
Mslm's APIs require an API key. If you don't have one, please read
|
|
@@ -12,73 +18,86 @@ get an API key before continuing.
|
|
|
12
18
|
|
|
13
19
|
## Installation
|
|
14
20
|
|
|
15
|
-
To install the
|
|
16
|
-
|
|
17
|
-
$ gem install 'mslm'
|
|
21
|
+
To install the main library, use the following command:
|
|
18
22
|
|
|
19
|
-
|
|
23
|
+
```bash
|
|
24
|
+
gem install mslm
|
|
25
|
+
```
|
|
20
26
|
|
|
21
|
-
|
|
27
|
+
## Usage
|
|
22
28
|
|
|
23
|
-
|
|
29
|
+
```ruby
|
|
30
|
+
require 'mslm'
|
|
24
31
|
|
|
25
|
-
|
|
32
|
+
# Initialize the Mslm object with your API key.
|
|
33
|
+
client = Mslm::Mslm.new('api_key')
|
|
34
|
+
```
|
|
26
35
|
|
|
27
|
-
|
|
36
|
+
#### Email Verify
|
|
28
37
|
|
|
29
|
-
|
|
38
|
+
- Single Verify
|
|
30
39
|
|
|
31
|
-
|
|
40
|
+
```ruby
|
|
41
|
+
response = client.verify_email("fakefake@mslm.io")
|
|
32
42
|
|
|
33
|
-
|
|
43
|
+
response.status //fake
|
|
44
|
+
response.domain //mslm.io
|
|
45
|
+
response.malformed //false
|
|
46
|
+
response.has_mailbox //false
|
|
47
|
+
response.disposable //false
|
|
34
48
|
|
|
35
|
-
|
|
36
|
-
details on each API's actual interface, which is implemented by this SDK.
|
|
49
|
+
```
|
|
37
50
|
|
|
38
|
-
|
|
51
|
+
#### OTP
|
|
39
52
|
|
|
40
|
-
|
|
53
|
+
- Sending an OTP.
|
|
41
54
|
|
|
42
|
-
|
|
55
|
+
```ruby
|
|
56
|
+
otp_send_req = {
|
|
57
|
+
"phone" => "+923214444444",
|
|
58
|
+
"tmpl_sms" => "Your verification code is {token}",
|
|
59
|
+
"token_len" => 4,
|
|
60
|
+
"expire_seconds" => 300,
|
|
61
|
+
}
|
|
43
62
|
|
|
44
|
-
|
|
63
|
+
response = client.send_otp(otp_send_req)
|
|
45
64
|
|
|
46
|
-
response
|
|
65
|
+
response.code //1000
|
|
66
|
+
respnse.msg //Successfully sent SMS.
|
|
47
67
|
|
|
48
|
-
|
|
68
|
+
```
|
|
49
69
|
|
|
50
|
-
|
|
70
|
+
- Verifying a token.
|
|
51
71
|
|
|
52
|
-
|
|
72
|
+
```ruby
|
|
73
|
+
otp_token_verify_request = {
|
|
74
|
+
"phone" => "+923214444444",
|
|
75
|
+
"token" => "123456",
|
|
76
|
+
"consume" => True,
|
|
77
|
+
}
|
|
53
78
|
|
|
54
|
-
|
|
79
|
+
otp_verify_resp = client.verify_otp(otp_verify_req)
|
|
55
80
|
|
|
56
|
-
|
|
81
|
+
response.code //1000
|
|
82
|
+
response.msg //Successfully verified.
|
|
83
|
+
```
|
|
57
84
|
|
|
58
|
-
|
|
85
|
+
### Error Handling
|
|
59
86
|
|
|
60
|
-
|
|
61
|
-
"phone" => "+921123454456",
|
|
62
|
-
"tmpl_sms" => "Your verification code is {112233}",
|
|
63
|
-
"token_len" => 4, # Hown much length is required
|
|
64
|
-
"expire_seconds" => 300,
|
|
65
|
-
}
|
|
87
|
+
We expose the following error types in the SDK:
|
|
66
88
|
|
|
67
|
-
|
|
89
|
+
#### Common Errors
|
|
68
90
|
|
|
69
|
-
|
|
91
|
+
- `MslmError`: The base error type.
|
|
70
92
|
|
|
71
|
-
|
|
72
|
-
"phone" => "+921123454456",
|
|
73
|
-
"token" => "Recieved Token",
|
|
74
|
-
"consume" => true,
|
|
75
|
-
}
|
|
93
|
+
#### Quota-Related Errors
|
|
76
94
|
|
|
77
|
-
|
|
95
|
+
- `RequestQuotaExceededError`: The request quota has been exceeded.
|
|
78
96
|
|
|
79
|
-
|
|
97
|
+
## Additional Resources
|
|
80
98
|
|
|
81
|
-
|
|
99
|
+
See the official [API Reference Documentation](https://mslm.io/docs/api) for
|
|
100
|
+
details on each API's actual interface, which is implemented by this SDK.
|
|
82
101
|
|
|
83
102
|
## Contributing
|
|
84
103
|
|
data/bin/console
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "bundler/setup"
|
|
5
|
+
require "mslm"
|
|
6
|
+
|
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
9
|
+
|
|
10
|
+
require "irb"
|
|
11
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/mslm/email_verify.rb
CHANGED
|
@@ -1,80 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
require 'json'
|
|
4
1
|
require_relative 'lib'
|
|
5
2
|
require_relative 'req_opts'
|
|
6
|
-
require_relative 'mslm_errors'
|
|
7
|
-
require_relative 'single_verify_resp'
|
|
8
|
-
|
|
9
|
-
module Mslm
|
|
10
|
-
class EmailVerify
|
|
11
3
|
|
|
4
|
+
class EmailVerify
|
|
12
5
|
# Class for performing email verification using an API.
|
|
13
6
|
attr_reader :lib
|
|
14
7
|
|
|
15
8
|
# Initializes an EmailVerify object with an API key.
|
|
16
9
|
def initialize(api_key)
|
|
17
|
-
|
|
10
|
+
@lib = Lib.new(api_key)
|
|
18
11
|
end
|
|
19
12
|
|
|
20
13
|
# Sets the HTTP client to be used for making requests.
|
|
21
14
|
def set_http_client(http_client)
|
|
22
|
-
|
|
15
|
+
@lib.set_http_client(http_client)
|
|
23
16
|
end
|
|
24
17
|
|
|
25
18
|
# Sets the user agent to be used in HTTP requests.
|
|
26
19
|
def set_user_agent(user_agent)
|
|
27
|
-
|
|
20
|
+
@lib.set_user_agent(user_agent)
|
|
28
21
|
end
|
|
29
22
|
|
|
30
23
|
# Sets the API key for authentication.
|
|
31
24
|
def set_api_key(api_key)
|
|
32
|
-
|
|
25
|
+
@lib.set_api_key(api_key)
|
|
33
26
|
end
|
|
34
27
|
|
|
35
28
|
# Performs a single email verification with optional request options.
|
|
36
29
|
def single_verify(email, opts = nil)
|
|
37
|
-
|
|
30
|
+
opt = ReqOpts::Builder.new
|
|
38
31
|
.with_api_key(@lib.api_key)
|
|
39
32
|
.with_base_url(@lib.base_url)
|
|
40
33
|
.with_http_client(@lib.http)
|
|
41
34
|
.with_user_agent(@lib.user_agent)
|
|
42
35
|
.build
|
|
43
36
|
|
|
37
|
+
opt = opts if opts
|
|
38
|
+
query_params = { 'email' => email }
|
|
39
|
+
target_url = @lib.prepare_url('/api/sv/v1', query_params, opt)
|
|
44
40
|
|
|
45
|
-
|
|
46
|
-
|
|
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
|
|
41
|
+
resp = @lib.req_and_resp(target_url, opt)
|
|
42
|
+
resp
|
|
78
43
|
end
|
|
79
|
-
end
|
|
80
44
|
end
|
data/lib/mslm/lib.rb
CHANGED
|
@@ -1,80 +1,79 @@
|
|
|
1
|
-
require 'json'
|
|
2
1
|
require 'uri'
|
|
3
2
|
require 'net/http'
|
|
3
|
+
require_relative 'version'
|
|
4
|
+
require_relative '../mslm'
|
|
4
5
|
|
|
5
6
|
class Lib
|
|
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(Mslm::Mslm::BASE_URL)
|
|
15
|
+
@user_agent = self.class.get_user_agent('mslm')
|
|
16
|
+
end
|
|
6
17
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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)
|
|
18
|
+
# Sets the HTTP client for making requests.
|
|
19
|
+
def set_http_client(http_client)
|
|
20
|
+
@http = http_client
|
|
21
|
+
end
|
|
45
22
|
|
|
46
|
-
|
|
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
|
|
47
27
|
|
|
48
|
-
|
|
49
|
-
|
|
28
|
+
# Sets the user agent for HTTP requests.
|
|
29
|
+
def set_user_agent(user_agent)
|
|
30
|
+
@user_agent = user_agent
|
|
31
|
+
end
|
|
50
32
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
qp_str
|
|
56
|
-
end
|
|
33
|
+
# Sets the API key for authentication.
|
|
34
|
+
def set_api_key(api_key)
|
|
35
|
+
@api_key = api_key
|
|
36
|
+
end
|
|
57
37
|
|
|
58
|
-
|
|
59
|
-
|
|
38
|
+
# Static method to generate a user agent string.
|
|
39
|
+
def self.get_user_agent(pkg)
|
|
40
|
+
"#{pkg}/ruby/#{Mslm::VERSION}"
|
|
41
|
+
end
|
|
60
42
|
|
|
61
|
-
|
|
62
|
-
|
|
43
|
+
# Prepares the URL for making a request.
|
|
44
|
+
def prepare_url(url_path, query_params, opt)
|
|
45
|
+
query_params['apikey'] = opt.api_key
|
|
63
46
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
headers = {}
|
|
47
|
+
target_url = @base_url.dup
|
|
48
|
+
target_url.path = url_path
|
|
49
|
+
query_params_str = URI.encode_www_form(query_params)
|
|
68
50
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
raise ArgumentError, 'Invalid HTTP method. Supported methods are GET and POST.'
|
|
51
|
+
target_url.query = if target_url.query
|
|
52
|
+
"#{target_url.query}&#{query_params_str}"
|
|
53
|
+
else
|
|
54
|
+
query_params_str
|
|
55
|
+
end
|
|
56
|
+
target_url
|
|
76
57
|
end
|
|
77
58
|
|
|
78
|
-
response
|
|
79
|
-
|
|
59
|
+
# Makes an HTTP request and returns the response.
|
|
60
|
+
def req_and_resp(target_url, opt, method = 'GET', data = nil)
|
|
61
|
+
uri = URI.parse(target_url)
|
|
62
|
+
@http = Net::HTTP.new(uri.host, uri.port)
|
|
63
|
+
http.use_ssl = true if uri.scheme == 'https'
|
|
64
|
+
headers = {
|
|
65
|
+
'User-Agent' => @user_agent,
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if method.upcase == 'GET'
|
|
69
|
+
response = @http.get(uri.request_uri,headers)
|
|
70
|
+
elsif method.upcase == 'POST'
|
|
71
|
+
headers['Content-Type'] = 'application/json'
|
|
72
|
+
response = @http.post(uri.request_uri,data,headers)
|
|
73
|
+
else
|
|
74
|
+
raise ArgumentError, 'Invalid HTTP method. Supported methods are GET and POST.'
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
response
|
|
78
|
+
end
|
|
80
79
|
end
|
data/lib/mslm/mslm_errors.rb
CHANGED
|
@@ -1,25 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
# Base class for errors
|
|
3
1
|
class MslmError < StandardError
|
|
4
|
-
|
|
2
|
+
attr_reader :code, :message
|
|
5
3
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
# Initializes a new MslmError object with a code and a message
|
|
5
|
+
def initialize(code, message)
|
|
6
|
+
@code = code
|
|
7
|
+
@message = message
|
|
8
|
+
end
|
|
11
9
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
# Returns a string representation of the error
|
|
11
|
+
def to_str
|
|
12
|
+
"Error: code: #{@code}, message: #{@message}"
|
|
13
|
+
end
|
|
16
14
|
end
|
|
17
15
|
|
|
18
16
|
# Error raised when the request quota for the API key has been exceeded
|
|
19
|
-
class RequestQuotaExceededError < MslmError
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
end
|
|
17
|
+
class RequestQuotaExceededError < MslmError
|
|
18
|
+
# Initializes a new RequestQuotaExceededError object with a default message and code
|
|
19
|
+
def initialize(message = "Request quota for API key has been exceeded.")
|
|
20
|
+
super(429, message)
|
|
21
|
+
end
|
|
25
22
|
end
|
data/lib/mslm/otp.rb
CHANGED
|
@@ -1,111 +1,75 @@
|
|
|
1
|
-
require 'json'
|
|
2
1
|
require_relative 'lib'
|
|
3
2
|
require_relative 'req_opts'
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
}
|
|
88
|
-
|
|
89
|
-
t_url = @lib.prepare_url('/api/otp/v1/token_verify', {}, opt)
|
|
90
|
-
|
|
91
|
-
resp = @lib.req_and_resp(t_url, opt, 'POST', qp.to_json)
|
|
92
|
-
resp_data = JSON.parse(resp.body)
|
|
93
|
-
|
|
94
|
-
code = resp_data['code']
|
|
95
|
-
msg = resp_data['msg']
|
|
96
|
-
|
|
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')
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
otp_verify_resp = OtpTokenVerifyResp.new(code,msg)
|
|
106
|
-
otp_verify_resp
|
|
107
|
-
end
|
|
3
|
+
|
|
4
|
+
class Otp
|
|
5
|
+
# Class for performing otp using an API.
|
|
6
|
+
attr_reader :lib
|
|
7
|
+
|
|
8
|
+
# Initializes an object with an API key.
|
|
9
|
+
def initialize(api_key)
|
|
10
|
+
@lib = Lib.new(api_key)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Sets the HTTP client to be used for making requests.
|
|
14
|
+
def set_http_client(http_client)
|
|
15
|
+
@lib.set_http_client(http_client)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Sets the user agent to be used in HTTP requests.
|
|
19
|
+
def set_user_agent(user_agent)
|
|
20
|
+
@lib.set_user_agent(user_agent)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Sets the API key for authentication.
|
|
24
|
+
def set_api_key(api_key)
|
|
25
|
+
@lib.set_api_key(api_key)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Sends an OTP to the specified phone number with the provided options.
|
|
29
|
+
def send(otp_req, opts = nil)
|
|
30
|
+
opt = ReqOpts::Builder.new
|
|
31
|
+
.with_api_key(@lib.api_key)
|
|
32
|
+
.with_base_url(@lib.base_url)
|
|
33
|
+
.with_http_client(@lib.http)
|
|
34
|
+
.with_user_agent(@lib.user_agent)
|
|
35
|
+
.build
|
|
36
|
+
|
|
37
|
+
opt = opts if opts
|
|
38
|
+
query_params = {
|
|
39
|
+
'phone' => otp_req['phone'],
|
|
40
|
+
'tmpl_sms' => otp_req['tmpl_sms'],
|
|
41
|
+
'token_len' => otp_req['token_len'],
|
|
42
|
+
'expire_seconds' => otp_req['expire_seconds']
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
target_url = @lib.prepare_url('/api/otp/v1/send', {}, opt)
|
|
46
|
+
|
|
47
|
+
resp = @lib.req_and_resp(target_url, opt, 'POST', query_params.to_json)
|
|
48
|
+
resp
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Verifies an OTP token for the specified phone number with the provided options.
|
|
52
|
+
def verify(otp_token_req, opts = nil)
|
|
53
|
+
opt = ReqOpts::Builder.new
|
|
54
|
+
.with_api_key(@lib.api_key)
|
|
55
|
+
.with_base_url(@lib.base_url)
|
|
56
|
+
.with_http_client(@lib.http)
|
|
57
|
+
.with_user_agent(@lib.user_agent)
|
|
58
|
+
.build
|
|
59
|
+
|
|
60
|
+
opt = opts if opts
|
|
61
|
+
query_params = {
|
|
62
|
+
'phone' => otp_token_req["phone"],
|
|
63
|
+
'token' => otp_token_req["token"],
|
|
64
|
+
'consume' => otp_token_req["consume"]
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
target_url = @lib.prepare_url('/api/otp/v1/token_verify', {}, opt)
|
|
68
|
+
|
|
69
|
+
resp = @lib.req_and_resp(target_url, opt, 'POST', query_params.to_json)
|
|
70
|
+
resp
|
|
108
71
|
end
|
|
109
72
|
end
|
|
110
73
|
|
|
111
74
|
|
|
75
|
+
|
data/lib/mslm/req_opts.rb
CHANGED
|
@@ -1,57 +1,54 @@
|
|
|
1
1
|
require 'uri'
|
|
2
|
-
|
|
2
|
+
require_relative '../mslm'
|
|
3
3
|
|
|
4
4
|
class ReqOpts
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
|
5
|
+
# Request options class for configuring HTTP requests.
|
|
6
|
+
attr_accessor :api_key, :http, :base_url, :user_agent
|
|
7
|
+
|
|
8
|
+
# Initializes a ReqOpts object with default or provided values.
|
|
9
|
+
def initialize(api_key: "", http: nil, base_url: Mslm::Mslm::BASE_URL, user_agent: "mslm")
|
|
10
|
+
@api_key = api_key
|
|
11
|
+
@http = http
|
|
12
|
+
@base_url = URI.parse(base_url)
|
|
13
|
+
@user_agent = user_agent
|
|
50
14
|
end
|
|
51
15
|
|
|
52
|
-
#
|
|
53
|
-
|
|
54
|
-
|
|
16
|
+
# Nested builder class for constructing instances of ReqOpts.
|
|
17
|
+
class Builder
|
|
18
|
+
# Builder class for constructing instances of ReqOpts.
|
|
19
|
+
attr_reader :opts
|
|
20
|
+
|
|
21
|
+
def initialize
|
|
22
|
+
@opts = ReqOpts.new
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Sets the API key.
|
|
26
|
+
def with_api_key(api_key)
|
|
27
|
+
@opts.api_key = api_key
|
|
28
|
+
self
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Sets the HTTP client.
|
|
32
|
+
def with_http_client(http)
|
|
33
|
+
@opts.http = http
|
|
34
|
+
self
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Sets the base URL.
|
|
38
|
+
def with_base_url(base_url)
|
|
39
|
+
@opts.base_url = URI.parse(base_url)
|
|
40
|
+
self
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Sets the user agent.
|
|
44
|
+
def with_user_agent(user_agent)
|
|
45
|
+
@opts.user_agent = user_agent
|
|
46
|
+
self
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Builds and returns an instance of ReqOpts.
|
|
50
|
+
def build
|
|
51
|
+
@opts
|
|
52
|
+
end
|
|
55
53
|
end
|
|
56
|
-
end
|
|
57
54
|
end
|
data/lib/mslm/version.rb
CHANGED
data/lib/mslm.rb
CHANGED
|
@@ -1,14 +1,48 @@
|
|
|
1
|
+
require 'json'
|
|
1
2
|
require_relative './mslm/otp'
|
|
2
3
|
require_relative './mslm/email_verify'
|
|
3
|
-
|
|
4
|
+
require_relative './mslm/mslm_errors'
|
|
5
|
+
require_relative './mslm/response'
|
|
4
6
|
|
|
5
7
|
module Mslm
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
class Mslm
|
|
9
|
+
BASE_URL = "https://mslm.io".freeze
|
|
10
|
+
attr_accessor :email_verify, :otp
|
|
11
|
+
|
|
12
|
+
def initialize(api_key)
|
|
13
|
+
@email_verify = EmailVerify.new(api_key)
|
|
14
|
+
@otp = Otp.new(api_key)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def verify_email(email, opts = nil)
|
|
18
|
+
resp = @email_verify.single_verify(email, opts)
|
|
19
|
+
|
|
20
|
+
handle_response(resp)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def send_otp(otp_req, opts = nil)
|
|
24
|
+
resp = @otp.send(otp_req, opts)
|
|
25
|
+
|
|
26
|
+
handle_response(resp)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def verify_otp(otp_token_req, opts = nil)
|
|
30
|
+
resp = @otp.verify(otp_token_req, opts)
|
|
31
|
+
|
|
32
|
+
handle_response(resp)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def handle_response(resp)
|
|
36
|
+
resp_data = JSON.parse(resp.body)
|
|
37
|
+
status_code = resp.code.to_i
|
|
38
|
+
|
|
39
|
+
if status_code == 429
|
|
40
|
+
return nil, RequestQuotaExceededError.new()
|
|
41
|
+
elsif status_code != 200
|
|
42
|
+
return nil, MslmError.new(status_code, 'API request failed')
|
|
43
|
+
end
|
|
8
44
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
@otp = Otp.new(api_key)
|
|
45
|
+
Response.new(resp_data)
|
|
46
|
+
end
|
|
12
47
|
end
|
|
13
|
-
|
|
14
|
-
end
|
|
48
|
+
end
|
data/mslm.gemspec
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
1
|
require_relative "lib/mslm/version"
|
|
4
2
|
|
|
5
3
|
Gem::Specification.new do |spec|
|
|
@@ -14,17 +12,24 @@ Gem::Specification.new do |spec|
|
|
|
14
12
|
spec.license = "MIT"
|
|
15
13
|
spec.required_ruby_version = ">= 3.0.0"
|
|
16
14
|
|
|
17
|
-
|
|
18
15
|
spec.metadata["homepage_uri"] = spec.homepage
|
|
19
16
|
spec.metadata["source_code_uri"] = "https://github.com/mslmio/sdk-ruby"
|
|
20
17
|
spec.metadata["changelog_uri"] = "https://github.com/mslmio/sdk-ruby/blob/main/CHANGELOG.md"
|
|
21
18
|
|
|
19
|
+
EXCLUDED_FILES = [
|
|
20
|
+
"lib/mslm/otp_resp.rb",
|
|
21
|
+
"lib/mslm/otp_send_req.rb",
|
|
22
|
+
"lib/mslm/otp_token_verify_req.rb",
|
|
23
|
+
"lib/mslm/single_verify_resp.rb",
|
|
24
|
+
"lib/mslm/single_verify_resp_mx.rb"
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
|
|
22
28
|
spec.files = Dir.chdir(__dir__) do
|
|
23
|
-
`git ls-files -z`.split("\x0")
|
|
24
|
-
|
|
25
|
-
f.start_with?(*%w[bin/ test/ spec/ features/ .git appveyor Gemfile])
|
|
26
|
-
end
|
|
29
|
+
all_files = `git ls-files -z`.split("\x0")
|
|
30
|
+
all_files.reject { |file| EXCLUDED_FILES.include?(file) }
|
|
27
31
|
end
|
|
32
|
+
|
|
28
33
|
spec.bindir = "exe"
|
|
29
34
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
30
35
|
spec.require_paths = ["lib"]
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
require 'minitest/autorun'
|
|
2
|
+
require_relative '../lib/mslm'
|
|
3
|
+
|
|
4
|
+
class TestEmailVerification < Minitest::Test
|
|
5
|
+
TEST_EMAIL_REAL = 'support@mslm.io'
|
|
6
|
+
TEST_EMAIL_FAKE = 'fakefakefake@mslm.io'
|
|
7
|
+
TEST_EMAIL_DISPOSABLE = 'asdfasdf@temp-mail.org'
|
|
8
|
+
|
|
9
|
+
def setup
|
|
10
|
+
@api_key = 'api_key'
|
|
11
|
+
@email_verify = Mslm::Mslm.new(@api_key)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def test_email_verify_sv_fake
|
|
15
|
+
resp, _ = @email_verify.verify_email(TEST_EMAIL_REAL)
|
|
16
|
+
assert_email_verify_sv_REAL(resp)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def assert_email_verify_sv_REAL(resp)
|
|
20
|
+
assert_equal(resp.email, TEST_EMAIL_REAL)
|
|
21
|
+
assert_equal(resp.username, 'support')
|
|
22
|
+
assert_equal(resp.domain, 'mslm.io')
|
|
23
|
+
assert_equal(resp.malformed, false)
|
|
24
|
+
assert_equal(resp.suggestion, '')
|
|
25
|
+
assert_equal(resp.status, 'real')
|
|
26
|
+
assert_equal(resp.has_mailbox, true)
|
|
27
|
+
assert_equal(resp.accept_all, false)
|
|
28
|
+
assert_equal(resp.disposable, false)
|
|
29
|
+
assert_equal(resp.free, false)
|
|
30
|
+
assert_equal(resp.role, true)
|
|
31
|
+
assert_equal(resp.mx, [[{"host"=>"mx.yandex.net.", "pref"=>10}]])
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def test_email_verify_sv_fake
|
|
35
|
+
resp, _ = @email_verify.verify_email(TEST_EMAIL_FAKE)
|
|
36
|
+
assert_email_verify_sv_fake(resp)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def assert_email_verify_sv_fake(resp)
|
|
40
|
+
assert_equal(resp.email, TEST_EMAIL_FAKE)
|
|
41
|
+
assert_equal(resp.username, 'fakefakefake')
|
|
42
|
+
assert_equal(resp.domain, 'mslm.io')
|
|
43
|
+
assert_equal(resp.malformed, false)
|
|
44
|
+
assert_equal(resp.suggestion, '')
|
|
45
|
+
assert_equal(resp.status, 'fake')
|
|
46
|
+
assert_equal(resp.has_mailbox, false)
|
|
47
|
+
assert_equal(resp.accept_all, false)
|
|
48
|
+
assert_equal(resp.disposable, false)
|
|
49
|
+
assert_equal(resp.free, false)
|
|
50
|
+
assert_equal(resp.role, false)
|
|
51
|
+
assert_equal(resp.mx, [
|
|
52
|
+
{"host"=>"ASPMX.L.GOOGLE.COM.", "pref"=>1},
|
|
53
|
+
{"host"=>"ALT2.ASPMX.L.GOOGLE.COM.", "pref"=>5},
|
|
54
|
+
{"host"=>"ALT1.ASPMX.L.GOOGLE.COM.", "pref"=>5},
|
|
55
|
+
{"host"=>"ALT4.ASPMX.L.GOOGLE.COM.", "pref"=>10},
|
|
56
|
+
{"host"=>"ALT3.ASPMX.L.GOOGLE.COM.", "pref"=>10}
|
|
57
|
+
])
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def test_email_verify_sv_disposable
|
|
61
|
+
resp, _ = @email_verify.verify_email(TEST_EMAIL_DISPOSABLE)
|
|
62
|
+
assert_email_verify_sv_disposable(resp)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def assert_email_verify_sv_disposable(resp)
|
|
66
|
+
assert_equal(resp.email, TEST_EMAIL_DISPOSABLE)
|
|
67
|
+
assert_equal(resp.username, 'asdfasdf')
|
|
68
|
+
assert_equal(resp.domain, 'temp-mail.org')
|
|
69
|
+
assert_equal(resp.malformed, false)
|
|
70
|
+
assert_equal(resp.suggestion, '')
|
|
71
|
+
assert_equal(resp.status, 'disposable')
|
|
72
|
+
assert_equal(resp.has_mailbox, true)
|
|
73
|
+
assert_equal(resp.accept_all, true)
|
|
74
|
+
assert_equal(resp.disposable, true)
|
|
75
|
+
assert_equal(resp.free, true)
|
|
76
|
+
assert_equal(resp.role, false)
|
|
77
|
+
assert_equal(resp.mx, [{"host"=>"mx.yandex.net.", "pref"=>10}])
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require 'minitest/autorun'
|
|
2
|
+
require_relative '../lib/mslm'
|
|
3
|
+
|
|
4
|
+
class TestOtp < Minitest::Test
|
|
5
|
+
|
|
6
|
+
def setup
|
|
7
|
+
@api_key = 'api_key'
|
|
8
|
+
@otp = Mslm::Mslm.new(@api_key)
|
|
9
|
+
@phone_number = '+923214444444'
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def test_otp_send_success
|
|
13
|
+
otp_send_req = {
|
|
14
|
+
"phone" => @phone_number,
|
|
15
|
+
"tmpl_sms" => "Your verification code is {token}",
|
|
16
|
+
"token_len" => 4,
|
|
17
|
+
"expire_seconds" => 300,
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
otp_send_resp = @otp.send_otp(otp_send_req)
|
|
21
|
+
|
|
22
|
+
assert_equal(1000, otp_send_resp.code)
|
|
23
|
+
assert_equal("Successfully sent SMS.", otp_send_resp.msg)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'minitest/autorun'
|
|
2
|
+
require_relative '../lib/mslm'
|
|
3
|
+
|
|
4
|
+
class TestOtp < Minitest::Test
|
|
5
|
+
|
|
6
|
+
def setup
|
|
7
|
+
@api_key = 'api_key'
|
|
8
|
+
@otp = Mslm::Mslm.new(@api_key)
|
|
9
|
+
@phone_number = '+923214444444'
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def test_otp_verify_success
|
|
13
|
+
otp_code = '9842'
|
|
14
|
+
|
|
15
|
+
otp_verify_req = {
|
|
16
|
+
"phone" => @phone_number,
|
|
17
|
+
"token" => otp_code,
|
|
18
|
+
"consume" => true,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
otp_verify_resp = @otp.verify_otp(otp_verify_req)
|
|
22
|
+
|
|
23
|
+
assert_equal(1000, otp_verify_resp.code)
|
|
24
|
+
assert_equal("Successfully verified.", otp_verify_resp.msg)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
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: 2.2.
|
|
4
|
+
version: 2.2.4
|
|
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-05-02 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
|
|
@@ -19,24 +19,26 @@ executables: []
|
|
|
19
19
|
extensions: []
|
|
20
20
|
extra_rdoc_files: []
|
|
21
21
|
files:
|
|
22
|
+
- ".gitignore"
|
|
22
23
|
- CHANGELOG.md
|
|
23
24
|
- CONTRIBUTING.md
|
|
25
|
+
- Gemfile
|
|
24
26
|
- LICENSE
|
|
25
27
|
- README.md
|
|
26
28
|
- Rakefile
|
|
29
|
+
- bin/console
|
|
30
|
+
- bin/setup
|
|
27
31
|
- lib/mslm.rb
|
|
28
32
|
- lib/mslm/email_verify.rb
|
|
29
33
|
- lib/mslm/lib.rb
|
|
30
34
|
- lib/mslm/mslm_errors.rb
|
|
31
35
|
- 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
36
|
- lib/mslm/req_opts.rb
|
|
36
|
-
- lib/mslm/single_verify_resp.rb
|
|
37
|
-
- lib/mslm/single_verify_resp_mx.rb
|
|
38
37
|
- lib/mslm/version.rb
|
|
39
38
|
- mslm.gemspec
|
|
39
|
+
- test/email_verify_test.rb
|
|
40
|
+
- test/otp_send_test.rb
|
|
41
|
+
- test/otp_verify_test.rb
|
|
40
42
|
homepage: https://github.com/mslmio/sdk-ruby
|
|
41
43
|
licenses:
|
|
42
44
|
- MIT
|
data/lib/mslm/otp_resp.rb
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
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
|
data/lib/mslm/otp_send_req.rb
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
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
|
|
@@ -1,33 +0,0 @@
|
|
|
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
|
-
"{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
|
|
@@ -1,26 +0,0 @@
|
|
|
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
|