pygeobox 1.0.2__py3-none-any.whl → 1.0.4__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/version.py CHANGED
@@ -1,249 +1,249 @@
1
- from typing import TYPE_CHECKING, Dict, List, Optional, Union
2
-
3
- from .base import Base
4
-
5
- if TYPE_CHECKING:
6
- from .api import GeoboxClient
7
- from .user import User
8
-
9
- class VectorLayerVersion(Base):
10
-
11
- BASE_ENDPOINT = 'vectorLayerVersions/'
12
-
13
- def __init__(self,
14
- api: 'GeoboxClient',
15
- uuid: str,
16
- data: Optional[Dict] = {}):
17
- """
18
- Initialize a vector layer version instance.
19
-
20
- Args:
21
- api (GeoboxClient): The GeoboxClient instance for making requests.
22
- uuid (str): The unique identifier for the version.
23
- data (Dict): The data of the version.
24
- """
25
- super().__init__(api, uuid=uuid, data=data)
26
-
27
-
28
- @classmethod
29
- def get_versions(cls, api: 'GeoboxClient', **kwargs) -> Union[List['VectorLayerVersion'], int]:
30
- """
31
- Get list of versions with optional filtering and pagination.
32
-
33
- Args:
34
- api (GeoboxClient): The GeoboxClient instance for making requests.
35
-
36
- Keyword Args:
37
- layer_id (str): the id of the vector layer.
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 versions. default is False.
47
-
48
- Returns:
49
- List[VectorLayerVersion] | int: A list of vector layer version instances or the total number of versions.
50
-
51
- Example:
52
- >>> from geobox import GeoboxClient
53
- >>> from geobox.version import VectorLayerVersion
54
- >>> client = GeoboxClient()
55
- >>> versions = VectorLayerVersion.get_versions(client, q="name LIKE '%My version%'")
56
- or
57
- >>> versions = client.get_versions(q="name LIKE '%My version%'")
58
- """
59
- params = {
60
- 'layer_id': kwargs.get('layer_id'),
61
- 'f': 'json',
62
- 'q': kwargs.get('q'),
63
- 'search': kwargs.get('search'),
64
- 'search_fields': kwargs.get('search_fields'),
65
- 'order_by': kwargs.get('order_by'),
66
- 'return_count': kwargs.get('return_count', False),
67
- 'skip': kwargs.get('skip', 0),
68
- 'limit': kwargs.get('limit', 10),
69
- 'user_id': kwargs.get('user_id'),
70
- 'shared': kwargs.get('shared', False)
71
- }
72
- return super()._get_list(api, cls.BASE_ENDPOINT, params, factory_func=lambda api, item: VectorLayerVersion(api, item['uuid'], item))
73
-
74
-
75
- @classmethod
76
- def get_version(cls, api: 'GeoboxClient', uuid: str, user_id: int = None) -> 'VectorLayerVersion':
77
- """
78
- Get a version by its UUID.
79
-
80
- Args:
81
- api (GeoboxClient): The GeoboxClient instance for making requests.
82
- uuid (str): The UUID of the version to get.
83
- user_id (int, optional): Specific user. privileges required.
84
-
85
- Returns:
86
- VectorLayerVersion: The vector layer version object.
87
-
88
- Raises:
89
- NotFoundError: If the version with the specified UUID is not found.
90
-
91
- Example:
92
- >>> from geobox import GeoboxClient
93
- >>> from geobox.version import VectorLayerVersion
94
- >>> client = GeoboxClient()
95
- >>> version = VectorLayerVersion.get_version(client, uuid="12345678-1234-5678-1234-567812345678")
96
- or
97
- >>> version = client.get_version(uuid="12345678-1234-5678-1234-567812345678")
98
- """
99
- params = {
100
- 'f': 'json',
101
- 'user_id': user_id,
102
- }
103
- return super()._get_detail(api, cls.BASE_ENDPOINT, uuid, params, factory_func=lambda api, item: VectorLayerVersion(api, item['uuid'], item))
104
-
105
-
106
- @classmethod
107
- def get_version_by_name(cls, api: 'GeoboxClient', name: str, user_id: int = None) -> 'VectorLayerVersion':
108
- """
109
- Get a version by name
110
-
111
- Args:
112
- api (GeoboxClient): The GeoboxClient instance for making requests.
113
- name (str): the name of the version to get
114
- user_id (int, optional): specific user. privileges required.
115
-
116
- Returns:
117
- VectorLayerVersion | None: returns the version if a version matches the given name, else None
118
-
119
- Example:
120
- >>> from geobox import GeoboxClient
121
- >>> from geobox.version import VectorLayerVersion
122
- >>> client = GeoboxClient()
123
- >>> version = VectorLayerView.get_version_by_name(client, name='test')
124
- or
125
- >>> version = client.get_version_by_name(name='test')
126
- """
127
- versions = cls.get_versions(api, q=f"name = '{name}'", user_id=user_id)
128
- if versions and versions[0].name == name:
129
- return versions[0]
130
- else:
131
- return None
132
-
133
-
134
- def update(self, **kwargs) -> Dict:
135
- """
136
- Update the version.
137
-
138
- Args:
139
- name (str): The name of the version.
140
- display_name (str): The display name of the version.
141
- description (str): The description of the version.
142
-
143
- Returns:
144
- Dict: The updated version data.
145
-
146
- Raises:
147
- ValidationError: If the version data is invalid.
148
-
149
- Example:
150
- >>> from geobox import GeoboxClient
151
- >>> from geobox.version import VectorLayerVersion
152
- >>> client = GeoboxClient()
153
- >>> version = VectorLayerVersion.get_version(client, uuid="12345678-1234-5678-1234-567812345678")
154
- >>> version.update_version(display_name="New Display Name")
155
- """
156
- data = {
157
- "name": kwargs.get('name'),
158
- "display_name": kwargs.get('display_name'),
159
- "description": kwargs.get('description'),
160
- }
161
- return super()._update(self.endpoint, data)
162
-
163
-
164
- def delete(self) -> None:
165
- """
166
- Delete the version.
167
-
168
- Returns:
169
- None
170
-
171
- Example:
172
- >>> from geobox import GeoboxClient
173
- >>> from geobox.version import VectorLayerVersion
174
- >>> client = GeoboxClient()
175
- >>> version = VectorLayerVersion.get_version(client, uuid="12345678-1234-5678-1234-567812345678")
176
- >>> version.delete()
177
- """
178
- super().delete(self.endpoint)
179
-
180
-
181
- def share(self, users: List['User']) -> None:
182
- """
183
- Shares the version with specified users.
184
-
185
- Args:
186
- users (List[User]): The list of user objects to share the version with.
187
-
188
- Returns:
189
- None
190
-
191
- Example:
192
- >>> from geobox import GeoboxClient
193
- >>> from geobox.version import VectorLayerVersion
194
- >>> client = GeoboxClient()
195
- >>> version = VectorLayerVersion.get_version(client, uuid="12345678-1234-5678-1234-567812345678")
196
- >>> users = client.search_users(search='John')
197
- >>> version.share(users=users)
198
- """
199
- super()._share(self.endpoint, users)
200
-
201
-
202
- def unshare(self, users: List['User']) -> None:
203
- """
204
- Unshares the version with specified users.
205
-
206
- Args:
207
- users (List[User]): The list of user objects to unshare the version with.
208
-
209
- Returns:
210
- None
211
-
212
- Example:
213
- >>> from geobox import GeoboxClient
214
- >>> from geobox.version import VectorLayerVersion
215
- >>> client = GeoboxClient()
216
- >>> version = VectorLayerVersion.get_version(client, uuid="12345678-1234-5678-1234-567812345678")
217
- >>> users = client.search_users(search='John')
218
- >>> version.unshare(users=users)
219
- """
220
- super()._unshare(self.endpoint, users)
221
-
222
-
223
- def get_shared_users(self, search: str = None, skip: int = 0, limit: int = 10) -> List['User']:
224
- """
225
- Retrieves the list of users the version is shared with.
226
-
227
- Args:
228
- search (str, optional): The search query.
229
- skip (int, optional): The number of users to skip.
230
- limit (int, optional): The maximum number of users to retrieve.
231
-
232
- Returns:
233
- List[User]: The list of shared users.
234
-
235
- Example:
236
- >>> from geobox import GeoboxClient
237
- >>> from geobox.version import VectorLayerVersion
238
- >>> client = GeoboxClient()
239
- >>> version = VectorLayerVersion.get_version(client, uuid="12345678-1234-5678-1234-567812345678")
240
- >>> version.get_shared_users(search='John', skip=0, limit=10)
241
- """
242
- params = {
243
- 'search': search,
244
- 'skip': skip,
245
- 'limit': limit
246
- }
247
- return super()._get_shared_users(self.endpoint, params)
248
-
1
+ from typing import TYPE_CHECKING, Dict, List, Optional, Union
2
+
3
+ from .base import Base
4
+
5
+ if TYPE_CHECKING:
6
+ from .api import GeoboxClient
7
+ from .user import User
8
+
9
+ class VectorLayerVersion(Base):
10
+
11
+ BASE_ENDPOINT = 'vectorLayerVersions/'
12
+
13
+ def __init__(self,
14
+ api: 'GeoboxClient',
15
+ uuid: str,
16
+ data: Optional[Dict] = {}):
17
+ """
18
+ Initialize a vector layer version instance.
19
+
20
+ Args:
21
+ api (GeoboxClient): The GeoboxClient instance for making requests.
22
+ uuid (str): The unique identifier for the version.
23
+ data (Dict): The data of the version.
24
+ """
25
+ super().__init__(api, uuid=uuid, data=data)
26
+
27
+
28
+ @classmethod
29
+ def get_versions(cls, api: 'GeoboxClient', **kwargs) -> Union[List['VectorLayerVersion'], int]:
30
+ """
31
+ Get list of versions with optional filtering and pagination.
32
+
33
+ Args:
34
+ api (GeoboxClient): The GeoboxClient instance for making requests.
35
+
36
+ Keyword Args:
37
+ layer_id (str): the id of the vector layer.
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 versions. default is False.
47
+
48
+ Returns:
49
+ List[VectorLayerVersion] | int: A list of vector layer version instances or the total number of versions.
50
+
51
+ Example:
52
+ >>> from geobox import GeoboxClient
53
+ >>> from geobox.version import VectorLayerVersion
54
+ >>> client = GeoboxClient()
55
+ >>> versions = VectorLayerVersion.get_versions(client, q="name LIKE '%My version%'")
56
+ or
57
+ >>> versions = client.get_versions(q="name LIKE '%My version%'")
58
+ """
59
+ params = {
60
+ 'layer_id': kwargs.get('layer_id'),
61
+ 'f': 'json',
62
+ 'q': kwargs.get('q'),
63
+ 'search': kwargs.get('search'),
64
+ 'search_fields': kwargs.get('search_fields'),
65
+ 'order_by': kwargs.get('order_by'),
66
+ 'return_count': kwargs.get('return_count', False),
67
+ 'skip': kwargs.get('skip', 0),
68
+ 'limit': kwargs.get('limit', 10),
69
+ 'user_id': kwargs.get('user_id'),
70
+ 'shared': kwargs.get('shared', False)
71
+ }
72
+ return super()._get_list(api, cls.BASE_ENDPOINT, params, factory_func=lambda api, item: VectorLayerVersion(api, item['uuid'], item))
73
+
74
+
75
+ @classmethod
76
+ def get_version(cls, api: 'GeoboxClient', uuid: str, user_id: int = None) -> 'VectorLayerVersion':
77
+ """
78
+ Get a version by its UUID.
79
+
80
+ Args:
81
+ api (GeoboxClient): The GeoboxClient instance for making requests.
82
+ uuid (str): The UUID of the version to get.
83
+ user_id (int, optional): Specific user. privileges required.
84
+
85
+ Returns:
86
+ VectorLayerVersion: The vector layer version object.
87
+
88
+ Raises:
89
+ NotFoundError: If the version with the specified UUID is not found.
90
+
91
+ Example:
92
+ >>> from geobox import GeoboxClient
93
+ >>> from geobox.version import VectorLayerVersion
94
+ >>> client = GeoboxClient()
95
+ >>> version = VectorLayerVersion.get_version(client, uuid="12345678-1234-5678-1234-567812345678")
96
+ or
97
+ >>> version = client.get_version(uuid="12345678-1234-5678-1234-567812345678")
98
+ """
99
+ params = {
100
+ 'f': 'json',
101
+ 'user_id': user_id,
102
+ }
103
+ return super()._get_detail(api, cls.BASE_ENDPOINT, uuid, params, factory_func=lambda api, item: VectorLayerVersion(api, item['uuid'], item))
104
+
105
+
106
+ @classmethod
107
+ def get_version_by_name(cls, api: 'GeoboxClient', name: str, user_id: int = None) -> 'VectorLayerVersion':
108
+ """
109
+ Get a version by name
110
+
111
+ Args:
112
+ api (GeoboxClient): The GeoboxClient instance for making requests.
113
+ name (str): the name of the version to get
114
+ user_id (int, optional): specific user. privileges required.
115
+
116
+ Returns:
117
+ VectorLayerVersion | None: returns the version if a version matches the given name, else None
118
+
119
+ Example:
120
+ >>> from geobox import GeoboxClient
121
+ >>> from geobox.version import VectorLayerVersion
122
+ >>> client = GeoboxClient()
123
+ >>> version = VectorLayerView.get_version_by_name(client, name='test')
124
+ or
125
+ >>> version = client.get_version_by_name(name='test')
126
+ """
127
+ versions = cls.get_versions(api, q=f"name = '{name}'", user_id=user_id)
128
+ if versions and versions[0].name == name:
129
+ return versions[0]
130
+ else:
131
+ return None
132
+
133
+
134
+ def update(self, **kwargs) -> Dict:
135
+ """
136
+ Update the version.
137
+
138
+ Args:
139
+ name (str): The name of the version.
140
+ display_name (str): The display name of the version.
141
+ description (str): The description of the version.
142
+
143
+ Returns:
144
+ Dict: The updated version data.
145
+
146
+ Raises:
147
+ ValidationError: If the version data is invalid.
148
+
149
+ Example:
150
+ >>> from geobox import GeoboxClient
151
+ >>> from geobox.version import VectorLayerVersion
152
+ >>> client = GeoboxClient()
153
+ >>> version = VectorLayerVersion.get_version(client, uuid="12345678-1234-5678-1234-567812345678")
154
+ >>> version.update_version(display_name="New Display Name")
155
+ """
156
+ data = {
157
+ "name": kwargs.get('name'),
158
+ "display_name": kwargs.get('display_name'),
159
+ "description": kwargs.get('description'),
160
+ }
161
+ return super()._update(self.endpoint, data)
162
+
163
+
164
+ def delete(self) -> None:
165
+ """
166
+ Delete the version.
167
+
168
+ Returns:
169
+ None
170
+
171
+ Example:
172
+ >>> from geobox import GeoboxClient
173
+ >>> from geobox.version import VectorLayerVersion
174
+ >>> client = GeoboxClient()
175
+ >>> version = VectorLayerVersion.get_version(client, uuid="12345678-1234-5678-1234-567812345678")
176
+ >>> version.delete()
177
+ """
178
+ super().delete(self.endpoint)
179
+
180
+
181
+ def share(self, users: List['User']) -> None:
182
+ """
183
+ Shares the version with specified users.
184
+
185
+ Args:
186
+ users (List[User]): The list of user objects to share the version with.
187
+
188
+ Returns:
189
+ None
190
+
191
+ Example:
192
+ >>> from geobox import GeoboxClient
193
+ >>> from geobox.version import VectorLayerVersion
194
+ >>> client = GeoboxClient()
195
+ >>> version = VectorLayerVersion.get_version(client, uuid="12345678-1234-5678-1234-567812345678")
196
+ >>> users = client.search_users(search='John')
197
+ >>> version.share(users=users)
198
+ """
199
+ super()._share(self.endpoint, users)
200
+
201
+
202
+ def unshare(self, users: List['User']) -> None:
203
+ """
204
+ Unshares the version with specified users.
205
+
206
+ Args:
207
+ users (List[User]): The list of user objects to unshare the version with.
208
+
209
+ Returns:
210
+ None
211
+
212
+ Example:
213
+ >>> from geobox import GeoboxClient
214
+ >>> from geobox.version import VectorLayerVersion
215
+ >>> client = GeoboxClient()
216
+ >>> version = VectorLayerVersion.get_version(client, uuid="12345678-1234-5678-1234-567812345678")
217
+ >>> users = client.search_users(search='John')
218
+ >>> version.unshare(users=users)
219
+ """
220
+ super()._unshare(self.endpoint, users)
221
+
222
+
223
+ def get_shared_users(self, search: str = None, skip: int = 0, limit: int = 10) -> List['User']:
224
+ """
225
+ Retrieves the list of users the version is shared with.
226
+
227
+ Args:
228
+ search (str, optional): The search query.
229
+ skip (int, optional): The number of users to skip.
230
+ limit (int, optional): The maximum number of users to retrieve.
231
+
232
+ Returns:
233
+ List[User]: The list of shared users.
234
+
235
+ Example:
236
+ >>> from geobox import GeoboxClient
237
+ >>> from geobox.version import VectorLayerVersion
238
+ >>> client = GeoboxClient()
239
+ >>> version = VectorLayerVersion.get_version(client, uuid="12345678-1234-5678-1234-567812345678")
240
+ >>> version.get_shared_users(search='John', skip=0, limit=10)
241
+ """
242
+ params = {
243
+ 'search': search,
244
+ 'skip': skip,
245
+ 'limit': limit
246
+ }
247
+ return super()._get_shared_users(self.endpoint, params)
248
+
249
249