Skip to content

Commit

Permalink
Added support for get by id in query param
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartikey authored and Kartikey committed Jun 22, 2021
1 parent 7627d39 commit 08f5716
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
5 changes: 5 additions & 0 deletions fyle/platform/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ class NotFoundItemError(PlatformError):
pass


class MultipleObjectReturned(PlatformError):
"""Multiple Object Returned Error"""
pass


class InternalServerError(PlatformError):
"""The rest FyleSDK errors, 500 error."""
pass
Expand Down
17 changes: 12 additions & 5 deletions fyle/platform/internals/get_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

from typing import Dict

from .. import exceptions
from .api_base import ApiBase


Expand All @@ -25,12 +25,19 @@ def get(self, id_: str = None, query_params=None) -> Dict:
:return: Resource Object
"""
query_params = {} if query_params is None else query_params
api_url = self.endpoint

if id_:
api_url = '{endpoint}/{id}'.format(endpoint=self.endpoint, id=id_)
else:
api_url = self.endpoint
query_params['id'] = 'eq.{}'.format(id_)

return self.api.make_get_request(
response = self.api.make_get_request(
api_url=api_url,
query_params=query_params,
)

if id_ and response['count'] < 1:
raise exceptions.NotFoundItemError('Not found item with ID')
elif id_ and response['count'] > 1:
raise exceptions.MultipleObjectReturned('Multiple Objects returned')

return response
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name='fyle',
version='v0.5.0',
version='v0.6.0',
author='Siva Narayanan',
author_email='[email protected]',
description='Python SDK for accessing Fyle Platform APIs',
Expand Down

0 comments on commit 08f5716

Please sign in to comment.