Skip to content

Commit

Permalink
Tornando o método query_asset mais flexível (#79)
Browse files Browse the repository at this point in the history
* Tornando o método query_asset mais flexível

* Atualizando a versão da API
  • Loading branch information
jamilatta authored and jfunez committed Jul 19, 2017
1 parent 89ae1bb commit e08374b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
32 changes: 16 additions & 16 deletions opac_ssm_api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 = []

Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__))

Expand Down

0 comments on commit e08374b

Please sign in to comment.