From c52a30a56546c05a5a486b69484f7a51c3bb371c Mon Sep 17 00:00:00 2001 From: Kartikey Date: Wed, 23 Jun 2021 13:39:45 +0530 Subject: [PATCH] Added support for get_by_id for resources --- fyle/platform/internals/get_resources.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/fyle/platform/internals/get_resources.py b/fyle/platform/internals/get_resources.py index e001451..1149470 100644 --- a/fyle/platform/internals/get_resources.py +++ b/fyle/platform/internals/get_resources.py @@ -17,19 +17,19 @@ def __init__(self, version, role, endpoint): self.api = ApiBase(self.version, self.role) - def get(self, id_: str = None, query_params=None) -> Dict: + def get_by_id(self, id_: str) -> Dict: """ Get Single Resource object by ID :param id_: Resource object ID - :param query_params: :return: Resource Object """ - query_params = {} if query_params is None else query_params + query_params = {} api_url = self.endpoint - if id_: - query_params['id'] = 'eq.{}'.format(id_) + if not id_: + raise exceptions.WrongParamsError('Invalid Parameters') + query_params['id'] = 'eq.{}'.format(id_) response = self.api.make_get_request( api_url=api_url, query_params=query_params, @@ -40,4 +40,6 @@ def get(self, id_: str = None, query_params=None) -> Dict: elif id_ and response['count'] > 1: raise exceptions.MultipleObjectReturned('Multiple Objects returned') - return response + return { + 'data': response.get('data')[0] + } \ No newline at end of file