exonetapi 5.0.0__tar.gz → 6.0.0__tar.gz

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 (24) hide show
  1. {exonetapi-5.0.0 → exonetapi-6.0.0}/PKG-INFO +36 -35
  2. {exonetapi-5.0.0 → exonetapi-6.0.0}/README.md +22 -22
  3. {exonetapi-5.0.0 → exonetapi-6.0.0}/exonetapi/Client.py +19 -15
  4. {exonetapi-5.0.0 → exonetapi-6.0.0}/exonetapi/RequestBuilder.py +63 -39
  5. {exonetapi-5.0.0 → exonetapi-6.0.0}/exonetapi/__init__.py +2 -2
  6. {exonetapi-5.0.0 → exonetapi-6.0.0}/exonetapi/auth/Authenticator.py +13 -13
  7. {exonetapi-5.0.0 → exonetapi-6.0.0}/exonetapi/create_resource.py +5 -1
  8. {exonetapi-5.0.0 → exonetapi-6.0.0}/exonetapi/exceptions/ValidationException.py +13 -6
  9. {exonetapi-5.0.0 → exonetapi-6.0.0}/exonetapi/result/Parser.py +34 -23
  10. {exonetapi-5.0.0 → exonetapi-6.0.0}/exonetapi/structures/ApiResource.py +28 -20
  11. {exonetapi-5.0.0 → exonetapi-6.0.0}/exonetapi/structures/ApiResourceIdentifier.py +45 -30
  12. exonetapi-6.0.0/exonetapi/structures/ApiResourceSet.py +91 -0
  13. exonetapi-6.0.0/exonetapi/structures/Relation.py +76 -0
  14. {exonetapi-5.0.0 → exonetapi-6.0.0}/exonetapi/structures/Relationship.py +1 -0
  15. exonetapi-6.0.0/pyproject.toml +113 -0
  16. exonetapi-6.0.0/pyproject.toml.orig +100 -0
  17. exonetapi-5.0.0/exonetapi/structures/ApiResourceSet.py +0 -76
  18. exonetapi-5.0.0/exonetapi/structures/Relation.py +0 -55
  19. exonetapi-5.0.0/pyproject.toml +0 -48
  20. {exonetapi-5.0.0 → exonetapi-6.0.0}/LICENSE.md +0 -0
  21. {exonetapi-5.0.0 → exonetapi-6.0.0}/exonetapi/auth/__init__.py +0 -0
  22. {exonetapi-5.0.0 → exonetapi-6.0.0}/exonetapi/exceptions/__init__.py +0 -0
  23. {exonetapi-5.0.0 → exonetapi-6.0.0}/exonetapi/result/__init__.py +0 -0
  24. {exonetapi-5.0.0 → exonetapi-6.0.0}/exonetapi/structures/__init__.py +0 -0
@@ -1,27 +1,29 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.4
2
2
  Name: exonetapi
3
- Version: 5.0.0
3
+ Version: 6.0.0
4
4
  Summary: Library to interact with the Exonet API.
5
- License: MIT
6
5
  Keywords: async,client,exonet,exonetapi
7
6
  Author: Exonet
8
- Author-email: development@exonet.nl
9
- Maintainer: Exonet
10
- Maintainer-email: development@exonet.nl
11
- Requires-Python: >=3.9
7
+ Author-email: Exonet <development@exonet.nl>
8
+ License-Expression: MIT
9
+ License-File: LICENSE.md
12
10
  Classifier: Development Status :: 4 - Beta
13
11
  Classifier: Intended Audience :: Developers
14
- Classifier: License :: OSI Approved :: MIT License
15
12
  Classifier: Natural Language :: English
16
- Classifier: Programming Language :: Python :: 3.9
17
- Classifier: Programming Language :: Python :: 3.10
18
13
  Classifier: Programming Language :: Python :: 3.11
19
14
  Classifier: Programming Language :: Python :: 3.12
20
15
  Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Programming Language :: Python :: 3.14
21
17
  Classifier: Programming Language :: Python :: 3
22
18
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
- Requires-Dist: inflection (==0.5.1)
24
- Requires-Dist: requests (==2.32.3)
19
+ Requires-Dist: inflection>=0.5.1,<0.6
20
+ Requires-Dist: requests>=2.33.0,<3
21
+ Maintainer: Exonet
22
+ Maintainer-email: Exonet <development@exonet.nl>
23
+ Requires-Python: >=3.11
24
+ Project-URL: Homepage, https://github.com/exonet/exonet-api-python
25
+ Project-URL: Repository, https://github.com/exonet/exonet-api-python
26
+ Project-URL: Documentation, https://github.com/exonet/exonet-api-python
25
27
  Description-Content-Type: text/markdown
26
28
 
27
29
  # exonetapi
@@ -45,18 +47,16 @@ Example to get the user details of the authorised user:
45
47
  from exonetapi import Client
46
48
 
47
49
  # Create a new Client.
48
- client = Client('https://api.exonet.nl')
50
+ client = Client("https://api.exonet.nl")
49
51
 
50
52
  # Authorize with a personal access token.
51
- client.authenticator.set_token('<YOUR_TOKEN>')
53
+ client.authenticator.set_token("<YOUR_TOKEN>")
52
54
 
53
55
  # Make an API call. Get details of the authorized user.
54
- user_details = client.resource('me').get()
56
+ user_details = client.resource("me").get()
55
57
 
56
58
  # Print user's name.
57
- print('Autorized as: {name}'.format(
58
- name=user_details.attribute('name')
59
- ))
59
+ print("Autorized as: {name}".format(name=user_details.attribute("name")))
60
60
  ```
61
61
 
62
62
  See the `/docs` directory for complete documentation and additional code snippets.
@@ -103,40 +103,42 @@ Even better: You could submit a pull request with a fix / new feature!
103
103
 
104
104
  ## Setting up development environment
105
105
 
106
- This Python project is fully managed using the [Poetry][poetry] dependency
107
- manager.
106
+ This Python project is fully managed using the [uv][uv] package manager.
108
107
 
109
108
  You need at least:
110
109
 
111
- - Python 3.9+
112
- - [Poetry][poetry-install]
110
+ - Python 3.11+
111
+ - [uv][uv-install]
113
112
 
114
113
  Install all packages, including all development requirements:
115
114
 
116
115
  ```bash
117
- poetry install
116
+ uv sync
118
117
  ```
119
118
 
120
- Poetry creates by default an virtual environment where it installs all
121
- necessary pip packages, to enter or exit the venv run the following commands:
122
-
123
- ```bash
124
- poetry shell
125
- exit
126
- ```
119
+ uv creates a virtual environment in `.venv` and installs all packages in it.
120
+ `uv run` runs a command inside that environment, so there is no need to
121
+ activate it.
127
122
 
128
123
  *Now you're all set to get started!*
129
124
 
130
125
  To run the Python tests:
131
126
 
132
127
  ```bash
133
- poetry run pytest
128
+ uv run pytest
134
129
  ```
135
130
 
136
131
  To run the bandit checks:
137
132
 
138
133
  ```bash
139
- poetry run bandit
134
+ uv run bandit -r exonetapi
135
+ ```
136
+
137
+ To lint and format the code:
138
+
139
+ ```bash
140
+ uv run ruff check .
141
+ uv run ruff format .
140
142
  ```
141
143
 
142
144
 
@@ -168,7 +170,6 @@ of using the issue tracker.
168
170
  [link-releases]: https://github.com/exonet/exonet-api-python/releases
169
171
  [link-contributors]: ../../contributors
170
172
 
171
- [poetry-install]: https://python-poetry.org/docs/#installation
172
- [poetry]: https://python-poetry.org
173
+ [uv-install]: https://docs.astral.sh/uv/getting-started/installation/
174
+ [uv]: https://docs.astral.sh/uv/
173
175
  [pre-commit]: https://pre-commit.com
174
-
@@ -19,18 +19,16 @@ Example to get the user details of the authorised user:
19
19
  from exonetapi import Client
20
20
 
21
21
  # Create a new Client.
22
- client = Client('https://api.exonet.nl')
22
+ client = Client("https://api.exonet.nl")
23
23
 
24
24
  # Authorize with a personal access token.
25
- client.authenticator.set_token('<YOUR_TOKEN>')
25
+ client.authenticator.set_token("<YOUR_TOKEN>")
26
26
 
27
27
  # Make an API call. Get details of the authorized user.
28
- user_details = client.resource('me').get()
28
+ user_details = client.resource("me").get()
29
29
 
30
30
  # Print user's name.
31
- print('Autorized as: {name}'.format(
32
- name=user_details.attribute('name')
33
- ))
31
+ print("Autorized as: {name}".format(name=user_details.attribute("name")))
34
32
  ```
35
33
 
36
34
  See the `/docs` directory for complete documentation and additional code snippets.
@@ -77,40 +75,42 @@ Even better: You could submit a pull request with a fix / new feature!
77
75
 
78
76
  ## Setting up development environment
79
77
 
80
- This Python project is fully managed using the [Poetry][poetry] dependency
81
- manager.
78
+ This Python project is fully managed using the [uv][uv] package manager.
82
79
 
83
80
  You need at least:
84
81
 
85
- - Python 3.9+
86
- - [Poetry][poetry-install]
82
+ - Python 3.11+
83
+ - [uv][uv-install]
87
84
 
88
85
  Install all packages, including all development requirements:
89
86
 
90
87
  ```bash
91
- poetry install
88
+ uv sync
92
89
  ```
93
90
 
94
- Poetry creates by default an virtual environment where it installs all
95
- necessary pip packages, to enter or exit the venv run the following commands:
96
-
97
- ```bash
98
- poetry shell
99
- exit
100
- ```
91
+ uv creates a virtual environment in `.venv` and installs all packages in it.
92
+ `uv run` runs a command inside that environment, so there is no need to
93
+ activate it.
101
94
 
102
95
  *Now you're all set to get started!*
103
96
 
104
97
  To run the Python tests:
105
98
 
106
99
  ```bash
107
- poetry run pytest
100
+ uv run pytest
108
101
  ```
109
102
 
110
103
  To run the bandit checks:
111
104
 
112
105
  ```bash
113
- poetry run bandit
106
+ uv run bandit -r exonetapi
107
+ ```
108
+
109
+ To lint and format the code:
110
+
111
+ ```bash
112
+ uv run ruff check .
113
+ uv run ruff format .
114
114
  ```
115
115
 
116
116
 
@@ -142,6 +142,6 @@ of using the issue tracker.
142
142
  [link-releases]: https://github.com/exonet/exonet-api-python/releases
143
143
  [link-contributors]: ../../contributors
144
144
 
145
- [poetry-install]: https://python-poetry.org/docs/#installation
146
- [poetry]: https://python-poetry.org
145
+ [uv-install]: https://docs.astral.sh/uv/getting-started/installation/
146
+ [uv]: https://docs.astral.sh/uv/
147
147
  [pre-commit]: https://pre-commit.com
@@ -1,17 +1,21 @@
1
- """
2
- Main class to interact with the Exonet API.
3
- """
1
+ """Main class to interact with the Exonet API."""
2
+
3
+ from typing import Any, ClassVar
4
+ from urllib.parse import urlparse
5
+
4
6
  from .auth import Authenticator
5
7
  from .RequestBuilder import RequestBuilder
6
- from urllib.parse import urlparse
7
8
 
8
9
 
9
10
  class Singleton(type):
10
- _instances = {}
11
+ """Metaclass that gives every class using it a single shared instance."""
11
12
 
12
- def __call__(cls, *args, **kwargs):
13
+ _instances: ClassVar[dict[type, Any]] = {}
14
+
15
+ def __call__(cls, *args: Any, **kwargs: Any) -> Any:
16
+ """Return the existing instance, or create it on the first call."""
13
17
  if cls not in cls._instances:
14
- cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
18
+ cls._instances[cls] = super().__call__(*args, **kwargs)
15
19
  return cls._instances[cls]
16
20
 
17
21
 
@@ -24,7 +28,7 @@ class Client(metaclass=Singleton):
24
28
  # The URL to use for authentication.
25
29
  authentication_endpoint = "/oauth/token"
26
30
 
27
- def __init__(self, host=None):
31
+ def __init__(self, host: str | None = None) -> None:
28
32
  self.__host = "https://api.exonet.nl"
29
33
 
30
34
  if host:
@@ -34,26 +38,26 @@ class Client(metaclass=Singleton):
34
38
  self.get_host(), self.authentication_endpoint
35
39
  )
36
40
 
37
- def set_host(self, host):
38
- """
39
- Set the API host.
41
+ def set_host(self, host: str) -> None:
42
+ """Set the API host.
43
+
40
44
  Make sure a protocol is set.
41
45
 
42
46
  :param host: The API host including the http(s) protocol.
43
- :return: The parsed API host.
44
47
  """
45
48
  parsed_host = urlparse(host)
46
49
 
47
50
  # Make sure the host uses a valid scheme.
48
51
  if parsed_host.scheme not in ("http", "https"):
49
- raise ConnectionAbortedError("Invalid protocol for host: %s" % host)
52
+ message = f"Invalid protocol for host: {host}"
53
+ raise ConnectionAbortedError(message)
50
54
 
51
55
  self.__host = parsed_host.geturl()
52
56
 
53
- def get_host(self):
57
+ def get_host(self) -> str:
54
58
  return self.__host
55
59
 
56
- def resource(self, resource):
60
+ def resource(self, resource: str) -> RequestBuilder:
57
61
  """Prepare a new request to a resource endpoint.
58
62
 
59
63
  :param resource: The type of resource.
@@ -1,17 +1,27 @@
1
- """
2
- Build requests to send to the API.
3
- """
1
+ """Build requests to send to the API."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import TYPE_CHECKING, Any, Self
6
+
4
7
  import requests
5
8
 
6
- from exonetapi.structures import ApiResourceSet
7
9
  from exonetapi.exceptions.ValidationException import ValidationException
8
- from .result import Parser
10
+ from exonetapi.structures.ApiResourceSet import ApiResourceSet
11
+
12
+ from .result.Parser import Parser
9
13
 
14
+ if TYPE_CHECKING:
15
+ from exonetapi.Client import Client
16
+ from exonetapi.structures.ApiResource import ApiResource
10
17
 
11
- class RequestBuilder(object):
18
+
19
+ class RequestBuilder:
12
20
  """Create and make requests to the API."""
13
21
 
14
- def __init__(self, resource=None, client=None):
22
+ def __init__(
23
+ self, resource: str | None = None, client: Client | None = None
24
+ ) -> None:
15
25
  if resource is not None and not resource.startswith("/"):
16
26
  resource = "/" + resource
17
27
 
@@ -20,17 +30,19 @@ class RequestBuilder(object):
20
30
  The query params that will be used in the GET requests.
21
31
  Can contain filters and page options.
22
32
  """
23
- self.__query_params = {}
33
+ self.__query_params: dict[str, Any] = {}
24
34
 
25
35
  if client:
26
36
  self.__client = client
27
37
  elif not hasattr(self, "__client"):
28
- from exonetapi import Client
38
+ # Client imports this module, so it can only be imported here.
39
+ from exonetapi import Client # noqa: PLC0415
29
40
 
30
41
  self.__client = Client()
31
42
 
32
- def filter(self, filter_name, filter_value):
43
+ def filter(self, filter_name: str, filter_value: Any) -> Self:
33
44
  """Prepare this RequestBuilder to apply a filter on the next get request.
45
+
34
46
  :param filter_name: The name of the filter to apply.
35
47
  :param filter_value: The value of the applied filter.
36
48
  :return: self
@@ -38,24 +50,27 @@ class RequestBuilder(object):
38
50
  self.__query_params["filter[" + filter_name + "]"] = filter_value
39
51
  return self
40
52
 
41
- def page(self, page_number):
53
+ def page(self, page_number: int) -> Self:
42
54
  """Prepare this RequestBuilder to get a specific page.
55
+
43
56
  :param page_number: The page number.
44
57
  :return: self
45
58
  """
46
59
  self.__query_params["page[number]"] = page_number
47
60
  return self
48
61
 
49
- def size(self, page_size):
62
+ def size(self, page_size: int) -> Self:
50
63
  """Prepare this RequestBuilder to apply a page size limit.
64
+
51
65
  :param page_size: The maximum number of returned resources.
52
66
  :return: self
53
67
  """
54
68
  self.__query_params["page[size]"] = page_size
55
69
  return self
56
70
 
57
- def sort(self, sort_field, sort_order="asc"):
71
+ def sort(self, sort_field: str, sort_order: str = "asc") -> Self:
58
72
  """Prepare this RequestBuilder to sort by a field.
73
+
59
74
  :param sort_field: The field name to sort on.
60
75
  :param sort_order: The order for sorting (asc/desc), default: asc.
61
76
  :return: self
@@ -69,26 +84,28 @@ class RequestBuilder(object):
69
84
  )
70
85
  return self
71
86
 
72
- def sort_asc(self, sort_field):
87
+ def sort_asc(self, sort_field: str) -> Self:
73
88
  """Prepare this RequestBuilder to sort by a field in ascending order.
89
+
74
90
  :param sort_field: The field name to sort on.
75
91
  :return: self
76
92
  """
77
93
  return self.sort(sort_field, "asc")
78
94
 
79
- def sort_desc(self, sort_field):
95
+ def sort_desc(self, sort_field: str) -> Self:
80
96
  """Prepare this RequestBuilder to sort by a field in descending order.
97
+
81
98
  :param sort_field: The field name to sort on.
82
99
  :return: self
83
100
  """
84
101
  return self.sort(sort_field, "desc")
85
102
 
86
- def get(self, identifier=None):
103
+ def get(self, identifier: str | None = None) -> ApiResource | ApiResourceSet:
87
104
  """Make a call to the API using the previously set options.
105
+
88
106
  :param: identifier The optional identifier to get.
89
107
  :return: A Resource or a Collection of Resources.
90
108
  """
91
-
92
109
  response = self.__make_call(
93
110
  "GET",
94
111
  self.__build_url(identifier),
@@ -97,10 +114,12 @@ class RequestBuilder(object):
97
114
 
98
115
  return Parser(response.content).parse()
99
116
 
100
- def get_recursive(self):
117
+ def get_recursive(self) -> ApiResourceSet:
101
118
  return self.__get_recursive()
102
119
 
103
- def post(self, resource):
120
+ def post(
121
+ self, resource: ApiResource
122
+ ) -> ApiResource | ApiResourceSet | list[ApiResource | ApiResourceSet] | None:
104
123
  """Make a POST request to the API with the provided resource as data.
105
124
 
106
125
  :param resource: The resource to use as POST data.
@@ -124,16 +143,16 @@ class RequestBuilder(object):
124
143
  for relation_name in changed_relations:
125
144
  response = self.__make_call(
126
145
  "POST",
127
- "{}/relationships/{}".format(
128
- self.__build_url(resource.id()), relation_name
129
- ),
146
+ f"{self.__build_url(resource.id())}/relationships/{relation_name}",
130
147
  changed_relations[relation_name],
131
148
  )
132
149
  responses.append(Parser(response.content).parse())
133
150
 
134
151
  return responses
135
152
 
136
- def patch(self, resource):
153
+ return None
154
+
155
+ def patch(self, resource: ApiResource) -> bool:
137
156
  changed_attributes = resource.to_json_changed_attributes()
138
157
  changed_relations = resource.get_json_changed_relationships()
139
158
 
@@ -148,15 +167,13 @@ class RequestBuilder(object):
148
167
  for relation_name in changed_relations:
149
168
  self.__make_call(
150
169
  "PATCH",
151
- "{}/relationships/{}".format(
152
- self.__build_url(resource.id()), relation_name
153
- ),
170
+ f"{self.__build_url(resource.id())}/relationships/{relation_name}",
154
171
  changed_relations[relation_name],
155
172
  )
156
173
 
157
174
  return True
158
175
 
159
- def delete(self, resource):
176
+ def delete(self, resource: ApiResource) -> bool:
160
177
  changed_relations = resource.get_json_changed_relationships()
161
178
 
162
179
  # If no relations are changed, DELETE the whole resource.
@@ -168,15 +185,13 @@ class RequestBuilder(object):
168
185
  for relation_name in changed_relations:
169
186
  self.__make_call(
170
187
  "DELETE",
171
- "{}/relationships/{}".format(
172
- self.__build_url(resource.id()), relation_name
173
- ),
188
+ f"{self.__build_url(resource.id())}/relationships/{relation_name}",
174
189
  changed_relations[relation_name],
175
190
  )
176
191
 
177
192
  return True
178
193
 
179
- def __build_url(self, identifier=None):
194
+ def __build_url(self, identifier: str | None = None) -> str:
180
195
  """Get the URL to call, based on all previously called setter methods.
181
196
 
182
197
  :return: A URL.
@@ -191,7 +206,7 @@ class RequestBuilder(object):
191
206
 
192
207
  return url
193
208
 
194
- def __get_headers(self):
209
+ def __get_headers(self) -> dict[str, str]:
195
210
  """Get the required headers to make an API request.
196
211
 
197
212
  :return: A dict with all the headers.
@@ -199,11 +214,18 @@ class RequestBuilder(object):
199
214
  return {
200
215
  "Accept": "application/vnd.Exonet.v1+json",
201
216
  "Content-Type": "application/json",
202
- "Authorization": "Bearer %s" % (self.__client.authenticator.get_token()),
217
+ "Authorization": f"Bearer {self.__client.authenticator.get_token()}",
203
218
  }
204
219
 
205
- def __make_call(self, method, url, json_data=None, params=None):
206
- response = requests.request(
220
+ def __make_call(
221
+ self,
222
+ method: str,
223
+ url: str,
224
+ json_data: dict[str, Any] | None = None,
225
+ params: dict[str, Any] | None = None,
226
+ ) -> requests.Response:
227
+ # A timeout here would change how long callers wait, so none is set.
228
+ response = requests.request( # noqa: S113
207
229
  method, url, headers=self.__get_headers(), json=json_data, params=params
208
230
  )
209
231
 
@@ -216,10 +238,12 @@ class RequestBuilder(object):
216
238
 
217
239
  return response
218
240
 
219
- def __get_recursive(self, data=None, url=None):
220
- """
221
- Get the URL and call this method recursivly as long as there is an URL in the
222
- 'next' field of the 'links' data.
241
+ def __get_recursive(
242
+ self, data: ApiResourceSet | None = None, url: str | None = None
243
+ ) -> ApiResourceSet:
244
+ """Get the URL and call this method recursively while there is a next link.
245
+
246
+ Follows the URL in the 'next' field of the 'links' data.
223
247
 
224
248
  :param data: The ApiResourceSet to append the resources to.
225
249
  :param url: The URL to call.
@@ -1,6 +1,6 @@
1
1
  from .Client import Client
2
+ from .create_resource import create_resource
2
3
  from .RequestBuilder import RequestBuilder
3
4
  from .result import Parser
4
- from .create_resource import create_resource
5
5
 
6
- __all__ = ["Client", "RequestBuilder", "Parser", "create_resource"]
6
+ __all__ = ["Client", "Parser", "RequestBuilder", "create_resource"]
@@ -1,28 +1,28 @@
1
- """
2
- Obtain tokens and keep track of authentication details.
3
- """
1
+ """Obtain tokens and keep track of authentication details."""
2
+
4
3
  import requests
5
4
 
6
5
 
7
6
  class Authenticator:
8
- """
9
- Manage the authentication and keep track of (valid) tokens.
10
- """
7
+ """Manage the authentication and keep track of (valid) tokens."""
11
8
 
12
- def __init__(self, host, authentication_endpoint):
9
+ def __init__(self, host: str, authentication_endpoint: str) -> None:
13
10
  self.__host = host
14
11
  self.__authentication_endpoint = authentication_endpoint
15
- self.__auth_details = None
12
+ self.__auth_details: dict[str, str] | None = None
16
13
 
17
- def get_token(self):
14
+ def get_token(self) -> str | None:
18
15
  """Get the obtained authentication token.
19
16
 
20
17
  :return: The token if available.
21
18
  """
22
19
  if self.__auth_details:
23
20
  return self.__auth_details["access_token"].strip()
21
+ return None
24
22
 
25
- def password_auth(self, username, password, client_id, client_secret):
23
+ def password_auth(
24
+ self, username: str, password: str, client_id: str, client_secret: str
25
+ ) -> None:
26
26
  """Authorize using the password grant.
27
27
 
28
28
  :param username: The username.
@@ -41,7 +41,7 @@ class Authenticator:
41
41
  }
42
42
  )
43
43
 
44
- def set_token(self, token):
44
+ def set_token(self, token: str) -> None:
45
45
  """Set a token to use when authorizing.
46
46
 
47
47
  This bypasses any calls to the authorization endpoint, but instead uses the
@@ -52,7 +52,7 @@ class Authenticator:
52
52
  """
53
53
  self.__auth_details = {"access_token": token}
54
54
 
55
- def get_new_token(self, payload):
55
+ def get_new_token(self, payload: dict[str, str]) -> str:
56
56
  """Get a new token via the authorization endpoint.
57
57
 
58
58
  :param payload:
@@ -64,7 +64,7 @@ class Authenticator:
64
64
  self.__host + self.__authentication_endpoint,
65
65
  headers=headers,
66
66
  data=payload,
67
- timeout=30
67
+ timeout=30,
68
68
  )
69
69
 
70
70
  # Raise exception on failed request.
@@ -1,9 +1,13 @@
1
+ from typing import Any
2
+
1
3
  from inflection import camelize
4
+
2
5
  from .structures.ApiResource import ApiResource
3
6
 
4
7
 
5
- def create_resource(resource):
8
+ def create_resource(resource: dict[str, Any]) -> ApiResource:
6
9
  """Create a dynamic Resource based on the type that is provided in the data.
10
+
7
11
  :param resource: The resource.
8
12
  :return: A Resource instance.
9
13
  """
@@ -1,14 +1,21 @@
1
+ """Http validation exception."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import TYPE_CHECKING
6
+
1
7
  from requests.exceptions import HTTPError
2
8
 
3
- """
4
- Http validation exception.
5
- """
9
+ if TYPE_CHECKING:
10
+ from requests import Response
6
11
 
7
12
 
8
13
  class ValidationException(HTTPError):
9
- def __init__(self, response):
14
+ """Raised when the API rejects a request because its data is invalid."""
15
+
16
+ def __init__(self, response: Response) -> None:
10
17
  # Collect validation errors as list of strings.
11
- self.validation_errors = {}
18
+ self.validation_errors: dict[str, list[str]] = {}
12
19
 
13
20
  # Loop errors.
14
21
  for error in response.json()["errors"]:
@@ -34,5 +41,5 @@ class ValidationException(HTTPError):
34
41
  response=response,
35
42
  )
36
43
 
37
- def get_failed_validations(self):
44
+ def get_failed_validations(self) -> dict[str, list[str]]:
38
45
  return self.validation_errors