diff --git a/opac_ssm_api/client.py b/opac_ssm_api/client.py index 2b2b700..19c7495 100644 --- a/opac_ssm_api/client.py +++ b/opac_ssm_api/client.py @@ -170,12 +170,12 @@ def get_asset(self, _id): 'bucket': asset.bucket, 'checksum': asset.checksum}) - def query_asset(self, checksum, metadata=None): + def query_asset(self, filters=None, metadata=None): """ - Get assets by checksum and any metadata. + Get assets by any filters and any metadata. Params: - :param checksum: String + :param filters: Dictionary :param metadata: JSON with metadada about asset Return a list of asset(dict) with all metadata, look: @@ -201,22 +201,22 @@ def query_asset(self, checksum, metadata=None): ] """ - if not isinstance(checksum, six.string_types): - msg = 'Param checksum must be a str|unicode.' - logger.exception(msg) - raise ValueError(msg) - - if not metadata: - metadata = {} - elif not isinstance(metadata, dict): - error_msg = 'Param "metadata" must be a Dict or None.' + if filters is None: + filters = {} + elif not isinstance(filters, dict): + error_msg = 'Param "filters" must be a Dict or None.' logger.error(error_msg) raise ValueError(error_msg) - meta = json.dumps(metadata) + if metadata: + if isinstance(metadata, str): + filters['metadata'] = metadata + elif isinstance(metadata, dict): + filters['metadata'] = json.dumps(metadata) + else: + raise ValueError("Metadada must be a dict or str") - assets = self.stubAsset.query(opac_pb2.Asset(checksum=checksum, - metadata=meta)).assets + assets = self.stubAsset.query(opac_pb2.Asset(**filters)).assets ret_list = [] @@ -314,7 +314,7 @@ def get_task_state(self, _id): return task_state.state def update_asset(self, uuid, pfile=None, filename=None, filetype=None, metadata=None, - bucket_name=None): + bucket_name=None): """ Update asset to SSM. diff --git a/setup.py b/setup.py index a54f26b..eeeb8c1 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from codecs import open from os import path -__version__ = 'v0.0.1' +__version__ = 'v1.0.0' here = path.abspath(path.dirname(__file__))