Coverage for src/integry/resources/apps/api.py: 100%
14 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-03-26 01:26 +0500
« prev ^ index » next coverage.py v7.6.1, created at 2025-03-26 01:26 +0500
1from integry.resources.base import BaseResource, AsyncPaginator
2from .types import App, AppsPage
5class Apps(BaseResource):
7 def list(self, user_id: str, cursor: str = "") -> AsyncPaginator[App, AppsPage]:
8 """
9 Lists all apps.
11 Args:
12 user_id: The ID of the user.
13 cursor: Provide the cursor from last page to fetch the next page of apps.
15 Returns:
16 List of apps.
17 """
18 return AsyncPaginator(
19 self,
20 user_id,
21 "",
22 explicit_cursor=cursor,
23 model=App,
24 paginated_response_model=AppsPage,
25 )
27 async def get(self, app_name: str, user_id: str):
28 """
29 Gets an app by name.
31 Args:
32 app_name: The name of the app.
33 user_id: The ID of the user.
35 Returns:
36 The app.
37 """
39 response = await self.http_client.post(
40 f"{self.name}/{app_name}/get/",
41 headers=self._get_signed_request_headers(user_id),
42 )
43 data = self._get_response_data_or_raise(response)
45 return App(**data)
47 async def is_connected(self, app_name: str, user_id: str) -> bool:
48 """
49 Returns whether user has connected an account of the app.
51 Args:
52 app_name: The name of the app.
53 user_id: The ID of the user.
55 Returns:
56 Whether user has connected an account of the app.
57 """
59 response = await self.http_client.post(
60 f"{self.name}/{app_name}/get/",
61 headers=self._get_signed_request_headers(user_id),
62 )
64 data = self._get_response_data_or_raise(response)
66 app = App(**data)
67 return len(app.connected_accounts) > 0