Esempio n. 1
0
    def get_occurrence_get_verbatim(self, key):
        """Does a GET request to /occurrence/{key}/verbatim.

        Gets the verbatim occurrence record without any interpretation

        Args:
            key (int): Gets the verbatim occurrence record without any
                interpretation

        Returns:
            VerbatimOccurrence: 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.

        """
        # The base uri for api requests
        query_builder = Configuration.BASE_URI

        # Prepare query string for API call
        query_builder += "/occurrence/{key}/verbatim"

        # Process optional template parameters
        query_builder = APIHelper.append_url_with_template_parameters(query_builder, {"key": key})

        # Validate and preprocess url
        query_url = APIHelper.clean_url(query_builder)

        # Prepare headers
        headers = {"user-agent": "APIMATIC 2.0", "accept": "application/json"}

        # Prepare and invoke the API call request to fetch the response
        response = unirest.get(query_url, headers=headers)

        # Error handling using HTTP status codes
        if response.code < 200 or response.code > 206:  # 200 = HTTP OK
            raise APIException("HTTP Response Not OK", response.code, response.body)

        # Try to cast response to desired type
        if isinstance(response.body, dict):
            # Response is already in a dictionary, return the object
            return VerbatimOccurrence(**response.body)

        # If we got here then an error occured while trying to parse the response
        raise APIException("Invalid JSON returned", response.code, response.body)
    def get_occurrence_download_metadata_by_key(self,
                                                key):
        """Does a GET request to /occurrence/download/{key}.

        Retrieves the occurrence download metadata by its unique key.

        Args:
            key (string): Retrieves the occurrence download metadata by its
                unique key.

        Returns:
            mixed: 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.

        """
        # The base uri for api requests
        query_builder = Configuration.BASE_URI
 
        # Prepare query string for API call
        query_builder += "/occurrence/download/{key}"

        # Process optional template parameters
        query_builder = APIHelper.append_url_with_template_parameters(query_builder, { 
            "key": key
        })

        # Validate and preprocess url
        query_url = APIHelper.clean_url(query_builder)

        # Prepare headers
        headers = {
            "user-agent": "APIMATIC 2.0",
            "accept": "application/json"
        }

        # Prepare and invoke the API call request to fetch the response
        response = unirest.get(query_url, headers=headers)

        # Error handling using HTTP status codes
        if response.code < 200 or response.code > 206:  # 200 = HTTP OK
            raise APIException("HTTP Response Not OK", response.code, response.body) 
    
        return response.body
    def update_occurrence_download_put_update_status(self,
                                                     key):
        """Does a PUT request to /occurrence/download/{key}.

        Updates the status of an existing occurrence download. This operation
        can be executed by the role ADMIN only.

        Args:
            key (string): Updates the status of an existing occurrence
                download.

        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.

        """
        # The base uri for api requests
        query_builder = Configuration.BASE_URI
 
        # Prepare query string for API call
        query_builder += "/occurrence/download/{key}"

        # Process optional template parameters
        query_builder = APIHelper.append_url_with_template_parameters(query_builder, { 
            "key": key
        })

        # Validate and preprocess url
        query_url = APIHelper.clean_url(query_builder)

        # Prepare headers
        headers = {
            "user-agent": "APIMATIC 2.0"
        }

        # Prepare and invoke the API call request to fetch the response
        response = unirest.put(query_url, headers=headers, params={}, auth=(self.__user, self.__password))

        # Error handling using HTTP status codes
        if response.code < 200 or response.code > 206:  # 200 = HTTP OK
            raise APIException("HTTP Response Not OK", response.code, response.body) 
    def get_occurrence_download_list(self,
                                     options=dict()):
        """Does a GET request to /occurrence/download/dataset/{datasetKey}.

        Lists the downloads activity of a dataset.

        Args:
            options (dict, optional): Key-value pairs for any of the
                parameters to this API Endpoint. All parameters to the
                endpoint are supplied through the dictionary with their names
                being the key and their desired values being the value. A list
                of parameters that can be used are::

                    dataset_key -- string -- Lists the downloads activity of
                        dataset.
                    limit -- int -- Controls the number of results in the
                        page. Using too high a value will be overwritten with
                        the default maximum threshold, depending on the
                        service. Sensible defaults are used so this may be
                        omitted.
                    offset -- int -- Determines the offset for the search
                        results. A limit of 20 and offset of 20, will get the
                        second page of 20 results.

        Returns:
            mixed: 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.

        """
        # The base uri for api requests
        query_builder = Configuration.BASE_URI
 
        # Prepare query string for API call
        query_builder += "/occurrence/download/dataset/{datasetKey}"

        # Process optional template parameters
        query_builder = APIHelper.append_url_with_template_parameters(query_builder, { 
            "datasetKey": options.get('dataset_key', None)
        })

        # Process optional query parameters
        query_builder = APIHelper.append_url_with_query_parameters(query_builder, {
            "limit":  options.get('limit', None) if options.get('limit', None) is not None else 300,
            "offset": options.get('offset', None)
        })

        # Validate and preprocess url
        query_url = APIHelper.clean_url(query_builder)

        # Prepare headers
        headers = {
            "user-agent": "APIMATIC 2.0",
            "accept": "application/json"
        }

        # Prepare and invoke the API call request to fetch the response
        response = unirest.get(query_url, headers=headers, params={}, auth=(self.__user, self.__password))

        # Error handling using HTTP status codes
        if response.code < 200 or response.code > 206:  # 200 = HTTP OK
            raise APIException("HTTP Response Not OK", response.code, response.body) 
    
        return response.body