Skip to content

feat: Add get_activities method to APIClient for fetching profile act… #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 57 additions & 1 deletion wise_api/client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime
from typing import Literal
from typing import Iterator, Literal

from requests import Response, Session

Expand Down Expand Up @@ -123,3 +123,59 @@ def get_recipient_account_by_id(self, account_id: WiseId):

def get_transfer_by_id(self, transfer_id: WiseId):
return self.get(f"/v1/transfers/{transfer_id}")

def get_activities(
self,
profile_id: WiseId,
*,
monetary_resource_type: str | None = None,
status: str | None = None,
since: datetime | None = None,
until: datetime | None = None,
size: int | None = None,
) -> Iterator[dict]:
"""
Iterate through activities for a profile, handling pagination automatically.

Args:
profile_id: The ID of the profile to fetch activities for.
monetary_resource_type: Filter activity by resource type.
status: Filter by activity status.
since: Filter activity list after a certain timestamp.
until: Filter activity list until a certain timestamp.
size: Desired size of the result set per page (min 1, max 100, default 10).

Yields:
Dictionaries representing individual activities.
"""
params = {}
if monetary_resource_type:
params["monetaryResourceType"] = monetary_resource_type
if status:
params["status"] = status
if since:
params["since"] = zulu_time(since)
if until:
params["until"] = zulu_time(until)
if size is not None:
if not 1 <= size <= 100:
raise ValueError("Size must be between 1 and 100")
params["size"] = size

next_cursor = None
while True:
current_params = params.copy()
if next_cursor:
current_params["nextCursor"] = next_cursor

response_data = self.get(f"/v1/profiles/{profile_id}/activities", params=current_params)

# Assuming the activities are in a list under the key 'activities'
# Adjust this key if the actual API response structure is different
activities = response_data.get("activities", [])
for activity in activities:
yield activity

next_cursor = response_data.get("cursor")
if not next_cursor:
break