exonetapi 3.0.3__tar.gz → 5.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 (42) hide show
  1. exonetapi-5.0.0/LICENSE.md +21 -0
  2. exonetapi-5.0.0/PKG-INFO +174 -0
  3. exonetapi-5.0.0/README.md +147 -0
  4. {exonetapi-3.0.3 → exonetapi-5.0.0}/exonetapi/Client.py +7 -5
  5. {exonetapi-3.0.3 → exonetapi-5.0.0}/exonetapi/RequestBuilder.py +48 -45
  6. {exonetapi-3.0.3 → exonetapi-5.0.0}/exonetapi/__init__.py +2 -0
  7. {exonetapi-3.0.3 → exonetapi-5.0.0}/exonetapi/auth/Authenticator.py +17 -15
  8. {exonetapi-3.0.3 → exonetapi-5.0.0}/exonetapi/auth/__init__.py +2 -0
  9. {exonetapi-3.0.3 → exonetapi-5.0.0}/exonetapi/create_resource.py +1 -2
  10. exonetapi-5.0.0/exonetapi/exceptions/ValidationException.py +38 -0
  11. {exonetapi-3.0.3 → exonetapi-5.0.0}/exonetapi/exceptions/__init__.py +2 -0
  12. {exonetapi-3.0.3 → exonetapi-5.0.0}/exonetapi/result/Parser.py +22 -22
  13. {exonetapi-3.0.3 → exonetapi-5.0.0}/exonetapi/result/__init__.py +2 -0
  14. {exonetapi-3.0.3 → exonetapi-5.0.0}/exonetapi/structures/ApiResource.py +14 -15
  15. {exonetapi-3.0.3 → exonetapi-5.0.0}/exonetapi/structures/ApiResourceIdentifier.py +25 -17
  16. {exonetapi-3.0.3 → exonetapi-5.0.0}/exonetapi/structures/ApiResourceSet.py +6 -6
  17. {exonetapi-3.0.3 → exonetapi-5.0.0}/exonetapi/structures/Relation.py +8 -4
  18. {exonetapi-3.0.3 → exonetapi-5.0.0}/exonetapi/structures/Relationship.py +1 -1
  19. exonetapi-5.0.0/exonetapi/structures/__init__.py +13 -0
  20. exonetapi-5.0.0/pyproject.toml +48 -0
  21. exonetapi-3.0.3/PKG-INFO +0 -98
  22. exonetapi-3.0.3/README.rst +0 -80
  23. exonetapi-3.0.3/exonetapi/exceptions/ValidationException.py +0 -35
  24. exonetapi-3.0.3/exonetapi/structures/__init__.py +0 -3
  25. exonetapi-3.0.3/exonetapi.egg-info/PKG-INFO +0 -98
  26. exonetapi-3.0.3/exonetapi.egg-info/SOURCES.txt +0 -35
  27. exonetapi-3.0.3/exonetapi.egg-info/dependency_links.txt +0 -1
  28. exonetapi-3.0.3/exonetapi.egg-info/requires.txt +0 -2
  29. exonetapi-3.0.3/exonetapi.egg-info/top_level.txt +0 -2
  30. exonetapi-3.0.3/setup.cfg +0 -9
  31. exonetapi-3.0.3/setup.py +0 -49
  32. exonetapi-3.0.3/tests/auth/__init__.py +0 -0
  33. exonetapi-3.0.3/tests/auth/testAuthenticator.py +0 -70
  34. exonetapi-3.0.3/tests/exceptions/__init__.py +0 -0
  35. exonetapi-3.0.3/tests/exceptions/testValidationException.py +0 -117
  36. exonetapi-3.0.3/tests/result/__init__.py +0 -0
  37. exonetapi-3.0.3/tests/result/testParser.py +0 -167
  38. exonetapi-3.0.3/tests/structures/__init__.py +0 -0
  39. exonetapi-3.0.3/tests/structures/testApiResource.py +0 -170
  40. exonetapi-3.0.3/tests/structures/testApiResourceIdentifier.py +0 -160
  41. exonetapi-3.0.3/tests/structures/testApiResourceSet.py +0 -73
  42. exonetapi-3.0.3/tests/structures/testRelation.py +0 -34
@@ -0,0 +1,21 @@
1
+ # The MIT License (MIT)
2
+
3
+ Copyright (c) 2020-2023 Exonet BV
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,174 @@
1
+ Metadata-Version: 2.3
2
+ Name: exonetapi
3
+ Version: 5.0.0
4
+ Summary: Library to interact with the Exonet API.
5
+ License: MIT
6
+ Keywords: async,client,exonet,exonetapi
7
+ Author: Exonet
8
+ Author-email: development@exonet.nl
9
+ Maintainer: Exonet
10
+ Maintainer-email: development@exonet.nl
11
+ Requires-Python: >=3.9
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Natural Language :: English
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Programming Language :: Python :: 3
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Requires-Dist: inflection (==0.5.1)
24
+ Requires-Dist: requests (==2.32.3)
25
+ Description-Content-Type: text/markdown
26
+
27
+ # exonetapi
28
+ Python 3 library for the Exonet API.
29
+
30
+ [![Latest Version on Packagist][ico-version]][link-pypi]
31
+ [![Python Versions][ico-pyversions]][link-pypi]
32
+ [![Software License][ico-license]](LICENSE.md)
33
+
34
+ ## Install
35
+ Install using pip:
36
+
37
+ ```bash
38
+ pip install exonetapi
39
+ ```
40
+
41
+ ## Usage
42
+ Example to get the user details of the authorised user:
43
+
44
+ ```py
45
+ from exonetapi import Client
46
+
47
+ # Create a new Client.
48
+ client = Client('https://api.exonet.nl')
49
+
50
+ # Authorize with a personal access token.
51
+ client.authenticator.set_token('<YOUR_TOKEN>')
52
+
53
+ # Make an API call. Get details of the authorized user.
54
+ user_details = client.resource('me').get()
55
+
56
+ # Print user's name.
57
+ print('Autorized as: {name}'.format(
58
+ name=user_details.attribute('name')
59
+ ))
60
+ ```
61
+
62
+ See the `/docs` directory for complete documentation and additional code snippets.
63
+
64
+ ## Examples
65
+
66
+ The `/examples` directory contains ready to use scripts to help you get started. These examples can be executed with your personal access token. One of them gets a ticket with it's emails and prints the details::
67
+
68
+ ```
69
+ $ python examples/ticket_details.py <YOUR-TOKEN>
70
+ ```
71
+ This should make two API calls and print the ticket and email details for one of your tickets.
72
+
73
+ ## Change log
74
+
75
+ Please see [releases][link-releases] for more information on what has changed recently.
76
+
77
+ # Contributing
78
+
79
+ When contributing to this repository, please first discuss the change you wish
80
+ to make via issue, email, or any other method with the owners of this repository
81
+ before making a change.
82
+
83
+ Please note we have a code of conduct, please follow it in all your interactions
84
+ with the project.
85
+
86
+ ### Issues and feature requests
87
+
88
+ You've found a bug in the source code, a mistake in the documentation or maybe
89
+ you'd like a new feature? You can help us by submitting an issue to our
90
+ [GitHub Repository][github]. Before you create an issue, make sure you search
91
+ the archive, maybe your question was already answered.
92
+
93
+ Even better: You could submit a pull request with a fix / new feature!
94
+
95
+ ### Pull request process
96
+
97
+ 1. Search our repository for open or closed [pull requests][prs] that relates
98
+ to your submission. You don't want to duplicate effort.
99
+
100
+ 2. You may merge the pull request in once you have the sign-off of two other
101
+ developers, or if you do not have permission to do that, you may request
102
+ the second reviewer to merge it for you.
103
+
104
+ ## Setting up development environment
105
+
106
+ This Python project is fully managed using the [Poetry][poetry] dependency
107
+ manager.
108
+
109
+ You need at least:
110
+
111
+ - Python 3.9+
112
+ - [Poetry][poetry-install]
113
+
114
+ Install all packages, including all development requirements:
115
+
116
+ ```bash
117
+ poetry install
118
+ ```
119
+
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
+ ```
127
+
128
+ *Now you're all set to get started!*
129
+
130
+ To run the Python tests:
131
+
132
+ ```bash
133
+ poetry run pytest
134
+ ```
135
+
136
+ To run the bandit checks:
137
+
138
+ ```bash
139
+ poetry run bandit
140
+ ```
141
+
142
+
143
+ ## Security
144
+
145
+ If you discover any security related issues please email [development@exonet.nl](mailto:development@exonet.nl) instead
146
+ of using the issue tracker.
147
+
148
+
149
+ ## Credits
150
+
151
+ - [Exonet][link-author]
152
+ - [All Contributors][link-contributors]
153
+
154
+
155
+ ## License
156
+
157
+ [MIT License](LICENSE.md)
158
+
159
+ [ico-version]: https://img.shields.io/pypi/v/exonetapi.svg?style=flat-square
160
+ [ico-license]: https://img.shields.io/pypi/l/exonetapi.svg?style=flat-square
161
+ [ico-pyversions]: https://img.shields.io/pypi/pyversions/exonetapi.svg?style=flat-square
162
+
163
+ [github]: https://github.com/exonet/exonet-api-python/issues
164
+ [prs]: https://github.com/exonet/exonet-api-python/pulls
165
+
166
+ [link-pypi]: https://pypi.org/project/exonetapi/
167
+ [link-author]: https://github.com/exonet
168
+ [link-releases]: https://github.com/exonet/exonet-api-python/releases
169
+ [link-contributors]: ../../contributors
170
+
171
+ [poetry-install]: https://python-poetry.org/docs/#installation
172
+ [poetry]: https://python-poetry.org
173
+ [pre-commit]: https://pre-commit.com
174
+
@@ -0,0 +1,147 @@
1
+ # exonetapi
2
+ Python 3 library for the Exonet API.
3
+
4
+ [![Latest Version on Packagist][ico-version]][link-pypi]
5
+ [![Python Versions][ico-pyversions]][link-pypi]
6
+ [![Software License][ico-license]](LICENSE.md)
7
+
8
+ ## Install
9
+ Install using pip:
10
+
11
+ ```bash
12
+ pip install exonetapi
13
+ ```
14
+
15
+ ## Usage
16
+ Example to get the user details of the authorised user:
17
+
18
+ ```py
19
+ from exonetapi import Client
20
+
21
+ # Create a new Client.
22
+ client = Client('https://api.exonet.nl')
23
+
24
+ # Authorize with a personal access token.
25
+ client.authenticator.set_token('<YOUR_TOKEN>')
26
+
27
+ # Make an API call. Get details of the authorized user.
28
+ user_details = client.resource('me').get()
29
+
30
+ # Print user's name.
31
+ print('Autorized as: {name}'.format(
32
+ name=user_details.attribute('name')
33
+ ))
34
+ ```
35
+
36
+ See the `/docs` directory for complete documentation and additional code snippets.
37
+
38
+ ## Examples
39
+
40
+ The `/examples` directory contains ready to use scripts to help you get started. These examples can be executed with your personal access token. One of them gets a ticket with it's emails and prints the details::
41
+
42
+ ```
43
+ $ python examples/ticket_details.py <YOUR-TOKEN>
44
+ ```
45
+ This should make two API calls and print the ticket and email details for one of your tickets.
46
+
47
+ ## Change log
48
+
49
+ Please see [releases][link-releases] for more information on what has changed recently.
50
+
51
+ # Contributing
52
+
53
+ When contributing to this repository, please first discuss the change you wish
54
+ to make via issue, email, or any other method with the owners of this repository
55
+ before making a change.
56
+
57
+ Please note we have a code of conduct, please follow it in all your interactions
58
+ with the project.
59
+
60
+ ### Issues and feature requests
61
+
62
+ You've found a bug in the source code, a mistake in the documentation or maybe
63
+ you'd like a new feature? You can help us by submitting an issue to our
64
+ [GitHub Repository][github]. Before you create an issue, make sure you search
65
+ the archive, maybe your question was already answered.
66
+
67
+ Even better: You could submit a pull request with a fix / new feature!
68
+
69
+ ### Pull request process
70
+
71
+ 1. Search our repository for open or closed [pull requests][prs] that relates
72
+ to your submission. You don't want to duplicate effort.
73
+
74
+ 2. You may merge the pull request in once you have the sign-off of two other
75
+ developers, or if you do not have permission to do that, you may request
76
+ the second reviewer to merge it for you.
77
+
78
+ ## Setting up development environment
79
+
80
+ This Python project is fully managed using the [Poetry][poetry] dependency
81
+ manager.
82
+
83
+ You need at least:
84
+
85
+ - Python 3.9+
86
+ - [Poetry][poetry-install]
87
+
88
+ Install all packages, including all development requirements:
89
+
90
+ ```bash
91
+ poetry install
92
+ ```
93
+
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
+ ```
101
+
102
+ *Now you're all set to get started!*
103
+
104
+ To run the Python tests:
105
+
106
+ ```bash
107
+ poetry run pytest
108
+ ```
109
+
110
+ To run the bandit checks:
111
+
112
+ ```bash
113
+ poetry run bandit
114
+ ```
115
+
116
+
117
+ ## Security
118
+
119
+ If you discover any security related issues please email [development@exonet.nl](mailto:development@exonet.nl) instead
120
+ of using the issue tracker.
121
+
122
+
123
+ ## Credits
124
+
125
+ - [Exonet][link-author]
126
+ - [All Contributors][link-contributors]
127
+
128
+
129
+ ## License
130
+
131
+ [MIT License](LICENSE.md)
132
+
133
+ [ico-version]: https://img.shields.io/pypi/v/exonetapi.svg?style=flat-square
134
+ [ico-license]: https://img.shields.io/pypi/l/exonetapi.svg?style=flat-square
135
+ [ico-pyversions]: https://img.shields.io/pypi/pyversions/exonetapi.svg?style=flat-square
136
+
137
+ [github]: https://github.com/exonet/exonet-api-python/issues
138
+ [prs]: https://github.com/exonet/exonet-api-python/pulls
139
+
140
+ [link-pypi]: https://pypi.org/project/exonetapi/
141
+ [link-author]: https://github.com/exonet
142
+ [link-releases]: https://github.com/exonet/exonet-api-python/releases
143
+ [link-contributors]: ../../contributors
144
+
145
+ [poetry-install]: https://python-poetry.org/docs/#installation
146
+ [poetry]: https://python-poetry.org
147
+ [pre-commit]: https://pre-commit.com
@@ -22,15 +22,17 @@ class Client(metaclass=Singleton):
22
22
  """
23
23
 
24
24
  # The URL to use for authentication.
25
- authentication_endpoint = '/oauth/token'
25
+ authentication_endpoint = "/oauth/token"
26
26
 
27
27
  def __init__(self, host=None):
28
- self.__host = 'https://api.exonet.nl'
28
+ self.__host = "https://api.exonet.nl"
29
29
 
30
30
  if host:
31
31
  self.set_host(host)
32
32
 
33
- self.authenticator = Authenticator(self.get_host(), self.authentication_endpoint)
33
+ self.authenticator = Authenticator(
34
+ self.get_host(), self.authentication_endpoint
35
+ )
34
36
 
35
37
  def set_host(self, host):
36
38
  """
@@ -43,8 +45,8 @@ class Client(metaclass=Singleton):
43
45
  parsed_host = urlparse(host)
44
46
 
45
47
  # Make sure the host uses a valid scheme.
46
- if parsed_host.scheme not in ('http', 'https'):
47
- raise ConnectionAbortedError('Invalid protocol for host: %s' % host)
48
+ if parsed_host.scheme not in ("http", "https"):
49
+ raise ConnectionAbortedError("Invalid protocol for host: %s" % host)
48
50
 
49
51
  self.__host = parsed_host.geturl()
50
52
 
@@ -9,12 +9,11 @@ from .result import Parser
9
9
 
10
10
 
11
11
  class RequestBuilder(object):
12
- """Create and make requests to the API.
13
- """
12
+ """Create and make requests to the API."""
14
13
 
15
14
  def __init__(self, resource=None, client=None):
16
- if resource is not None and not resource.startswith('/'):
17
- resource = '/' + resource
15
+ if resource is not None and not resource.startswith("/"):
16
+ resource = "/" + resource
18
17
 
19
18
  self.__resource = resource
20
19
  """
@@ -25,8 +24,9 @@ class RequestBuilder(object):
25
24
 
26
25
  if client:
27
26
  self.__client = client
28
- elif not hasattr(self, '__client'):
27
+ elif not hasattr(self, "__client"):
29
28
  from exonetapi import Client
29
+
30
30
  self.__client = Client()
31
31
 
32
32
  def filter(self, filter_name, filter_value):
@@ -35,7 +35,7 @@ class RequestBuilder(object):
35
35
  :param filter_value: The value of the applied filter.
36
36
  :return: self
37
37
  """
38
- self.__query_params['filter[' + filter_name + ']'] = filter_value
38
+ self.__query_params["filter[" + filter_name + "]"] = filter_value
39
39
  return self
40
40
 
41
41
  def page(self, page_number):
@@ -43,7 +43,7 @@ class RequestBuilder(object):
43
43
  :param page_number: The page number.
44
44
  :return: self
45
45
  """
46
- self.__query_params['page[number]'] = page_number
46
+ self.__query_params["page[number]"] = page_number
47
47
  return self
48
48
 
49
49
  def size(self, page_size):
@@ -51,20 +51,20 @@ class RequestBuilder(object):
51
51
  :param page_size: The maximum number of returned resources.
52
52
  :return: self
53
53
  """
54
- self.__query_params['page[size]'] = page_size
54
+ self.__query_params["page[size]"] = page_size
55
55
  return self
56
56
 
57
- def sort(self, sort_field, sort_order='asc'):
57
+ def sort(self, sort_field, sort_order="asc"):
58
58
  """Prepare this RequestBuilder to sort by a field.
59
59
  :param sort_field: The field name to sort on.
60
60
  :param sort_order: The order for sorting (asc/desc), default: asc.
61
61
  :return: self
62
62
  """
63
- if sort_order not in ['asc', 'desc']:
63
+ if sort_order not in ["asc", "desc"]:
64
64
  raise ValueError('Sort order can only be "asc" or "desc".')
65
65
 
66
- self.__query_params['sort'] = '{sort}{field}'.format(
67
- sort='-' if sort_order == 'desc' else '',
66
+ self.__query_params["sort"] = "{sort}{field}".format(
67
+ sort="-" if sort_order == "desc" else "",
68
68
  field=sort_field,
69
69
  )
70
70
  return self
@@ -74,14 +74,14 @@ class RequestBuilder(object):
74
74
  :param sort_field: The field name to sort on.
75
75
  :return: self
76
76
  """
77
- return self.sort(sort_field, 'asc')
77
+ return self.sort(sort_field, "asc")
78
78
 
79
79
  def sort_desc(self, sort_field):
80
80
  """Prepare this RequestBuilder to sort by a field in descending order.
81
81
  :param sort_field: The field name to sort on.
82
82
  :return: self
83
83
  """
84
- return self.sort(sort_field, 'desc')
84
+ return self.sort(sort_field, "desc")
85
85
 
86
86
  def get(self, identifier=None):
87
87
  """Make a call to the API using the previously set options.
@@ -90,9 +90,9 @@ class RequestBuilder(object):
90
90
  """
91
91
 
92
92
  response = self.__make_call(
93
- 'GET',
93
+ "GET",
94
94
  self.__build_url(identifier),
95
- params=self.__query_params if not identifier else None
95
+ params=self.__query_params if not identifier else None,
96
96
  )
97
97
 
98
98
  return Parser(response.content).parse()
@@ -111,18 +111,23 @@ class RequestBuilder(object):
111
111
 
112
112
  # If there are changed attributes, assume it s a new resource.
113
113
  if len(changed_attributes) > 0:
114
- response = self.__make_call('POST', self.__build_url(), {'data': resource.to_json()})
114
+ response = self.__make_call(
115
+ "POST", self.__build_url(), {"data": resource.to_json()}
116
+ )
115
117
 
116
118
  return Parser(response.content).parse()
117
119
 
118
- # If there are changed relations and no changed attributes, assume a POST to the relation.
120
+ # If there are changed relations and no changed attributes, assume a POST to
121
+ # the relation.
119
122
  if len(changed_relations) > 0:
120
123
  responses = []
121
124
  for relation_name in changed_relations:
122
125
  response = self.__make_call(
123
- 'POST',
124
- '{}/relationships/{}'.format(self.__build_url(resource.id()), relation_name),
125
- changed_relations[relation_name]
126
+ "POST",
127
+ "{}/relationships/{}".format(
128
+ self.__build_url(resource.id()), relation_name
129
+ ),
130
+ changed_relations[relation_name],
126
131
  )
127
132
  responses.append(Parser(response.content).parse())
128
133
 
@@ -135,18 +140,18 @@ class RequestBuilder(object):
135
140
  # Patch changed attributes.
136
141
  if len(changed_attributes) > 0:
137
142
  self.__make_call(
138
- 'PATCH',
139
- self.__build_url(resource.id()),
140
- {'data': changed_attributes}
143
+ "PATCH", self.__build_url(resource.id()), {"data": changed_attributes}
141
144
  )
142
145
 
143
146
  # Patch changed relations.
144
147
  if len(changed_relations) > 0:
145
148
  for relation_name in changed_relations:
146
149
  self.__make_call(
147
- 'PATCH',
148
- '{}/relationships/{}'.format(self.__build_url(resource.id()), relation_name),
149
- changed_relations[relation_name]
150
+ "PATCH",
151
+ "{}/relationships/{}".format(
152
+ self.__build_url(resource.id()), relation_name
153
+ ),
154
+ changed_relations[relation_name],
150
155
  )
151
156
 
152
157
  return True
@@ -156,15 +161,17 @@ class RequestBuilder(object):
156
161
 
157
162
  # If no relations are changed, DELETE the whole resource.
158
163
  if len(changed_relations) == 0:
159
- self.__make_call('DELETE', self.__build_url(resource.id()))
164
+ self.__make_call("DELETE", self.__build_url(resource.id()))
160
165
 
161
166
  return True
162
167
 
163
168
  for relation_name in changed_relations:
164
169
  self.__make_call(
165
- 'DELETE',
166
- '{}/relationships/{}'.format(self.__build_url(resource.id()), relation_name),
167
- changed_relations[relation_name]
170
+ "DELETE",
171
+ "{}/relationships/{}".format(
172
+ self.__build_url(resource.id()), relation_name
173
+ ),
174
+ changed_relations[relation_name],
168
175
  )
169
176
 
170
177
  return True
@@ -180,7 +187,7 @@ class RequestBuilder(object):
180
187
  url += self.__resource
181
188
 
182
189
  if identifier:
183
- url += '/' + identifier
190
+ url += "/" + identifier
184
191
 
185
192
  return url
186
193
 
@@ -190,18 +197,14 @@ class RequestBuilder(object):
190
197
  :return: A dict with all the headers.
191
198
  """
192
199
  return {
193
- 'Accept': 'application/vnd.Exonet.v1+json',
194
- 'Content-Type': 'application/json',
195
- 'Authorization': 'Bearer %s' % (self.__client.authenticator.get_token())
200
+ "Accept": "application/vnd.Exonet.v1+json",
201
+ "Content-Type": "application/json",
202
+ "Authorization": "Bearer %s" % (self.__client.authenticator.get_token()),
196
203
  }
197
204
 
198
205
  def __make_call(self, method, url, json_data=None, params=None):
199
206
  response = requests.request(
200
- method,
201
- url,
202
- headers=self.__get_headers(),
203
- json=json_data,
204
- params=params
207
+ method, url, headers=self.__get_headers(), json=json_data, params=params
205
208
  )
206
209
 
207
210
  # Handle validation errors.
@@ -215,17 +218,17 @@ class RequestBuilder(object):
215
218
 
216
219
  def __get_recursive(self, data=None, url=None):
217
220
  """
218
- Get the URL and call this method recursivly as long as there is an URL in the 'next' field
219
- of the 'links' data.
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.
220
223
 
221
224
  :param data: The ApiResourceSet to append the resources to.
222
225
  :param url: The URL to call.
223
226
  :return: The ApiResourceSet containing all requested resources.
224
227
  """
225
228
  response = self.__make_call(
226
- 'GET',
229
+ "GET",
227
230
  url or self.__build_url(),
228
- params=self.__query_params if not url else None
231
+ params=self.__query_params if not url else None,
229
232
  )
230
233
 
231
234
  content = Parser(response.content).parse()
@@ -236,7 +239,7 @@ class RequestBuilder(object):
236
239
 
237
240
  data.add_resource(content.resources())
238
241
 
239
- next_link = content.links().get('next')
242
+ next_link = content.links().get("next")
240
243
  if next_link is not None:
241
244
  return self.__get_recursive(data, next_link)
242
245
 
@@ -2,3 +2,5 @@ from .Client import Client
2
2
  from .RequestBuilder import RequestBuilder
3
3
  from .result import Parser
4
4
  from .create_resource import create_resource
5
+
6
+ __all__ = ["Client", "RequestBuilder", "Parser", "create_resource"]
@@ -20,7 +20,7 @@ class Authenticator:
20
20
  :return: The token if available.
21
21
  """
22
22
  if self.__auth_details:
23
- return self.__auth_details['access_token'].strip()
23
+ return self.__auth_details["access_token"].strip()
24
24
 
25
25
  def password_auth(self, username, password, client_id, client_secret):
26
26
  """Authorize using the password grant.
@@ -31,25 +31,26 @@ class Authenticator:
31
31
  :param client_secret: The OAuth client secret.
32
32
  :return: None
33
33
  """
34
- self.get_new_token({
35
- 'grant_type': 'password',
36
- 'username': username,
37
- 'password': password,
38
- 'client_id': client_id,
39
- 'client_secret': client_secret
40
- })
34
+ self.get_new_token(
35
+ {
36
+ "grant_type": "password",
37
+ "username": username,
38
+ "password": password,
39
+ "client_id": client_id,
40
+ "client_secret": client_secret,
41
+ }
42
+ )
41
43
 
42
44
  def set_token(self, token):
43
45
  """Set a token to use when authorizing.
44
46
 
45
- This bypasses any calls to the authorization endpoint, but instead uses the provided token.
47
+ This bypasses any calls to the authorization endpoint, but instead uses the
48
+ provided token.
46
49
 
47
50
  :param token: A previously obtained token.
48
51
  :return: None
49
52
  """
50
- self.__auth_details = {
51
- 'access_token': token
52
- }
53
+ self.__auth_details = {"access_token": token}
53
54
 
54
55
  def get_new_token(self, payload):
55
56
  """Get a new token via the authorization endpoint.
@@ -57,12 +58,13 @@ class Authenticator:
57
58
  :param payload:
58
59
  :return: A new access token.
59
60
  """
60
- headers = {'Accept': 'application/vnd.Exonet.v1+json'}
61
+ headers = {"Accept": "application/vnd.Exonet.v1+json"}
61
62
 
62
63
  response = requests.post(
63
64
  self.__host + self.__authentication_endpoint,
64
65
  headers=headers,
65
- data=payload
66
+ data=payload,
67
+ timeout=30
66
68
  )
67
69
 
68
70
  # Raise exception on failed request.
@@ -71,4 +73,4 @@ class Authenticator:
71
73
  # Set the auth details in the request for later use.
72
74
  self.__auth_details = response.json()
73
75
 
74
- return response.json()['access_token']
76
+ return response.json()["access_token"]