Skip to content

Commit 97b496a

Browse files
committed
Add support for custom user agent
1 parent c178740 commit 97b496a

3 files changed

Lines changed: 25 additions & 3 deletions

File tree

README.rst

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,18 @@ Create a new task
6868
project_id = kb.create_project(name='My project')
6969
task_id = kb.create_task(project_id=project_id, title='My task title')
7070
71+
Use a personalized user agent
72+
-----------------------------
73+
74+
.. code-block:: python
75+
76+
import kanboard
77+
78+
kb = kanboard.Client(url='http://localhost/jsonrpc.php',
79+
username='admin',
80+
password='secret',
81+
user_agent='My Kanboard client')
82+
7183
SSL connection and self-signed certificates
7284
===========================================
7385

@@ -86,7 +98,10 @@ Example with a custom certificate:
8698
8799
import kanboard
88100
89-
kb = kanboard.Client('https://example.org/jsonrpc.php', 'admin', 'secret', cafile='/path/to/my/cert.pem')
101+
kb = kanboard.Client(url='https://example.org/jsonrpc.php',
102+
username='admin',
103+
password='secret',
104+
cafile='/path/to/my/cert.pem')
90105
kb.get_my_projects()
91106
92107
Example with a custom certificate and hostname mismatch:
@@ -108,7 +123,10 @@ Ignore invalid/expired certificates and hostname mismatches, which will make you
108123
109124
import kanboard
110125
111-
kb = kanboard.Client('https://example.org/jsonrpc.php', 'admin', 'secret', insecure=True)
126+
kb = kanboard.Client(url='https://example.org/jsonrpc.php',
127+
username='admin',
128+
password='secret',
129+
insecure=True)
112130
kb.get_my_projects()
113131
114132
Asynchronous I/O

kanboard.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def __init__(self,
6161
cafile: Optional[str] = None,
6262
insecure: bool = False,
6363
ignore_hostname_verification: bool = False,
64+
user_agent: str = 'Kanboard Python API Client',
6465
loop: Optional[asyncio.AbstractEventLoop] = None):
6566
"""
6667
Constructor
@@ -73,6 +74,7 @@ def __init__(self,
7374
cafile: Path to a custom CA certificate
7475
insecure: Ignore SSL certificate errors and ignore hostname mismatches
7576
ignore_hostname_verification: Ignore SSL certificate hostname verification
77+
user_agent: Use a personalized user agent
7678
loop: An asyncio event loop. Default: asyncio.get_event_loop()
7779
"""
7880
self._url = url
@@ -81,6 +83,7 @@ def __init__(self,
8183
self._auth_header = auth_header
8284
self._cafile = cafile
8385
self._insecure = insecure
86+
self._user_agent = user_agent
8487
self._ignore_hostname_verification = ignore_hostname_verification
8588

8689
if not loop:
@@ -174,6 +177,7 @@ def execute(self, method: str, **kwargs):
174177
headers = {
175178
self._auth_header: auth_header_prefix + credentials.decode(),
176179
'Content-Type': 'application/json',
180+
'User-Agent': self._user_agent,
177181
}
178182

179183
return self._do_request(headers, payload)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def readme():
3030

3131
setup(
3232
name='kanboard',
33-
version='1.1.4',
33+
version='1.1.5',
3434
description='Client library for Kanboard',
3535
long_description=readme(),
3636
keywords='kanboard api client',

0 commit comments

Comments
 (0)