|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +""" |
| 4 | +bandwidth |
| 5 | +
|
| 6 | +This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). |
| 7 | +""" |
| 8 | + |
| 9 | +from bandwidth.api_helper import APIHelper |
| 10 | +from bandwidth.configuration import Server |
| 11 | +from bandwidth.http.api_response import ApiResponse |
| 12 | +from bandwidth.twofactorauth.controllers.base_controller import BaseController |
| 13 | +from bandwidth.http.auth.two_factor_auth_basic_auth import TwoFactorAuthBasicAuth |
| 14 | +from bandwidth.twofactorauth.models.two_factor_voice_response import TwoFactorVoiceResponse |
| 15 | +from bandwidth.twofactorauth.models.two_factor_messaging_response import TwoFactorMessagingResponse |
| 16 | +from bandwidth.twofactorauth.models.two_factor_verify_code_response import TwoFactorVerifyCodeResponse |
| 17 | + |
| 18 | + |
| 19 | +class APIController(BaseController): |
| 20 | + |
| 21 | + """A Controller to access Endpoints in the bandwidth API.""" |
| 22 | + |
| 23 | + def __init__(self, config, call_back=None): |
| 24 | + super(APIController, self).__init__(config, call_back) |
| 25 | + |
| 26 | + def create_voice_two_factor(self, |
| 27 | + account_id, |
| 28 | + body): |
| 29 | + """Does a POST request to /accounts/{accountId}/code/voice. |
| 30 | +
|
| 31 | + Two-Factor authentication with Bandwidth Voice services |
| 32 | +
|
| 33 | + Args: |
| 34 | + account_id (string): Bandwidth Account ID with Voice service |
| 35 | + enabled |
| 36 | + body (TwoFactorCodeRequestSchema): TODO: type description here. |
| 37 | +
|
| 38 | + Returns: |
| 39 | + ApiResponse: An object with the response value as well as other |
| 40 | + useful information such as status codes and headers. |
| 41 | + successful operation |
| 42 | +
|
| 43 | + Raises: |
| 44 | + APIException: When an error occurs while fetching the data from |
| 45 | + the remote API. This exception includes the HTTP Response |
| 46 | + code, an error message, and the HTTP body that was received in |
| 47 | + the request. |
| 48 | +
|
| 49 | + """ |
| 50 | + |
| 51 | + # Prepare query URL |
| 52 | + _url_path = '/accounts/{accountId}/code/voice' |
| 53 | + _url_path = APIHelper.append_url_with_template_parameters(_url_path, { |
| 54 | + 'accountId': account_id |
| 55 | + }) |
| 56 | + _query_builder = self.config.get_base_uri(Server.TWOFACTORAUTHDEFAULT) |
| 57 | + _query_builder += _url_path |
| 58 | + _query_url = APIHelper.clean_url(_query_builder) |
| 59 | + |
| 60 | + # Prepare headers |
| 61 | + _headers = { |
| 62 | + 'accept': 'application/json', |
| 63 | + 'content-type': 'application/json; charset=utf-8' |
| 64 | + } |
| 65 | + |
| 66 | + # Prepare and execute request |
| 67 | + _request = self.config.http_client.post(_query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) |
| 68 | + TwoFactorAuthBasicAuth.apply(self.config, _request) |
| 69 | + _response = self.execute_request(_request) |
| 70 | + self.validate_response(_response) |
| 71 | + |
| 72 | + decoded = APIHelper.json_deserialize(_response.text, TwoFactorVoiceResponse.from_dictionary) |
| 73 | + _result = ApiResponse(_response, body=decoded) |
| 74 | + return _result |
| 75 | + |
| 76 | + def create_messaging_two_factor(self, |
| 77 | + account_id, |
| 78 | + body): |
| 79 | + """Does a POST request to /accounts/{accountId}/code/messaging. |
| 80 | +
|
| 81 | + Two-Factor authentication with Bandwidth messaging services |
| 82 | +
|
| 83 | + Args: |
| 84 | + account_id (string): Bandwidth Account ID with Messaging service |
| 85 | + enabled |
| 86 | + body (TwoFactorCodeRequestSchema): TODO: type description here. |
| 87 | +
|
| 88 | + Returns: |
| 89 | + ApiResponse: An object with the response value as well as other |
| 90 | + useful information such as status codes and headers. |
| 91 | + successful operation |
| 92 | +
|
| 93 | + Raises: |
| 94 | + APIException: When an error occurs while fetching the data from |
| 95 | + the remote API. This exception includes the HTTP Response |
| 96 | + code, an error message, and the HTTP body that was received in |
| 97 | + the request. |
| 98 | +
|
| 99 | + """ |
| 100 | + |
| 101 | + # Prepare query URL |
| 102 | + _url_path = '/accounts/{accountId}/code/messaging' |
| 103 | + _url_path = APIHelper.append_url_with_template_parameters(_url_path, { |
| 104 | + 'accountId': account_id |
| 105 | + }) |
| 106 | + _query_builder = self.config.get_base_uri(Server.TWOFACTORAUTHDEFAULT) |
| 107 | + _query_builder += _url_path |
| 108 | + _query_url = APIHelper.clean_url(_query_builder) |
| 109 | + |
| 110 | + # Prepare headers |
| 111 | + _headers = { |
| 112 | + 'accept': 'application/json', |
| 113 | + 'content-type': 'application/json; charset=utf-8' |
| 114 | + } |
| 115 | + |
| 116 | + # Prepare and execute request |
| 117 | + _request = self.config.http_client.post(_query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) |
| 118 | + TwoFactorAuthBasicAuth.apply(self.config, _request) |
| 119 | + _response = self.execute_request(_request) |
| 120 | + self.validate_response(_response) |
| 121 | + |
| 122 | + decoded = APIHelper.json_deserialize(_response.text, TwoFactorMessagingResponse.from_dictionary) |
| 123 | + _result = ApiResponse(_response, body=decoded) |
| 124 | + return _result |
| 125 | + |
| 126 | + def create_verify_two_factor(self, |
| 127 | + account_id, |
| 128 | + body): |
| 129 | + """Does a POST request to /accounts/{accountId}/code/verify. |
| 130 | +
|
| 131 | + Verify a previously sent two-factor authentication code |
| 132 | +
|
| 133 | + Args: |
| 134 | + account_id (string): Bandwidth Account ID with Two-Factor enabled |
| 135 | + body (TwoFactorVerifyRequestSchema): TODO: type description here. |
| 136 | +
|
| 137 | + Returns: |
| 138 | + ApiResponse: An object with the response value as well as other |
| 139 | + useful information such as status codes and headers. |
| 140 | + successful operation |
| 141 | +
|
| 142 | + Raises: |
| 143 | + APIException: When an error occurs while fetching the data from |
| 144 | + the remote API. This exception includes the HTTP Response |
| 145 | + code, an error message, and the HTTP body that was received in |
| 146 | + the request. |
| 147 | +
|
| 148 | + """ |
| 149 | + |
| 150 | + # Prepare query URL |
| 151 | + _url_path = '/accounts/{accountId}/code/verify' |
| 152 | + _url_path = APIHelper.append_url_with_template_parameters(_url_path, { |
| 153 | + 'accountId': account_id |
| 154 | + }) |
| 155 | + _query_builder = self.config.get_base_uri(Server.TWOFACTORAUTHDEFAULT) |
| 156 | + _query_builder += _url_path |
| 157 | + _query_url = APIHelper.clean_url(_query_builder) |
| 158 | + |
| 159 | + # Prepare headers |
| 160 | + _headers = { |
| 161 | + 'accept': 'application/json', |
| 162 | + 'content-type': 'application/json; charset=utf-8' |
| 163 | + } |
| 164 | + |
| 165 | + # Prepare and execute request |
| 166 | + _request = self.config.http_client.post(_query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) |
| 167 | + TwoFactorAuthBasicAuth.apply(self.config, _request) |
| 168 | + _response = self.execute_request(_request) |
| 169 | + self.validate_response(_response) |
| 170 | + |
| 171 | + decoded = APIHelper.json_deserialize(_response.text, TwoFactorVerifyCodeResponse.from_dictionary) |
| 172 | + _result = ApiResponse(_response, body=decoded) |
| 173 | + return _result |
0 commit comments