Skip to content

Commit

Permalink
add proxy support [#16]
Browse files Browse the repository at this point in the history
  • Loading branch information
dnl-blkv committed Aug 21, 2017
1 parent 2c945ae commit 8d8fbac
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
6 changes: 5 additions & 1 deletion bunq/sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class ApiClient(object):
:type _api_context: context.ApiContext
"""

# HTTPS type of proxy, the only used at bunq
_FIELD_PROXY_HTTPS = 'https'

# Header constants
HEADER_ATTACHMENT_DESCRIPTION = 'X-Bunq-Attachment-Description'
HEADER_CONTENT_TYPE = 'Content-Type'
Expand Down Expand Up @@ -98,7 +101,8 @@ def _request(self, method, uri_relative, request_bytes, custom_headers):
method,
self._get_uri_full(uri_relative),
data=request_bytes,
headers=all_headers
headers=all_headers,
proxies={self._FIELD_PROXY_HTTPS: self._api_context.proxy_url}
)

self._assert_response_success(response)
Expand Down
16 changes: 13 additions & 3 deletions bunq/sdk/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class ApiContext(object):
:type _api_key: str
:type _session_context: SessionContext
:type _installation_context: InstallationContext
:type _proxy_url: str|None
"""

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

def __init__(self, environment_type, api_key, device_description,
permitted_ips=None):
permitted_ips=None, proxy_url=None):
"""
:type environment_type: ApiEnvironmentType
:type api_key: str
:type device_description: str
:type permitted_ips: list[str]|None
:type proxy_url: str|None
"""

if permitted_ips is None:
permitted_ips = []
permitted_ips = permitted_ips or []

self._environment_type = environment_type
self._api_key = api_key
self._installation_context = None
self._session_context = None
self._proxy_url = proxy_url
self._initialize(device_description, permitted_ips)

def _initialize(self, device_description, permitted_ips):
Expand Down Expand Up @@ -254,6 +256,14 @@ def session_context(self):

return self._session_context

@property
def proxy_url(self):
"""
:rtype: str
"""

return self._proxy_url

def save(self, path=None):
"""
:type path: str
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
aenum==2.0.8
chardet==3.0.4
pycryptodomex==3.4.6
requests==2.18.1
requests[socks]==2.18.1
simplejson==3.11.1
urllib3==1.21.1

0 comments on commit 8d8fbac

Please sign in to comment.