Skip to content

Commit ac82c1d

Browse files
authored
Merge pull request #25 from sypht-team/get_all_entity_ids_options
Get all entity_ids options
2 parents 5e7e8ea + a67fa80 commit ac82c1d

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ sypht.egg-info
1414
coverage.xml
1515

1616
venv
17+
.env

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from setuptools import find_packages, setup
22

3-
__version__ = "0.5.8"
3+
__version__ = "0.5.9"
44
__pkg_name__ = "sypht"
55

66
setup(

sypht/client.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,15 +510,28 @@ def list_entities(self, entity_type, company_id=None, page=None, limit=None, end
510510
params["limit"] = int(limit)
511511
return self._parse_response(self.requests.get(endpoint, headers=headers, params=params))
512512

513-
def get_all_entity_ids(self, entity_type, company_id=None, endpoint=None):
513+
def get_all_entity_ids(self, entity_type, verbose=True, company_id=None, endpoint=None):
514+
"""Get all entity_ids for specified entity_type.
515+
516+
Returns list of objects if verbose (by default):
517+
[{"entity_id": "id_0"}, {"entity_id": "id_1"}, ...]
518+
519+
Returns list of entity_id if not verbose:
520+
["id_0", "id_1", ...]
521+
"""
514522
entity_ids = []
515523
next_page = True
516524
while next_page:
517525
if next_page is True:
518526
next_page = None # first page request
519527
res = self.list_entities(entity_type, company_id, page=next_page)
520528
next_page = res.get("next_page")
521-
entity_ids.extend([{"entity_id": entity_id} for entity_id in res.get("entities")])
529+
if verbose:
530+
entity_ids.extend(
531+
[{"entity_id": entity_id} for entity_id in res.get("entities")]
532+
)
533+
else:
534+
entity_ids.extend(res.get("entities"))
522535
return entity_ids
523536

524537
def set_entity(self, entity_id, entity_type, data, company_id=None, endpoint=None):

0 commit comments

Comments
 (0)