From 7d0749bf690b36d0f5443a3a0adf133df08aff01 Mon Sep 17 00:00:00 2001 From: Chris Simmons Date: Mon, 18 Sep 2023 08:51:21 -0700 Subject: [PATCH 1/2] ApiClient information in README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 00bf1f6..350cd25 100644 --- a/README.md +++ b/README.md @@ -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. From f16ccf6ece56630f8dfd0496652d3f6a3472841c Mon Sep 17 00:00:00 2001 From: Chris Simmons Date: Mon, 18 Sep 2023 08:53:45 -0700 Subject: [PATCH 2/2] Try for more meaningful name than "now" --- src/main/java/com/gettyimages/api/Credentials.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/gettyimages/api/Credentials.java b/src/main/java/com/gettyimages/api/Credentials.java index dc934ff..dcdeb5f 100644 --- a/src/main/java/com/gettyimages/api/Credentials.java +++ b/src/main/java/com/gettyimages/api/Credentials.java @@ -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; }