-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added isSessionExpired() method #31. #32
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,16 @@ class ApiClient(object): | |
:type _api_context: bunq.sdk.context.ApiContext | ||
""" | ||
|
||
# Endpoints not requiring active session for the request to succeed. | ||
_URL_DEVICE_SERVER = 'device-server' | ||
_URI_INSTALLATION = 'installation' | ||
_URI_SESSION_SERVER = 'session-server' | ||
_URIS_NOT_REQUIRING_ACTIVE_SESSION = [ | ||
_URI_INSTALLATION, | ||
_URI_SESSION_SERVER, | ||
_URL_DEVICE_SERVER, | ||
] | ||
|
||
# HTTPS type of proxy, the only used at bunq | ||
_FIELD_PROXY_HTTPS = 'https' | ||
|
||
|
@@ -93,7 +103,8 @@ def _request(self, method, uri_relative, request_bytes, params, | |
|
||
uri_relative_with_params = self._append_params_to_uri(uri_relative, | ||
params) | ||
self._api_context.ensure_session_active() | ||
if uri_relative not in self._URIS_NOT_REQUIRING_ACTIVE_SESSION: | ||
self._api_context.ensure_session_active() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a newline after the if body! :) |
||
all_headers = self._get_all_headers( | ||
method, | ||
uri_relative_with_params, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -166,17 +166,29 @@ def _get_session_timeout_seconds(cls, session_server): | |
return session_server.user_person.session_timeout | ||
|
||
def ensure_session_active(self): | ||
""" | ||
Resets the session if it has expired. | ||
""" | ||
|
||
if not self.is_session_active(): | ||
self.reset_session() | ||
|
||
def is_session_active(self): | ||
""" | ||
:return: True if it has expired, otherwise false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please kill this |
||
:rtype: bool | ||
""" | ||
|
||
if self.session_context is None: | ||
return | ||
return False | ||
|
||
time_now = datetime.datetime.now() | ||
time_to_expiry = self.session_context.expiry_time - time_now | ||
time_to_expiry_minimum = datetime.timedelta( | ||
seconds=self._TIME_TO_SESSION_EXPIRY_MINIMUM_SECONDS | ||
) | ||
|
||
if time_to_expiry < time_to_expiry_minimum: | ||
self.reset_session() | ||
return time_to_expiry > time_to_expiry_minimum | ||
|
||
def reset_session(self): | ||
""" | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please put these constants after the map (just like we do in PHP).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That won't work in python 😅 ?
https://stackoverflow.com/questions/1590608/is-it-possible-to-forward-declare-a-function-in-python
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, you're right! My apologies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
python is not that magical ✨ 😂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@OGKevin declare time mixed with run time? Tell me it is not magical :P