Skip to content

Commit 509d1d8

Browse files
committed
Initial release
1 parent c1b7b7b commit 509d1d8

36 files changed

Lines changed: 1442 additions & 1 deletion

.coveragerc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[run]
2+
source =
3+
exonetapi
4+
omit =
5+
tests/*

.editorconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 4
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
*.pyc
2+
.idea/*
3+
*.egg-info/*
4+
dist/*
5+
6+
# Unit test / coverage reports
7+
.tox/
8+
.coverage
9+
.coverage.*
10+
.pytest_cache/*
11+
/htmlcov/

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Changelog
2+
3+
All notable changes to `exonet-api-python` will be documented in this file.
4+
5+
Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
6+
7+
## Unreleased
8+
[Compare v0.0.1 - Unreleased](https://github.com/exonet/exonet-api-python/compare/v0.0.1...develop)
9+
10+
## [v0.0.1](https://github.com/exonet/exonet-api-python/releases/tag/v0.0.1) - 2018-??-??
11+
### Added
12+
- Initial release.

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# The MIT License (MIT)
2+
3+
Copyright (c) 2018 Exonet <support@exonet.nl>
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
13+
> all 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
21+
> THE SOFTWARE.

README.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

README.rst

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
Exonet API python package
2+
=========================
3+
4+
.. image:: https://img.shields.io/pypi/v/exonetapi.svg?style=flat-square
5+
.. image:: https://img.shields.io/pypi/pyversions/exonetapi.svg?style=flat-square
6+
.. image:: https://img.shields.io/pypi/l/exonetapi.svg?style=flat-square
7+
8+
Python 3 library for the Exonet API.
9+
10+
Conventions
11+
-----------
12+
13+
- Code style guide: PEP 8.
14+
- Docstring conventions: PEP 257 and reStructuredText.
15+
16+
Install
17+
-------
18+
Install using pip::
19+
20+
pip install exonetapi
21+
22+
Usage
23+
-----
24+
Example to get the user details of the authorised user::
25+
26+
from exonetapi import Client
27+
28+
# Create a new Client.
29+
client = Client('https://api.exonet.nl')
30+
31+
# Authorize with a personal access token.
32+
client.authenticator.set_token('<YOUR_TOKEN>')
33+
34+
# Make an API call. Get details of the authorized user.
35+
user_details = client.resource('me').get()
36+
37+
# Print user's name.
38+
print('Autorized as: {name}'.format(
39+
name=user_details.attribute('name')
40+
))
41+
42+
Please see the `/docs` folder for complete documentation and additional examples.
43+
44+
Testing
45+
-------
46+
47+
Run unit tests and coverage::
48+
49+
coverage run -m unittest discover tests -v && coverage html
50+
51+
Change log
52+
----------
53+
54+
Please see `CHANGELOG <https://github.com/exonet/exonet-api-python/blob/master/CHANGELOG.md>`_ for more information on what has changed recently.
55+
56+
Security
57+
--------
58+
59+
If you discover any security related issues please email `support@exonet.nl <mailto:support@exonet.nl>`_ instead of using the issue tracker.
60+
61+
Credits
62+
-------
63+
64+
- `Exonet <https://github.com/exonet>`_
65+
- `All Contributors <https://github.com/exonet/exonet-api-python/graphs/contributors>`_
66+
67+
License
68+
-------
69+
70+
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

docs/calls.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Making API calls
2+
After the client has been initialised, use the `resource` method to define which type of resource you want to get from
3+
the API:
4+
5+
```python
6+
certificates_request = client.resource('certificates')
7+
```
8+
9+
This will return a `RequestBuilder` instance on which additional request parameters can be set:
10+
11+
```python
12+
# Define which filters must be applied:
13+
certificates_request.filter('expired', True)
14+
15+
# Set the number of resources to get:
16+
certificates_request.size(10)
17+
18+
# Set the page to get:
19+
certificates_request.page(2)
20+
```
21+
22+
After setting the options you can call the `get()` method to retrieve the resource:
23+
```python
24+
certificates = certificates_request.get()
25+
```
26+
27+
## Getting a single resource by ID
28+
If you want to get a specific resource by its ID, you can pass it as an argument to the `get` method:
29+
```python
30+
certificate = client.resource('certificates').get('VX09kwR3KxNo')
31+
```
32+
33+
---
34+
35+
[Back to the index](index.md)

docs/error_handling.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Error handling
2+
3+
For incorrect or failed requests the Exonet API will return exceptions or errors. In most cases this will be because
4+
invalid data is provided (validation) or because the authenticated user does not have the right permissions to make
5+
the request. These exceptions can be handled in the following way.
6+
7+
## Default exception behavior
8+
A failed request will result in an exception containing the error message. The following example has no custom error
9+
handling and will throw an exception when the request fails.
10+
```python
11+
from exonetapi import Client
12+
13+
# Create a new Client.
14+
client = Client('https://api.exonet.nl')
15+
16+
# Login with machine token.
17+
client.authenticator.set_token('INVALID_TOKEN')
18+
19+
# Try to make a request, will fail due to invalid token.
20+
myDetails = client.resource('me').get()
21+
```
22+
23+
## Catching exceptions and outputting errors
24+
For validation exceptions you might be interested in the response body, since this can contain detail information about
25+
why the request was invalid. Catch the exception and output the request body containing the validation exception.
26+
27+
```python
28+
from exonetapi import Client
29+
# Import the exception to catch.
30+
from requests.exceptions import HTTPError
31+
32+
# Create a new Client.
33+
client = Client('https://api.exonet.nl')
34+
35+
# Login with machine token.
36+
client.Authenticator.set_token('A_PREVIOUSLY_OBTAINED_TOKEN')
37+
38+
try:
39+
# Try to get a certificate while providing an invalid ID.
40+
certificate = client.request('certificates').id('invalidID').get()
41+
except HTTPError as e:
42+
print(e.response.text)
43+
raise e
44+
```
45+
46+
This will output the request body where the details of the error can be found:
47+
```
48+
{"errors":[{"status":400,"code":"101.10002","title":"request.invalidId","detail":"The id provided for 'certificate' is invalid.","variables":[]}]}
49+
50+
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api.exonet.nl/certificates/invalidID
51+
```
52+
53+
---
54+
55+
[Back to the index](index.md)

docs/index.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Exonet API Client Documentation
2+
3+
- [Using this package](using.md)
4+
- [Making API calls](calls.md)
5+
- [Responses](responses.md)
6+
- [Error handling](error_handling.md)
7+

0 commit comments

Comments
 (0)