|
1 |
| -from __future__ import annotations |
2 |
| - |
3 |
| -from typing import Sequence, overload |
4 |
| -from urllib.parse import quote |
5 |
| - |
6 |
| -from cognite.client._api_client import APIClient |
7 |
| -from cognite.client.data_classes import Project, ProjectList, ProjectUpdate, ProjectURLNameList, ProjectWrite |
8 |
| - |
9 |
| - |
10 |
| -class ProjectsAPI(APIClient): |
11 |
| - _RESOURCE_PATH = "/projects" |
12 |
| - |
13 |
| - @overload |
14 |
| - def create(self, item: ProjectWrite) -> Project: |
15 |
| - ... |
16 |
| - |
17 |
| - @overload |
18 |
| - def create(self, item: Sequence[ProjectWrite]) -> ProjectList: |
19 |
| - ... |
20 |
| - |
21 |
| - def create(self, item: ProjectWrite | Sequence[ProjectWrite]) -> Project | ProjectList: |
22 |
| - """`Create a project <https://developer.cognite.com/api#tag/Projects/operation/createProject>`_""" |
23 |
| - return self._create_multiple(item, list_cls=ProjectList, resource_cls=Project, input_resource_cls=ProjectWrite) |
24 |
| - |
25 |
| - def retrieve(self, project: str) -> Project: |
26 |
| - """`Retrieve a project <https://developer.cognite.com/api#tag/Projects/operation/getProject>`_""" |
27 |
| - item = self._get(f"{self._RESOURCE_PATH}/{quote(project, '')}") |
28 |
| - return Project._load(item.json(), cognite_client=self._cognite_client) |
29 |
| - |
30 |
| - def update(self, item: ProjectUpdate) -> Project: |
31 |
| - """`Update a project <https://developer.cognite.com/api#tag/Projects/operation/updateProject>`_""" |
32 |
| - project = item._project |
33 |
| - response = self._post( |
34 |
| - url_path=f"{self._RESOURCE_PATH}/{quote(project, '')}/update", json=item.dump(camel_case=True) |
35 |
| - ) |
36 |
| - return Project._load(response.json(), cognite_client=self._cognite_client) |
37 |
| - |
38 |
| - def list(self) -> ProjectURLNameList: |
39 |
| - """`List all projects <https://developer.cognite.com/api#tag/Projects/operation/listProjects>`_""" |
40 |
| - items = self._get(self._RESOURCE_PATH) |
41 |
| - return ProjectURLNameList.load(items.json(), cognite_client=self._cognite_client) |
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from typing import Sequence, overload |
| 4 | +from urllib.parse import quote |
| 5 | + |
| 6 | +from cognite.client._api_client import APIClient |
| 7 | +from cognite.client.data_classes import Project, ProjectList, ProjectUpdate, ProjectURLNameList, ProjectWrite |
| 8 | + |
| 9 | + |
| 10 | +class ProjectsAPI(APIClient): |
| 11 | + _RESOURCE_PATH = "/projects" |
| 12 | + |
| 13 | + @overload |
| 14 | + def create(self, item: ProjectWrite) -> Project: |
| 15 | + ... |
| 16 | + |
| 17 | + @overload |
| 18 | + def create(self, item: Sequence[ProjectWrite]) -> ProjectList: |
| 19 | + ... |
| 20 | + |
| 21 | + def create(self, item: ProjectWrite | Sequence[ProjectWrite]) -> Project | ProjectList: |
| 22 | + """`Create a project <https://developer.cognite.com/api#tag/Projects/operation/createProject>`_ |
| 23 | +
|
| 24 | + Args: |
| 25 | + item (ProjectWrite | Sequence[ProjectWrite]): Project(s) to create |
| 26 | +
|
| 27 | + Returns: |
| 28 | + Project | ProjectList: Created project(s) |
| 29 | +
|
| 30 | + Examples: |
| 31 | + Create a new project with the name "my project" |
| 32 | +
|
| 33 | + >>> from cognite.client import CogniteClient |
| 34 | + >>> from cognite.client.data_classes import ProjectWrite |
| 35 | + >>> c = CogniteClient() |
| 36 | + >>> project = ProjectWrite(name="my project", url_name="my-project", parent_project_url_name="root") |
| 37 | + >>> res = c.iam.projects.create(project) |
| 38 | + """ |
| 39 | + return self._create_multiple(item, list_cls=ProjectList, resource_cls=Project, input_resource_cls=ProjectWrite) |
| 40 | + |
| 41 | + def retrieve(self, project: str) -> Project: |
| 42 | + """`Retrieve a project <https://developer.cognite.com/api#tag/Projects/operation/getProject>`_ |
| 43 | +
|
| 44 | + Args: |
| 45 | + project (str): Project to retrieve |
| 46 | +
|
| 47 | + Returns: |
| 48 | + Project: The requested project |
| 49 | +
|
| 50 | + Examples: |
| 51 | +
|
| 52 | + Retrieve the project with the name "publicdata" |
| 53 | +
|
| 54 | + >>> from cognite.client import CogniteClient |
| 55 | + >>> c = CogniteClient() |
| 56 | + >>> res = c.iam.projects.retrieve("publicdata") |
| 57 | + """ |
| 58 | + item = self._get(f"{self._RESOURCE_PATH}/{quote(project, '')}") |
| 59 | + return Project._load(item.json(), cognite_client=self._cognite_client) |
| 60 | + |
| 61 | + def update(self, item: ProjectUpdate) -> Project: |
| 62 | + """`Update a project <https://developer.cognite.com/api#tag/Projects/operation/updateProject>`_ |
| 63 | +
|
| 64 | + Args: |
| 65 | + item (ProjectUpdate): Project to update |
| 66 | +
|
| 67 | + Returns: |
| 68 | + Project: Updated project |
| 69 | +
|
| 70 | + Examples: |
| 71 | +
|
| 72 | + >>> from cognite.client import CogniteClient |
| 73 | + >>> from cognite.client.data_classes import ProjectUpdate |
| 74 | + >>> c = CogniteClient() |
| 75 | + >>> my_update = ProjectUpdate("my_project").name.set("new name").oidc_configuration.modify.skew_ms.set(100) |
| 76 | + >>> res = c.iam.projects.update(my_update) |
| 77 | + """ |
| 78 | + project = item._project |
| 79 | + response = self._post( |
| 80 | + url_path=f"{self._RESOURCE_PATH}/{quote(project, '')}/update", json=item.dump(camel_case=True) |
| 81 | + ) |
| 82 | + return Project._load(response.json(), cognite_client=self._cognite_client) |
| 83 | + |
| 84 | + def list(self) -> ProjectURLNameList: |
| 85 | + """`List all projects <https://developer.cognite.com/api#tag/Projects/operation/listProjects>`_ |
| 86 | +
|
| 87 | + Returns: |
| 88 | + ProjectURLNameList: List of project URL names |
| 89 | +
|
| 90 | + Examples: |
| 91 | +
|
| 92 | + List all projects |
| 93 | +
|
| 94 | + >>> from cognite.client import CogniteClient |
| 95 | + >>> c = CogniteClient() |
| 96 | + >>> res = c.iam.projects.list() |
| 97 | + """ |
| 98 | + items = self._get(self._RESOURCE_PATH) |
| 99 | + return ProjectURLNameList.load(items.json(), cognite_client=self._cognite_client) |
0 commit comments