Skip to content

Commit

Permalink
Merge pull request gettyimages#24 from gettyimages/ChrisSimmons-patch-1
Browse files Browse the repository at this point in the history
ApiClient and Credentials "help"
  • Loading branch information
ChrisSimmons authored Sep 18, 2023
2 parents 43a4a63 + f16ccf6 commit 9566a26
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,7 @@ ApiClient client = ApiClient.GetApiClientWithClientCredentials(apiKey, apiSecret
```

For more examples, see unittests package.

## `ApiClient` lifecycle

In production applications, we recommend utilizing the `ApiClient` as a global singleton. This ensures that token caching is properly performed.
6 changes: 3 additions & 3 deletions src/main/java/com/gettyimages/api/Credentials.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ public static Credentials GetInstance(String apiKey, String apiSecret, String us
}

public Token GetAccessToken() throws SdkException {
Calendar now = Calendar.getInstance();
now.add(Calendar.MINUTE, 5);
Calendar expirationCushion = Calendar.getInstance();
expirationCushion.add(Calendar.MINUTE, 5);

if (CredentialType != CredentialType.ClientCredentials && CredentialType != CredentialType.ResourceOwner && CredentialType != CredentialType.RefreshToken
||
(accessToken != null && accessToken.getExpiration().compareTo(now.getTime()) >= 0)) {
(accessToken != null && accessToken.getExpiration().compareTo(expirationCushion.getTime()) >= 0)) {
return accessToken;
}

Expand Down

0 comments on commit 9566a26

Please sign in to comment.