Skip to content

Commit

Permalink
Fixed session active method. (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
OGKevin committed Jul 16, 2018
1 parent 88def02 commit 5d723db
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
16 changes: 10 additions & 6 deletions BunqSdk/Context/ApiContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,14 @@ private void DeleteSession()
/// <summary>
/// Check if current time is too close to the saved session expiry time and reset session if needed.
/// </summary>
public void EnsureSessionActive()
public bool EnsureSessionActive()
{
if (!IsSessionActive())
{
ResetSession();
}
if (IsSessionActive()) return false;

ResetSession();

return true;

}

public bool IsSessionActive()
Expand All @@ -196,7 +198,9 @@ public bool IsSessionActive()
TIME_TO_SESSION_EXPIRY_MINIMUM_SECONDS
);

return timeToExpiry > timeToExpiryMinimum;
var comparison = timeToExpiry.CompareTo(timeToExpiryMinimum);

return comparison <= 0;
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions BunqSdk/Http/ApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ private BunqResponseRaw SendRequest(HttpMethod method, string uriRelative,
private BunqResponseRaw SendRequest(HttpRequestMessage requestMessage,
IDictionary<string, string> customHeaders, string uriRelative)
{
if (!URIS_NOT_REQUIRING_ACTIVE_SESSION.Contains(uriRelative))
if (!URIS_NOT_REQUIRING_ACTIVE_SESSION.Contains(uriRelative) && apiContext.EnsureSessionActive())
{
apiContext.EnsureSessionActive();
BunqContext.UpdateApiContext(apiContext);
}

SetDefaultHeaders(requestMessage);
Expand Down

0 comments on commit 5d723db

Please sign in to comment.