pygeobox 1.0.0__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.
pygeobox/route.py ADDED
@@ -0,0 +1,63 @@
1
+ from typing import Dict, TYPE_CHECKING
2
+ from urllib.parse import urljoin, urlencode
3
+
4
+ from .enums import RoutingGeometryType, RoutingOverviewLevel
5
+ from .utils import clean_data
6
+
7
+ if TYPE_CHECKING:
8
+ from . import GeoboxClient
9
+
10
+ class Routing:
11
+
12
+ BASE_ENDPOINT = 'routing/'
13
+
14
+ @classmethod
15
+ def route(cls, api: 'GeoboxClient', stops: str, **kwargs) -> Dict:
16
+ """
17
+ Find best driving routes between coordinates and return results.
18
+
19
+ Args:
20
+ api (GeoboxClient): The GeoboxClient instance for making requests.
21
+ stops (str): Comma-separated list of stop coordinates in the format lon,lat;lon,lat.
22
+
23
+ Keyword Args:
24
+ alternatives (bool): Whether to return alternative routes. Default value : False.
25
+ steps (bool): Whether to include step-by-step navigation instructions. Default value : False.
26
+ geometries (RoutingGeometryType): Format of the returned geometry.
27
+ overview (RoutingOverviewLevel): Level of detail in the returned geometry.
28
+ annotations (bool): Whether to include additional metadata like speed, weight, etc.
29
+
30
+ Returns:
31
+ Dict: the routing output
32
+
33
+ Example:
34
+ >>> from geobox import GeoboxClient
35
+ >>> from geobox.route import Routing
36
+ >>> client = GeoboxClient()
37
+ >>> route = routing.route(client,
38
+ ... stops="53,33;56,36",
39
+ ... alternatives=True,
40
+ ... steps=True,
41
+ ... geometries=RoutingGeometryType.geojson,
42
+ ... overview=RoutingOverviewLevel.full,
43
+ ... annotations=True)
44
+ or
45
+ >>> route = client.route(stops="53,33;56,36",
46
+ ... alternatives=True,
47
+ ... steps=True,
48
+ ... geometries=RoutingGeometryType.geojson,
49
+ ... overview=RoutingOverviewLevel.full,
50
+ ... annotations=True)
51
+ """
52
+ params = clean_data({
53
+ 'stops': stops,
54
+ 'alternatives': kwargs.get('alternatives'),
55
+ 'steps': kwargs.get('steps'),
56
+ 'geometries': kwargs.get('geometries').value if kwargs.get('geometries') else None,
57
+ 'overview': kwargs.get('overview').value if kwargs.get('geometries') else None,
58
+ 'annotaions': kwargs.get('annotations')
59
+ })
60
+ query_string = urlencode(params)
61
+ endpoint = f"{cls.BASE_ENDPOINT}route?{query_string}"
62
+ return api.get(endpoint)
63
+
pygeobox/scene.py ADDED
@@ -0,0 +1,317 @@
1
+ from typing import List, Dict, Optional, TYPE_CHECKING, Union
2
+ from urllib.parse import urljoin
3
+
4
+ from .base import Base
5
+
6
+ if TYPE_CHECKING:
7
+ from . import GeoboxClient
8
+ from .user import User
9
+
10
+ class Scene(Base):
11
+
12
+ BASE_ENDPOINT = 'scenes/'
13
+
14
+ def __init__(self,
15
+ api: 'GeoboxClient',
16
+ uuid: str,
17
+ data: Optional[Dict] = {}):
18
+ """
19
+ Initialize a Scene instance.
20
+
21
+ Args:
22
+ api (GeoboxClient): The GeoboxClient instance for making requests.
23
+ uuid (str): The unique identifier for the Scene.
24
+ data (Dict): The data of the Scene.
25
+ """
26
+ super().__init__(api, uuid=uuid, data=data)
27
+
28
+
29
+ @classmethod
30
+ def get_scenes(cls, api: 'GeoboxClient', **kwargs) -> Union[List['Scene'], int]:
31
+ """
32
+ Get list of scenes with optional filtering and pagination.
33
+
34
+ Args:
35
+ api (GeoboxClient): The GeoboxClient instance for making requests.
36
+
37
+ Keyword Args:
38
+ q (str): query filter based on OGC CQL standard. e.g. "field1 LIKE '%GIS%' AND created_at > '2021-01-01'"
39
+ search (str): search term for keyword-based searching among search_fields or all textual fields if search_fields does not have value. NOTE: if q param is defined this param will be ignored.
40
+ search_fields (str): comma separated list of fields for searching.
41
+ order_by (str): comma separated list of fields for sorting results [field1 A|D, field2 A|D, …]. e.g. name A, type D. NOTE: "A" denotes ascending order and "D" denotes descending order.
42
+ return_count (bool): Whether to return total count. default is False.
43
+ skip (int): Number of items to skip. default is 0.
44
+ limit (int): Number of items to return. default is 10.
45
+ user_id (int): Specific user. privileges required.
46
+ shared (bool): Whether to return shared scenes. default is False.
47
+
48
+ Returns:
49
+ List[Scene] | int: A list of scene instances or the total number of scenes.
50
+
51
+ Example:
52
+ >>> from geobox import GeoboxClient
53
+ >>> from geobox.scene import Scene
54
+ >>> client = GeoboxClient()
55
+ >>> scenes = Scene.get_scenes(client, q="name LIKE '%My scene%'")
56
+ or
57
+ >>> scenes = client.get_scenes(q="name LIKE '%My scene%'")
58
+ """
59
+ params = {
60
+ 'f': 'json',
61
+ 'q': kwargs.get('q'),
62
+ 'search': kwargs.get('search'),
63
+ 'search_fields': kwargs.get('search_fields'),
64
+ 'order_by': kwargs.get('order_by'),
65
+ 'return_count': kwargs.get('return_count', False),
66
+ 'skip': kwargs.get('skip', 0),
67
+ 'limit': kwargs.get('limit', 10),
68
+ 'user_id': kwargs.get('user_id'),
69
+ 'shared': kwargs.get('shared', False)
70
+ }
71
+ return super()._get_list(api, cls.BASE_ENDPOINT, params, factory_func=lambda api, item: Scene(api, item['uuid'], item))
72
+
73
+
74
+ @classmethod
75
+ def create_scene(cls,
76
+ api: 'GeoboxClient',
77
+ name: str,
78
+ display_name: str = None,
79
+ description: str = None,
80
+ settings: Dict = {},
81
+ thumbnail: str = None,
82
+ user_id: int = None) -> 'Scene':
83
+ """
84
+ Create a new scene.
85
+
86
+ Args:
87
+ api (GeoboxClient): The GeoboxClient instance for making requests.
88
+ name (str): The name of the scene.
89
+ display_name (str, optional): The display name of the scene.
90
+ description (str, optional): The description of the scene.
91
+ settings (Dict,optional): The settings of the scene.
92
+ thumbnail (str, optional): The thumbnail of the scene.
93
+ user_id (int, optional): Specific user. privileges required.
94
+
95
+ Returns:
96
+ Scene: The newly created scene instance.
97
+
98
+ Raises:
99
+ ValidationError: If the scene data is invalid.
100
+
101
+ Example:
102
+ >>> from geobox import GeoboxClient
103
+ >>> from geobox.scene import Scene
104
+ >>> client = GeoboxClient()
105
+ >>> scene = Scene.create_scene(client, name="my_scene")
106
+ or
107
+ >>> scene = client.create_scene(name="my_scene")
108
+ """
109
+ data = {
110
+ "name": name,
111
+ "display_name": display_name,
112
+ "description": description,
113
+ "settings": settings,
114
+ "thumbnail": thumbnail,
115
+ "user_id": user_id,
116
+ }
117
+ return super()._create(api, cls.BASE_ENDPOINT, data, factory_func=lambda api, item: Scene(api, item['uuid'], item))
118
+
119
+
120
+ @classmethod
121
+ def get_scene(cls, api: 'GeoboxClient', uuid: str, user_id: int = None) -> 'Scene':
122
+ """
123
+ Get a scene by its UUID.
124
+
125
+ Args:
126
+ api (GeoboxClient): The GeoboxClient instance for making requests.
127
+ uuid (str): The UUID of the scene to get.
128
+ user_id (int, optional): Specific user. privileges required.
129
+
130
+ Returns:
131
+ Scene: The scene object.
132
+
133
+ Raises:
134
+ NotFoundError: If the scene with the specified UUID is not found.
135
+
136
+ Example:
137
+ >>> from geobox import GeoboxClient
138
+ >>> from geobox.scene import Scene
139
+ >>> client = GeoboxClient()
140
+ >>> scene = Scene.get_scene(client, uuid="12345678-1234-5678-1234-567812345678")
141
+ or
142
+ >>> scene = client.get_scene(uuid="12345678-1234-5678-1234-567812345678")
143
+ """
144
+ params = {
145
+ 'f': 'json',
146
+ 'user_id': user_id,
147
+ }
148
+ return super()._get_detail(api, cls.BASE_ENDPOINT, uuid, params, factory_func=lambda api, item: Scene(api, item['uuid'], item))
149
+
150
+
151
+ @classmethod
152
+ def get_scene_by_name(cls, api: 'GeoboxClient', name: str, user_id: int = None) -> Union['Scene', None]:
153
+ """
154
+ Get a scene by name
155
+
156
+ Args:
157
+ api (GeoboxClient): The GeoboxClient instance for making requests.
158
+ name (str): the name of the scene to get
159
+ user_id (int, optional): specific user. privileges required.
160
+
161
+ Returns:
162
+ Scene | None: returns the scene if a scene matches the given name, else None
163
+
164
+ Example:
165
+ >>> from geobox import GeoboxClient
166
+ >>> from geobox.scene import Scene
167
+ >>> client = GeoboxClient()
168
+ >>> scene = Scene.get_scene_by_name(client, name='test')
169
+ or
170
+ >>> scene = client.get_scene_by_name(name='test')
171
+ """
172
+ scenes = cls.get_scenes(api, q=f"name = '{name}'", user_id=user_id)
173
+ if scenes and scenes[0].name == name:
174
+ return scenes[0]
175
+ else:
176
+ return None
177
+
178
+
179
+ def update(self, **kwargs) -> Dict:
180
+ """
181
+ Update the scene.
182
+
183
+ Keyword Args:
184
+ name (str): The name of the scene.
185
+ display_name (str): The display name of the scene.
186
+ description (str): The description of the scene.
187
+ settings (Dict): The settings of the scene.
188
+ thumbnail (str): The thumbnail of the scene.
189
+
190
+ Returns:
191
+ Dict: The updated scene data.
192
+
193
+ Raises:
194
+ ApiRequestError: If the API request fails.
195
+ ValidationError: If the scene data is invalid.
196
+
197
+ Example:
198
+ >>> from geobox import GeoboxClient
199
+ >>> from geobox.scene import Scene
200
+ >>> client = GeoboxClient()
201
+ >>> scene = Scene.get_scene(client, uuid="12345678-1234-5678-1234-567812345678")
202
+ >>> scene.update(display_name="New Display Name")
203
+ """
204
+ data = {
205
+ "name": kwargs.get('name'),
206
+ "display_name": kwargs.get('display_name'),
207
+ "description": kwargs.get('description'),
208
+ "settings": kwargs.get('settings'),
209
+ "thumbnail": kwargs.get('thumbnail')
210
+ }
211
+ return super()._update(self.endpoint, data)
212
+
213
+
214
+ def delete(self) -> None:
215
+ """
216
+ Delete the scene.
217
+
218
+ Returns:
219
+ None
220
+
221
+ Example:
222
+ >>> from geobox import GeoboxClient
223
+ >>> from geobox.scene import Scene
224
+ >>> client = GeoboxClient()
225
+ >>> scene = Scene.get_scene(client, uuid="12345678-1234-5678-1234-567812345678")
226
+ >>> scene.delete()
227
+ """
228
+ super().delete(self.endpoint)
229
+
230
+
231
+ @property
232
+ def thumbnail(self) -> str:
233
+ """
234
+ Get the thumbnail URL of the scene.
235
+
236
+ Returns:
237
+ str: The thumbnail of the scene.
238
+
239
+ Example:
240
+ >>> from geobox import GeoboxClient
241
+ >>> from geobox.scene import Scene
242
+ >>> client = GeoboxClient()
243
+ >>> scene = Scene.get_scene(client, uuid="12345678-1234-5678-1234-567812345678")
244
+ >>> scene.thumbnail
245
+ 'https://example.com/thumbnail.png'
246
+ """
247
+ endpoint = urljoin(self.api.base_url, f'{self.endpoint}thumbnail.png')
248
+ return endpoint
249
+
250
+
251
+ def share(self, users: List['User']) -> None:
252
+ """
253
+ Shares the scene with specified users.
254
+
255
+ Args:
256
+ users (List[User]): The list of user objects to share the scene with.
257
+
258
+ Returns:
259
+ None
260
+
261
+ Example:
262
+ >>> from geobox import GeoboxClient
263
+ >>> from geobox.scene import Scene
264
+ >>> client = GeoboxClient()
265
+ >>> scene = Scene.get_scene(client, uuid="12345678-1234-5678-1234-567812345678")
266
+ >>> users = client.search_users(search='John')
267
+ >>> scene.share(users=users)
268
+ """
269
+ super()._share(self.endpoint, users)
270
+
271
+
272
+ def unshare(self, users: List['User']) -> None:
273
+ """
274
+ Unshares the scene with specified users.
275
+
276
+ Args:
277
+ users (List[User]): The list of user objects to unshare the scene with.
278
+
279
+ Returns:
280
+ None
281
+
282
+ Example:
283
+ >>> from geobox import GeoboxClient
284
+ >>> from geobox.scene import Scene
285
+ >>> client = GeoboxClient()
286
+ >>> scene = Scene.get_scene(client, uuid="12345678-1234-5678-1234-567812345678")
287
+ >>> users = client.search_users(search='John')
288
+ >>> scene.unshare(users=users)
289
+ """
290
+ super()._unshare(self.endpoint, users)
291
+
292
+
293
+ def get_shared_users(self, search: str = None, skip: int = 0, limit: int = 10) -> List['User']:
294
+ """
295
+ Retrieves the list of users the scene is shared with.
296
+
297
+ Args:
298
+ search (str, optional): The search query.
299
+ skip (int, optional): The number of users to skip.
300
+ limit (int, optional): The maximum number of users to retrieve.
301
+
302
+ Returns:
303
+ List[User]: The list of shared users.
304
+
305
+ Example:
306
+ >>> from geobox import GeoboxClient
307
+ >>> from geobox.scene import Scene
308
+ >>> client = GeoboxClient()
309
+ >>> scene = Scene.get_scene(client, uuid="12345678-1234-5678-1234-567812345678")
310
+ >>> scene.get_shared_users(search='John', skip=0, limit=10)
311
+ """
312
+ params = {
313
+ 'search': search,
314
+ 'skip': skip,
315
+ 'limit': limit
316
+ }
317
+ return super()._get_shared_users(self.endpoint, params)
pygeobox/settings.py ADDED
@@ -0,0 +1,166 @@
1
+ from typing import List, Dict, Optional, TYPE_CHECKING
2
+ from urllib.parse import urljoin, urlencode
3
+
4
+ from .base import Base
5
+ from .utils import clean_data
6
+ from .enums import MaxLogPolicy, InvalidDataPolicy, LoginFailurePolicy, MaxConcurrentSessionPolicy
7
+
8
+
9
+ if TYPE_CHECKING:
10
+ from . import GeoboxClient
11
+
12
+ class SystemSettings(Base):
13
+
14
+ BASE_ENDPOINT = 'settings/'
15
+
16
+ def __init__(self,
17
+ api: 'GeoboxClient',
18
+ data: Optional[Dict] = {}):
19
+ """
20
+ Initialize a System Settings instance.
21
+
22
+ Args:
23
+ api (GeoboxClient): The GeoboxClient instance for making requests.
24
+ data (Dict, optional): The data of the Setting.
25
+ """
26
+ super().__init__(api, data=data)
27
+
28
+
29
+ @property
30
+ def max_log_policy(self) -> 'MaxLogPolicy':
31
+ """
32
+ Get max log policy
33
+
34
+ Returns:
35
+ MaxLogPolicy: max log policy
36
+ """
37
+ return MaxLogPolicy(self.data.get('max_log_policy'))
38
+
39
+
40
+ @property
41
+ def invalid_data_policy(self) -> 'InvalidDataPolicy':
42
+ """
43
+ Get invalid data policy
44
+
45
+ Returns:
46
+ InvalidDataPolicy: invalid data policy
47
+ """
48
+ return InvalidDataPolicy(self.data.get('invalid_data_policy'))
49
+
50
+
51
+ @property
52
+ def login_failure_policy(self) -> 'LoginFailurePolicy':
53
+ """
54
+ Get login failure policy
55
+
56
+ Returns:
57
+ LoginFailurePolicy: login failure policy
58
+ """
59
+ return LoginFailurePolicy(self.data.get('login_failure_policy'))
60
+
61
+
62
+ @property
63
+ def max_concurrent_session_policy(self) -> 'MaxConcurrentSessionPolicy':
64
+ """
65
+ Get max concurrent sessions
66
+
67
+ Returns:
68
+ MaxConcurrentSessionPolicy: max concurrent sessions
69
+ """
70
+ return MaxConcurrentSessionPolicy(self.data.get('max_concurrent_session_policy'))
71
+
72
+
73
+ def __repr__(self) -> str:
74
+ """
75
+ Return a string representation of the system setting instance.
76
+
77
+ Returns:
78
+ str: A string representation of the system setting instance.
79
+ """
80
+ return "SystemSettings()"
81
+
82
+
83
+ @classmethod
84
+ def get_system_settings(cls, api: 'GeoboxClient') -> 'SystemSettings':
85
+ """
86
+ Get System Settings object (Permission Required).
87
+
88
+ Args:
89
+ api (GeoboxClient): The GeoboxClient instance for making requests.
90
+
91
+ Returns:
92
+ SystemSetting: the system settings object.
93
+
94
+ Example:
95
+ >>> from geobox import GeoboxClient
96
+ >>> from geobox.setting import SystemSettings
97
+ >>> client = GeoboxClient()
98
+ >>> setting = SystemSettings.get_system_settings(client)
99
+ or
100
+ >>> setting = client.get_system_settings()
101
+ """
102
+ params = clean_data({
103
+ 'f': 'json'
104
+ })
105
+ query_string = urlencode(params)
106
+ endpoint = urljoin(cls.BASE_ENDPOINT, f"?{query_string}")
107
+ response = api.get(endpoint)
108
+ return SystemSettings(api, response)
109
+
110
+
111
+ def update(self, **kwargs) -> Dict:
112
+ """
113
+ Update the system settings.
114
+
115
+ Keyword Args:
116
+ brand_name (str)
117
+ brand_website (str)
118
+ max_log (int)
119
+ max_log_policy (MaxLogPolicy)
120
+ users_can_view_their_own_logs (bool)
121
+ max_upload_file_size (int)
122
+ invalid_data_policy (InvalidDataPolicy)
123
+ max_login_attempts (int)
124
+ login_failure_policy (LoginFailurePolicy)
125
+ login_attempts_duration (int)
126
+ min_password_length (int)
127
+ max_concurrent_session (int)
128
+ max_concurrent_session_policy (MaxConcurrentSessionPolicy)
129
+ session_timeout (int)
130
+ allowed_ip_addresses (Dict)
131
+ blocked_ip_addresses (Dict)
132
+
133
+ Returns:
134
+ Dict: The updated system settings data.
135
+
136
+ Raises:
137
+ ValidationError: If the system settings data is invalid.
138
+
139
+ Example:
140
+ >>> from geobox import GeoboxClient
141
+ >>> from geobox.setting import SystemSettings
142
+ >>> client = GeoboxClient()
143
+ >>> settings = SystemSetting.get_system_settings(client)
144
+ or
145
+ >>> settings = client.get_system_settings()
146
+ >>> settings.update_system_settings(max_log=100000)
147
+ """
148
+ data = {
149
+ "brand_name": kwargs.get('brand_name'),
150
+ "brand_website": kwargs.get('brand_website'),
151
+ "max_log": kwargs.get('max_log'),
152
+ "max_log_policy": kwargs.get('max_log_policy').value if kwargs.get('max_log_policy') else None,
153
+ "max_upload_file_size": kwargs.get('max_upload_file_size'),
154
+ "invalid_data_policy": kwargs.get('invalid_data_policy').value if kwargs.get('invalid_data_policy') else None,
155
+ "max_login_attempts": kwargs.get('max_login_attempts'),
156
+ "login_failure_policy": kwargs.get('login_failure_policy').value if kwargs.get('login_failure_policy') else None,
157
+ "login_attempts_duration": kwargs.get('login_attempts_duration'),
158
+ "min_password_length": kwargs.get('min_password_length'),
159
+ "max_concurrent_session": kwargs.get('max_concurrent_session'),
160
+ "max_concurrent_session_policy": kwargs.get('max_concurrent_session_policy').value if kwargs.get('max_concurrent_session_policy') else None,
161
+ "session_timeout": kwargs.get('session_timeout'),
162
+ "allowed_ip_addresses": kwargs.get('allowed_ip_addresses'),
163
+ "blocked_ip_addresses": kwargs.get('blocked_ip_addresses'),
164
+
165
+ }
166
+ return super()._update(self.BASE_ENDPOINT, data)