Skip to content

Commit 8d8fbac

Browse files
committed
add proxy support [#16]
1 parent 2c945ae commit 8d8fbac

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

bunq/sdk/client.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ class ApiClient(object):
1919
:type _api_context: context.ApiContext
2020
"""
2121

22+
# HTTPS type of proxy, the only used at bunq
23+
_FIELD_PROXY_HTTPS = 'https'
24+
2225
# Header constants
2326
HEADER_ATTACHMENT_DESCRIPTION = 'X-Bunq-Attachment-Description'
2427
HEADER_CONTENT_TYPE = 'Content-Type'
@@ -98,7 +101,8 @@ def _request(self, method, uri_relative, request_bytes, custom_headers):
98101
method,
99102
self._get_uri_full(uri_relative),
100103
data=request_bytes,
101-
headers=all_headers
104+
headers=all_headers,
105+
proxies={self._FIELD_PROXY_HTTPS: self._api_context.proxy_url}
102106
)
103107

104108
self._assert_response_success(response)

bunq/sdk/context.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class ApiContext(object):
4141
:type _api_key: str
4242
:type _session_context: SessionContext
4343
:type _installation_context: InstallationContext
44+
:type _proxy_url: str|None
4445
"""
4546

4647
# File mode for saving and restoring the context
@@ -57,21 +58,22 @@ class ApiContext(object):
5758
_PATH_API_CONTEXT_DEFAULT = 'bunq.conf'
5859

5960
def __init__(self, environment_type, api_key, device_description,
60-
permitted_ips=None):
61+
permitted_ips=None, proxy_url=None):
6162
"""
6263
:type environment_type: ApiEnvironmentType
6364
:type api_key: str
6465
:type device_description: str
6566
:type permitted_ips: list[str]|None
67+
:type proxy_url: str|None
6668
"""
6769

68-
if permitted_ips is None:
69-
permitted_ips = []
70+
permitted_ips = permitted_ips or []
7071

7172
self._environment_type = environment_type
7273
self._api_key = api_key
7374
self._installation_context = None
7475
self._session_context = None
76+
self._proxy_url = proxy_url
7577
self._initialize(device_description, permitted_ips)
7678

7779
def _initialize(self, device_description, permitted_ips):
@@ -254,6 +256,14 @@ def session_context(self):
254256

255257
return self._session_context
256258

259+
@property
260+
def proxy_url(self):
261+
"""
262+
:rtype: str
263+
"""
264+
265+
return self._proxy_url
266+
257267
def save(self, path=None):
258268
"""
259269
:type path: str

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
aenum==2.0.8
22
chardet==3.0.4
33
pycryptodomex==3.4.6
4-
requests==2.18.1
4+
requests[socks]==2.18.1
55
simplejson==3.11.1
66
urllib3==1.21.1

0 commit comments

Comments
 (0)