Exemplo n.º 1
0
    def get_stream_recording_media(self,
                                   account_id,
                                   call_id,
                                   recording_id):
        """Does a GET request to /api/v2/accounts/{accountId}/calls/{callId}/recordings/{recordingId}/media.

        Downloads the specified recording

        Args:
            account_id (string): TODO: type description here.
            call_id (string): TODO: type description here.
            recording_id (string): TODO: type description here.

        Returns:
            binary: 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 = '/api/v2/accounts/{accountId}/calls/{callId}/recordings/{recordingId}/media'
        _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 and execute request
        _request = self.config.http_client.get(_query_url)
        VoiceBasicAuth.apply(self.config, _request)
        _response = self.execute_request(_request, binary=True)

        # 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 == 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)

        decoded = _response.text
        _result = ApiResponse(_response, body=decoded)
        return _result
Exemplo n.º 2
0
    def get_query_metadata_for_account(self,
                                       account_id,
                                       mfrom=None,
                                       to=None,
                                       min_start_time=None,
                                       max_start_time=None):
        """Does a GET request to /api/v2/accounts/{accountId}/recordings.

        Returns a list of metadata for the recordings associated with the
        specified account. The list can be filtered by the optional from, to,
        minStartTime, and maxStartTime arguments. The list is capped at 1000
        entries and may be empty if no recordings match the specified
        criteria.

        Args:
            account_id (string): TODO: type description here.
            mfrom (string, optional): TODO: type description here.
            to (string, optional): TODO: type description here.
            min_start_time (string, optional): TODO: type description here.
            max_start_time (string, optional): TODO: type description here.

        Returns:
            list of RecordingMetadataResponse: 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 = '/api/v2/accounts/{accountId}/recordings'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, {
            'accountId': account_id
        })
        _query_builder = self.config.get_base_uri(Server.VOICEDEFAULT)
        _query_builder += _url_path
        _query_parameters = {
            'from': mfrom,
            'to': to,
            'minStartTime': min_start_time,
            'maxStartTime': max_start_time
        }
        _query_builder = APIHelper.append_url_with_query_parameters(
            _query_builder,
            _query_parameters
        )
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare headers
        _headers = {
            'accept': 'application/json'
        }

        # Prepare and execute request
        _request = self.config.http_client.get(_query_url, headers=_headers)
        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 == 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)

        decoded = APIHelper.json_deserialize(_response.text, RecordingMetadataResponse.from_dictionary)
        _result = ApiResponse(_response, body=decoded)
        return _result
Exemplo n.º 3
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)