Example #1
0
    def one_node_rendering(
        self,
        nodeId,
        layoutDocument,
    ):
        """Does a POST request to /nodes/{node_id}/renders.

        Retrieves Rendering result with the associated renderId.

        Args:
            id (string): The unique identifier for the 'rendering' action
            (please see the the response body of POST /renders).

        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 = '/nodes/{id}/renders'
        _url_path = APIHelper.append_url_with_template_parameters(
            _url_path, {'id': {
                'value': nodeId,
                'encode': False
            }})
        _query_builder = self.config.get_base_uri()
        _query_builder += _url_path
        _query_url = APIHelper.clean_url(_query_builder)

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

        # Prepare body
        _parameters = {"layout": json.loads(layoutDocument)}

        # Prepare and execute request
        _request = self.config.http_client.post(
            _query_url, headers=_headers, parameters=json.dumps(_parameters))
        OAuth2.apply(self.config, _request)
        _response = self.execute_request(_request)

        decoded = APIHelper.json_deserialize(_response.text)
        if type(decoded) is dict:
            _errors = decoded.get('error')
        else:
            _errors = None
        _result = ApiResponse(_response, body=decoded, errors=_errors)
        return _result
Example #2
0
    def add_query_parameter(self, name, value):
        """ Add a query parameter to the HttpRequest.

        Args:
            name (string): The name of the query parameter.
            value (string): The value of the query parameter.

        """
        self.query_url = APIHelper.append_url_with_query_parameters(
            self.query_url, {name: value})
        self.query_url = APIHelper.clean_url(self.query_url)
Example #3
0
    def execute_request(self, request, binary=False):
        """Executes an HttpRequest.

        Args:
            request (HttpRequest): The HttpRequest to execute.
            binary (bool): A flag which should be set to True if
                a binary response is expected.

        Returns:
            HttpResponse: The HttpResponse received.

        """
        # Invoke the on before request HttpCallBack if specified
        if self.http_call_back is not None:
            self.http_call_back.on_before_request(request)

        # Add global headers to request
        request.headers = APIHelper.merge_dicts(self.global_headers(), request.headers)
        if self.config.additional_headers is not None:
            request.headers.update(self.config.additional_headers)

        # Invoke the API call to fetch the response.
        func = self.config.http_client.execute_as_binary if binary else self.config.http_client.execute_as_string
        response = func(request)

        # Invoke the on after response HttpCallBack if specified
        if self.http_call_back is not None:
            self.http_call_back.on_after_response(response)

        return response
    def get_base_uri(self):
        """Generates the appropriate base URI for the environment and the
        server.

        Args:
            server (Configuration.Server): The server enum for which the base
            URI is required.

        Returns:
            String: The base URI.

        """
        parameters = {
            "custom_url": {
                'value': self.custom_url,
                'encode': False
            },
        }

        if self.access_token:
            server = 'default'
        else:
            server = 'simple'
            parameters['api_version'] = {
                'value': self.api_version,
                'encode': False
            }
            parameters['api_key'] = {'value': self.api_key, 'encode': False}
        return APIHelper.append_url_with_template_parameters(
            self.environments[self.environment][server], parameters)
Example #5
0
    def info(self):
        """Does a GET request to /

        Returns `User` information for a given access token.
        If you don't know a `User` ID, you can use this endpoint to
        retrieve the User ID for an access token.

        Args:
            None

        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 = '/'
        _query_builder = self.config.get_base_uri()
        _query_builder += _url_path
        _query_parameters = {}
        _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)
        OAuth2.apply(self.config, _request)
        _response = self.execute_request(_request)

        decoded = APIHelper.json_deserialize(_response.text)
        if type(decoded) is dict:
            _errors = decoded.get('error')
        else:
            _errors = None
        _result = ApiResponse(_response, body=decoded, errors=_errors)
        return _result
Example #6
0
    def get_device(self, sn):
        """Does a GET request to /devices/{sn}.

        Retrieves Device with the associated Serial Number.

        Args:
            sn (string): The unique identifier for the device.

        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 = '/devices/{sn}'
        _url_path = APIHelper.append_url_with_template_parameters(
            _url_path, {'sn': {
                'value': sn,
                'encode': False
            }})
        _query_builder = self.config.get_base_uri()
        _query_builder += _url_path
        _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)
        OAuth2.apply(self.config, _request)
        _response = self.execute_request(_request)

        decoded = APIHelper.json_deserialize(_response.text)
        if type(decoded) is dict:
            _errors = decoded.get('error')
        else:
            _errors = None
        _result = ApiResponse(_response, body=decoded, errors=_errors)
        return _result