geobox 2.0.1__py3-none-any.whl → 2.2.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.
Files changed (70) hide show
  1. geobox/__init__.py +61 -63
  2. geobox/aio/__init__.py +61 -63
  3. geobox/aio/api.py +489 -473
  4. geobox/aio/apikey.py +263 -263
  5. geobox/aio/attachment.py +341 -339
  6. geobox/aio/base.py +261 -262
  7. geobox/aio/basemap.py +196 -196
  8. geobox/aio/dashboard.py +340 -342
  9. geobox/aio/feature.py +23 -33
  10. geobox/aio/field.py +315 -321
  11. geobox/aio/file.py +72 -72
  12. geobox/aio/layout.py +340 -341
  13. geobox/aio/log.py +23 -23
  14. geobox/aio/map.py +1033 -1034
  15. geobox/aio/model3d.py +415 -415
  16. geobox/aio/mosaic.py +696 -696
  17. geobox/aio/plan.py +314 -314
  18. geobox/aio/query.py +693 -693
  19. geobox/aio/raster.py +907 -869
  20. geobox/aio/raster_analysis.py +740 -0
  21. geobox/aio/route.py +4 -4
  22. geobox/aio/scene.py +340 -342
  23. geobox/aio/settings.py +18 -18
  24. geobox/aio/task.py +404 -402
  25. geobox/aio/tile3d.py +337 -339
  26. geobox/aio/tileset.py +102 -103
  27. geobox/aio/usage.py +52 -51
  28. geobox/aio/user.py +506 -507
  29. geobox/aio/vector_tool.py +1968 -0
  30. geobox/aio/vectorlayer.py +315 -306
  31. geobox/aio/version.py +272 -273
  32. geobox/aio/view.py +1019 -983
  33. geobox/aio/workflow.py +340 -341
  34. geobox/api.py +18 -2
  35. geobox/apikey.py +262 -262
  36. geobox/attachment.py +336 -337
  37. geobox/base.py +384 -384
  38. geobox/basemap.py +194 -194
  39. geobox/dashboard.py +339 -341
  40. geobox/enums.py +432 -348
  41. geobox/feature.py +5 -5
  42. geobox/field.py +320 -320
  43. geobox/file.py +4 -4
  44. geobox/layout.py +339 -340
  45. geobox/log.py +4 -4
  46. geobox/map.py +1031 -1032
  47. geobox/model3d.py +410 -410
  48. geobox/mosaic.py +696 -696
  49. geobox/plan.py +313 -313
  50. geobox/query.py +691 -691
  51. geobox/raster.py +907 -863
  52. geobox/raster_analysis.py +737 -0
  53. geobox/scene.py +341 -342
  54. geobox/settings.py +194 -194
  55. geobox/task.py +399 -400
  56. geobox/tile3d.py +337 -338
  57. geobox/tileset.py +4 -4
  58. geobox/usage.py +3 -3
  59. geobox/user.py +503 -503
  60. geobox/vector_tool.py +1968 -0
  61. geobox/vectorlayer.py +5 -5
  62. geobox/version.py +272 -272
  63. geobox/view.py +981 -981
  64. geobox/workflow.py +338 -339
  65. {geobox-2.0.1.dist-info → geobox-2.2.0.dist-info}/METADATA +15 -1
  66. geobox-2.2.0.dist-info/RECORD +72 -0
  67. geobox-2.0.1.dist-info/RECORD +0 -68
  68. {geobox-2.0.1.dist-info → geobox-2.2.0.dist-info}/WHEEL +0 -0
  69. {geobox-2.0.1.dist-info → geobox-2.2.0.dist-info}/licenses/LICENSE +0 -0
  70. {geobox-2.0.1.dist-info → geobox-2.2.0.dist-info}/top_level.txt +0 -0
geobox/aio/plan.py CHANGED
@@ -1,315 +1,315 @@
1
- from typing import List, Dict, Optional, TYPE_CHECKING, Union
2
- from urllib.parse import urljoin
3
-
4
- from .base import AsyncBase
5
-
6
- if TYPE_CHECKING:
7
- from . import AsyncGeoboxClient
8
- from ..api import GeoboxClient as SyncGeoboxClient
9
- from ..plan import Plan as SyncPlan
10
-
11
-
12
- class Plan(AsyncBase):
13
-
14
- BASE_ENDPOINT = 'plans/'
15
-
16
- def __init__(self,
17
- api: 'AsyncGeoboxClient',
18
- plan_id: int,
19
- data: Optional[Dict] = {}):
20
- """
21
- Initialize a plan instance.
22
-
23
- Args:
24
- api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
25
- plan_id (str): The id for the plan.
26
- data (Dict, optional): The data of the plan.
27
- """
28
- super().__init__(api, data=data)
29
- self.plan_id = plan_id
30
- self.endpoint = urljoin(self.BASE_ENDPOINT, str(self.id))
31
-
32
-
33
- @classmethod
34
- async def get_plans(cls, api: 'AsyncGeoboxClient', **kwargs) -> Union[List['Plan'], int]:
35
- """
36
- [async] Get list of plans with optional filtering and pagination.
37
-
38
- Args:
39
- api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
40
-
41
- Keyword Args:
42
- q (str): query filter based on OGC CQL standard. e.g. "field1 LIKE '%GIS%' AND created_at > '2021-01-01'"
43
- 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.
44
- search_fields (str): comma separated list of fields for searching.
45
- 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.
46
- return_count (bool): Whether to return total count. default is False.
47
- skip (int): Number of items to skip. default is 0.
48
- limit (int): Number of items to return. default is 10.
49
- user_id (int): Specific user. privileges required.
50
- shared (bool): Whether to return shared plans. default is False.
51
-
52
- Returns:
53
- List[Plan] | int: A list of plan instances or the total number of plans.
54
-
55
- Example:
56
- >>> from geobox.aio import AsyncGeoboxClient
57
- >>> from geobox.aio.plan import Plan
58
- >>> async with AsyncGeoboxClient() as client:
59
- >>> plans = await Plan.get_plan(client, q="name LIKE '%My plan%'")
60
- or
61
- >>> plans = await client.get_plan(q="name LIKE '%My plan%'")
62
- """
63
- params = {
64
- 'f': 'json',
65
- 'q': kwargs.get('q'),
66
- 'search': kwargs.get('search'),
67
- 'search_fields': kwargs.get('search_fields'),
68
- 'order_by': kwargs.get('order_by'),
69
- 'return_count': kwargs.get('return_count', False),
70
- 'skip': kwargs.get('skip', 0),
71
- 'limit': kwargs.get('limit', 10),
72
- 'user_id': kwargs.get('user_id'),
73
- 'shared': kwargs.get('shared', False)
74
- }
75
- return await super()._get_list(api, cls.BASE_ENDPOINT, params, factory_func=lambda api, item: Plan(api, item['id'], item))
76
-
77
-
78
- @classmethod
79
- async def create_plan(cls,
80
- api: 'AsyncGeoboxClient',
81
- name: str,
82
- plan_color: str,
83
- storage: int,
84
- concurrent_tasks: int,
85
- daily_api_calls: int,
86
- monthly_api_calls: int,
87
- daily_traffic: int,
88
- monthly_traffic: int,
89
- daily_process: int,
90
- monthly_process: int,
91
- number_of_days: int = None,
92
- display_name: str = None,
93
- description: str = None) -> 'Plan':
94
- """
95
- [async] Create a new plan.
96
-
97
- Args:
98
- api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
99
- name (str): The name of the plan.
100
- plan_color (str): hex value of the color. e.g. #000000.
101
- storage (int): storage value in bytes. must be greater that 1.
102
- concurrent_tasks (int): number of concurrent tasks. must be greater that 1.
103
- daily_api_calls (int): number of daily api calls. must be greater that 1.
104
- monthly_api_calls (int): number of monthly api calls. must be greater that 1.
105
- daily_traffic (int): number of daily traffic. must be greater that 1.
106
- monthly_traffic (int): number of monthly traffic. must be greater that 1.
107
- daily_process (int): number of daily processes. must be greater that 1.
108
- monthly_process (int): number of monthly processes. must be greater that 1.
109
- number_of_days (int, optional): number of days. must be greater that 1.
110
- display_name (str, optional): display name of the plan.
111
- description (str, optional): description of the plan.
112
-
113
- Returns:
114
- Plan: The newly created plan instance.
115
-
116
- Raises:
117
- ValidationError: If the plan data is invalid.
118
-
119
- Example:
120
- >>> from geobox.aio import AsyncGeoboxClient
121
- >>> from geobox.aio.plan import Plan
122
- >>> async with AsyncGeoboxClient() as client:
123
- >>> plan = await Plan.create_plan(client,
124
- ... name="new_plan",
125
- ... display_name=" New Plan",
126
- ... description="new plan description",
127
- ... plan_color="#000000",
128
- ... storage=10,
129
- ... concurrent_tasks=10,
130
- ... daily_api_calls=10,
131
- ... monthly_api_calls=10,
132
- ... daily_traffic=10,
133
- ... monthly_traffic=10,
134
- ... daily_process=10,
135
- ... monthly_process=10,
136
- ... number_of_days=10)
137
- or
138
- >>> plan = await client.create_plan(name="new_plan",
139
- ... display_name=" New Plan",
140
- ... description="new plan description",
141
- ... plan_color="#000000",
142
- ... storage=10,
143
- ... concurrent_tasks=10,
144
- ... daily_api_calls=10,
145
- ... monthly_api_calls=10,
146
- ... daily_traffic=10,
147
- ... monthly_traffic=10,
148
- ... daily_process=10,
149
- ... monthly_process=10,
150
- ... number_of_days=10)
151
- """
152
- data = {
153
- "name": name,
154
- "display_name": display_name,
155
- "description": description,
156
- "plan_color": plan_color,
157
- "storage": storage,
158
- "concurrent_tasks": concurrent_tasks,
159
- "daily_api_calls": daily_api_calls,
160
- "monthly_api_calls": monthly_api_calls,
161
- "daily_traffic": daily_traffic,
162
- "monthly_traffic": monthly_traffic,
163
- "daily_process": daily_process,
164
- "monthly_process": monthly_process,
165
- "number_of_days": number_of_days
166
- }
167
- return await super()._create(api, cls.BASE_ENDPOINT, data, factory_func=lambda api, item: Plan(api, item['id'], item))
168
-
169
-
170
- @classmethod
171
- async def get_plan(cls, api: 'AsyncGeoboxClient', plan_id: int) -> 'Plan':
172
- """
173
- [async] Get a plan by its id.
174
-
175
- Args:
176
- api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
177
- plan_id (int): The id of the plan to get.
178
-
179
- Returns:
180
- Plan: The plan object
181
-
182
- Raises:
183
- NotFoundError: If the plan with the specified id is not found.
184
-
185
- Example:
186
- >>> from geobox.aio import AsyncGeoboxClient
187
- >>> from geobox.aio.plan import Plan
188
- >>> async with AsyncGeoboxClient() as client:
189
- >>> plan = await Plan.get_plan(client, plan_id=1)
190
- or
191
- >>> plan = await client.get_plan(plan_id=1)
192
- """
193
- params = {
194
- 'f': 'json'
195
- }
196
- return await super()._get_detail(api, cls.BASE_ENDPOINT, plan_id, params, factory_func=lambda api, item: Plan(api, item['id'], item))
197
-
198
-
199
- @classmethod
200
- async def get_plan_by_name(cls, api: 'AsyncGeoboxClient', name: str) -> Union['Plan', None]:
201
- """
202
- [async] Get a plan by name
203
-
204
- Args:
205
- api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
206
- name (str): the name of the plan to get
207
-
208
- Returns:
209
- Plan | None: returns the plan if a plan matches the given name, else None
210
-
211
- Example:
212
- >>> from geobox.aio import AsyncGeoboxClient
213
- >>> from geobox.aio.plan import Plan
214
- >>> async with AsyncGeoboxClient() as client:
215
- >>> plan = await Plan.get_plan_by_name(client, name='test')
216
- or
217
- >>> plan = await client.get_plan_by_name(name='test')
218
- """
219
- plans = await cls.get_plans(api, q=f"name = '{name}'")
220
- if plans and plans[0].name == name:
221
- return plans[0]
222
- else:
223
- return None
224
-
225
-
226
- async def update(self, **kwargs) -> Dict:
227
- """
228
- [async] Update the plan
229
-
230
- Keyword Args:
231
- name (str): The name of the plan.
232
- plan_color (str): hex value of the color. e.g. #000000.
233
- storage (int): storage value in bytes. must be greater that 1.
234
- concurrent_tasks (int): number of concurrent tasks. must be greater that 1.
235
- daily_api_calls (int): number of daily api calls. must be greater that 1.
236
- monthly_api_calls (int): number of monthly api calls. must be greater that 1.
237
- daily_traffic (int): number of daily traffic. must be greater that 1.
238
- monthly_traffic (int): number of monthly traffic. must be greater that 1.
239
- daily_processes (int): number of daily processes. must be greater that 1.
240
- monthly_processes (int): number of monthly processes. must be greater that 1.
241
- number_of_days (int): number of days. must be greater that 1.
242
- display_name (str): display name of the plan.
243
- description (str): description of the plan.
244
-
245
- Returns:
246
- Dict: The updated plan data.
247
-
248
- Raises:
249
- ValidationError: If the plan data is invalid.
250
-
251
- Example:
252
- >>> from geobox.aio import AsyncGeoboxClient
253
- >>> from geobox.aio.plan import Plan
254
- >>> async with AsyncGeoboxClient() as client:
255
- >>> plan = await Plan.get_plan(client, plan_id=1)
256
- >>> await plan.update(display_name="New Display Name")
257
- """
258
- data = {
259
- "name": kwargs.get('name'),
260
- "display_name": kwargs.get('display_name'),
261
- "description": kwargs.get('description'),
262
- "plan_color": kwargs.get('plan_color'),
263
- "storage": kwargs.get('storage'),
264
- "concurrent_tasks": kwargs.get('concurrent_tasks'),
265
- "daily_api_calls": kwargs.get('daily_api_calls'),
266
- "monthly_api_calls": kwargs.get('monthly_api_calls'),
267
- "daily_traffic": kwargs.get('daily_traffic'),
268
- "monthly_traffic": kwargs.get('monthly_traffic'),
269
- "daily_process": kwargs.get('daily_process'),
270
- "monthly_process": kwargs.get('monthly_process'),
271
- "number_of_days": kwargs.get('number_of_days')
272
- }
273
- return await super()._update(self.endpoint, data)
274
-
275
-
276
- async def delete(self) -> None:
277
- """
278
- [async] Delete the plan.
279
-
280
- Returns:
281
- None
282
-
283
- Example:
284
- >>> from geobox.aio import AsyncGeoboxClient
285
- >>> from geobox.aio.plan import Plan
286
- >>> async with AsyncGeoboxClient() as client:
287
- >>> plan = await Plan.get_plan(client, plan_id=1)
288
- >>> await plan.delete()
289
- """
290
- await super().delete(self.endpoint)
291
- self.plan_id = None
292
-
293
-
294
- def to_sync(self, sync_client: 'SyncGeoboxClient') -> 'SyncPlan':
295
- """
296
- Switch to sync version of the plan instance to have access to the sync methods
297
-
298
- Args:
299
- sync_client (SyncGeoboxClient): The sync version of the GeoboxClient instance for making requests.
300
-
301
- Returns:
302
- geobox.plan.Plan: the sync instance of the plan.
303
-
304
- Example:
305
- >>> from geobox import Geoboxclient
306
- >>> from geobox.aio import AsyncGeoboxClient
307
- >>> from geobox.aio.plan import Plan
308
- >>> client = GeoboxClient()
309
- >>> async with AsyncGeoboxClient() as async_client:
310
- >>> plan = await Plan.get_plan(async_client, plan_id=1)
311
- >>> sync_plan = plan.to_sync(client)
312
- """
313
- from ..plan import Plan as SyncPlan
314
-
1
+ from typing import List, Dict, Optional, TYPE_CHECKING, Union
2
+ from urllib.parse import urljoin
3
+
4
+ from .base import AsyncBase
5
+
6
+ if TYPE_CHECKING:
7
+ from . import AsyncGeoboxClient
8
+ from ..api import GeoboxClient
9
+ from ..plan import Plan
10
+
11
+
12
+ class AsyncPlan(AsyncBase):
13
+
14
+ BASE_ENDPOINT = 'plans/'
15
+
16
+ def __init__(self,
17
+ api: 'AsyncGeoboxClient',
18
+ plan_id: int,
19
+ data: Optional[Dict] = {}):
20
+ """
21
+ Initialize a plan instance.
22
+
23
+ Args:
24
+ api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
25
+ plan_id (str): The id for the plan.
26
+ data (Dict, optional): The data of the plan.
27
+ """
28
+ super().__init__(api, data=data)
29
+ self.plan_id = plan_id
30
+ self.endpoint = urljoin(self.BASE_ENDPOINT, str(self.id))
31
+
32
+
33
+ @classmethod
34
+ async def get_plans(cls, api: 'AsyncGeoboxClient', **kwargs) -> Union[List['AsyncPlan'], int]:
35
+ """
36
+ [async] Get list of plans with optional filtering and pagination.
37
+
38
+ Args:
39
+ api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
40
+
41
+ Keyword Args:
42
+ q (str): query filter based on OGC CQL standard. e.g. "field1 LIKE '%GIS%' AND created_at > '2021-01-01'"
43
+ 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.
44
+ search_fields (str): comma separated list of fields for searching.
45
+ 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.
46
+ return_count (bool): Whether to return total count. default is False.
47
+ skip (int): Number of items to skip. default is 0.
48
+ limit (int): Number of items to return. default is 10.
49
+ user_id (int): Specific user. privileges required.
50
+ shared (bool): Whether to return shared plans. default is False.
51
+
52
+ Returns:
53
+ List[AsyncPlan] | int: A list of plan instances or the total number of plans.
54
+
55
+ Example:
56
+ >>> from geobox.aio import AsyncGeoboxClient
57
+ >>> from geobox.aio.plan import AsyncPlan
58
+ >>> async with AsyncGeoboxClient() as client:
59
+ >>> plans = await AsyncPlan.get_plan(client, q="name LIKE '%My plan%'")
60
+ or
61
+ >>> plans = await client.get_plan(q="name LIKE '%My plan%'")
62
+ """
63
+ params = {
64
+ 'f': 'json',
65
+ 'q': kwargs.get('q'),
66
+ 'search': kwargs.get('search'),
67
+ 'search_fields': kwargs.get('search_fields'),
68
+ 'order_by': kwargs.get('order_by'),
69
+ 'return_count': kwargs.get('return_count', False),
70
+ 'skip': kwargs.get('skip', 0),
71
+ 'limit': kwargs.get('limit', 10),
72
+ 'user_id': kwargs.get('user_id'),
73
+ 'shared': kwargs.get('shared', False)
74
+ }
75
+ return await super()._get_list(api, cls.BASE_ENDPOINT, params, factory_func=lambda api, item: AsyncPlan(api, item['id'], item))
76
+
77
+
78
+ @classmethod
79
+ async def create_plan(cls,
80
+ api: 'AsyncGeoboxClient',
81
+ name: str,
82
+ plan_color: str,
83
+ storage: int,
84
+ concurrent_tasks: int,
85
+ daily_api_calls: int,
86
+ monthly_api_calls: int,
87
+ daily_traffic: int,
88
+ monthly_traffic: int,
89
+ daily_process: int,
90
+ monthly_process: int,
91
+ number_of_days: int = None,
92
+ display_name: str = None,
93
+ description: str = None) -> 'AsyncPlan':
94
+ """
95
+ [async] Create a new plan.
96
+
97
+ Args:
98
+ api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
99
+ name (str): The name of the plan.
100
+ plan_color (str): hex value of the color. e.g. #000000.
101
+ storage (int): storage value in bytes. must be greater that 1.
102
+ concurrent_tasks (int): number of concurrent tasks. must be greater that 1.
103
+ daily_api_calls (int): number of daily api calls. must be greater that 1.
104
+ monthly_api_calls (int): number of monthly api calls. must be greater that 1.
105
+ daily_traffic (int): number of daily traffic. must be greater that 1.
106
+ monthly_traffic (int): number of monthly traffic. must be greater that 1.
107
+ daily_process (int): number of daily processes. must be greater that 1.
108
+ monthly_process (int): number of monthly processes. must be greater that 1.
109
+ number_of_days (int, optional): number of days. must be greater that 1.
110
+ display_name (str, optional): display name of the plan.
111
+ description (str, optional): description of the plan.
112
+
113
+ Returns:
114
+ AsyncPlan: The newly created plan instance.
115
+
116
+ Raises:
117
+ ValidationError: If the plan data is invalid.
118
+
119
+ Example:
120
+ >>> from geobox.aio import AsyncGeoboxClient
121
+ >>> from geobox.aio.plan import AsyncPlan
122
+ >>> async with AsyncGeoboxClient() as client:
123
+ >>> plan = await Plan.create_plan(client,
124
+ ... name="new_plan",
125
+ ... display_name=" New Plan",
126
+ ... description="new plan description",
127
+ ... plan_color="#000000",
128
+ ... storage=10,
129
+ ... concurrent_tasks=10,
130
+ ... daily_api_calls=10,
131
+ ... monthly_api_calls=10,
132
+ ... daily_traffic=10,
133
+ ... monthly_traffic=10,
134
+ ... daily_process=10,
135
+ ... monthly_process=10,
136
+ ... number_of_days=10)
137
+ or
138
+ >>> plan = await client.create_plan(name="new_plan",
139
+ ... display_name=" New Plan",
140
+ ... description="new plan description",
141
+ ... plan_color="#000000",
142
+ ... storage=10,
143
+ ... concurrent_tasks=10,
144
+ ... daily_api_calls=10,
145
+ ... monthly_api_calls=10,
146
+ ... daily_traffic=10,
147
+ ... monthly_traffic=10,
148
+ ... daily_process=10,
149
+ ... monthly_process=10,
150
+ ... number_of_days=10)
151
+ """
152
+ data = {
153
+ "name": name,
154
+ "display_name": display_name,
155
+ "description": description,
156
+ "plan_color": plan_color,
157
+ "storage": storage,
158
+ "concurrent_tasks": concurrent_tasks,
159
+ "daily_api_calls": daily_api_calls,
160
+ "monthly_api_calls": monthly_api_calls,
161
+ "daily_traffic": daily_traffic,
162
+ "monthly_traffic": monthly_traffic,
163
+ "daily_process": daily_process,
164
+ "monthly_process": monthly_process,
165
+ "number_of_days": number_of_days
166
+ }
167
+ return await super()._create(api, cls.BASE_ENDPOINT, data, factory_func=lambda api, item: AsyncPlan(api, item['id'], item))
168
+
169
+
170
+ @classmethod
171
+ async def get_plan(cls, api: 'AsyncGeoboxClient', plan_id: int) -> 'AsyncPlan':
172
+ """
173
+ [async] Get a plan by its id.
174
+
175
+ Args:
176
+ api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
177
+ plan_id (int): The id of the plan to get.
178
+
179
+ Returns:
180
+ AsyncPlan: The plan object
181
+
182
+ Raises:
183
+ NotFoundError: If the plan with the specified id is not found.
184
+
185
+ Example:
186
+ >>> from geobox.aio import AsyncGeoboxClient
187
+ >>> from geobox.aio.plan import AsyncPlan
188
+ >>> async with AsyncGeoboxClient() as client:
189
+ >>> plan = await AsyncPlan.get_plan(client, plan_id=1)
190
+ or
191
+ >>> plan = await client.get_plan(plan_id=1)
192
+ """
193
+ params = {
194
+ 'f': 'json'
195
+ }
196
+ return await super()._get_detail(api, cls.BASE_ENDPOINT, plan_id, params, factory_func=lambda api, item: AsyncPlan(api, item['id'], item))
197
+
198
+
199
+ @classmethod
200
+ async def get_plan_by_name(cls, api: 'AsyncGeoboxClient', name: str) -> Union['AsyncPlan', None]:
201
+ """
202
+ [async] Get a plan by name
203
+
204
+ Args:
205
+ api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
206
+ name (str): the name of the plan to get
207
+
208
+ Returns:
209
+ AsyncPlan | None: returns the plan if a plan matches the given name, else None
210
+
211
+ Example:
212
+ >>> from geobox.aio import AsyncGeoboxClient
213
+ >>> from geobox.aio.plan import AsyncPlan
214
+ >>> async with AsyncGeoboxClient() as client:
215
+ >>> plan = await AsyncPlan.get_plan_by_name(client, name='test')
216
+ or
217
+ >>> plan = await client.get_plan_by_name(name='test')
218
+ """
219
+ plans = await cls.get_plans(api, q=f"name = '{name}'")
220
+ if plans and plans[0].name == name:
221
+ return plans[0]
222
+ else:
223
+ return None
224
+
225
+
226
+ async def update(self, **kwargs) -> Dict:
227
+ """
228
+ [async] Update the plan
229
+
230
+ Keyword Args:
231
+ name (str): The name of the plan.
232
+ plan_color (str): hex value of the color. e.g. #000000.
233
+ storage (int): storage value in bytes. must be greater that 1.
234
+ concurrent_tasks (int): number of concurrent tasks. must be greater that 1.
235
+ daily_api_calls (int): number of daily api calls. must be greater that 1.
236
+ monthly_api_calls (int): number of monthly api calls. must be greater that 1.
237
+ daily_traffic (int): number of daily traffic. must be greater that 1.
238
+ monthly_traffic (int): number of monthly traffic. must be greater that 1.
239
+ daily_processes (int): number of daily processes. must be greater that 1.
240
+ monthly_processes (int): number of monthly processes. must be greater that 1.
241
+ number_of_days (int): number of days. must be greater that 1.
242
+ display_name (str): display name of the plan.
243
+ description (str): description of the plan.
244
+
245
+ Returns:
246
+ Dict: The updated plan data.
247
+
248
+ Raises:
249
+ ValidationError: If the plan data is invalid.
250
+
251
+ Example:
252
+ >>> from geobox.aio import AsyncGeoboxClient
253
+ >>> from geobox.aio.plan import AsyncPlan
254
+ >>> async with AsyncGeoboxClient() as client:
255
+ >>> plan = await AsyncPlan.get_plan(client, plan_id=1)
256
+ >>> await plan.update(display_name="New Display Name")
257
+ """
258
+ data = {
259
+ "name": kwargs.get('name'),
260
+ "display_name": kwargs.get('display_name'),
261
+ "description": kwargs.get('description'),
262
+ "plan_color": kwargs.get('plan_color'),
263
+ "storage": kwargs.get('storage'),
264
+ "concurrent_tasks": kwargs.get('concurrent_tasks'),
265
+ "daily_api_calls": kwargs.get('daily_api_calls'),
266
+ "monthly_api_calls": kwargs.get('monthly_api_calls'),
267
+ "daily_traffic": kwargs.get('daily_traffic'),
268
+ "monthly_traffic": kwargs.get('monthly_traffic'),
269
+ "daily_process": kwargs.get('daily_process'),
270
+ "monthly_process": kwargs.get('monthly_process'),
271
+ "number_of_days": kwargs.get('number_of_days')
272
+ }
273
+ return await super()._update(self.endpoint, data)
274
+
275
+
276
+ async def delete(self) -> None:
277
+ """
278
+ [async] Delete the plan.
279
+
280
+ Returns:
281
+ None
282
+
283
+ Example:
284
+ >>> from geobox.aio import AsyncGeoboxClient
285
+ >>> from geobox.aio.plan import AsyncPlan
286
+ >>> async with AsyncGeoboxClient() as client:
287
+ >>> plan = await AsyncPlan.get_plan(client, plan_id=1)
288
+ >>> await plan.delete()
289
+ """
290
+ await super()._delete(self.endpoint)
291
+ self.plan_id = None
292
+
293
+
294
+ def to_sync(self, sync_client: 'GeoboxClient') -> 'Plan':
295
+ """
296
+ Switch to sync version of the plan instance to have access to the sync methods
297
+
298
+ Args:
299
+ sync_client (GeoboxClient): The sync version of the GeoboxClient instance for making requests.
300
+
301
+ Returns:
302
+ Plan: the sync instance of the plan.
303
+
304
+ Example:
305
+ >>> from geobox import Geoboxclient
306
+ >>> from geobox.aio import AsyncGeoboxClient
307
+ >>> from geobox.aio.plan import AsyncPlan
308
+ >>> client = GeoboxClient()
309
+ >>> async with AsyncGeoboxClient() as async_client:
310
+ >>> plan = await AsyncPlan.get_plan(async_client, plan_id=1)
311
+ >>> sync_plan = plan.to_sync(client)
312
+ """
313
+ from ..plan import Plan as SyncPlan
314
+
315
315
  return SyncPlan(api=sync_client, plan_id=self.plan_id, data=self.data)