Skip to content

Commit

Permalink
Add support for custom user agent
Browse files Browse the repository at this point in the history
  • Loading branch information
fguillot committed Feb 12, 2023
1 parent c178740 commit 97b496a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
22 changes: 20 additions & 2 deletions README.rst
Expand Up @@ -68,6 +68,18 @@ Create a new task
project_id = kb.create_project(name='My project')
task_id = kb.create_task(project_id=project_id, title='My task title')
Use a personalized user agent
-----------------------------

.. code-block:: python
import kanboard
kb = kanboard.Client(url='http://localhost/jsonrpc.php',
username='admin',
password='secret',
user_agent='My Kanboard client')
SSL connection and self-signed certificates
===========================================

Expand All @@ -86,7 +98,10 @@ Example with a custom certificate:
import kanboard
kb = kanboard.Client('https://example.org/jsonrpc.php', 'admin', 'secret', cafile='/path/to/my/cert.pem')
kb = kanboard.Client(url='https://example.org/jsonrpc.php',
username='admin',
password='secret',
cafile='/path/to/my/cert.pem')
kb.get_my_projects()
Example with a custom certificate and hostname mismatch:
Expand All @@ -108,7 +123,10 @@ Ignore invalid/expired certificates and hostname mismatches, which will make you
import kanboard
kb = kanboard.Client('https://example.org/jsonrpc.php', 'admin', 'secret', insecure=True)
kb = kanboard.Client(url='https://example.org/jsonrpc.php',
username='admin',
password='secret',
insecure=True)
kb.get_my_projects()
Asynchronous I/O
Expand Down
4 changes: 4 additions & 0 deletions kanboard.py
Expand Up @@ -61,6 +61,7 @@ def __init__(self,
cafile: Optional[str] = None,
insecure: bool = False,
ignore_hostname_verification: bool = False,
user_agent: str = 'Kanboard Python API Client',
loop: Optional[asyncio.AbstractEventLoop] = None):
"""
Constructor
Expand All @@ -73,6 +74,7 @@ def __init__(self,
cafile: Path to a custom CA certificate
insecure: Ignore SSL certificate errors and ignore hostname mismatches
ignore_hostname_verification: Ignore SSL certificate hostname verification
user_agent: Use a personalized user agent
loop: An asyncio event loop. Default: asyncio.get_event_loop()
"""
self._url = url
Expand All @@ -81,6 +83,7 @@ def __init__(self,
self._auth_header = auth_header
self._cafile = cafile
self._insecure = insecure
self._user_agent = user_agent
self._ignore_hostname_verification = ignore_hostname_verification

if not loop:
Expand Down Expand Up @@ -174,6 +177,7 @@ def execute(self, method: str, **kwargs):
headers = {
self._auth_header: auth_header_prefix + credentials.decode(),
'Content-Type': 'application/json',
'User-Agent': self._user_agent,
}

return self._do_request(headers, payload)
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -30,7 +30,7 @@ def readme():

setup(
name='kanboard',
version='1.1.4',
version='1.1.5',
description='Client library for Kanboard',
long_description=readme(),
keywords='kanboard api client',
Expand Down

0 comments on commit 97b496a

Please sign in to comment.