Ejemplo n.º 1
0
    def create_messaging_two_factor(self, account_id, body):
        """Does a POST request to /accounts/{accountId}/code/messaging.

        Two-Factor authentication with Bandwidth messaging services

        Args:
            account_id (string): Bandwidth Account ID with Messaging service
                enabled
            body (TwoFactorCodeRequestSchema): TODO: type description here.

        Returns:
            ApiResponse: An object with the response value as well as other
                useful information such as status codes and headers.
                successful operation

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        # Prepare query URL
        _url_path = '/accounts/{accountId}/code/messaging'
        _url_path = APIHelper.append_url_with_template_parameters(
            _url_path, {'accountId': {
                'value': account_id,
                'encode': True
            }})
        _query_builder = self.config.get_base_uri(Server.TWOFACTORAUTHDEFAULT)
        _query_builder += _url_path
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare headers
        _headers = {
            'accept': 'application/json',
            'content-type': 'application/json; charset=utf-8'
        }

        # Prepare and execute request
        _request = self.config.http_client.post(
            _query_url,
            headers=_headers,
            parameters=APIHelper.json_serialize(body))
        TwoFactorAuthBasicAuth.apply(self.config, _request)
        _response = self.execute_request(_request)

        # Endpoint and global error handling using HTTP status codes.
        if _response.status_code == 400:
            raise InvalidRequestException('client request error', _response)
        self.validate_response(_response)

        decoded = APIHelper.json_deserialize(
            _response.text, TwoFactorMessagingResponse.from_dictionary)
        _result = ApiResponse(_response, body=decoded)
        return _result
Ejemplo n.º 2
0
    def create_message(self,
                       user_id,
                       body=None):
        """Does a POST request to /users/{userId}/messages.

        createMessage

        Args:
            user_id (string): TODO: type description here.
            body (MessageRequest, optional): TODO: type description here.

        Returns:
            BandwidthMessage: Response from the API. successful operation

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        # Prepare query URL
        _url_path = '/users/{userId}/messages'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, {
            'userId': user_id
        })
        _query_builder = self.config.get_base_uri(Server.MESSAGINGDEFAULT)
        _query_builder += _url_path
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare headers
        _headers = {
            'accept': 'application/json',
            'content-type': 'application/json; charset=utf-8'
        }

        # Prepare and execute request
        _request = self.config.http_client.post(_query_url, headers=_headers, parameters=APIHelper.json_serialize(body))
        MessagingBasicAuth.apply(self.config, _request)
        _response = self.execute_request(_request)

        # Endpoint and global error handling using HTTP status codes.
        if _response.status_code == 400:
            raise MessagingException('400 Request is malformed or invalid', _response)
        elif _response.status_code == 401:
            raise MessagingException('401 The specified user does not have access to the account', _response)
        elif _response.status_code == 403:
            raise MessagingException('403 The user does not have access to this API', _response)
        elif _response.status_code == 404:
            raise MessagingException('404 Path not found', _response)
        elif _response.status_code == 415:
            raise MessagingException('415 The content-type of the request is incorrect', _response)
        elif _response.status_code == 429:
            raise MessagingException('429 The rate limit has been reached', _response)
        self.validate_response(_response)

        decoded = APIHelper.json_deserialize(_response.text, BandwidthMessage.from_dictionary)
        _result = ApiResponse(_response, body=decoded)
        return _result
Ejemplo n.º 3
0
    def update_participant_subscriptions(self,
                                         account_id,
                                         session_id,
                                         participant_id,
                                         body=None):
        """Does a PUT request to /accounts/{accountId}/sessions/{sessionId}/participants/{participantId}/subscriptions.

        Update a participant's subscriptions.
        This is a full update that will replace the participant's
        subscriptions. First call `getParticipantSubscriptions` if you need
        the current subscriptions. Call this function with no `Subscriptions`
        object to remove all subscriptions.

        Args:
            account_id (string): Account ID
            session_id (string): Session ID
            participant_id (string): Participant ID
            body (Subscriptions, optional): Initial state

        Returns:
            ApiResponse: An object with the response value as well as other
                useful information such as status codes and headers. No
                Content

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        # Prepare query URL
        _url_path = '/accounts/{accountId}/sessions/{sessionId}/participants/{participantId}/subscriptions'
        _url_path = APIHelper.append_url_with_template_parameters(
            _url_path, {
                'accountId': {
                    'value': account_id,
                    'encode': False
                },
                'sessionId': {
                    'value': session_id,
                    'encode': False
                },
                'participantId': {
                    'value': participant_id,
                    'encode': False
                }
            })
        _query_builder = self.config.get_base_uri(Server.WEBRTCDEFAULT)
        _query_builder += _url_path
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare headers
        _headers = {'content-type': 'application/json; charset=utf-8'}

        # Prepare and execute request
        _request = self.config.http_client.put(
            _query_url,
            headers=_headers,
            parameters=APIHelper.json_serialize(body))
        WebRtcBasicAuth.apply(self.config, _request)
        _response = self.execute_request(_request)

        # Endpoint and global error handling using HTTP status codes.
        if _response.status_code == 400:
            raise APIException('Bad Request', _response)
        elif _response.status_code == 401:
            raise APIException('Unauthorized', _response)
        elif _response.status_code == 403:
            raise APIException('Access Denied', _response)
        elif _response.status_code == 404:
            raise APIException('Not Found', _response)
        elif (_response.status_code < 200) or (_response.status_code > 208):
            raise ErrorException('Unexpected Error', _response)
        self.validate_response(_response)

        # Return appropriate type
        return ApiResponse(_response)
Ejemplo n.º 4
0
    def create_participant(self, account_id, body=None):
        """Does a POST request to /accounts/{accountId}/participants.

        Create a new participant under this account.
        Participants are idempotent, so relevant parameters must be set in
        this function if desired.

        Args:
            account_id (string): Account ID
            body (Participant, optional): Participant parameters

        Returns:
            ApiResponse: An object with the response value as well as other
                useful information such as status codes and headers. Success

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        # Prepare query URL
        _url_path = '/accounts/{accountId}/participants'
        _url_path = APIHelper.append_url_with_template_parameters(
            _url_path, {'accountId': {
                'value': account_id,
                'encode': False
            }})
        _query_builder = self.config.get_base_uri(Server.WEBRTCDEFAULT)
        _query_builder += _url_path
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare headers
        _headers = {
            'accept': 'application/json',
            'content-type': 'application/json; charset=utf-8'
        }

        # Prepare and execute request
        _request = self.config.http_client.post(
            _query_url,
            headers=_headers,
            parameters=APIHelper.json_serialize(body))
        WebRtcBasicAuth.apply(self.config, _request)
        _response = self.execute_request(_request)

        # Endpoint and global error handling using HTTP status codes.
        if _response.status_code == 400:
            raise APIException('Bad Request', _response)
        elif _response.status_code == 401:
            raise APIException('Unauthorized', _response)
        elif _response.status_code == 403:
            raise APIException('Access Denied', _response)
        elif (_response.status_code < 200) or (_response.status_code > 208):
            raise ErrorException('Unexpected Error', _response)
        self.validate_response(_response)

        decoded = APIHelper.json_deserialize(
            _response.text, AccountsParticipantsResponse.from_dictionary)
        _result = ApiResponse(_response, body=decoded)
        return _result
Ejemplo n.º 5
0
    def create_transcribe_recording(self,
                                    account_id,
                                    call_id,
                                    recording_id,
                                    body=None):
        """Does a POST request to /api/v2/accounts/{accountId}/calls/{callId}/recordings/{recordingId}/transcription.

        Requests that the specified recording be transcribed

        Args:
            account_id (string): TODO: type description here.
            call_id (string): TODO: type description here.
            recording_id (string): TODO: type description here.
            body (ApiTranscribeRecordingRequest, optional): TODO: type
                description here.

        Returns:
            void: Response from the API.

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        # Prepare query URL
        _url_path = '/api/v2/accounts/{accountId}/calls/{callId}/recordings/{recordingId}/transcription'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, {
            'accountId': account_id,
            'callId': call_id,
            'recordingId': recording_id
        })
        _query_builder = self.config.get_base_uri(Server.VOICEDEFAULT)
        _query_builder += _url_path
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare headers
        _headers = {
            'content-type': 'application/json; charset=utf-8'
        }

        # Prepare and execute request
        _request = self.config.http_client.post(_query_url, headers=_headers, parameters=APIHelper.json_serialize(body))
        VoiceBasicAuth.apply(self.config, _request)
        _response = self.execute_request(_request)

        # Endpoint and global error handling using HTTP status codes.
        if _response.status_code == 400:
            raise ApiErrorResponseException('Something\'s not quite right... Either your request is invalid or you\'re requesting it at a bad time. Please fix it before trying again.', _response)
        elif _response.status_code == 401:
            raise APIException('Please authenticate yourself.', _response)
        elif _response.status_code == 403:
            raise ApiErrorResponseException('Your credentials are invalid. Please use your API credentials for the Bandwidth Dashboard.', _response)
        elif _response.status_code == 404:
            raise ApiErrorResponseException('The resource specified cannot be found or does not belong to you.', _response)
        elif _response.status_code == 410:
            raise ApiErrorResponseException('The media for this recording has been deleted, so we can\'t transcribe it', _response)
        elif _response.status_code == 415:
            raise ApiErrorResponseException('We don\'t support that media type. If a request body is required, please send it to us as `application/json`.', _response)
        elif _response.status_code == 429:
            raise ApiErrorResponseException('You\'re sending requests to this endpoint too frequently. Please slow your request rate down and try again.', _response)
        elif _response.status_code == 500:
            raise ApiErrorResponseException('Something unexpected happened. Please try again.', _response)
        self.validate_response(_response)

        # Return appropriate type
        ApiResponse(_response)
Ejemplo n.º 6
0
    def create_voice_two_factor(self, account_id, body):
        """Does a POST request to /accounts/{accountId}/code/voice.

        Multi-Factor authentication with Bandwidth Voice services. Allows for
        a user to send an MFA code via a phone call.

        Args:
            account_id (string): Bandwidth Account ID with Voice service
                enabled
            body (TwoFactorCodeRequestSchema): TODO: type description here.

        Returns:
            ApiResponse: An object with the response value as well as other
                useful information such as status codes and headers.
                successful operation

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        # Prepare query URL
        _url_path = '/accounts/{accountId}/code/voice'
        _url_path = APIHelper.append_url_with_template_parameters(
            _url_path, {'accountId': {
                'value': account_id,
                'encode': False
            }})
        _query_builder = self.config.get_base_uri(
            Server.MULTIFACTORAUTHDEFAULT)
        _query_builder += _url_path
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare headers
        _headers = {
            'accept': 'application/json',
            'content-type': 'application/json; charset=utf-8'
        }

        # Prepare and execute request
        _request = self.config.http_client.post(
            _query_url,
            headers=_headers,
            parameters=APIHelper.json_serialize(body))
        MultiFactorAuthBasicAuth.apply(self.config, _request)
        _response = self.execute_request(_request)

        # Endpoint and global error handling using HTTP status codes.
        if _response.status_code == 400:
            raise ErrorWithRequestException(
                'If there is any issue with values passed in by the user',
                _response)
        elif _response.status_code == 401:
            raise UnauthorizedRequestException(
                'Authentication is either incorrect or not present', _response)
        elif _response.status_code == 403:
            raise ForbiddenRequestException(
                'The user is not authorized to access this resource',
                _response)
        elif _response.status_code == 500:
            raise ErrorWithRequestException(
                'An internal server error occurred', _response)
        self.validate_response(_response)

        decoded = APIHelper.json_deserialize(
            _response.text, TwoFactorVoiceResponse.from_dictionary)
        _result = ApiResponse(_response, body=decoded)
        return _result