mslm 2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ef29e7107da0fc04c7853ede27bb2a9ddd1c5dfb31cb9551a00844f0dfa0f702
4
- data.tar.gz: 7cdccfd1a89b0d6f6031eb1175c2c3b5f088ea64ac55985a7ab1f635039c413b
3
+ metadata.gz: 2d94f857bd5851ae64057c5bbec4cbc08c3d0a6fc8d2604e81f6a060be3d6048
4
+ data.tar.gz: bd315b955fef052d9d9f07f08afc41443fe7dd62b76e3cea0b7e874b947938fd
5
5
  SHA512:
6
- metadata.gz: 668881352faa56001656c49981ffa973c3dc00d36c532011fef21eaa6961d6c2a9a1db2628b3eaecc702f35515be9e71b45316dbaa792a4313decc2977efe1c4
7
- data.tar.gz: 70d04cacb05f8762e2cf1abbfaab5aa21fd9594de3ff196bb0000780517438d31701386cda1b401806d4e9f99e04fa0130ea0df68697f8944d7e09c3293d482b
6
+ metadata.gz: a8103350a873165f4a36d2a2b637e732188bb5ac773619f8550e0664d25201f691af650fd79c0bf7482f8c30a55c33a72b2d27ce83f65dc6ccf928f1c06cb373
7
+ data.tar.gz: '06628bbf04c38b2a15838a02cfde5ad0bfd7fb01de8e69801f9e19bb6742eefd38678c7a20af16a781d717dca6f62ff6df3e849b86689f47abdebc235a06d071'
@@ -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 '../mslm'
3
- require_relative './constants/constants.rb'
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
- class SingleVerifyReqOpts
10
- attr_accessor :disable_url_encode
11
- attr_accessor :api_key
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
- class Otp_send_verify
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
- def send_otp(otp_send_req, opts = nil)
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
- t_url = Mslm::Constants.prepare_url(Mslm::EmailVerification::BASE_URL + 'api/otp/v1/send', qp, opt)
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
- otp_send_resp = Mslm::Constants.req_and_resp('POST', t_url, otp_send_req, opt)
30
- return otp_send_resp
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
- def verify(otp_token_verify_req, opts = nil)
34
- opt = SingleVerifyReqOpts.new
35
- opt = opts.last unless opts.nil? || opts.empty?
36
- opt.disable_url_encode = true if opt.disable_url_encode.nil?
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
- qp = {}
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
- t_url = Mslm::Constants.prepare_url(Mslm::EmailVerification::BASE_URL + 'api/otp/v1/token_verify', qp, opt)
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
- otp_token_verify_resp = Mslm::Constants.req_and_resp('POST', t_url, otp_token_verify_req, opt)
48
- return otp_token_verify_resp
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,10 @@
1
+ class OtpTokenVerifyReq
2
+ attr_reader :phone, :token, :consume
3
+
4
+ # Constructor method to initialize OtpTokenVerifyReq object.
5
+ def initialize(phone, token, consume)
6
+ @phone = phone
7
+ @token = token
8
+ @consume = consume
9
+ end
10
+ 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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mslm
4
- VERSION = "2.1.1"
4
+ VERSION = "2.2.1"
5
5
  end
data/lib/mslm.rb CHANGED
@@ -1,13 +1,14 @@
1
+ require_relative './mslm/otp'
1
2
  require_relative './mslm/email_verify'
2
- # require_relative './mslm/otp'
3
+
3
4
 
4
5
  module Mslm
5
6
  class << self
6
- attr_reader :email_verify, :otp
7
+ attr_accessor :email_verify, :otp
7
8
 
8
9
  def initialize(api_key)
9
10
  @email_verify = EmailVerify.new(api_key)
10
- # @otp = Otp.new(api_key)
11
+ @otp = Otp.new(api_key)
11
12
  end
12
13
  end
13
14
  end
data/mslm.gemspec CHANGED
@@ -19,21 +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
- excluded_files = [
24
- "lib/mslm/constants/constants.rb",
25
- "lib/mslm/email_verification.rb",
26
- "sig/mslm.rbs",
27
- "test/email_verification_test.rb",
28
- "CODE_OF_CONDUCT.md"
29
- ]
30
-
31
-
32
22
  spec.files = Dir.chdir(__dir__) do
33
23
  `git ls-files -z`.split("\x0").reject do |f|
34
24
  (File.expand_path(f) == __FILE__) ||
35
25
  f.start_with?(*%w[bin/ test/ spec/ features/ .git appveyor Gemfile])
36
- excluded_files.include?(f)
26
+ # excluded_files.include?(f)
37
27
  end
38
28
  end
39
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: 2.1.1
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-04-22 00:00:00.000000000 Z
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
@@ -19,20 +19,24 @@ executables: []
19
19
  extensions: []
20
20
  extra_rdoc_files: []
21
21
  files:
22
- - ".gitignore"
23
22
  - CHANGELOG.md
24
23
  - CONTRIBUTING.md
25
- - Gemfile
26
24
  - LICENSE
27
25
  - README.md
28
26
  - Rakefile
29
- - bin/console
30
- - bin/setup
31
27
  - lib/mslm.rb
28
+ - lib/mslm/email_verify.rb
29
+ - lib/mslm/lib.rb
30
+ - lib/mslm/mslm_errors.rb
32
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
33
38
  - lib/mslm/version.rb
34
39
  - mslm.gemspec
35
- - test/otp_verification_test.rb
36
40
  homepage: https://github.com/mslmio/sdk-ruby
37
41
  licenses:
38
42
  - MIT
data/.gitignore DELETED
File without changes
data/Gemfile DELETED
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- # Specify your gem's dependencies in mslm.gemspec
6
- gemspec
7
-
8
- gem "rake", "~> 13.0"
data/bin/console DELETED
@@ -1,11 +0,0 @@
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 DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
@@ -1,40 +0,0 @@
1
-
2
-
3
- require 'minitest/autorun'
4
- require_relative '../lib/mslm/otp'
5
-
6
- class OtpTest < Minitest::Test
7
- def setup
8
- @otp= Mslm::Otp::Otp_send_verify.new
9
-
10
- end
11
-
12
- def test_valid_otp_send
13
- c = Mslm.init("YOUR_API_KEY")
14
- expected_response = {
15
- "code" => 1000,
16
- "msg"=> "Successfully sent SMS."
17
- }
18
- phone_number = "+92334455112"
19
- otp_send_req = {
20
- "phone" => phone_number,
21
- "tmpl_sms" => "Your verification code is {112233}",
22
- "token_len" => 6,
23
- "expire_seconds" => 300
24
- }
25
- response = @otp.send_otp(otp_send_req)
26
- assert_equal expected_response, response
27
- end
28
-
29
- def test_valid_otp_verification
30
- phone_number = "+92334455112"
31
- otp_verify_req = {
32
- "phone" => phone_number,
33
- "token" => "123456", # Replace with actual OTP received
34
- "consume" => true
35
- }
36
- response = @otp.verify(otp_verify_req)
37
- assert_equal "expected_response", response
38
- end
39
-
40
- end