inmotion-sdk 0.2.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- inmotion/__init__.py +37 -0
- inmotion/accounts.py +229 -0
- inmotion/activities.py +381 -0
- inmotion/activity_config.py +90 -0
- inmotion/api.py +2499 -0
- inmotion/apikey.py +52 -0
- inmotion/apikey_client.py +170 -0
- inmotion/audit.py +18 -0
- inmotion/credentials_client.py +215 -0
- inmotion/datastream.py +205 -0
- inmotion/devkey.py +52 -0
- inmotion/event.py +69 -0
- inmotion/exceptions.py +30 -0
- inmotion/folio.py +149 -0
- inmotion/model.py +99 -0
- inmotion/models.py +2413 -0
- inmotion/py.typed +0 -0
- inmotion/raster_overlay.py +67 -0
- inmotion/shape.py +86 -0
- inmotion/shapegenerator.py +74 -0
- inmotion/upload.py +114 -0
- inmotion/user.py +125 -0
- inmotion/utils.py +110 -0
- inmotion_sdk-0.2.3.dist-info/METADATA +488 -0
- inmotion_sdk-0.2.3.dist-info/RECORD +28 -0
- inmotion_sdk-0.2.3.dist-info/WHEEL +4 -0
- inmotion_sdk-0.2.3.dist-info/entry_points.txt +2 -0
- inmotion_sdk-0.2.3.dist-info/licenses/LICENSE +21 -0
inmotion/__init__.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
from inmotion.api import (
|
|
2
|
+
InMotionSession,
|
|
3
|
+
InMotionAccounts,
|
|
4
|
+
InMotionActivities,
|
|
5
|
+
InMotionActivityConfig,
|
|
6
|
+
InMotionApiKeys,
|
|
7
|
+
InMotionAudit,
|
|
8
|
+
InMotionDataStream,
|
|
9
|
+
InMotionDevKeys,
|
|
10
|
+
InMotionEvents,
|
|
11
|
+
InMotionFolio,
|
|
12
|
+
InMotionModel,
|
|
13
|
+
InMotionRasterOverlay,
|
|
14
|
+
InMotionShape,
|
|
15
|
+
InMotionShapeGenerator,
|
|
16
|
+
InMotionUpload,
|
|
17
|
+
InMotionUser,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
__all__ = [
|
|
21
|
+
"InMotionSession",
|
|
22
|
+
"InMotionAccounts",
|
|
23
|
+
"InMotionActivities",
|
|
24
|
+
"InMotionActivityConfig",
|
|
25
|
+
"InMotionApiKeys",
|
|
26
|
+
"InMotionAudit",
|
|
27
|
+
"InMotionDataStream",
|
|
28
|
+
"InMotionDevKeys",
|
|
29
|
+
"InMotionEvents",
|
|
30
|
+
"InMotionFolio",
|
|
31
|
+
"InMotionModel",
|
|
32
|
+
"InMotionRasterOverlay",
|
|
33
|
+
"InMotionShape",
|
|
34
|
+
"InMotionShapeGenerator",
|
|
35
|
+
"InMotionUpload",
|
|
36
|
+
"InMotionUser",
|
|
37
|
+
]
|
inmotion/accounts.py
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
from dataclasses import asdict
|
|
2
|
+
|
|
3
|
+
from inmotion.api import InMotionSession, InMotionAccounts
|
|
4
|
+
from inmotion.models import (
|
|
5
|
+
AccountDetailsModel,
|
|
6
|
+
AccountMarkedForDeletionModel,
|
|
7
|
+
AccountModel,
|
|
8
|
+
AccountPrivilegesModel,
|
|
9
|
+
AccountTagsModel,
|
|
10
|
+
AccountUpdateBatchCommandModel,
|
|
11
|
+
AccountUpdateBatchResultsModel,
|
|
12
|
+
AccountUserSummaryModel,
|
|
13
|
+
AccountUserUnregisteredModel,
|
|
14
|
+
DeviceConfigSyncRequestModel,
|
|
15
|
+
DeviceConfigSyncResultModel,
|
|
16
|
+
UserAccountSummaryModel,
|
|
17
|
+
)
|
|
18
|
+
from inmotion.utils import request_json, request_json_map, stringify
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _text_headers(session: InMotionSession, content: str) -> dict[str, str]:
|
|
22
|
+
headers = session.build_headers(content=content)
|
|
23
|
+
headers['Content-Type'] = 'text/plain'
|
|
24
|
+
return headers
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class InMotionAccountsImpl(InMotionAccounts):
|
|
28
|
+
|
|
29
|
+
def __init__(self, session: InMotionSession):
|
|
30
|
+
self._session = session
|
|
31
|
+
self._prefix_path = f"{session.base_url}{session.api_path}"
|
|
32
|
+
|
|
33
|
+
def find_account(self, account_key: str) -> AccountDetailsModel:
|
|
34
|
+
return request_json('GET', f"{self._prefix_path}/account/{account_key}",
|
|
35
|
+
self._session.build_headers(content=''),
|
|
36
|
+
'',
|
|
37
|
+
'Failed to retrieve account',
|
|
38
|
+
AccountDetailsModel)
|
|
39
|
+
|
|
40
|
+
def find_account_tags(self, account_key: str) -> AccountTagsModel:
|
|
41
|
+
return request_json('GET', f"{self._prefix_path}/account/tags/{account_key}",
|
|
42
|
+
self._session.build_headers(content=''),
|
|
43
|
+
'',
|
|
44
|
+
'Failed to retrieve account tags',
|
|
45
|
+
AccountTagsModel)
|
|
46
|
+
|
|
47
|
+
def update_account(self, account_key: str, account: AccountModel) -> AccountDetailsModel:
|
|
48
|
+
account_data = stringify(account)
|
|
49
|
+
return request_json('POST', f"{self._prefix_path}/account/{account_key}",
|
|
50
|
+
self._session.build_headers(content=account_data),
|
|
51
|
+
account_data,
|
|
52
|
+
'Failed to update account',
|
|
53
|
+
AccountDetailsModel)
|
|
54
|
+
|
|
55
|
+
def find_account_users(self, account_key: str) -> list[AccountUserSummaryModel]:
|
|
56
|
+
return request_json('GET', f"{self._prefix_path}/account/{account_key}/users",
|
|
57
|
+
self._session.build_headers(content=''),
|
|
58
|
+
'',
|
|
59
|
+
'Failed to retrieve account users',
|
|
60
|
+
AccountUserSummaryModel, many=True)
|
|
61
|
+
|
|
62
|
+
def register_account_user(self, account_key: str, user_key: str, privileges: AccountPrivilegesModel) -> list[AccountUserSummaryModel]:
|
|
63
|
+
privileges_data = stringify(privileges)
|
|
64
|
+
return request_json('POST', f"{self._prefix_path}/account/{account_key}/register/{user_key}",
|
|
65
|
+
self._session.build_headers(content=privileges_data),
|
|
66
|
+
privileges_data,
|
|
67
|
+
'Failed to register account user',
|
|
68
|
+
AccountUserSummaryModel, many=True)
|
|
69
|
+
|
|
70
|
+
def unregister_account_user(self, account_key: str, user_key: str) -> AccountUserUnregisteredModel:
|
|
71
|
+
return request_json('POST', f"{self._prefix_path}/account/{account_key}/unregister/{user_key}",
|
|
72
|
+
self._session.build_headers(content=''),
|
|
73
|
+
'',
|
|
74
|
+
'Failed to unregister account user',
|
|
75
|
+
AccountUserUnregisteredModel)
|
|
76
|
+
|
|
77
|
+
def batch_update_account_users(self, account_key: str, commands: list[AccountUpdateBatchCommandModel]) -> AccountUpdateBatchResultsModel:
|
|
78
|
+
batch_data = stringify([asdict(c) for c in commands])
|
|
79
|
+
return request_json('POST', f"{self._prefix_path}/account/{account_key}/batch",
|
|
80
|
+
self._session.build_headers(content=batch_data),
|
|
81
|
+
batch_data,
|
|
82
|
+
'Failed to batch update account users',
|
|
83
|
+
AccountUpdateBatchResultsModel)
|
|
84
|
+
|
|
85
|
+
def create_account_only(self, account: AccountModel) -> AccountDetailsModel:
|
|
86
|
+
account_data = stringify(account)
|
|
87
|
+
return request_json('POST', f"{self._prefix_path}/account/create/only",
|
|
88
|
+
self._session.build_headers(content=account_data),
|
|
89
|
+
account_data,
|
|
90
|
+
'Failed to create account',
|
|
91
|
+
AccountDetailsModel)
|
|
92
|
+
|
|
93
|
+
def mark_account_for_deletion(self, account_key: str, and_user: bool) -> AccountMarkedForDeletionModel:
|
|
94
|
+
and_user_segment = 'true' if and_user else 'false'
|
|
95
|
+
return request_json('DELETE', f"{self._prefix_path}/account/delete/{account_key}/{and_user_segment}",
|
|
96
|
+
self._session.build_headers(content=''),
|
|
97
|
+
'',
|
|
98
|
+
'Failed to mark account for deletion',
|
|
99
|
+
AccountMarkedForDeletionModel)
|
|
100
|
+
|
|
101
|
+
def find_my_accounts(self) -> dict[str, UserAccountSummaryModel]:
|
|
102
|
+
return request_json_map('GET', f"{self._prefix_path}/accounts",
|
|
103
|
+
self._session.build_headers(content=''),
|
|
104
|
+
'',
|
|
105
|
+
'Failed to retrieve accounts',
|
|
106
|
+
UserAccountSummaryModel)
|
|
107
|
+
|
|
108
|
+
def fetch_global_device_configs(self) -> dict:
|
|
109
|
+
return request_json('GET', f"{self._prefix_path}/device-config",
|
|
110
|
+
self._session.build_headers(content=''),
|
|
111
|
+
'',
|
|
112
|
+
'Failed to fetch global device configs')
|
|
113
|
+
|
|
114
|
+
def sync_device_configs(self, request: DeviceConfigSyncRequestModel) -> DeviceConfigSyncResultModel:
|
|
115
|
+
request_data = stringify(request)
|
|
116
|
+
return request_json('POST', f"{self._prefix_path}/device-config/sync",
|
|
117
|
+
self._session.build_headers(content=request_data),
|
|
118
|
+
request_data,
|
|
119
|
+
'Failed to sync device configs',
|
|
120
|
+
DeviceConfigSyncResultModel)
|
|
121
|
+
|
|
122
|
+
def list_standard_data_types(self, account_key: str) -> list[dict]:
|
|
123
|
+
return request_json('GET', f"{self._prefix_path}/account/{account_key}/sdt/data-types",
|
|
124
|
+
self._session.build_headers(content=''),
|
|
125
|
+
'',
|
|
126
|
+
'Failed to list standard data types')
|
|
127
|
+
|
|
128
|
+
def create_standard_data_type(self, account_key: str, yaml_document: str) -> dict:
|
|
129
|
+
return request_json('POST', f"{self._prefix_path}/account/{account_key}/sdt/data-types",
|
|
130
|
+
_text_headers(self._session, yaml_document),
|
|
131
|
+
yaml_document,
|
|
132
|
+
'Failed to create standard data type')
|
|
133
|
+
|
|
134
|
+
def update_standard_data_type(self, account_key: str, key: str, yaml_document: str) -> dict:
|
|
135
|
+
return request_json('PUT', f"{self._prefix_path}/account/{account_key}/sdt/data-types/{key}",
|
|
136
|
+
_text_headers(self._session, yaml_document),
|
|
137
|
+
yaml_document,
|
|
138
|
+
'Failed to update standard data type')
|
|
139
|
+
|
|
140
|
+
def delete_standard_data_type(self, account_key: str, key: str) -> None:
|
|
141
|
+
request_json('DELETE', f"{self._prefix_path}/account/{account_key}/sdt/data-types/{key}",
|
|
142
|
+
self._session.build_headers(content=''),
|
|
143
|
+
'',
|
|
144
|
+
'Failed to delete standard data type')
|
|
145
|
+
|
|
146
|
+
def list_standard_data_variant_types(self, account_key: str) -> list[dict]:
|
|
147
|
+
return request_json('GET', f"{self._prefix_path}/account/{account_key}/sdt/data-variant-types",
|
|
148
|
+
self._session.build_headers(content=''),
|
|
149
|
+
'',
|
|
150
|
+
'Failed to list standard data variant types')
|
|
151
|
+
|
|
152
|
+
def create_standard_data_variant_type(self, account_key: str, yaml_document: str) -> dict:
|
|
153
|
+
return request_json('POST', f"{self._prefix_path}/account/{account_key}/sdt/data-variant-types",
|
|
154
|
+
_text_headers(self._session, yaml_document),
|
|
155
|
+
yaml_document,
|
|
156
|
+
'Failed to create standard data variant type')
|
|
157
|
+
|
|
158
|
+
def update_standard_data_variant_type(self, account_key: str, key: str, yaml_document: str) -> dict:
|
|
159
|
+
return request_json('PUT', f"{self._prefix_path}/account/{account_key}/sdt/data-variant-types/{key}",
|
|
160
|
+
_text_headers(self._session, yaml_document),
|
|
161
|
+
yaml_document,
|
|
162
|
+
'Failed to update standard data variant type')
|
|
163
|
+
|
|
164
|
+
def delete_standard_data_variant_type(self, account_key: str, key: str) -> None:
|
|
165
|
+
request_json('DELETE', f"{self._prefix_path}/account/{account_key}/sdt/data-variant-types/{key}",
|
|
166
|
+
self._session.build_headers(content=''),
|
|
167
|
+
'',
|
|
168
|
+
'Failed to delete standard data variant type')
|
|
169
|
+
|
|
170
|
+
def fetch_device_configs(self, account_key: str, preview: bool = False) -> dict:
|
|
171
|
+
qs = '?preview=true' if preview else ''
|
|
172
|
+
return request_json('GET', f"{self._prefix_path}/account/{account_key}/device-config{qs}",
|
|
173
|
+
self._session.build_headers(content=''),
|
|
174
|
+
'',
|
|
175
|
+
'Failed to fetch device configs')
|
|
176
|
+
|
|
177
|
+
def list_device_configs(self, account_key: str) -> dict:
|
|
178
|
+
return request_json('GET', f"{self._prefix_path}/account/{account_key}/device-configs",
|
|
179
|
+
self._session.build_headers(content=''),
|
|
180
|
+
'',
|
|
181
|
+
'Failed to list device configs')
|
|
182
|
+
|
|
183
|
+
def create_device_config(self, account_key: str, yaml_document: str) -> dict:
|
|
184
|
+
return request_json('POST', f"{self._prefix_path}/account/{account_key}/device-configs",
|
|
185
|
+
_text_headers(self._session, yaml_document),
|
|
186
|
+
yaml_document,
|
|
187
|
+
'Failed to create device config')
|
|
188
|
+
|
|
189
|
+
def save_device_config(self, account_key: str, name: str, yaml_document: str) -> dict:
|
|
190
|
+
return request_json('PUT', f"{self._prefix_path}/account/{account_key}/device-configs/{name}",
|
|
191
|
+
_text_headers(self._session, yaml_document),
|
|
192
|
+
yaml_document,
|
|
193
|
+
'Failed to save device config')
|
|
194
|
+
|
|
195
|
+
def delete_device_config(self, account_key: str, name: str) -> None:
|
|
196
|
+
request_json('DELETE', f"{self._prefix_path}/account/{account_key}/device-configs/{name}",
|
|
197
|
+
self._session.build_headers(content=''),
|
|
198
|
+
'',
|
|
199
|
+
'Failed to delete device config')
|
|
200
|
+
|
|
201
|
+
def start_device_config_development(self, account_key: str, name: str) -> dict:
|
|
202
|
+
return request_json('POST', f"{self._prefix_path}/account/{account_key}/device-configs/{name}/development",
|
|
203
|
+
self._session.build_headers(content=''),
|
|
204
|
+
'',
|
|
205
|
+
'Failed to start device config development')
|
|
206
|
+
|
|
207
|
+
def discard_device_config_development(self, account_key: str, name: str) -> None:
|
|
208
|
+
request_json('DELETE', f"{self._prefix_path}/account/{account_key}/device-configs/{name}/development",
|
|
209
|
+
self._session.build_headers(content=''),
|
|
210
|
+
'',
|
|
211
|
+
'Failed to discard device config development')
|
|
212
|
+
|
|
213
|
+
def publish_device_config(self, account_key: str, name: str, semantic_version: str) -> dict:
|
|
214
|
+
return request_json('POST', f"{self._prefix_path}/account/{account_key}/device-configs/{name}/publish?semanticVersion={semantic_version}",
|
|
215
|
+
self._session.build_headers(content=''),
|
|
216
|
+
'',
|
|
217
|
+
'Failed to publish device config')
|
|
218
|
+
|
|
219
|
+
def withdraw_device_config(self, account_key: str, name: str, version: int) -> dict:
|
|
220
|
+
return request_json('POST', f"{self._prefix_path}/account/{account_key}/device-configs/{name}/{version}/withdraw",
|
|
221
|
+
self._session.build_headers(content=''),
|
|
222
|
+
'',
|
|
223
|
+
'Failed to withdraw device config')
|
|
224
|
+
|
|
225
|
+
def republish_device_config(self, account_key: str, name: str, version: int) -> dict:
|
|
226
|
+
return request_json('POST', f"{self._prefix_path}/account/{account_key}/device-configs/{name}/{version}/republish",
|
|
227
|
+
self._session.build_headers(content=''),
|
|
228
|
+
'',
|
|
229
|
+
'Failed to republish device config')
|
inmotion/activities.py
ADDED
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
from dataclasses import asdict
|
|
2
|
+
from datetime import datetime
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
from inmotion.api import InMotionSession, InMotionActivities
|
|
6
|
+
from inmotion.models import (
|
|
7
|
+
ActivitiesModel,
|
|
8
|
+
ActivityAnalyticsRequestModel,
|
|
9
|
+
ActivityAnalyticsResultModel,
|
|
10
|
+
ActivityBatchCommandsModel,
|
|
11
|
+
ActivityBatchResultModel,
|
|
12
|
+
ActivitySearchFilterModel,
|
|
13
|
+
ActivityTrackMetricsResultModel,
|
|
14
|
+
ActivityUpdateResponseModel,
|
|
15
|
+
ActivityVariableStatsResultModel,
|
|
16
|
+
CreateSiteActivityModel,
|
|
17
|
+
CreateTrackActivityModel,
|
|
18
|
+
LastActivitiesModel,
|
|
19
|
+
MasterDataModel,
|
|
20
|
+
ModelFieldGroupModel,
|
|
21
|
+
QCConfigModel,
|
|
22
|
+
SetModelFieldValueRequestModel,
|
|
23
|
+
SiteActivityModel,
|
|
24
|
+
SiteRecordsModel,
|
|
25
|
+
TrackActivityModel,
|
|
26
|
+
TrackRecordsModel,
|
|
27
|
+
UpdateSiteActivityModel,
|
|
28
|
+
UpdateTrackActivityModel,
|
|
29
|
+
)
|
|
30
|
+
from inmotion.utils import request_json, request_raw, stringify
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class InMotionActivitiesImpl(InMotionActivities):
|
|
34
|
+
|
|
35
|
+
def __init__(self, session: InMotionSession):
|
|
36
|
+
self._session = session
|
|
37
|
+
self._prefix_path = f"{session.base_url}{session.api_path}"
|
|
38
|
+
|
|
39
|
+
def find_activities(self, act_filter: ActivitySearchFilterModel) -> ActivitiesModel:
|
|
40
|
+
filter_data = stringify(act_filter)
|
|
41
|
+
postfix_path = f"activities/{self._session.account}"
|
|
42
|
+
return request_json('POST', f"{self._prefix_path}/{postfix_path}",
|
|
43
|
+
self._session.build_headers(content=filter_data),
|
|
44
|
+
filter_data,
|
|
45
|
+
'Failed to retrieve activities',
|
|
46
|
+
ActivitiesModel)
|
|
47
|
+
|
|
48
|
+
def find_activities_within_time_range(self, act_filter: ActivitySearchFilterModel, start: datetime, finish: datetime) -> ActivitiesModel:
|
|
49
|
+
start_millis = int(start.timestamp() * 1000)
|
|
50
|
+
finish_millis = int(finish.timestamp() * 1000)
|
|
51
|
+
postfix_path = f"activities/{self._session.account}/{start_millis}/{finish_millis}"
|
|
52
|
+
return request_json('GET', f"{self._prefix_path}/{postfix_path}",
|
|
53
|
+
self._session.build_headers(content=''),
|
|
54
|
+
'',
|
|
55
|
+
'Failed to retrieve activities',
|
|
56
|
+
ActivitiesModel)
|
|
57
|
+
|
|
58
|
+
def find_latest_activity_stats(self, since: datetime, max_records: int) -> LastActivitiesModel:
|
|
59
|
+
since_millis = int(since.timestamp() * 1000)
|
|
60
|
+
postfix_path = f"activities/latest/{self._session.account}/{since_millis}/{max_records}"
|
|
61
|
+
return request_json('GET', f"{self._prefix_path}/{postfix_path}",
|
|
62
|
+
self._session.build_headers(content=''),
|
|
63
|
+
'',
|
|
64
|
+
'Failed to load latest activities',
|
|
65
|
+
LastActivitiesModel)
|
|
66
|
+
|
|
67
|
+
def find_latest_activity_stats_by_type(self, since: datetime, coord_conv: str) -> LastActivitiesModel:
|
|
68
|
+
since_millis = int(since.timestamp() * 1000)
|
|
69
|
+
postfix_path = f"activities/latest/{self._session.account}/{since_millis}/{coord_conv}"
|
|
70
|
+
return request_json('GET', f"{self._prefix_path}/{postfix_path}",
|
|
71
|
+
self._session.build_headers(content=''),
|
|
72
|
+
'',
|
|
73
|
+
'Failed to load latest activities',
|
|
74
|
+
LastActivitiesModel)
|
|
75
|
+
|
|
76
|
+
def find_activity_master_data(self) -> MasterDataModel:
|
|
77
|
+
return request_json('GET', f"{self._prefix_path}/activity/master-data",
|
|
78
|
+
self._session.build_headers(content=''),
|
|
79
|
+
'',
|
|
80
|
+
'Failed to retrieve activity master data',
|
|
81
|
+
MasterDataModel)
|
|
82
|
+
|
|
83
|
+
def find_activity_analytics(self, request: ActivityAnalyticsRequestModel) -> ActivityAnalyticsResultModel:
|
|
84
|
+
request_data = stringify(request)
|
|
85
|
+
return request_json('POST', f"{self._prefix_path}/activities/analytics",
|
|
86
|
+
self._session.build_headers(content=request_data),
|
|
87
|
+
request_data,
|
|
88
|
+
'Failed to retrieve activity analytics',
|
|
89
|
+
ActivityAnalyticsResultModel)
|
|
90
|
+
|
|
91
|
+
def find_activity_track_metrics(self, request: ActivityAnalyticsRequestModel) -> ActivityTrackMetricsResultModel:
|
|
92
|
+
request_data = stringify(request)
|
|
93
|
+
return request_json('POST', f"{self._prefix_path}/activities/analytics/track-metrics",
|
|
94
|
+
self._session.build_headers(content=request_data),
|
|
95
|
+
request_data,
|
|
96
|
+
'Failed to retrieve activity track metrics',
|
|
97
|
+
ActivityTrackMetricsResultModel)
|
|
98
|
+
|
|
99
|
+
def find_activity_variable_stats(self, request: ActivityAnalyticsRequestModel) -> ActivityVariableStatsResultModel:
|
|
100
|
+
request_data = stringify(request)
|
|
101
|
+
return request_json('POST', f"{self._prefix_path}/activities/analytics/variable-stats",
|
|
102
|
+
self._session.build_headers(content=request_data),
|
|
103
|
+
request_data,
|
|
104
|
+
'Failed to retrieve activity variable stats',
|
|
105
|
+
ActivityVariableStatsResultModel)
|
|
106
|
+
|
|
107
|
+
def batch_record_update(self, commands: ActivityBatchCommandsModel) -> list[ActivityBatchResultModel]:
|
|
108
|
+
commands_data = stringify(commands)
|
|
109
|
+
return request_json('POST', f"{self._prefix_path}/activities/batch",
|
|
110
|
+
self._session.build_headers(content=commands_data),
|
|
111
|
+
commands_data,
|
|
112
|
+
'Failed to apply batch record update',
|
|
113
|
+
ActivityBatchResultModel, many=True)
|
|
114
|
+
|
|
115
|
+
def create_track_activity(self, ctam: CreateTrackActivityModel) -> ActivityUpdateResponseModel:
|
|
116
|
+
site_data = stringify({
|
|
117
|
+
"recordInterval": ctam.recordInterval,
|
|
118
|
+
"activity": asdict(ctam.activity)
|
|
119
|
+
})
|
|
120
|
+
return request_json('POST', f"{self._prefix_path}/activity/track",
|
|
121
|
+
self._session.build_headers(content=site_data),
|
|
122
|
+
site_data,
|
|
123
|
+
'Failed to create track activity',
|
|
124
|
+
ActivityUpdateResponseModel)
|
|
125
|
+
|
|
126
|
+
def update_track_activity(self, track_key: str, utam: UpdateTrackActivityModel) -> ActivityUpdateResponseModel:
|
|
127
|
+
track_data = stringify({
|
|
128
|
+
"activity": asdict(utam.activity)
|
|
129
|
+
})
|
|
130
|
+
return request_json('POST', f"{self._prefix_path}/activity/track/{track_key}",
|
|
131
|
+
self._session.build_headers(content=track_data),
|
|
132
|
+
track_data,
|
|
133
|
+
'Failed to update track activity',
|
|
134
|
+
ActivityUpdateResponseModel)
|
|
135
|
+
|
|
136
|
+
def find_track_activity(self, track_key: str) -> TrackActivityModel:
|
|
137
|
+
return request_json('GET', f"{self._prefix_path}/activity/track/{track_key}",
|
|
138
|
+
self._session.build_headers(content=''),
|
|
139
|
+
'',
|
|
140
|
+
'Failed to retrieve track activity',
|
|
141
|
+
TrackActivityModel)
|
|
142
|
+
|
|
143
|
+
def delete_track_activity(self, track_key: str) -> None:
|
|
144
|
+
request_json('DELETE', f"{self._prefix_path}/activity/track/{track_key}",
|
|
145
|
+
self._session.build_headers(content=''),
|
|
146
|
+
'',
|
|
147
|
+
'Failed to delete track activity')
|
|
148
|
+
|
|
149
|
+
def unlock_track_activity(self, track_key: str) -> None:
|
|
150
|
+
request_json('PUT', f"{self._prefix_path}/activity/track/unlock/{track_key}",
|
|
151
|
+
self._session.build_headers(content=''),
|
|
152
|
+
'',
|
|
153
|
+
'Failed to unlock track activity')
|
|
154
|
+
|
|
155
|
+
def get_track_records(self, track_key: str, start_time: Optional[datetime], end_time: Optional[datetime]) -> TrackRecordsModel:
|
|
156
|
+
start_millis = int(start_time.timestamp() * 1000) if start_time else 0
|
|
157
|
+
end_millis = int(end_time.timestamp() * 1000) if end_time else 0
|
|
158
|
+
return request_json('GET', f"{self._prefix_path}/activity/track/records/{track_key}/{start_millis}/{end_millis}",
|
|
159
|
+
self._session.build_headers(content=''),
|
|
160
|
+
'',
|
|
161
|
+
'Failed to retrieve track records',
|
|
162
|
+
TrackRecordsModel)
|
|
163
|
+
|
|
164
|
+
def find_all_track_records(self, track_key: str) -> TrackRecordsModel:
|
|
165
|
+
return request_json('GET', f"{self._prefix_path}/activity/track/records/{track_key}",
|
|
166
|
+
self._session.build_headers(content=''),
|
|
167
|
+
'',
|
|
168
|
+
'Failed to retrieve track records',
|
|
169
|
+
TrackRecordsModel)
|
|
170
|
+
|
|
171
|
+
def publish_track_records(self, track_key: str, records: dict) -> ActivityUpdateResponseModel:
|
|
172
|
+
""" Publish a set of site records to inmotion """
|
|
173
|
+
record_data = stringify(records)
|
|
174
|
+
return request_json('POST', f"{self._prefix_path}/activity/track/records/{track_key}",
|
|
175
|
+
self._session.build_headers(content=record_data),
|
|
176
|
+
record_data,
|
|
177
|
+
'Failed to publish track records',
|
|
178
|
+
ActivityUpdateResponseModel)
|
|
179
|
+
|
|
180
|
+
def download_track_records(self, track_key: str, file_format: str) -> bytes:
|
|
181
|
+
return request_raw('GET', f"{self._prefix_path}/activity/track/download/{track_key}/{file_format}",
|
|
182
|
+
self._session.build_headers(content=''),
|
|
183
|
+
'',
|
|
184
|
+
'Failed to download track records')
|
|
185
|
+
|
|
186
|
+
def share_track_activity(self, track_key: str, kind: str) -> None:
|
|
187
|
+
request_json('POST', f"{self._prefix_path}/activity/track/share/{track_key}/{kind}",
|
|
188
|
+
self._session.build_headers(content=''),
|
|
189
|
+
'',
|
|
190
|
+
'Failed to share track activity')
|
|
191
|
+
|
|
192
|
+
def unshare_track_activity(self, track_key: str, kind: str) -> None:
|
|
193
|
+
request_json('PUT', f"{self._prefix_path}/activity/track/unshare/{track_key}/{kind}",
|
|
194
|
+
self._session.build_headers(content=''),
|
|
195
|
+
'',
|
|
196
|
+
'Failed to unshare track activity')
|
|
197
|
+
|
|
198
|
+
def find_shared_track_activity(self, track_key: str) -> TrackActivityModel:
|
|
199
|
+
return request_json('GET', f"{self._prefix_path}/activity/track/shared/{track_key}",
|
|
200
|
+
self._session.build_headers(content=''),
|
|
201
|
+
'',
|
|
202
|
+
'Failed to retrieve shared track activity',
|
|
203
|
+
TrackActivityModel)
|
|
204
|
+
|
|
205
|
+
def find_all_shared_track_records(self, track_key: str) -> TrackRecordsModel:
|
|
206
|
+
return request_json('GET', f"{self._prefix_path}/activity/track/shared/records/{track_key}",
|
|
207
|
+
self._session.build_headers(content=''),
|
|
208
|
+
'',
|
|
209
|
+
'Failed to retrieve shared track records',
|
|
210
|
+
TrackRecordsModel)
|
|
211
|
+
|
|
212
|
+
def convert_track_to_route(self, track_key: str, name: Optional[str] = None) -> str:
|
|
213
|
+
body_data = stringify({"name": name} if name is not None else {})
|
|
214
|
+
result = request_json('POST', f"{self._prefix_path}/activity/track/convert-to-route/{track_key}",
|
|
215
|
+
self._session.build_headers(content=body_data),
|
|
216
|
+
body_data,
|
|
217
|
+
'Failed to convert track activity to route')
|
|
218
|
+
return result['key']
|
|
219
|
+
|
|
220
|
+
def preview_track_records(self, track_key: str, qc_config: QCConfigModel) -> dict:
|
|
221
|
+
qc_data = stringify(qc_config)
|
|
222
|
+
return request_json('POST', f"{self._prefix_path}/activity/track/records/{track_key}/preview",
|
|
223
|
+
self._session.build_headers(content=qc_data),
|
|
224
|
+
qc_data,
|
|
225
|
+
'Failed to preview track records')
|
|
226
|
+
|
|
227
|
+
def preview_track_records_within_range(self, track_key: str, start_time: datetime, end_time: datetime, qc_config: QCConfigModel) -> dict:
|
|
228
|
+
start_millis = int(start_time.timestamp() * 1000)
|
|
229
|
+
end_millis = int(end_time.timestamp() * 1000)
|
|
230
|
+
qc_data = stringify(qc_config)
|
|
231
|
+
return request_json('POST', f"{self._prefix_path}/activity/track/records/{track_key}/preview/{start_millis}/{end_millis}",
|
|
232
|
+
self._session.build_headers(content=qc_data),
|
|
233
|
+
qc_data,
|
|
234
|
+
'Failed to preview track records within range')
|
|
235
|
+
|
|
236
|
+
def find_track_model_field_groups(self, track_key: str) -> list[ModelFieldGroupModel]:
|
|
237
|
+
return request_json('GET', f"{self._prefix_path}/activity/track/{track_key}/model-fields",
|
|
238
|
+
self._session.build_headers(content=''),
|
|
239
|
+
'',
|
|
240
|
+
'Failed to find track model field groups',
|
|
241
|
+
ModelFieldGroupModel, many=True)
|
|
242
|
+
|
|
243
|
+
def set_track_model_field_value(self, track_key: str, request: SetModelFieldValueRequestModel) -> list[ModelFieldGroupModel]:
|
|
244
|
+
request_data = stringify(request)
|
|
245
|
+
return request_json('PUT', f"{self._prefix_path}/activity/track/{track_key}/model-fields",
|
|
246
|
+
self._session.build_headers(content=request_data),
|
|
247
|
+
request_data,
|
|
248
|
+
'Failed to set track model field value',
|
|
249
|
+
ModelFieldGroupModel, many=True)
|
|
250
|
+
|
|
251
|
+
def create_site_activity(self, csam: CreateSiteActivityModel) -> ActivityUpdateResponseModel:
|
|
252
|
+
site_data = stringify({
|
|
253
|
+
"activity": asdict(csam.activity),
|
|
254
|
+
"location": asdict(csam.location),
|
|
255
|
+
"recordInterval": csam.recordInterval
|
|
256
|
+
})
|
|
257
|
+
return request_json('POST', f"{self._prefix_path}/activity/site",
|
|
258
|
+
self._session.build_headers(content=site_data),
|
|
259
|
+
site_data,
|
|
260
|
+
'Failed to create site activity',
|
|
261
|
+
ActivityUpdateResponseModel)
|
|
262
|
+
|
|
263
|
+
def update_site_activity(self, site_key: str, usam: UpdateSiteActivityModel) -> ActivityUpdateResponseModel:
|
|
264
|
+
site_data = stringify({
|
|
265
|
+
"location": asdict(usam.location),
|
|
266
|
+
"activity": asdict(usam.activity)
|
|
267
|
+
})
|
|
268
|
+
return request_json('POST', f"{self._prefix_path}/activity/site/{site_key}",
|
|
269
|
+
self._session.build_headers(content=site_data),
|
|
270
|
+
site_data,
|
|
271
|
+
'Failed to update site activity',
|
|
272
|
+
ActivityUpdateResponseModel)
|
|
273
|
+
|
|
274
|
+
def find_site_activity(self, site_key: str) -> SiteActivityModel:
|
|
275
|
+
return request_json('GET', f"{self._prefix_path}/activity/site/{site_key}",
|
|
276
|
+
self._session.build_headers(content=''),
|
|
277
|
+
'',
|
|
278
|
+
'Failed to retrieve site activity',
|
|
279
|
+
SiteActivityModel)
|
|
280
|
+
|
|
281
|
+
def delete_site_activity(self, site_key: str) -> None:
|
|
282
|
+
request_json('DELETE', f"{self._prefix_path}/activity/site/{site_key}",
|
|
283
|
+
self._session.build_headers(content=''),
|
|
284
|
+
'',
|
|
285
|
+
'Failed to delete site activity')
|
|
286
|
+
|
|
287
|
+
def unlock_site_activity(self, site_key: str) -> None:
|
|
288
|
+
request_json('PUT', f"{self._prefix_path}/activity/site/unlock/{site_key}",
|
|
289
|
+
self._session.build_headers(content=''),
|
|
290
|
+
'',
|
|
291
|
+
'Failed to unlock site activity')
|
|
292
|
+
|
|
293
|
+
def get_site_records(self, site_key: str, start_time: Optional[datetime], end_time: Optional[datetime]) -> SiteRecordsModel:
|
|
294
|
+
start_millis = int(start_time.timestamp() * 1000) if start_time else 0
|
|
295
|
+
end_millis = int(end_time.timestamp() * 1000) if end_time else 0
|
|
296
|
+
return request_json('GET', f"{self._prefix_path}/activity/site/records/{site_key}/{start_millis}/{end_millis}",
|
|
297
|
+
self._session.build_headers(content=''),
|
|
298
|
+
'',
|
|
299
|
+
'Failed to retrieve site records',
|
|
300
|
+
SiteRecordsModel)
|
|
301
|
+
|
|
302
|
+
def find_all_site_records(self, site_key: str) -> SiteRecordsModel:
|
|
303
|
+
return request_json('GET', f"{self._prefix_path}/activity/site/records/{site_key}",
|
|
304
|
+
self._session.build_headers(content=''),
|
|
305
|
+
'',
|
|
306
|
+
'Failed to retrieve site records',
|
|
307
|
+
SiteRecordsModel)
|
|
308
|
+
|
|
309
|
+
def publish_site_records(self, site_key: str, records: dict) -> ActivityUpdateResponseModel:
|
|
310
|
+
""" Publish a set of site records to inmotion """
|
|
311
|
+
record_data = stringify(records)
|
|
312
|
+
return request_json('POST', f"{self._prefix_path}/activity/site/records/{site_key}",
|
|
313
|
+
self._session.build_headers(content=record_data),
|
|
314
|
+
record_data,
|
|
315
|
+
'Failed to publish site records',
|
|
316
|
+
ActivityUpdateResponseModel)
|
|
317
|
+
|
|
318
|
+
def download_site_records(self, site_key: str, file_format: str) -> bytes:
|
|
319
|
+
return request_raw('GET', f"{self._prefix_path}/activity/site/download/{site_key}/{file_format}",
|
|
320
|
+
self._session.build_headers(content=''),
|
|
321
|
+
'',
|
|
322
|
+
'Failed to download site records')
|
|
323
|
+
|
|
324
|
+
def share_site_activity(self, site_key: str, kind: str) -> None:
|
|
325
|
+
request_json('POST', f"{self._prefix_path}/activity/site/share/{site_key}/{kind}",
|
|
326
|
+
self._session.build_headers(content=''),
|
|
327
|
+
'',
|
|
328
|
+
'Failed to share site activity')
|
|
329
|
+
|
|
330
|
+
def unshare_site_activity(self, site_key: str, kind: str) -> None:
|
|
331
|
+
request_json('PUT', f"{self._prefix_path}/activity/site/unshare/{site_key}/{kind}",
|
|
332
|
+
self._session.build_headers(content=''),
|
|
333
|
+
'',
|
|
334
|
+
'Failed to unshare site activity')
|
|
335
|
+
|
|
336
|
+
def find_shared_site_activity(self, site_key: str) -> SiteActivityModel:
|
|
337
|
+
return request_json('GET', f"{self._prefix_path}/activity/site/shared/{site_key}",
|
|
338
|
+
self._session.build_headers(content=''),
|
|
339
|
+
'',
|
|
340
|
+
'Failed to retrieve shared site activity',
|
|
341
|
+
SiteActivityModel)
|
|
342
|
+
|
|
343
|
+
def find_shared_site_records(self, site_key: str, start_time: datetime, end_time: datetime) -> SiteRecordsModel:
|
|
344
|
+
start_millis = int(start_time.timestamp() * 1000)
|
|
345
|
+
end_millis = int(end_time.timestamp() * 1000)
|
|
346
|
+
return request_json('GET', f"{self._prefix_path}/activity/site/shared/records/{site_key}/{start_millis}/{end_millis}",
|
|
347
|
+
self._session.build_headers(content=''),
|
|
348
|
+
'',
|
|
349
|
+
'Failed to retrieve shared site records',
|
|
350
|
+
SiteRecordsModel)
|
|
351
|
+
|
|
352
|
+
def preview_site_records(self, site_key: str, qc_config: QCConfigModel) -> dict:
|
|
353
|
+
qc_data = stringify(qc_config)
|
|
354
|
+
return request_json('POST', f"{self._prefix_path}/activity/site/records/{site_key}/preview",
|
|
355
|
+
self._session.build_headers(content=qc_data),
|
|
356
|
+
qc_data,
|
|
357
|
+
'Failed to preview site records')
|
|
358
|
+
|
|
359
|
+
def preview_site_records_within_range(self, site_key: str, start_time: datetime, end_time: datetime, qc_config: QCConfigModel) -> dict:
|
|
360
|
+
start_millis = int(start_time.timestamp() * 1000)
|
|
361
|
+
end_millis = int(end_time.timestamp() * 1000)
|
|
362
|
+
qc_data = stringify(qc_config)
|
|
363
|
+
return request_json('POST', f"{self._prefix_path}/activity/site/records/{site_key}/preview/{start_millis}/{end_millis}",
|
|
364
|
+
self._session.build_headers(content=qc_data),
|
|
365
|
+
qc_data,
|
|
366
|
+
'Failed to preview site records within range')
|
|
367
|
+
|
|
368
|
+
def find_site_model_field_groups(self, site_key: str) -> list[ModelFieldGroupModel]:
|
|
369
|
+
return request_json('GET', f"{self._prefix_path}/activity/site/{site_key}/model-fields",
|
|
370
|
+
self._session.build_headers(content=''),
|
|
371
|
+
'',
|
|
372
|
+
'Failed to find site model field groups',
|
|
373
|
+
ModelFieldGroupModel, many=True)
|
|
374
|
+
|
|
375
|
+
def set_site_model_field_value(self, site_key: str, request: SetModelFieldValueRequestModel) -> list[ModelFieldGroupModel]:
|
|
376
|
+
request_data = stringify(request)
|
|
377
|
+
return request_json('PUT', f"{self._prefix_path}/activity/site/{site_key}/model-fields",
|
|
378
|
+
self._session.build_headers(content=request_data),
|
|
379
|
+
request_data,
|
|
380
|
+
'Failed to set site model field value',
|
|
381
|
+
ModelFieldGroupModel, many=True)
|