55
66module Bandwidth
77module TwoFactorAuth
8- # APIController
9- class APIController < BaseController
8+ # MFAController
9+ class MFAController < BaseController
1010 def initialize ( config , http_call_back : nil )
1111 super ( config , http_call_back : http_call_back )
1212 end
1313
14- # Two-Factor authentication with Bandwidth Voice services
14+ # Allows a user to send a MFA code through a phone call
1515 # @param [String] account_id Required parameter: Bandwidth Account ID with
1616 # Voice service enabled
1717 # @param [TwoFactorCodeRequestSchema] body Required parameter: Example:
@@ -44,8 +44,23 @@ def create_voice_two_factor(account_id,
4444
4545 # Validate response against endpoint and global error codes.
4646 if _response . status_code == 400
47- raise InvalidRequestException . new (
48- 'client request error' ,
47+ raise ErrorWithRequestException . new (
48+ 'If there is any issue with values passed in by the user' ,
49+ _response
50+ )
51+ elsif _response . status_code == 401
52+ raise UnauthorizedRequestException . new (
53+ 'Authentication is either incorrect or not present' ,
54+ _response
55+ )
56+ elsif _response . status_code == 403
57+ raise ForbiddenRequestException . new (
58+ 'The user is not authorized to access this resource' ,
59+ _response
60+ )
61+ elsif _response . status_code == 500
62+ raise ErrorWithRequestException . new (
63+ 'An internal server error occurred' ,
4964 _response
5065 )
5166 end
@@ -58,7 +73,7 @@ def create_voice_two_factor(account_id,
5873 )
5974 end
6075
61- # Two-Factor authentication with Bandwidth messaging services
76+ # Allows a user to send a MFA code through a text message (SMS)
6277 # @param [String] account_id Required parameter: Bandwidth Account ID with
6378 # Messaging service enabled
6479 # @param [TwoFactorCodeRequestSchema] body Required parameter: Example:
@@ -91,8 +106,23 @@ def create_messaging_two_factor(account_id,
91106
92107 # Validate response against endpoint and global error codes.
93108 if _response . status_code == 400
94- raise InvalidRequestException . new (
95- 'client request error' ,
109+ raise ErrorWithRequestException . new (
110+ 'If there is any issue with values passed in by the user' ,
111+ _response
112+ )
113+ elsif _response . status_code == 401
114+ raise UnauthorizedRequestException . new (
115+ 'Authentication is either incorrect or not present' ,
116+ _response
117+ )
118+ elsif _response . status_code == 403
119+ raise ForbiddenRequestException . new (
120+ 'The user is not authorized to access this resource' ,
121+ _response
122+ )
123+ elsif _response . status_code == 500
124+ raise ErrorWithRequestException . new (
125+ 'An internal server error occurred' ,
96126 _response
97127 )
98128 end
@@ -106,7 +136,7 @@ def create_messaging_two_factor(account_id,
106136 )
107137 end
108138
109- # Verify a previously sent two-factor authentication code
139+ # Allows a user to verify an MFA code
110140 # @param [String] account_id Required parameter: Bandwidth Account ID with
111141 # Two-Factor enabled
112142 # @param [TwoFactorVerifyRequestSchema] body Required parameter: Example:
@@ -139,8 +169,29 @@ def create_verify_two_factor(account_id,
139169
140170 # Validate response against endpoint and global error codes.
141171 if _response . status_code == 400
142- raise InvalidRequestException . new (
143- 'client request error' ,
172+ raise ErrorWithRequestException . new (
173+ 'If there is any issue with values passed in by the user' ,
174+ _response
175+ )
176+ elsif _response . status_code == 401
177+ raise UnauthorizedRequestException . new (
178+ 'Authentication is either incorrect or not present' ,
179+ _response
180+ )
181+ elsif _response . status_code == 403
182+ raise ForbiddenRequestException . new (
183+ 'The user is not authorized to access this resource' ,
184+ _response
185+ )
186+ elsif _response . status_code == 429
187+ raise ErrorWithRequestException . new (
188+ 'The user has made too many bad requests and is temporarily locked' \
189+ ' out' ,
190+ _response
191+ )
192+ elsif _response . status_code == 500
193+ raise ErrorWithRequestException . new (
194+ 'An internal server error occurred' ,
144195 _response
145196 )
146197 end
0 commit comments