Skip to content

Commit f505717

Browse files
author
Kevin Hellemun
committed
Reflected PHP review changes.
1 parent a68ec14 commit f505717

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

bunq/sdk/client.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ class ApiClient(object):
1515
:type _api_context: bunq.sdk.context.ApiContext
1616
"""
1717

18+
# Endpoints not requiring active session for the request to succeed.
19+
_URL_DEVICE_SERVER = 'device-server'
20+
_URI_INSTALLATION = 'installation'
21+
_URI_SESSION_SERVER = 'session-server'
22+
_URIS_NOT_REQUIRING_ACTIVE_SESSION = [
23+
_URI_INSTALLATION,
24+
_URI_SESSION_SERVER,
25+
_URL_DEVICE_SERVER,
26+
]
27+
1828
# HTTPS type of proxy, the only used at bunq
1929
_FIELD_PROXY_HTTPS = 'https'
2030

@@ -93,7 +103,8 @@ def _request(self, method, uri_relative, request_bytes, params,
93103

94104
uri_relative_with_params = self._append_params_to_uri(uri_relative,
95105
params)
96-
self._api_context.ensure_session_active()
106+
if uri_relative not in self._URIS_NOT_REQUIRING_ACTIVE_SESSION:
107+
self._api_context.ensure_session_active()
97108
all_headers = self._get_all_headers(
98109
method,
99110
uri_relative_with_params,

bunq/sdk/context.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,14 @@ def _get_session_timeout_seconds(cls, session_server):
166166
return session_server.user_person.session_timeout
167167

168168
def ensure_session_active(self):
169-
if self.is_session_expired() and self.session_context is not None:
169+
"""
170+
Resets the session if it has expired.
171+
"""
172+
173+
if not self.is_session_active():
170174
self.reset_session()
171175

172-
def is_session_expired(self):
176+
def is_session_active(self):
173177
"""
174178
:return: True if it has expired, otherwise false
175179
:rtype: bool
@@ -184,7 +188,7 @@ def is_session_expired(self):
184188
seconds=self._TIME_TO_SESSION_EXPIRY_MINIMUM_SECONDS
185189
)
186190

187-
return time_to_expiry < time_to_expiry_minimum
191+
return time_to_expiry > time_to_expiry_minimum
188192

189193
def reset_session(self):
190194
"""

0 commit comments

Comments
 (0)