Skip to content
This repository was archived by the owner on Jun 28, 2024. It is now read-only.

Commit 3743539

Browse files
fix: Update events methods params (#93)
* Update events methods' params * Update docs for events methods
1 parent cefafc1 commit 3743539

File tree

3 files changed

+65
-21
lines changed

3 files changed

+65
-21
lines changed

seamapi/events.py

Lines changed: 56 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
from seamapi.types import (
2+
AccessCode,
3+
ConnectedAccount,
4+
Device,
25
Event,
36
AbstractEvents,
47
AbstractSeam as Seam,
58
)
6-
from typing import List, Optional
9+
from typing import List, Optional, Union
710
import requests
11+
from seamapi.utils.convert_to_id import (
12+
to_access_code_id,
13+
to_connected_account_id,
14+
to_device_id,
15+
to_event_id,
16+
)
817

918
from seamapi.utils.report_error import report_error
1019

@@ -22,8 +31,11 @@ class Events(AbstractEvents):
2231
2332
Methods
2433
-------
25-
list(since, device_id=None, device_ids=None, event_type=None, event_types=None)
34+
list(since=None, between=None, device_id=None, device_ids=None, access_code_id=None, access_code_ids=None, event_type=None, event_types=None, connected_account_id=None)
2635
Gets a list of events
36+
37+
get(device_id=None, event_id=None, event_type=None)
38+
Gets an event
2739
"""
2840

2941
seam: Seam
@@ -33,33 +45,45 @@ def __init__(self, seam: Seam):
3345
Parameters
3446
----------
3547
seam : Seam
36-
Intial seam class
48+
Initial seam class
3749
"""
3850
self.seam = seam
3951

4052
@report_error
4153
def list(
4254
self,
43-
since: str,
44-
device_id: Optional[str] = None,
55+
since: Optional[str] = None,
56+
between: Optional[list] = None,
57+
device_id: Union[str, Device] = None,
4558
device_ids: Optional[list] = None,
59+
access_code_id: Union[str, AccessCode] = None,
60+
access_code_ids: Optional[list] = None,
4661
event_type: Optional[str] = None,
4762
event_types: Optional[list] = None,
63+
connected_account_id: Union[str, ConnectedAccount] = None,
4864
) -> List[Event]:
4965
"""Gets a list of events.
5066
5167
Parameters
5268
----------
53-
since : str
69+
since : Optional[str]
5470
ISO 8601 timestamp of the earliest event to return
55-
device_id : Optional[str]
56-
Device ID to filter events by
71+
between : Optional[list]
72+
List of two ISO 8601 timestamps to specify a date range for filtering events
73+
device_id : Union[str, Device]
74+
Device ID or Device to filter events by
5775
device_ids : Optional[list]
5876
Device IDs to filter events by
77+
access_code_id : Union[str, AccessCode]
78+
Access Code ID or AccessCode to filter events by
79+
access_code_ids : Optional[list]
80+
Access Code IDs to filter events by
5981
event_type : Optional[str]
6082
Event type to filter events by
6183
event_types : Optional[list]
6284
Event types to filter events by
85+
connected_account_id : Union[str, ConnectedAccount]
86+
Connected Account ID or ConnectedAccount to filter events by
6387
6488
Raises
6589
------
@@ -70,18 +94,27 @@ def list(
7094
------
7195
A list of events.
7296
"""
73-
if not since:
74-
raise Exception("'since' is required")
75-
76-
params = {
77-
"since": since,
78-
}
97+
device_id = to_device_id(device_id) if device_id else None
98+
access_code_id = (
99+
to_access_code_id(access_code_id) if access_code_id else None
100+
)
101+
connected_account_id = (
102+
to_connected_account_id(connected_account_id)
103+
if connected_account_id
104+
else None
105+
)
79106

107+
params = {}
80108
arguments = {
109+
"since": since,
110+
"between": between,
81111
"device_id": device_id,
82112
"device_ids": device_ids,
113+
"access_code_id": access_code_id,
114+
"access_code_ids": access_code_ids,
83115
"event_type": event_type,
84116
"event_types": event_types,
117+
"connected_account_id": connected_account_id,
85118
}
86119

87120
for name in arguments:
@@ -99,20 +132,20 @@ def list(
99132
@report_error
100133
def get(
101134
self,
102-
event_id: Optional[str] = None,
135+
event_id: Union[str, Event] = None,
103136
event_type: Optional[str] = None,
104-
device_id: Optional[str] = None,
137+
device_id: Union[str, Device] = None,
105138
) -> Event:
106139
"""Get an Event.
107140
108141
Parameters
109142
----------
110-
event_id : Optional[str]
111-
Event ID to filter events by
143+
event_id : Union[str, Event]
144+
Event ID or Event to filter events by
112145
event_type : Optional[str]
113146
Event type to filter events by
114-
device_id : Optional[str]
115-
Device ID to filter events by
147+
device_id : Union[str, Device]
148+
Device ID or Device to filter events by
116149
117150
Raises
118151
------
@@ -123,8 +156,10 @@ def get(
123156
------
124157
An event or None.
125158
"""
126-
params = {}
159+
device_id = to_device_id(device_id) if device_id else None
160+
event_id = to_event_id(event_id) if event_id else None
127161

162+
params = {}
128163
arguments = {
129164
"event_id": event_id,
130165
"event_type": event_type,

seamapi/types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
AccessCodeId = str
1010
ActionAttemptId = str
1111
DeviceId = str
12+
EventId = str
1213
AcceptedProvider = str # e.g. august or noiseaware
1314
ConnectWebviewId = str
1415
ConnectedAccountId = str

seamapi/utils/convert_to_id.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
DeviceId,
1414
Workspace,
1515
WorkspaceId,
16+
Event,
17+
EventId,
1618
)
1719

1820

@@ -56,3 +58,9 @@ def to_workspace_id(workspace: Union[WorkspaceId, Workspace]) -> str:
5658
if isinstance(workspace, str):
5759
return workspace
5860
return workspace.workspace_id
61+
62+
63+
def to_event_id(event: Union[EventId, Event]) -> str:
64+
if isinstance(event, str):
65+
return event
66+
return event.event_id

0 commit comments

Comments
 (0)