def __init__(self, api_key, webserver_host, api_members=[], suppress_warnings=False): """ Constructor. :param api_key: Authentication token for the Citrination site :type api_key: str :param host: The base URL of the citrination site, e.g. https://citrination.com :type host: str :param api_members: The names of the member methods for this client :type api_members: str[] :param suppress_warnings: A flag indicating whether or not warning messages to stdout should be printed :type suppress_warnings: bool """ if api_key == None or len(api_key) == 0: raise CitrinationClientError( "API key must be present to instantiate the client") self.headers = { 'X-API-Key': quote(api_key), 'Content-Type': 'application/json', 'X-Citrination-API-Version': '1.0.0' } self.suppress_warnings = suppress_warnings self.api_url = webserver_host + '/api' self.api_members = api_members
def get_dataset_file(self, dataset_id, file_path, version=None): """ Retrieves the URL for a file contained in a given dataset by version (optional) and filepath. :param data_set_id: The id of the dataset to retrieve file from :param file_path: The file path within the dataset :param version: The dataset version to look for the file in. If nothing is supplied, the latest dataset version will be searched :return: The response object, or an error message object if the request failed """ if version == None: return self._get_content_from_url(self.api_url + '/data_sets/' + str(dataset_id) + '/file/' + quote(file_path)) else: return self._get_content_from_url(self.api_url + '/data_sets/' + str(dataset_id) + '/version/' + str(version) + '/files/' + quote(file_path))
def __init__(self, api_key, site='https://citrination.com'): """ Constructor. :param api_key: Authentication token. :param site: Specific site on citrination.com to work with. By default this client interacts with https://citrination.com. This should point to the full url of the site to access. For example, to access the STEEL site on citrination, use 'https://STEEL.citrination.com'. """ self.headers = {'X-API-Key': quote(api_key), 'Content-Type': 'application/json'} self.api_url = site + '/api' self.pif_search_url = self.api_url + '/search/pif_search'
def get_dataset_file(self, dataset_id, file_path, version=None): """ Retrieves the URL for a file contained in a given dataset by version (optional) and filepath. :param data_set_id: The id of the dataset to retrieve file from :param file_path: The file path within the dataset :param version: The dataset version to look for the file in. If nothing is supplied, the latest dataset version will be searched :return: The response object, or an error message object if the request failed """ if version == None: return self._get_content_from_url( self.api_url + "/data_sets/" + str(dataset_id) + "/file/" + quote(file_path) ) else: return self._get_content_from_url( self.api_url + "/data_sets/" + str(dataset_id) + "/version/" + str(version) + "/files/" + quote(file_path) )
def file_dataset_version_path(dataset_id, version, file_path): return 'datasets/{}/version/{}/files/{}'.format(dataset_id, version, quote(file_path))
def file_dataset_path(dataset_id, file_path): return 'datasets/{}/file/{}'.format(dataset_id, quote(file_path))