Skip to content

Commit d8a6e5a

Browse files
committed
Simplify client class
1 parent 2f9cac6 commit d8a6e5a

9 files changed

Lines changed: 54 additions & 96 deletions

File tree

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ matrix:
1313
dist: xenial
1414
sudo: true
1515

16-
install:
17-
- pip install -r test-requirements.txt
16+
before_install:
17+
- pip install flake8
1818

1919
script:
2020
- python setup.py test
21-
- flake8 --ignore E125,E123,E129 --max-line-length 120 --exclude kanboard/__init__.py kanboard/ tests/
21+
- flake8 --max-line-length 120 *.py

README.rst

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,28 @@ Installation
1818
pip install kanboard
1919
2020
21-
This library is compatible with Python 3.5, 3.6, and 3.7.
21+
This library is compatible with Python >= 3.5.
22+
23+
Note: **Support for Python 2.7 has been dropped from version 1.1.0.**
2224

2325
Examples
2426
========
2527

26-
Methods and arguments are the same as the JSON-RPC procedures described in the `official documentation <https://docs.kanboard.org/en/latest/api/index.html>`_.
28+
Methods and arguments are the same as the JSON-RPC procedures described in the
29+
`official documentation <https://docs.kanboard.org/en/latest/api/index.html>`_.
2730

28-
Python methods are dynamically mapped to the API procedures. You must use named arguments.
31+
Python methods are dynamically mapped to the API procedures. **You must use named arguments.**
2932

30-
By default, the calls are made synchronously, meaning that they will block the program until completed.
33+
By default, calls are made synchronously, meaning that they will block the program until completed.
3134

32-
Create a new team project
33-
-------------------------
35+
Creating a new team project
36+
---------------------------
3437

3538
.. code-block:: python
3639
37-
from kanboard import Kanboard
40+
import kanboard
3841
39-
kb = Kanboard('http://localhost/jsonrpc.php', 'jsonrpc', 'your_api_token')
42+
kb = kanboard.Client('http://localhost/jsonrpc.php', 'jsonrpc', 'your_api_token')
4043
project_id = kb.create_project(name='My project')
4144
4245
@@ -45,34 +48,37 @@ Authenticate as user
4548

4649
.. code-block:: python
4750
48-
from kanboard import Kanboard
51+
import kanboard
4952
50-
kb = Kanboard('http://localhost/jsonrpc.php', 'admin', 'admin')
53+
kb = kanboard.Client('http://localhost/jsonrpc.php', 'admin', 'secret')
5154
kb.get_my_projects()
5255
5356
Create a new task
5457
-----------------
5558

5659
.. code-block:: python
5760
58-
from kanboard import Kanboard
61+
import kanboard
5962
60-
kb = Kanboard('http://localhost/jsonrpc.php', 'jsonrpc', 'your_api_token')
63+
kb = kanboard.Client('http://localhost/jsonrpc.php', 'jsonrpc', 'your_api_token')
6164
project_id = kb.create_project(name='My project')
6265
task_id = kb.create_task(project_id=project_id, title='My task title')
6366
6467
Asynchronous I/O
6568
================
6669

67-
The client also exposes async/await style method calls. Similarly to the synchronous calls (see above), the method names are mapped to the API methods.
68-
To invoke an asynchronous call, the method name must be appended with `_async`: for example, a synchronous call to `create_project` can be made asynchronous by calling `create_project_async` instead.
70+
The client also exposes async/await style method calls. Similarly to the synchronous calls (see above),
71+
the method names are mapped to the API methods.
72+
73+
To invoke an asynchronous call, the method name must be appended with ``_async``. For example, a synchronous call
74+
to ``create_project`` can be made asynchronous by calling ``create_project_async`` instead.
6975

7076
.. code-block:: python
7177
7278
import asyncio
73-
from kanboard import Kanboard
79+
import kanboard
7480
75-
kb = Kanboard('http://localhost/jsonrpc.php', 'jsonrpc', 'your_api_token')
81+
kb = kanboard.Client('http://localhost/jsonrpc.php', 'jsonrpc', 'your_api_token')
7682
7783
loop = asyncio.get_event_loop()
7884
project_id = loop.run_until_complete(kb.create_project_async(name='My project'))
@@ -81,13 +87,15 @@ To invoke an asynchronous call, the method name must be appended with `_async`:
8187
.. code-block:: python
8288
8389
import asyncio
84-
from kanboard import Kanboard
90+
import kanboard
8591
8692
async def call_within_function()
87-
kb = Kanboard('http://localhost/jsonrpc.php', 'jsonrpc', 'your_api_token')
88-
return await kb.create_project_async(name='My project')
93+
kb = kanboard.Client('http://localhost/jsonrpc.php', 'jsonrpc', 'your_api_token')
94+
return await kb.create_project_async(name='My project')
8995
9096
loop = asyncio.get_event_loop()
9197
project_id = loop.run_until_complete(call_within_function())
9298
93-
See the `official API documentation <https://docs.kanboard.org/en/latest/api/index.html>`_ for the complete list of methods and arguments.
99+
100+
See the `official API documentation <https://docs.kanboard.org/en/latest/api/index.html>`_ for the complete list of
101+
methods and arguments.

kanboard/client.py renamed to kanboard.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# The MIT License (MIT)
22
#
3-
# Copyright (c) 2016-2018 Frederic Guillot
3+
# Copyright (c) 2016-2019 Frederic Guillot
44
#
55
# Permission is hereby granted, free of charge, to any person obtaining a copy
66
# of this software and associated documentation files (the "Software"), to deal
@@ -24,26 +24,28 @@
2424
import base64
2525
import functools
2626
import asyncio
27-
28-
from kanboard import exceptions
2927
from urllib import request as http
3028

3129

3230
DEFAULT_AUTH_HEADER = 'Authorization'
3331
ASYNC_FUNCNAME_MARKER = "_async"
3432

3533

36-
class Kanboard(object):
34+
class ClientError(Exception):
35+
pass
36+
37+
38+
class Client:
3739
"""
3840
Kanboard API client
3941
4042
Example:
4143
42-
from kanboard import Kanboard
44+
from kanboard import Client
4345
44-
kb = Kanboard(url="http://localhost/jsonrpc.php",
45-
username="jsonrpc",
46-
password="your_api_token")
46+
kb = Client(url="http://localhost/jsonrpc.php",
47+
username="jsonrpc",
48+
password="your_api_token")
4749
4850
project_id = kb.create_project(name="My project")
4951
@@ -75,7 +77,7 @@ def __init__(self,
7577
self._event_loop = loop
7678

7779
def __getattr__(self, name):
78-
if(self.is_async_method_name(name)):
80+
if self.is_async_method_name(name):
7981
async def function(*args, **kwargs):
8082
return await self._event_loop.run_in_executor(
8183
None,
@@ -108,7 +110,7 @@ def _parse_response(response):
108110

109111
if 'error' in body:
110112
message = body.get('error').get('message')
111-
raise exceptions.KanboardClientException(message)
113+
raise ClientError(message)
112114

113115
return body.get('result')
114116
except ValueError:
@@ -124,7 +126,7 @@ def _do_request(self, headers, body):
124126
else:
125127
response = http.urlopen(request).read()
126128
except Exception as e:
127-
raise exceptions.KanboardClientException(str(e))
129+
raise ClientError(str(e))
128130
return self._parse_response(response)
129131

130132
def execute(self, method, **kwargs):
@@ -139,7 +141,6 @@ def execute(self, method, **kwargs):
139141
Procedure result
140142
141143
Raises:
142-
urllib2.HTTPError: Any HTTP error (Python 2)
143144
urllib.error.HTTPError: Any HTTP error (Python 3)
144145
"""
145146
payload = {

kanboard/__init__.py

Lines changed: 0 additions & 23 deletions
This file was deleted.

kanboard/exceptions.py

Lines changed: 0 additions & 25 deletions
This file was deleted.

setup.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# The MIT License (MIT)
22
#
3-
# Copyright (c) 2016-2018 Frederic Guillot
3+
# Copyright (c) 2016-2019 Frederic Guillot
44
#
55
# Permission is hereby granted, free of charge, to any person obtaining a copy
66
# of this software and associated documentation files (the "Software"), to deal
@@ -20,16 +20,14 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
# THE SOFTWARE.
2222

23-
try:
24-
from setuptools import setup
25-
except ImportError:
26-
from distutils.core import setup
23+
from setuptools import setup
2724

2825

2926
def readme():
3027
with open('README.rst') as f:
3128
return f.read()
3229

30+
3331
setup(
3432
name='kanboard',
3533
version='1.1.0',
@@ -40,7 +38,8 @@ def readme():
4038
author='Frederic Guillot',
4139
author_email='fred@kanboard.net',
4240
license='MIT',
43-
packages=['kanboard'],
41+
py_modules=['miniflux'],
42+
test_suite='test_kanboard',
4443
classifiers=[
4544
'Intended Audience :: Developers',
4645
'Intended Audience :: Information Technology',

test-requirements.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,14 @@
2525
import types
2626
import warnings
2727

28-
from kanboard import client
29-
from kanboard import exceptions
28+
import kanboard
3029

3130

32-
class TestKanboard(unittest.TestCase):
31+
class TestClient(unittest.TestCase):
3332

3433
def setUp(self):
3534
self.url = 'some api url'
36-
self.client = client.Kanboard(self.url, 'username', 'password')
35+
self.client = kanboard.Client(self.url, 'username', 'password')
3736
self.request, self.urlopen = self._create_mocks()
3837

3938
def ignore_warnings(test_func):
@@ -64,14 +63,14 @@ def test_custom_auth_header(self):
6463

6564
def test_http_error(self):
6665
self.urlopen.side_effect = Exception()
67-
with self.assertRaises(exceptions.KanboardClientException):
66+
with self.assertRaises(kanboard.ClientError):
6867
self.client.remote_procedure()
6968

7069
def test_application_error(self):
7170
body = b'{"jsonrpc": "2.0", "error": {"code": -32603, "message": "Internal error"}, "id": 123}'
7271
self.urlopen.return_value.read.return_value = body
7372

74-
with self.assertRaises(exceptions.KanboardClientException, msg='Internal error'):
73+
with self.assertRaises(kanboard.ClientError, msg='Internal error'):
7574
self.client.remote_procedure()
7675

7776
def test_async_method_call_recognised(self):

tests/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)