Class: Bandwidth::TwoFactorAuth::APIController
- Inherits:
-
BaseController
- Object
- BaseController
- Bandwidth::TwoFactorAuth::APIController
- Defined in:
- lib/bandwidth/two_factor_auth_lib/two_factor_auth/controllers/api_controller.rb
Overview
APIController
Instance Attribute Summary
Attributes inherited from BaseController
Instance Method Summary collapse
-
#create_messaging_two_factor(account_id, body) ⇒ TwoFactorMessagingResponse
Two-Factor authentication with Bandwidth messaging services Messaging service enabled.
-
#create_verify_two_factor(account_id, body) ⇒ TwoFactorVerifyCodeResponse
Verify a previously sent two-factor authentication code Two-Factor enabled.
-
#create_voice_two_factor(account_id, body) ⇒ TwoFactorVoiceResponse
Two-Factor authentication with Bandwidth Voice services Voice service enabled.
-
#initialize(config, http_call_back: nil) ⇒ APIController
constructor
A new instance of APIController.
Methods inherited from BaseController
#execute_request, #validate_parameters, #validate_response
Constructor Details
#initialize(config, http_call_back: nil) ⇒ APIController
Returns a new instance of APIController.
10 11 12 |
# File 'lib/bandwidth/two_factor_auth_lib/two_factor_auth/controllers/api_controller.rb', line 10 def initialize(config, http_call_back: nil) super(config, http_call_back: http_call_back) end |
Instance Method Details
#create_messaging_two_factor(account_id, body) ⇒ TwoFactorMessagingResponse
Two-Factor authentication with Bandwidth messaging services Messaging service enabled
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/bandwidth/two_factor_auth_lib/two_factor_auth/controllers/api_controller.rb', line 57 def create_messaging_two_factor(account_id, body) # Prepare query url. _query_builder = config.get_base_uri(Server::TWOFACTORAUTHDEFAULT) _query_builder << '/accounts/{accountId}/code/messaging' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'accountId' => account_id ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json', 'content-type' => 'application/json; charset=utf-8' } # Prepare and execute HttpRequest. _request = config.http_client.post( _query_url, headers: _headers, parameters: body.to_json ) TwoFactorAuthBasicAuth.apply(config, _request) _response = execute_request(_request) validate_response(_response) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) ApiResponse.new(_response, data: TwoFactorMessagingResponse.from_hash(decoded)) end |
#create_verify_two_factor(account_id, body) ⇒ TwoFactorVerifyCodeResponse
Verify a previously sent two-factor authentication code Two-Factor enabled
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/bandwidth/two_factor_auth_lib/two_factor_auth/controllers/api_controller.rb', line 95 def create_verify_two_factor(account_id, body) # Prepare query url. _query_builder = config.get_base_uri(Server::TWOFACTORAUTHDEFAULT) _query_builder << '/accounts/{accountId}/code/verify' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'accountId' => account_id ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json', 'content-type' => 'application/json; charset=utf-8' } # Prepare and execute HttpRequest. _request = config.http_client.post( _query_url, headers: _headers, parameters: body.to_json ) TwoFactorAuthBasicAuth.apply(config, _request) _response = execute_request(_request) validate_response(_response) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) ApiResponse.new(_response, data: TwoFactorVerifyCodeResponse.from_hash(decoded)) end |
#create_voice_two_factor(account_id, body) ⇒ TwoFactorVoiceResponse
Two-Factor authentication with Bandwidth Voice services Voice service enabled
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 |
# File 'lib/bandwidth/two_factor_auth_lib/two_factor_auth/controllers/api_controller.rb', line 19 def create_voice_two_factor(account_id, body) # Prepare query url. _query_builder = config.get_base_uri(Server::TWOFACTORAUTHDEFAULT) _query_builder << '/accounts/{accountId}/code/voice' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'accountId' => account_id ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json', 'content-type' => 'application/json; charset=utf-8' } # Prepare and execute HttpRequest. _request = config.http_client.post( _query_url, headers: _headers, parameters: body.to_json ) TwoFactorAuthBasicAuth.apply(config, _request) _response = execute_request(_request) validate_response(_response) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) ApiResponse.new(_response, data: TwoFactorVoiceResponse.from_hash(decoded)) end |