Skip to content

Commit 60a9159

Browse files
authored
Merge pull request #61 from livechat/API-10249/Add-proxy-support
Add support to use proxy in httpx client
2 parents 5364835 + 61c003e commit 60a9159

File tree

5 files changed

+48
-13
lines changed

5 files changed

+48
-13
lines changed

changelog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# Change Log
22
All notable changes to this project will be documented in this file.
33

4+
## [0.1.11] - Unreleased
5+
6+
### Added
7+
8+
- Added proxy support to web interfaces
9+
10+
411
## [0.1.10] - 2021-12-02
512

613
### Added

livechat/agent/web/client.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,23 @@ def get_client(access_token: str,
4949

5050
class AgentWebInterface(metaclass=ABCMeta):
5151
''' Main class containing API methods. '''
52-
def __init__(self, access_token: str, version: str, base_url: str,
53-
http2: bool) -> AgentWebInterface:
52+
def __init__(self,
53+
access_token: str,
54+
version: str,
55+
base_url: str,
56+
http2: bool,
57+
proxies=None,
58+
verify: bool = True) -> AgentWebInterface:
5459
logger = HttpxLogger()
5560
self.api_url = f'https://{base_url}/v{version}/agent/action'
5661
self.session = httpx.Client(http2=http2,
5762
headers={'Authorization': access_token},
5863
event_hooks={
5964
'request': [logger.log_request],
6065
'response': [logger.log_response]
61-
})
66+
},
67+
proxies=proxies,
68+
verify=verify)
6269

6370
def modify_header(self, header: dict) -> None:
6471
''' Modifies provided header in session object.

livechat/configuration/client.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,23 @@ def get_client(token: str,
4646

4747
class ConfigurationApiInterface(metaclass=ABCMeta):
4848
''' Interface class. '''
49-
def __init__(self, token: str, version: str, base_url: str,
50-
http2: bool) -> ConfigurationApiInterface:
49+
def __init__(self,
50+
token: str,
51+
version: str,
52+
base_url: str,
53+
http2: bool,
54+
proxies=None,
55+
verify: bool = True) -> ConfigurationApiInterface:
5156
logger = HttpxLogger()
5257
self.api_url = f'https://{base_url}/v{version}/configuration/action'
5358
self.session = httpx.Client(http2=http2,
5459
headers={'Authorization': token},
5560
event_hooks={
5661
'request': [logger.log_request],
5762
'response': [logger.log_response]
58-
})
63+
},
64+
proxies=proxies,
65+
verify=verify)
5966

6067
def modify_header(self, header: dict) -> None:
6168
''' Modifies provided header in session object.

livechat/customer/web/client.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def get_client(license_id: int = None,
2727
2828
Args:
2929
license_id (int): License ID. Required to use API v3.3.
30-
token (str): Full token with type (Bearer/Basic) that will be
30+
token (str): Full token with type (Bearer) that will be
3131
used as `Authorization` header in requests to API.
3232
version (str): API's version. Defaults to `3.3`.
3333
base_url (str): API's base url. Defaults to `api.livechatinc.com`.
@@ -66,8 +66,13 @@ def get_client(license_id: int = None,
6666

6767
class CustomerWebInterface(metaclass=ABCMeta):
6868
''' Main class containing API methods. '''
69-
def __init__(self, access_token: str, version: str, base_url: str,
70-
http2: bool) -> CustomerWebInterface:
69+
def __init__(self,
70+
access_token: str,
71+
version: str,
72+
base_url: str,
73+
http2: bool,
74+
proxies=None,
75+
verify: bool = True) -> CustomerWebInterface:
7176
logger = HttpxLogger()
7277
self.api_url = f'https://{base_url}/v{version}/customer/action'
7378
if all([access_token, isinstance(access_token, str)]):
@@ -77,7 +82,9 @@ def __init__(self, access_token: str, version: str, base_url: str,
7782
event_hooks={
7883
'request': [logger.log_request],
7984
'response': [logger.log_response]
80-
})
85+
},
86+
proxies=proxies,
87+
verify=verify)
8188
else:
8289
raise ValueError(
8390
'Incorrect or missing `access_token` argument (should be of type str.)'

livechat/reports/client.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,23 @@ def get_client(token: str,
4747

4848
class ReportsApiInterface(metaclass=ABCMeta):
4949
''' Interface class. '''
50-
def __init__(self, token: str, version: str, base_url: str,
51-
http2: bool) -> ReportsApiInterface:
50+
def __init__(self,
51+
token: str,
52+
version: str,
53+
base_url: str,
54+
http2: bool,
55+
proxies=None,
56+
verify: bool = True) -> ReportsApiInterface:
5257
logger = HttpxLogger()
5358
self.api_url = f'https://{base_url}/v{version}/reports'
5459
self.session = httpx.Client(http2=http2,
5560
headers={'Authorization': token},
5661
event_hooks={
5762
'request': [logger.log_request],
5863
'response': [logger.log_response]
59-
})
64+
},
65+
proxies=proxies,
66+
verify=verify)
6067

6168
def modify_header(self, header: dict) -> None:
6269
''' Modifies provided header in session object.

0 commit comments

Comments
 (0)