pygeobox 1.0.1__py3-none-any.whl → 1.0.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.
- pygeobox/__init__.py +63 -63
- pygeobox/api.py +2517 -2517
- pygeobox/apikey.py +232 -232
- pygeobox/attachment.py +297 -297
- pygeobox/base.py +364 -364
- pygeobox/basemap.py +162 -162
- pygeobox/dashboard.py +316 -316
- pygeobox/enums.py +354 -354
- pygeobox/exception.py +47 -47
- pygeobox/field.py +309 -309
- pygeobox/map.py +858 -858
- pygeobox/model3d.py +334 -334
- pygeobox/mosaic.py +647 -647
- pygeobox/plan.py +260 -260
- pygeobox/query.py +668 -668
- pygeobox/raster.py +756 -756
- pygeobox/route.py +63 -63
- pygeobox/scene.py +317 -317
- pygeobox/settings.py +165 -165
- pygeobox/task.py +354 -354
- pygeobox/tile3d.py +294 -294
- pygeobox/tileset.py +585 -585
- pygeobox/user.py +423 -423
- pygeobox/utils.py +43 -43
- pygeobox/vectorlayer.py +1149 -1149
- pygeobox/version.py +248 -248
- pygeobox/view.py +859 -859
- pygeobox/workflow.py +315 -315
- {pygeobox-1.0.1.dist-info → pygeobox-1.0.3.dist-info}/METADATA +18 -33
- pygeobox-1.0.3.dist-info/RECORD +37 -0
- {pygeobox-1.0.1.dist-info → pygeobox-1.0.3.dist-info}/licenses/LICENSE +21 -21
- pygeobox-1.0.1.dist-info/RECORD +0 -37
- {pygeobox-1.0.1.dist-info → pygeobox-1.0.3.dist-info}/WHEEL +0 -0
- {pygeobox-1.0.1.dist-info → pygeobox-1.0.3.dist-info}/top_level.txt +0 -0
pygeobox/attachment.py
CHANGED
@@ -1,298 +1,298 @@
|
|
1
|
-
from typing import List, Dict, Optional, TYPE_CHECKING, Union
|
2
|
-
from urllib.parse import urljoin
|
3
|
-
|
4
|
-
from .base import Base
|
5
|
-
from .utils import clean_data
|
6
|
-
from .enums import AttachmentResourceType
|
7
|
-
from .map import Map
|
8
|
-
from .vectorlayer import VectorLayer
|
9
|
-
from .view import VectorLayerView
|
10
|
-
from .file import File
|
11
|
-
|
12
|
-
if TYPE_CHECKING:
|
13
|
-
from . import GeoboxClient
|
14
|
-
from .feature import Feature
|
15
|
-
|
16
|
-
class Attachment(Base):
|
17
|
-
|
18
|
-
BASE_ENDPOINT = 'attachments/'
|
19
|
-
|
20
|
-
def __init__(self,
|
21
|
-
api: 'GeoboxClient',
|
22
|
-
attachment_id: str,
|
23
|
-
data: Optional[Dict] = {}):
|
24
|
-
"""
|
25
|
-
Initialize an Attachment instance.
|
26
|
-
|
27
|
-
Args:
|
28
|
-
api (GeoboxClient): The GeoboxClient instance for making requests.
|
29
|
-
attachment_id (str): The id for the attachment.
|
30
|
-
data (Dict, optional): The data of the attachment.
|
31
|
-
"""
|
32
|
-
super().__init__(api, data=data)
|
33
|
-
self.attachment_id = attachment_id
|
34
|
-
self.endpoint = urljoin(self.BASE_ENDPOINT, str(self.attachment_id))
|
35
|
-
|
36
|
-
|
37
|
-
def __repr__(self) -> str:
|
38
|
-
"""
|
39
|
-
Return a string representation of the attachment.
|
40
|
-
|
41
|
-
Returns:
|
42
|
-
str: The string representation of the attachment.
|
43
|
-
"""
|
44
|
-
return f"Attachment(name={self.name}, id={self.attachment_id})"
|
45
|
-
|
46
|
-
|
47
|
-
@property
|
48
|
-
def file(self) -> 'File':
|
49
|
-
"""
|
50
|
-
Attachment file property
|
51
|
-
|
52
|
-
Returns:
|
53
|
-
File: the file object
|
54
|
-
"""
|
55
|
-
return File(self.api, self.data['file'].get('uuid'), self.data['file'])
|
56
|
-
|
57
|
-
|
58
|
-
@classmethod
|
59
|
-
def get_attachments(cls, api: 'GeoboxClient', resource_type: AttachmentResourceType, resource_uuid: str, **kwargs) -> Union[List['Attachment'], int]:
|
60
|
-
"""
|
61
|
-
Get list of attachments with optional filtering and pagination.
|
62
|
-
|
63
|
-
Args:
|
64
|
-
api (GeoboxClient): The GeoboxClient instance for making requests.
|
65
|
-
resource_type (AttachmentResourceType): The resource type of the attachment. options are: Map, Vector, View
|
66
|
-
resource_uuid (str): The Resoource uuid of the attachment.
|
67
|
-
|
68
|
-
Keyword Args:
|
69
|
-
element_id (str): the id of the element with attachment.
|
70
|
-
search (str): search term for keyword-based searching among all textual fields.
|
71
|
-
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.
|
72
|
-
skip (int): Number of items to skip. default is 0.
|
73
|
-
limit (int): Number of items to return. default is 10.
|
74
|
-
return_count (bool): Whether to return total count. default is False.
|
75
|
-
|
76
|
-
Returns:
|
77
|
-
List[Attachment] | int: A list of attachments instances or the total number of attachments.
|
78
|
-
|
79
|
-
Example:
|
80
|
-
>>> from geobox import GeoboxClient
|
81
|
-
>>> from geobox.attachment import Attachment
|
82
|
-
>>> client = GeoboxClient()
|
83
|
-
>>> attachments = Attachment.get_attachments(client, q="name LIKE '%My attachment%'")
|
84
|
-
or
|
85
|
-
>>> attachments = client.get_attachments(q="name LIKE '%My attachment%'")
|
86
|
-
"""
|
87
|
-
params = {
|
88
|
-
'resource_type': resource_type.value,
|
89
|
-
'resource_uuid': resource_uuid,
|
90
|
-
'element_id': kwargs.get('element_id'),
|
91
|
-
'search': kwargs.get('search'),
|
92
|
-
'order_by': kwargs.get('order_by'),
|
93
|
-
'skip': kwargs.get('skip', 0),
|
94
|
-
'limit': kwargs.get('limit', 10),
|
95
|
-
'return_count': kwargs.get('return_count')
|
96
|
-
}
|
97
|
-
return super()._get_list(api, cls.BASE_ENDPOINT, params, factory_func=lambda api, item: Attachment(api, item['id'], item))
|
98
|
-
|
99
|
-
|
100
|
-
@classmethod
|
101
|
-
def create_attachment(cls,
|
102
|
-
api: 'GeoboxClient',
|
103
|
-
name: str,
|
104
|
-
loc_x: int,
|
105
|
-
loc_y: int,
|
106
|
-
resource: Union['Map', 'VectorLayer', 'VectorLayerView'],
|
107
|
-
file: 'File',
|
108
|
-
feature: 'Feature' = None,
|
109
|
-
display_name: str = None,
|
110
|
-
description: str = None, ) -> 'Attachment':
|
111
|
-
"""
|
112
|
-
Create a new Attachment.
|
113
|
-
|
114
|
-
Args:
|
115
|
-
api (GeoboxClient): The GeoboxClient instance for making requests.
|
116
|
-
name (str): The name of the scene.
|
117
|
-
loc_x (int): x parameter of the attachment location.
|
118
|
-
loc_y (int): y parameter of the attachment location.
|
119
|
-
resource (Map | VectorLayer | VectorLayerView): the resource object.
|
120
|
-
file (File): the file object.
|
121
|
-
feature (Feature, optional): the feature object.
|
122
|
-
display_name (str, optional): The display name of the scene.
|
123
|
-
description (str, optional): The description of the scene.
|
124
|
-
|
125
|
-
Returns:
|
126
|
-
Attachment: The newly created Attachment instance.
|
127
|
-
|
128
|
-
Raises:
|
129
|
-
ValidationError: If the Attachment data is invalid.
|
130
|
-
|
131
|
-
Example:
|
132
|
-
>>> from geobox import GeoboxClient
|
133
|
-
>>> from geobox.attachment import Attachment
|
134
|
-
>>> client = GeoboxClient()
|
135
|
-
>>> layer = client.get_vector(uuid="12345678-1234-5678-1234-567812345678")
|
136
|
-
>>> feature = layer.get_feature(feature_id=1)
|
137
|
-
>>> file = client.get_file(uuid="12345678-1234-5678-1234-567812345678")
|
138
|
-
>>> attachment = Attachment.create_attachment(client,
|
139
|
-
... name="my_attachment",
|
140
|
-
... loc_x=30,
|
141
|
-
... loc_y=50,
|
142
|
-
... resource=layer,
|
143
|
-
... file=file,
|
144
|
-
... feature=feature,
|
145
|
-
... display_name="My Attachment",
|
146
|
-
... description="Attachment Description")
|
147
|
-
or
|
148
|
-
>>> attachment = client.create_attachment(name="my_attachment",
|
149
|
-
... loc_x=30,
|
150
|
-
... loc_y=50,
|
151
|
-
... resource=layer,
|
152
|
-
... file=file,
|
153
|
-
... feature=feature,
|
154
|
-
... display_name="My Attachment",
|
155
|
-
... description="Attachment Description")
|
156
|
-
"""
|
157
|
-
if isinstance(resource, VectorLayer):
|
158
|
-
resource_type = AttachmentResourceType.Vector.value
|
159
|
-
|
160
|
-
if isinstance(resource, VectorLayerView):
|
161
|
-
resource_type = AttachmentResourceType.View.value
|
162
|
-
|
163
|
-
if isinstance(resource, Map):
|
164
|
-
resource_type = AttachmentResourceType.Map.value
|
165
|
-
|
166
|
-
data = {
|
167
|
-
"name": name,
|
168
|
-
"display_name": display_name,
|
169
|
-
"description": description,
|
170
|
-
"loc_x": loc_x,
|
171
|
-
"loc_y": loc_y,
|
172
|
-
"resource_type": resource_type,
|
173
|
-
"resource_uuid": resource.uuid,
|
174
|
-
"element_id": feature.id,
|
175
|
-
"file_id": file.id
|
176
|
-
}
|
177
|
-
return super()._create(api, cls.BASE_ENDPOINT, data, factory_func=lambda api, item: Attachment(api, item['id'], item))
|
178
|
-
|
179
|
-
|
180
|
-
@classmethod
|
181
|
-
def update_attachment(cls, api: 'GeoboxClient', attachment_id: int, **kwargs) -> Dict:
|
182
|
-
"""
|
183
|
-
Update the attachment.
|
184
|
-
|
185
|
-
Args:
|
186
|
-
api (GeoboxClient): The GeoboxClient instance for making requests.
|
187
|
-
attachment_id (int): the attachment id.
|
188
|
-
|
189
|
-
Keyword Args:
|
190
|
-
name (str): The name of the attachment.
|
191
|
-
display_name (str): The display name of the attachment.
|
192
|
-
description (str): The description of the attachment.
|
193
|
-
loc_x (int): x parameter of the attachment location.
|
194
|
-
loc_y (int): y parameter of the attachment location.
|
195
|
-
|
196
|
-
Returns:
|
197
|
-
Dict: The updated attachment data.
|
198
|
-
|
199
|
-
Raises:
|
200
|
-
ValidationError: If the attachment data is invalid.
|
201
|
-
|
202
|
-
Example:
|
203
|
-
>>> from geobox import GeoboxClient
|
204
|
-
>>> from geobox.attachment import Attachment
|
205
|
-
>>> client = GeoboxClient()
|
206
|
-
>>> Attachment.update_attachment(client, attachment_id=1, display_name="New Display Name")
|
207
|
-
or
|
208
|
-
>>> client.update_attachment(attachment_id=1, display_name="New Display Name")
|
209
|
-
"""
|
210
|
-
data = clean_data({
|
211
|
-
"name": kwargs.get('name'),
|
212
|
-
"display_name": kwargs.get('display_name'),
|
213
|
-
"description": kwargs.get('description'),
|
214
|
-
"loc_x": kwargs.get('loc_x'),
|
215
|
-
"loc_y": kwargs.get('loc_y')
|
216
|
-
})
|
217
|
-
endpoint = urljoin(cls.BASE_ENDPOINT, str(attachment_id))
|
218
|
-
response = api.put(endpoint, data)
|
219
|
-
return response
|
220
|
-
|
221
|
-
|
222
|
-
def update(self, **kwargs) -> Dict:
|
223
|
-
"""
|
224
|
-
Update the attachment.
|
225
|
-
|
226
|
-
Keyword Args:
|
227
|
-
name (str): The name of the attachment.
|
228
|
-
display_name (str): The display name of the attachment.
|
229
|
-
description (str): The description of the attachment.
|
230
|
-
loc_x (int): x parameter of the attachment location.
|
231
|
-
loc_y (int): y parameter of the attachment location.
|
232
|
-
|
233
|
-
Returns:
|
234
|
-
Dict: The updated attachment data.
|
235
|
-
|
236
|
-
Raises:
|
237
|
-
ValidationError: If the attachment data is invalid.
|
238
|
-
|
239
|
-
Example:
|
240
|
-
>>> from geobox import GeoboxClient
|
241
|
-
>>> from geobox.attachment import Attachment
|
242
|
-
>>> client = GeoboxClient()
|
243
|
-
>>> attachment = Attachment.get_attachments(client)[0]
|
244
|
-
>>> attachment.update(display_name="New Display Name")
|
245
|
-
"""
|
246
|
-
data = clean_data({
|
247
|
-
"name": kwargs.get('name'),
|
248
|
-
"display_name": kwargs.get('display_name'),
|
249
|
-
"description": kwargs.get('description'),
|
250
|
-
"loc_x": kwargs.get('loc_x'),
|
251
|
-
"loc_y": kwargs.get('loc_y')
|
252
|
-
})
|
253
|
-
response = self.api.put(self.endpoint, data)
|
254
|
-
self._update_properties(response)
|
255
|
-
return response
|
256
|
-
|
257
|
-
|
258
|
-
def delete(self) -> None:
|
259
|
-
"""
|
260
|
-
Delete the scene.
|
261
|
-
|
262
|
-
Returns:
|
263
|
-
None
|
264
|
-
|
265
|
-
Raises:
|
266
|
-
ApiRequestError: If the API request fails.
|
267
|
-
ValidationError: If the scene data is invalid.
|
268
|
-
|
269
|
-
Example:
|
270
|
-
>>> from geobox import GeoboxClient
|
271
|
-
>>> from geobox.attachment import Attachment
|
272
|
-
>>> client = GeoboxClient()
|
273
|
-
>>> attachment = Attachment.get_attachments(client)[0]
|
274
|
-
>>> attachment.delete()
|
275
|
-
"""
|
276
|
-
super().delete(self.endpoint)
|
277
|
-
self.attachment_id = None
|
278
|
-
|
279
|
-
|
280
|
-
@property
|
281
|
-
def thumbnail(self) -> str:
|
282
|
-
"""
|
283
|
-
Get the thumbnail URL of the attachment.
|
284
|
-
|
285
|
-
Returns:
|
286
|
-
str: The thumbnail of the scene.
|
287
|
-
|
288
|
-
Example:
|
289
|
-
>>> from geobox import GeoboxClient
|
290
|
-
>>> from geobox.attachment import Attachment
|
291
|
-
>>> client = GeoboxClient()
|
292
|
-
>>> attachment = Attachment.get_attachment(client, uuid="12345678-1234-5678-1234-567812345678")
|
293
|
-
>>> attachment.thumbnail
|
294
|
-
'https://example.com/thumbnail.png'
|
295
|
-
"""
|
296
|
-
endpoint = f"{self.api.base_url}{self.endpoint}thumbnail"
|
297
|
-
return endpoint
|
1
|
+
from typing import List, Dict, Optional, TYPE_CHECKING, Union
|
2
|
+
from urllib.parse import urljoin
|
3
|
+
|
4
|
+
from .base import Base
|
5
|
+
from .utils import clean_data
|
6
|
+
from .enums import AttachmentResourceType
|
7
|
+
from .map import Map
|
8
|
+
from .vectorlayer import VectorLayer
|
9
|
+
from .view import VectorLayerView
|
10
|
+
from .file import File
|
11
|
+
|
12
|
+
if TYPE_CHECKING:
|
13
|
+
from . import GeoboxClient
|
14
|
+
from .feature import Feature
|
15
|
+
|
16
|
+
class Attachment(Base):
|
17
|
+
|
18
|
+
BASE_ENDPOINT = 'attachments/'
|
19
|
+
|
20
|
+
def __init__(self,
|
21
|
+
api: 'GeoboxClient',
|
22
|
+
attachment_id: str,
|
23
|
+
data: Optional[Dict] = {}):
|
24
|
+
"""
|
25
|
+
Initialize an Attachment instance.
|
26
|
+
|
27
|
+
Args:
|
28
|
+
api (GeoboxClient): The GeoboxClient instance for making requests.
|
29
|
+
attachment_id (str): The id for the attachment.
|
30
|
+
data (Dict, optional): The data of the attachment.
|
31
|
+
"""
|
32
|
+
super().__init__(api, data=data)
|
33
|
+
self.attachment_id = attachment_id
|
34
|
+
self.endpoint = urljoin(self.BASE_ENDPOINT, str(self.attachment_id))
|
35
|
+
|
36
|
+
|
37
|
+
def __repr__(self) -> str:
|
38
|
+
"""
|
39
|
+
Return a string representation of the attachment.
|
40
|
+
|
41
|
+
Returns:
|
42
|
+
str: The string representation of the attachment.
|
43
|
+
"""
|
44
|
+
return f"Attachment(name={self.name}, id={self.attachment_id})"
|
45
|
+
|
46
|
+
|
47
|
+
@property
|
48
|
+
def file(self) -> 'File':
|
49
|
+
"""
|
50
|
+
Attachment file property
|
51
|
+
|
52
|
+
Returns:
|
53
|
+
File: the file object
|
54
|
+
"""
|
55
|
+
return File(self.api, self.data['file'].get('uuid'), self.data['file'])
|
56
|
+
|
57
|
+
|
58
|
+
@classmethod
|
59
|
+
def get_attachments(cls, api: 'GeoboxClient', resource_type: AttachmentResourceType, resource_uuid: str, **kwargs) -> Union[List['Attachment'], int]:
|
60
|
+
"""
|
61
|
+
Get list of attachments with optional filtering and pagination.
|
62
|
+
|
63
|
+
Args:
|
64
|
+
api (GeoboxClient): The GeoboxClient instance for making requests.
|
65
|
+
resource_type (AttachmentResourceType): The resource type of the attachment. options are: Map, Vector, View
|
66
|
+
resource_uuid (str): The Resoource uuid of the attachment.
|
67
|
+
|
68
|
+
Keyword Args:
|
69
|
+
element_id (str): the id of the element with attachment.
|
70
|
+
search (str): search term for keyword-based searching among all textual fields.
|
71
|
+
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.
|
72
|
+
skip (int): Number of items to skip. default is 0.
|
73
|
+
limit (int): Number of items to return. default is 10.
|
74
|
+
return_count (bool): Whether to return total count. default is False.
|
75
|
+
|
76
|
+
Returns:
|
77
|
+
List[Attachment] | int: A list of attachments instances or the total number of attachments.
|
78
|
+
|
79
|
+
Example:
|
80
|
+
>>> from geobox import GeoboxClient
|
81
|
+
>>> from geobox.attachment import Attachment
|
82
|
+
>>> client = GeoboxClient()
|
83
|
+
>>> attachments = Attachment.get_attachments(client, q="name LIKE '%My attachment%'")
|
84
|
+
or
|
85
|
+
>>> attachments = client.get_attachments(q="name LIKE '%My attachment%'")
|
86
|
+
"""
|
87
|
+
params = {
|
88
|
+
'resource_type': resource_type.value,
|
89
|
+
'resource_uuid': resource_uuid,
|
90
|
+
'element_id': kwargs.get('element_id'),
|
91
|
+
'search': kwargs.get('search'),
|
92
|
+
'order_by': kwargs.get('order_by'),
|
93
|
+
'skip': kwargs.get('skip', 0),
|
94
|
+
'limit': kwargs.get('limit', 10),
|
95
|
+
'return_count': kwargs.get('return_count')
|
96
|
+
}
|
97
|
+
return super()._get_list(api, cls.BASE_ENDPOINT, params, factory_func=lambda api, item: Attachment(api, item['id'], item))
|
98
|
+
|
99
|
+
|
100
|
+
@classmethod
|
101
|
+
def create_attachment(cls,
|
102
|
+
api: 'GeoboxClient',
|
103
|
+
name: str,
|
104
|
+
loc_x: int,
|
105
|
+
loc_y: int,
|
106
|
+
resource: Union['Map', 'VectorLayer', 'VectorLayerView'],
|
107
|
+
file: 'File',
|
108
|
+
feature: 'Feature' = None,
|
109
|
+
display_name: str = None,
|
110
|
+
description: str = None, ) -> 'Attachment':
|
111
|
+
"""
|
112
|
+
Create a new Attachment.
|
113
|
+
|
114
|
+
Args:
|
115
|
+
api (GeoboxClient): The GeoboxClient instance for making requests.
|
116
|
+
name (str): The name of the scene.
|
117
|
+
loc_x (int): x parameter of the attachment location.
|
118
|
+
loc_y (int): y parameter of the attachment location.
|
119
|
+
resource (Map | VectorLayer | VectorLayerView): the resource object.
|
120
|
+
file (File): the file object.
|
121
|
+
feature (Feature, optional): the feature object.
|
122
|
+
display_name (str, optional): The display name of the scene.
|
123
|
+
description (str, optional): The description of the scene.
|
124
|
+
|
125
|
+
Returns:
|
126
|
+
Attachment: The newly created Attachment instance.
|
127
|
+
|
128
|
+
Raises:
|
129
|
+
ValidationError: If the Attachment data is invalid.
|
130
|
+
|
131
|
+
Example:
|
132
|
+
>>> from geobox import GeoboxClient
|
133
|
+
>>> from geobox.attachment import Attachment
|
134
|
+
>>> client = GeoboxClient()
|
135
|
+
>>> layer = client.get_vector(uuid="12345678-1234-5678-1234-567812345678")
|
136
|
+
>>> feature = layer.get_feature(feature_id=1)
|
137
|
+
>>> file = client.get_file(uuid="12345678-1234-5678-1234-567812345678")
|
138
|
+
>>> attachment = Attachment.create_attachment(client,
|
139
|
+
... name="my_attachment",
|
140
|
+
... loc_x=30,
|
141
|
+
... loc_y=50,
|
142
|
+
... resource=layer,
|
143
|
+
... file=file,
|
144
|
+
... feature=feature,
|
145
|
+
... display_name="My Attachment",
|
146
|
+
... description="Attachment Description")
|
147
|
+
or
|
148
|
+
>>> attachment = client.create_attachment(name="my_attachment",
|
149
|
+
... loc_x=30,
|
150
|
+
... loc_y=50,
|
151
|
+
... resource=layer,
|
152
|
+
... file=file,
|
153
|
+
... feature=feature,
|
154
|
+
... display_name="My Attachment",
|
155
|
+
... description="Attachment Description")
|
156
|
+
"""
|
157
|
+
if isinstance(resource, VectorLayer):
|
158
|
+
resource_type = AttachmentResourceType.Vector.value
|
159
|
+
|
160
|
+
if isinstance(resource, VectorLayerView):
|
161
|
+
resource_type = AttachmentResourceType.View.value
|
162
|
+
|
163
|
+
if isinstance(resource, Map):
|
164
|
+
resource_type = AttachmentResourceType.Map.value
|
165
|
+
|
166
|
+
data = {
|
167
|
+
"name": name,
|
168
|
+
"display_name": display_name,
|
169
|
+
"description": description,
|
170
|
+
"loc_x": loc_x,
|
171
|
+
"loc_y": loc_y,
|
172
|
+
"resource_type": resource_type,
|
173
|
+
"resource_uuid": resource.uuid,
|
174
|
+
"element_id": feature.id,
|
175
|
+
"file_id": file.id
|
176
|
+
}
|
177
|
+
return super()._create(api, cls.BASE_ENDPOINT, data, factory_func=lambda api, item: Attachment(api, item['id'], item))
|
178
|
+
|
179
|
+
|
180
|
+
@classmethod
|
181
|
+
def update_attachment(cls, api: 'GeoboxClient', attachment_id: int, **kwargs) -> Dict:
|
182
|
+
"""
|
183
|
+
Update the attachment.
|
184
|
+
|
185
|
+
Args:
|
186
|
+
api (GeoboxClient): The GeoboxClient instance for making requests.
|
187
|
+
attachment_id (int): the attachment id.
|
188
|
+
|
189
|
+
Keyword Args:
|
190
|
+
name (str): The name of the attachment.
|
191
|
+
display_name (str): The display name of the attachment.
|
192
|
+
description (str): The description of the attachment.
|
193
|
+
loc_x (int): x parameter of the attachment location.
|
194
|
+
loc_y (int): y parameter of the attachment location.
|
195
|
+
|
196
|
+
Returns:
|
197
|
+
Dict: The updated attachment data.
|
198
|
+
|
199
|
+
Raises:
|
200
|
+
ValidationError: If the attachment data is invalid.
|
201
|
+
|
202
|
+
Example:
|
203
|
+
>>> from geobox import GeoboxClient
|
204
|
+
>>> from geobox.attachment import Attachment
|
205
|
+
>>> client = GeoboxClient()
|
206
|
+
>>> Attachment.update_attachment(client, attachment_id=1, display_name="New Display Name")
|
207
|
+
or
|
208
|
+
>>> client.update_attachment(attachment_id=1, display_name="New Display Name")
|
209
|
+
"""
|
210
|
+
data = clean_data({
|
211
|
+
"name": kwargs.get('name'),
|
212
|
+
"display_name": kwargs.get('display_name'),
|
213
|
+
"description": kwargs.get('description'),
|
214
|
+
"loc_x": kwargs.get('loc_x'),
|
215
|
+
"loc_y": kwargs.get('loc_y')
|
216
|
+
})
|
217
|
+
endpoint = urljoin(cls.BASE_ENDPOINT, str(attachment_id))
|
218
|
+
response = api.put(endpoint, data)
|
219
|
+
return response
|
220
|
+
|
221
|
+
|
222
|
+
def update(self, **kwargs) -> Dict:
|
223
|
+
"""
|
224
|
+
Update the attachment.
|
225
|
+
|
226
|
+
Keyword Args:
|
227
|
+
name (str): The name of the attachment.
|
228
|
+
display_name (str): The display name of the attachment.
|
229
|
+
description (str): The description of the attachment.
|
230
|
+
loc_x (int): x parameter of the attachment location.
|
231
|
+
loc_y (int): y parameter of the attachment location.
|
232
|
+
|
233
|
+
Returns:
|
234
|
+
Dict: The updated attachment data.
|
235
|
+
|
236
|
+
Raises:
|
237
|
+
ValidationError: If the attachment data is invalid.
|
238
|
+
|
239
|
+
Example:
|
240
|
+
>>> from geobox import GeoboxClient
|
241
|
+
>>> from geobox.attachment import Attachment
|
242
|
+
>>> client = GeoboxClient()
|
243
|
+
>>> attachment = Attachment.get_attachments(client)[0]
|
244
|
+
>>> attachment.update(display_name="New Display Name")
|
245
|
+
"""
|
246
|
+
data = clean_data({
|
247
|
+
"name": kwargs.get('name'),
|
248
|
+
"display_name": kwargs.get('display_name'),
|
249
|
+
"description": kwargs.get('description'),
|
250
|
+
"loc_x": kwargs.get('loc_x'),
|
251
|
+
"loc_y": kwargs.get('loc_y')
|
252
|
+
})
|
253
|
+
response = self.api.put(self.endpoint, data)
|
254
|
+
self._update_properties(response)
|
255
|
+
return response
|
256
|
+
|
257
|
+
|
258
|
+
def delete(self) -> None:
|
259
|
+
"""
|
260
|
+
Delete the scene.
|
261
|
+
|
262
|
+
Returns:
|
263
|
+
None
|
264
|
+
|
265
|
+
Raises:
|
266
|
+
ApiRequestError: If the API request fails.
|
267
|
+
ValidationError: If the scene data is invalid.
|
268
|
+
|
269
|
+
Example:
|
270
|
+
>>> from geobox import GeoboxClient
|
271
|
+
>>> from geobox.attachment import Attachment
|
272
|
+
>>> client = GeoboxClient()
|
273
|
+
>>> attachment = Attachment.get_attachments(client)[0]
|
274
|
+
>>> attachment.delete()
|
275
|
+
"""
|
276
|
+
super().delete(self.endpoint)
|
277
|
+
self.attachment_id = None
|
278
|
+
|
279
|
+
|
280
|
+
@property
|
281
|
+
def thumbnail(self) -> str:
|
282
|
+
"""
|
283
|
+
Get the thumbnail URL of the attachment.
|
284
|
+
|
285
|
+
Returns:
|
286
|
+
str: The thumbnail of the scene.
|
287
|
+
|
288
|
+
Example:
|
289
|
+
>>> from geobox import GeoboxClient
|
290
|
+
>>> from geobox.attachment import Attachment
|
291
|
+
>>> client = GeoboxClient()
|
292
|
+
>>> attachment = Attachment.get_attachment(client, uuid="12345678-1234-5678-1234-567812345678")
|
293
|
+
>>> attachment.thumbnail
|
294
|
+
'https://example.com/thumbnail.png'
|
295
|
+
"""
|
296
|
+
endpoint = f"{self.api.base_url}{self.endpoint}thumbnail"
|
297
|
+
return endpoint
|
298
298
|
|