Class: Wavix::TwoFa::Verification::Client
- Inherits:
-
Object
- Object
- Wavix::TwoFa::Verification::Client
- Defined in:
- lib/wavix/two_fa/verification/client.rb
Instance Method Summary collapse
-
#cancel(request_options: {}, **params) ⇒ Wavix::Types::SuccessResponse
Cancels the 2FA verification identified by
session_id. -
#check(request_options: {}, **params) ⇒ Wavix::Types::TwoFactorVerificationCheckResponse
Validates the OTP submitted by the end user against the verification identified by
session_id. -
#create(request_options: {}, **params) ⇒ Wavix::Types::TwoFactorVerificationResponse
Creates a 2FA verification and sends a real one-time password (OTP) to the destination phone number over the selected channel; this bills the account per OTP sent.
- #initialize(client:) ⇒ void constructor
-
#resend(request_options: {}, **params) ⇒ Wavix::Types::TwoFactorVerificationResendResponse
Resends the OTP for the verification identified by
session_idover the specified channel.
Constructor Details
#initialize(client:) ⇒ void
10 11 12 |
# File 'lib/wavix/two_fa/verification/client.rb', line 10 def initialize(client:) @client = client end |
Instance Method Details
#cancel(request_options: {}, **params) ⇒ Wavix::Types::SuccessResponse
Cancels the 2FA verification identified by session_id. No further codes are sent, and previously sent codes
can no longer be validated. A new verification is required to send another code.
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/wavix/two_fa/verification/client.rb', line 149 def cancel(request_options: {}, **params) params = Wavix::Internal::Types::Utils.normalize_keys(params) request = Wavix::Internal::JSON::Request.new( base_url: [:base_url], method: "PATCH", path: "v1/two-fa/verification/#{URI.encode_uri_component(params[:session_id].to_s)}/cancel", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Wavix::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Wavix::Types::SuccessResponse.load(response.body) else error_class = Wavix::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#check(request_options: {}, **params) ⇒ Wavix::Types::TwoFactorVerificationCheckResponse
Validates the OTP submitted by the end user against the verification identified by session_id.
Non-idempotent — each call consumes one of a limited number of attempts tracked server-side; once exhausted,
the verification returns 429 until a new verification is created.
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/wavix/two_fa/verification/client.rb', line 109 def check(request_options: {}, **params) params = Wavix::Internal::Types::Utils.normalize_keys(params) request_data = Wavix::TwoFa::Verification::Types::TwoFactorVerificationCheckRequest.new(params).to_h non_body_param_names = %w[session_id] body = request_data.except(*non_body_param_names) request = Wavix::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v1/two-fa/verification/#{URI.encode_uri_component(params[:session_id].to_s)}/check", body: body, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Wavix::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Wavix::Types::TwoFactorVerificationCheckResponse.load(response.body) else error_class = Wavix::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#create(request_options: {}, **params) ⇒ Wavix::Types::TwoFactorVerificationResponse
Creates a 2FA verification and sends a real one-time password (OTP) to the destination phone number over the selected channel; this bills the account per OTP sent. Requires a 2FA service configured in the Wavix portal; the service is reused to generate and validate OTPs.
The verification proceeds through three steps:
- Create a verification to generate and send an OTP.
- Resend the OTP on the same verification if needed.
- Validate the OTP through the check endpoint.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/wavix/two_fa/verification/client.rb', line 32 def create(request_options: {}, **params) params = Wavix::Internal::Types::Utils.normalize_keys(params) request = Wavix::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v1/two-fa/verification", body: Wavix::TwoFa::Verification::Types::TwoFactorVerificationCreateRequest.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Wavix::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Wavix::Types::TwoFactorVerificationResponse.load(response.body) else error_class = Wavix::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#resend(request_options: {}, **params) ⇒ Wavix::Types::TwoFactorVerificationResendResponse
Resends the OTP for the verification identified by session_id over the specified channel. Previously sent
codes are invalidated.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/wavix/two_fa/verification/client.rb', line 68 def resend(request_options: {}, **params) params = Wavix::Internal::Types::Utils.normalize_keys(params) request_data = Wavix::TwoFa::Verification::Types::TwoFactorVerificationResendRequest.new(params).to_h non_body_param_names = %w[session_id] body = request_data.except(*non_body_param_names) request = Wavix::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v1/two-fa/verification/#{URI.encode_uri_component(params[:session_id].to_s)}", body: body, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Wavix::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Wavix::Types::TwoFactorVerificationResendResponse.load(response.body) else error_class = Wavix::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |