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/dashboard.py ADDED
@@ -0,0 +1,316 @@
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 Dashboard(Base):
11
+
12
+ BASE_ENDPOINT = 'dashboards/'
13
+
14
+ def __init__(self,
15
+ api: 'GeoboxClient',
16
+ uuid: str,
17
+ data: Optional[Dict] = {}):
18
+ """
19
+ Initialize a Dashboard instance.
20
+
21
+ Args:
22
+ api (GeoboxClient): The GeoboxClient instance for making requests.
23
+ uuid (str): The unique identifier for the Dashboard.
24
+ data (Dict, optional): The data of the Dashboard.
25
+ """
26
+ super().__init__(api, uuid=uuid, data=data)
27
+
28
+
29
+ @classmethod
30
+ def get_dashboards(cls, api: 'GeoboxClient', **kwargs) -> Union[List['Dashboard'], int]:
31
+ """
32
+ Get list of Dashboards
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 Dashboards. default is False.
47
+
48
+ Returns:
49
+ List[Dashboard] | int: A list of Dashboard instances or the total number of Dashboards.
50
+
51
+ Example:
52
+ >>> from geobox import GeoboxClient
53
+ >>> from geobox.dashboard import Dashboard
54
+ >>> client = GeoboxClient()
55
+ >>> dashboards = Dashboard.get_dashboards(client)
56
+ or
57
+ >>> dashboards = client.get_dashboards()
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: Dashboard(api, item['uuid'], item))
72
+
73
+
74
+ @classmethod
75
+ def create_dashboard(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) -> 'Dashboard':
83
+ """
84
+ Create a new Dashboard.
85
+
86
+ Args:
87
+ api (GeoboxClient): The GeoboxClient instance for making requests.
88
+ name (str): The name of the Dashboard.
89
+ display_name (str, optional): The display name of the Dashboard.
90
+ description (str, optional): The description of the Dashboard.
91
+ settings (Dict, optional): The settings of the sceDashboarde.
92
+ thumbnail (str, optional): The thumbnail of the Dashboard.
93
+ user_id (int, optional): Specific user. privileges required.
94
+
95
+ Returns:
96
+ Dashboard: The newly created Dashboard instance.
97
+
98
+ Raises:
99
+ ValidationError: If the Dashboard data is invalid.
100
+
101
+ Example:
102
+ >>> from geobox import GeoboxClient
103
+ >>> from geobox.dashboard import Dashboard
104
+ >>> client = GeoboxClient()
105
+ >>> dashboard = Dashboard.create_dashboard(client, name="my_dashboard")
106
+ or
107
+ >>> dashboard = client.create_dashboard(name="my_dashboard")
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: Dashboard(api, item['uuid'], item))
118
+
119
+
120
+ @classmethod
121
+ def get_dashboard(cls, api: 'GeoboxClient', uuid: str, user_id: int = None) -> 'Dashboard':
122
+ """
123
+ Get a Dashboard by its UUID.
124
+
125
+ Args:
126
+ api (GeoboxClient): The GeoboxClient instance for making requests.
127
+ uuid (str): The UUID of the Dashboard to get.
128
+ user_id (int, optional): Specific user. privileges required.
129
+
130
+ Returns:
131
+ Dashboard: The dashboard object.
132
+
133
+ Raises:
134
+ NotFoundError: If the Dashboard with the specified UUID is not found.
135
+
136
+ Example:
137
+ >>> from geobox import GeoboxClient
138
+ >>> from geobox.dashboard import Dashboard
139
+ >>> client = GeoboxClient()
140
+ >>> dashboard = Dashboard.get_dashboard(client, uuid="12345678-1234-5678-1234-567812345678")
141
+ or
142
+ >>> dashboard = client.get_dashboard(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: Dashboard(api, item['uuid'], item))
149
+
150
+
151
+ @classmethod
152
+ def get_dashboard_by_name(cls, api: 'GeoboxClient', name: str, user_id: int = None) -> Union['Dashboard', None]:
153
+ """
154
+ Get a dashboard by name
155
+
156
+ Args:
157
+ api (GeoboxClient): The GeoboxClient instance for making requests.
158
+ name (str): the name of the dashboard to get
159
+ user_id (int, optional): specific user. privileges required.
160
+
161
+ Returns:
162
+ Dashboard | None: returns the dashboard if a dashboard matches the given name, else None
163
+
164
+ Example:
165
+ >>> from geobox import GeoboxClient
166
+ >>> from geobox.dashboard import Dashboard
167
+ >>> client = GeoboxClient()
168
+ >>> dashboard = Dashboard.get_dashboard_by_name(client, name='test')
169
+ or
170
+ >>> dashboard = client.get_dashboard_by_name(name='test')
171
+ """
172
+ dashboards = cls.get_dashboards(api, q=f"name = '{name}'", user_id=user_id)
173
+ if dashboards and dashboards[0].name == name:
174
+ return dashboards[0]
175
+ else:
176
+ return None
177
+
178
+
179
+ def update(self, **kwargs) -> Dict:
180
+ """
181
+ Update the Dashboard
182
+
183
+ Keyword Args:
184
+ name (str): The name of the Dashboard.
185
+ display_name (str): The display name of the Dashboard.
186
+ description (str): The description of the Dashboard.
187
+ settings (Dict): The settings of the Dashboard.
188
+ thumbnail (str): The thumbnail of the Dashboard.
189
+
190
+ Returns:
191
+ Dict: The updated Dashboard data.
192
+
193
+ Raises:
194
+ ValidationError: If the Dashboard data is invalid.
195
+
196
+ Example:
197
+ >>> from geobox import GeoboxClient
198
+ >>> from geobox.dashboard import Dashboard
199
+ >>> client = GeoboxClient()
200
+ >>> dashboard = Dashboard.get_dashboard(client, uuid="12345678-1234-5678-1234-567812345678")
201
+ >>> dashboard.update(display_name="New Display Name")
202
+ """
203
+ data = {
204
+ "name": kwargs.get('name'),
205
+ "display_name": kwargs.get('display_name'),
206
+ "description": kwargs.get('description'),
207
+ "settings": kwargs.get('settings'),
208
+ "thumbnail": kwargs.get('thumbnail')
209
+ }
210
+ return super()._update(self.endpoint, data)
211
+
212
+
213
+ def delete(self) -> None:
214
+ """
215
+ Delete the dashboard.
216
+
217
+ Returns:
218
+ None
219
+
220
+ Example:
221
+ >>> from geobox import GeoboxClient
222
+ >>> from geobox.dashboard import Dashboard
223
+ >>> client = GeoboxClient()
224
+ >>> dashboard = Dashboard.get_dashboard(client, uuid="12345678-1234-5678-1234-567812345678")
225
+ >>> dashboard.delete()
226
+ """
227
+ super().delete(self.endpoint)
228
+
229
+
230
+ @property
231
+ def thumbnail(self) -> str:
232
+ """
233
+ Get the thumbnail URL of the dashboard.
234
+
235
+ Returns:
236
+ str: The thumbnail of the dashboard.
237
+
238
+ Example:
239
+ >>> from geobox import GeoboxClient
240
+ >>> from geobox.dashboard import Dashboard
241
+ >>> client = GeoboxClient()
242
+ >>> dashboard = Dashboard.get_dashboard(client, uuid="12345678-1234-5678-1234-567812345678")
243
+ >>> dashboard.thumbnail
244
+ 'https://example.com/thumbnail.png'
245
+ """
246
+ endpoint = urljoin(self.api.base_url, f'{self.endpoint}thumbnail.png')
247
+ return endpoint
248
+
249
+
250
+ def share(self, users: List['User']) -> None:
251
+ """
252
+ Shares the Dashboard with specified users.
253
+
254
+ Args:
255
+ users (List[User]): The list of user objects to share the Dashboard with.
256
+
257
+ Returns:
258
+ None
259
+
260
+ Example:
261
+ >>> from geobox import GeoboxClient
262
+ >>> from geobox.dashboard import Dashboard
263
+ >>> client = GeoboxClient()
264
+ >>> dashboard = Dashboard.get_dashboard(client, uuid="12345678-1234-5678-1234-567812345678")
265
+ >>> users = client.search_users(search='John')
266
+ >>> dashboard.share(users=users)
267
+ """
268
+ super()._share(self.endpoint, users)
269
+
270
+
271
+ def unshare(self, users: List['User']) -> None:
272
+ """
273
+ Unshares the Dashboard with specified users.
274
+
275
+ Args:
276
+ users (List[User]): The list of user objects to unshare the Dashboard with.
277
+
278
+ Returns:
279
+ None
280
+
281
+ Example:
282
+ >>> from geobox import GeoboxClient
283
+ >>> from geobox.dashboard import Dashboard
284
+ >>> client = GeoboxClient()
285
+ >>> dashboard = Dashboard.get_dashboard(client, uuid="12345678-1234-5678-1234-567812345678")
286
+ >>> users = client.search_users(search='John')
287
+ >>> dashboard.unshare(users=users)
288
+ """
289
+ super()._unshare(self.endpoint, users)
290
+
291
+
292
+ def get_shared_users(self, search: str = None, skip: int = 0, limit: int = 10) -> List['User']:
293
+ """
294
+ Retrieves the list of users the dashboard is shared with.
295
+
296
+ Args:
297
+ search (str, optional): The search query.
298
+ skip (int, optional): The number of users to skip.
299
+ limit (int, optional): The maximum number of users to retrieve.
300
+
301
+ Returns:
302
+ List[User]: The list of shared users.
303
+
304
+ Example:
305
+ >>> from geobox import GeoboxClient
306
+ >>> from geobox.dashboard import Dashboard
307
+ >>> client = GeoboxClient()
308
+ >>> dashboard = Dashboard.get_dashboard(client, uuid="12345678-1234-5678-1234-567812345678")
309
+ >>> dashboard.get_shared_users(search='John', skip=0, limit=10)
310
+ """
311
+ params = {
312
+ 'search': search,
313
+ 'skip': skip,
314
+ 'limit': limit
315
+ }
316
+ return super()._get_shared_users(self.endpoint, params)
pygeobox/enums.py ADDED
@@ -0,0 +1,355 @@
1
+ from enum import Enum
2
+
3
+ # File Enums
4
+ class InputGeomType(Enum):
5
+ POINT = 'POINT'
6
+ LINE = 'LINE'
7
+ POLYGON = 'POLYGON'
8
+ MULTIPOINT = 'MULTIPOINT'
9
+ MULTILINE = 'MULTILINE'
10
+ MULTIPOLYGON = 'MULTIPOLYGON'
11
+ POINT_Z = 'POINTZ'
12
+ LINE_Z = 'LINEZ'
13
+ POLYGON_Z = 'POLYGONZ'
14
+ MULTIPOINT_Z = 'MULTIPOINTZ'
15
+ MULTILINE_Z = 'MULTILINEZ'
16
+ MULTIPOLYGON_Z = 'MULTIPOLYGONZ'
17
+
18
+ class PublishFileType(Enum):
19
+ VECTOR = 'vector'
20
+ RASTER = 'raster'
21
+ MODEL3D = 'model3d'
22
+
23
+ class FileType(Enum):
24
+ # Spatial Data Formats
25
+ Shapefile = '.shp'
26
+ FileGDB = '.gdb'
27
+ CSV = '.csv'
28
+ KML = '.kml'
29
+ DXF = '.dxf'
30
+ GPX = '.gpx'
31
+ GPKG = '.gpkg'
32
+ GeoJSON = '.geojson'
33
+ GeoTIFF = '.tif'
34
+
35
+ # Image Formats
36
+ JPG = '.jpg'
37
+ JPEG = '.jpeg'
38
+ SVG = '.svg'
39
+ PNG = '.png'
40
+ BMP = '.bmp'
41
+ TIF = '.tif'
42
+ GIF = '.gif'
43
+
44
+ # Video Formats
45
+ MP4 = '.mp4'
46
+ AVI = '.avi'
47
+ OGG = '.ogg'
48
+ WEBM = '.webm'
49
+ MPEG = '.mpeg'
50
+ WMV = '.wmv'
51
+
52
+ # Document Formats
53
+ TXT = '.txt'
54
+ DOC = '.doc'
55
+ DOCX = '.docx'
56
+ XLS = '.xls'
57
+ XLSX = '.xlsx'
58
+ PPT = '.ppt'
59
+ PPTX = '.pptx'
60
+ PDF = '.pdf'
61
+
62
+ # Compressed Formats
63
+ ZIP = '.zip'
64
+ SEVEN_Z = '.7z' # 7z
65
+ RAR = '.rar'
66
+ ISO = '.iso'
67
+ GZ = '.gz'
68
+ BZ2 = '.bz2'
69
+ TAR = '.tar'
70
+ CAB = '.cab'
71
+ IMG = '.img'
72
+
73
+
74
+ # Field Enums
75
+ class FieldType(Enum):
76
+ """
77
+ A class representing the data type of a field.
78
+ """
79
+ Integer = "Integer"
80
+ """
81
+ An integer field.
82
+ """
83
+ Float = "Float"
84
+ """
85
+ A float field.
86
+ """
87
+ String = "String"
88
+ """
89
+ A string field.
90
+ """
91
+ Long = "Long"
92
+ """
93
+ A Long field.
94
+ """
95
+ DATE = "Date"
96
+ """
97
+ A Date field.
98
+ """
99
+ TIME = "Time"
100
+ """
101
+ A Time Field.
102
+ """
103
+ DATETIME = "DateTime"
104
+ """
105
+ A DateTime Field.
106
+ """
107
+
108
+
109
+ # Layer Enums
110
+ class LayerType(Enum):
111
+ """
112
+ Enumeration of supported vector layer geometry types.
113
+
114
+ This enum defines the different types of geometric shapes that can be stored in a vector layer.
115
+ Each type represents a specific geometric structure supported by the Geobox API.
116
+ """
117
+ Point = "Point"
118
+ """A single point in 2D space"""
119
+
120
+ LineString = "LineString"
121
+ """A sequence of points forming a line"""
122
+
123
+ Polygon = "Polygon"
124
+ """A closed shape defined by a sequence of points"""
125
+
126
+ MultiPoint = "MultiPoint"
127
+ """A collection of points"""
128
+
129
+ MultiLineString = "MultiLineString"
130
+ """A collection of lines"""
131
+
132
+ MultiPolygon = "MultiPolygon"
133
+ """A collection of polygons"""
134
+
135
+ Polyline = "Polyline"
136
+ """A polyline geometry"""
137
+
138
+
139
+ # Layer Enums
140
+ class FeatureType(Enum):
141
+ """
142
+ Enumeration of supported feature geometry types.
143
+
144
+ This enum defines the different types of geometric shapes that can be stored in a feature.
145
+ Each type represents a specific geometric structure supported by the Geobox API.
146
+ """
147
+ Point = "Point"
148
+ """A single point in 2D space"""
149
+
150
+ LineString = "LineString"
151
+ """A sequence of points forming a line"""
152
+
153
+ Polygon = "Polygon"
154
+ """A closed shape defined by a sequence of points"""
155
+
156
+ MultiPoint = "MultiPoint"
157
+ """A collection of points"""
158
+
159
+ MultiLineString = "MultiLineString"
160
+ """A collection of lines"""
161
+
162
+ MultiPolygon = "MultiPolygon"
163
+ """A collection of polygons"""
164
+
165
+ Polyline = "Polyline"
166
+ """A polyline geometry"""
167
+
168
+
169
+ # Task Enums
170
+ class TaskStatus(Enum):
171
+ """
172
+ Enumeration of possible task statuses.
173
+ """
174
+ PENDING = "PENDING"
175
+ """
176
+ The task is pending.
177
+ """
178
+ PROGRESS = "PROGRESS"
179
+ """
180
+ The task is in progress.
181
+ """
182
+ SUCCESS = "SUCCESS"
183
+ """
184
+ The task is successful.
185
+ """
186
+ FAILURE = "FAILURE"
187
+ """
188
+ The task is failed.
189
+ """
190
+ ABORTED = "ABORTED"
191
+ """
192
+ The task is aborted.
193
+ """
194
+
195
+ class QueryGeometryType(Enum):
196
+ """
197
+ Enumeration of possible query geometry types.
198
+ """
199
+ POINT = "Point"
200
+ """
201
+ A point geometry.
202
+ """
203
+ MULTIPOINT = "Multipoint"
204
+ """
205
+ A multipoint geometry.
206
+ """
207
+ POLYLINE = "Polyline"
208
+ """
209
+ A polyline geometry.
210
+ """
211
+ POLYGON = "Polygon"
212
+ """
213
+ A polygon geometry.
214
+ """
215
+
216
+ class QueryParamType(Enum):
217
+ """
218
+ Enumeration of possible query parameter types.
219
+ """
220
+ LAYER = "Layer"
221
+ """
222
+ A layer parameter.
223
+ """
224
+ ATTRIBUTE = "Attribute"
225
+ """
226
+ A Attribute parameter.
227
+ """
228
+ FLOAT = "Float"
229
+ """
230
+ A Float parameter.
231
+ """
232
+ INTEGER = "Integer"
233
+ """
234
+ A Integer parameter.
235
+ """
236
+ TEXT = "Text"
237
+ """
238
+ A Text parameter.
239
+ """
240
+ BOOLEAN = "Boolean"
241
+ """
242
+ A Boolean parameter.
243
+ """
244
+
245
+
246
+ class UserRole(Enum):
247
+ SYSTEM_ADMIN = "System Admin"
248
+
249
+ ACCOUNT_ADMIN = "Account Admin"
250
+
251
+ PUBLISHER = "Publisher"
252
+
253
+ EDITOR = "Editor"
254
+
255
+ VIEWR = "Viewer"
256
+
257
+
258
+ class UserStatus(Enum):
259
+ NEW = "New"
260
+
261
+ PENDING = "Pending"
262
+
263
+ ACTIVE = "Active"
264
+
265
+ DISABLED = "Disabled"
266
+
267
+
268
+ class AttachmentResourceType(Enum):
269
+ Map = "map"
270
+
271
+ Vector = "vector"
272
+
273
+ View = "view"
274
+
275
+
276
+ class MaxLogPolicy(Enum):
277
+ OverwriteFirstLog = "OverwriteFirstLog"
278
+
279
+ IgnoreLogging = "IgnoreLogging"
280
+
281
+
282
+ class InvalidDataPolicy(Enum):
283
+ ReportToAdmin = "ReportToAdmin"
284
+
285
+ LogOnly = "LogOnly"
286
+
287
+
288
+ class LoginFailurePolicy(Enum):
289
+ BlockIPTemporarily = "BlockIPTemporarily"
290
+
291
+ DisableAccount = "DisableAccount"
292
+
293
+
294
+ class MaxConcurrentSessionPolicy(Enum):
295
+ CloseLastSession = "CloseLastSession"
296
+
297
+ CloseMostInactiveSession = "CloseMostInactiveSession"
298
+
299
+ PreventNewSession = "PreventNewSession"
300
+
301
+
302
+ class RoutingGeometryType(Enum):
303
+ geojson = "geojson"
304
+
305
+ polyline = "polyline"
306
+
307
+ polyline6= "polyline6"
308
+
309
+
310
+ class RoutingOverviewLevel(Enum):
311
+ Full = 'full'
312
+
313
+ Simplified = 'simplified'
314
+
315
+
316
+ class QueryResultType(Enum):
317
+ metadata = "metadata"
318
+
319
+ data = "data"
320
+
321
+ both = "both"
322
+
323
+
324
+ class TilesetLayerType(Enum):
325
+ Vector = "vector"
326
+
327
+ View = "view"
328
+
329
+
330
+ class FileOutputFormat(Enum):
331
+ Shapefile = "Shapefile"
332
+
333
+ GPKG = "GPKG"
334
+
335
+ GeoJSON = "GeoJSON"
336
+
337
+ CSV = "CSV"
338
+
339
+ KML = "KML"
340
+
341
+ DXF = "DXF"
342
+
343
+
344
+ class UsageScale(Enum):
345
+ Hour = 'hour'
346
+
347
+ Day = 'day'
348
+
349
+ Month = 'month'
350
+
351
+
352
+ class UsageParam(Enum):
353
+ Traffict = 'traffic'
354
+
355
+ Calls = 'calls'