Skip to content

Commit

Permalink
added AMcardsClient.card_count
Browse files Browse the repository at this point in the history
  • Loading branch information
simonesestili committed Apr 15, 2024
1 parent 31c8f91 commit 78cdb4d
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions amcards/amcards.py
Expand Up @@ -265,6 +265,29 @@ def card(self, id: str | int) -> Card:
card_json = res.json()
return Card._from_json(card_json)

def card_count(self, filters: dict = None) -> int:
"""Fetches count of client's AMcards cards.
:param Optional[dict] filters: Defaults to ``None``. Filters to be applied when counting cards.
A common use case is to use ``filter = {'third_party_contact_id': 'some_target_id'}``, this will fetch all cards that were shipped to a recipient with a ``third_party_contact_id == 'some_target_id'``.
:return: The count of client's cards.
:rtype: int
:raises AuthenticationError: When the client's ``access_token`` is invalid.
"""
params = {
'limit': 1,
} | (filters or {})

res = requests.get(url=f'{DOMAIN}/.api/v1/card/', headers=self._HEADERS, params=params)
if not res.ok:
raise exceptions.AuthenticationError('Access token provided to client is unauthorized')

return res.json()['meta']['total_count']

def mailing(self, id: str | int) -> Mailing:
"""Fetches client's AMcards mailing with a specified id.
Expand Down

0 comments on commit 78cdb4d

Please sign in to comment.