Skip to content

Commit ff07b08

Browse files
author
Kevin Hellemun
committed
Update bunqContext when apiContext has expired. (#65)
1 parent b451aa9 commit ff07b08

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

bunq/sdk/client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,10 @@ def _request(self, method, uri_relative, request_bytes, params,
113113
uri_relative_with_params = self._append_params_to_uri(uri_relative,
114114
params)
115115
if uri_relative not in self._URIS_NOT_REQUIRING_ACTIVE_SESSION:
116-
self._api_context.ensure_session_active()
116+
if self._api_context.ensure_session_active():
117+
from bunq.sdk.context import BunqContext
118+
119+
BunqContext.update_api_context(self._api_context)
117120

118121
all_headers = self._get_all_headers(
119122
method,

bunq/sdk/context.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,20 @@ def _get_session_timeout_seconds(cls, session_server):
167167
else:
168168
return session_server.user_person.session_timeout
169169

170-
def ensure_session_active(self):
170+
def ensure_session_active(self) -> bool:
171171
"""
172172
Resets the session if it has expired.
173+
174+
:rtype: bool
173175
"""
174176

175177
if not self.is_session_active():
176178
self.reset_session()
177179

180+
return True
181+
182+
return False
183+
178184
def is_session_active(self):
179185
"""
180186
:rtype: bool
@@ -564,3 +570,7 @@ def user_context(cls):
564570
return cls._user_context
565571

566572
raise BunqException(cls._ERROR_USER_CONTEXT_HAS_NOT_BEEN_LOADED)
573+
574+
@classmethod
575+
def update_api_context(cls, api_context: ApiContext):
576+
cls._api_context = api_context

0 commit comments

Comments
 (0)