-
Notifications
You must be signed in to change notification settings - Fork 2
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
Review2 #5
Open
KoenDG
wants to merge
2
commits into
master
Choose a base branch
from
review2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Review2 #5
Changes from all commits
Commits
Show all changes
2 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 |
---|---|---|
|
@@ -29,7 +29,7 @@ public class ApiClient { | |
private final String APPID; | ||
|
||
/** API_PATH, API_VERSION for request URL. */ | ||
private final String API_PATH = "api"; | ||
private static final String API_PATH = "api"; | ||
private String API_VERSION = "v1"; | ||
|
||
/** URL path separator */ | ||
|
@@ -199,19 +199,20 @@ public int getDeserializationExceptions() { | |
* used by request. | ||
* @param uri | ||
* of the API call. | ||
* @param data | ||
* in string format to pass to the request. | ||
* @param payload | ||
* data in string format to pass to the request. | ||
* @param authenticate | ||
* True if the call requires authenticate, false if not. | ||
* @return String response for the request. | ||
* @throws IOException | ||
*/ | ||
private String doHttpRequest(String method, String uri, String payload, boolean authenticate) | ||
throws IOException { | ||
URL url; | ||
HttpURLConnection conn = null; | ||
int responseCode = -1; | ||
|
||
try { | ||
url = new URL(uri); | ||
URL url = new URL(uri); | ||
conn = (HttpURLConnection) url.openConnection(); | ||
|
||
// Set connection timeout. | ||
|
@@ -288,8 +289,7 @@ private void login() throws IOException { | |
String uri = credentials.usesToken() ? getAppRequestURL("/login/") | ||
: getGlobalRequestURL("/users/login/"); | ||
Credentials.TokenHelper data = call("POST", uri, credentials, | ||
new TypeReference<Credentials.TokenHelper>() { | ||
}, false); | ||
new TokenHelperTypeReference(), false); | ||
|
||
token = data.token; | ||
} | ||
|
@@ -328,6 +328,7 @@ public <T> T callWithAuth(String method, String endpoint, Object obj, TypeRefere | |
} catch (CoscaleApiException e) { | ||
if (e.statusCode == HttpURLConnection.HTTP_UNAUTHORIZED) { | ||
this.token = null; // will trigger new login | ||
responseCode = 401; // 401 means login failed: https://httpstatuses.com/401 | ||
} else { | ||
throw e; | ||
} | ||
|
@@ -349,6 +350,8 @@ public <T> T callWithAuth(String method, String endpoint, Object obj, TypeRefere | |
* object with data for the request. This parameter can be null. | ||
* @param valueType | ||
* is the type expected. | ||
* @param auth | ||
* true if the call requires authentication, false if not. | ||
* @return The Object received as a result for the request. | ||
* @throws IOException | ||
*/ | ||
|
@@ -410,11 +413,11 @@ public String getGlobalRequestURL(String endpoint) { | |
public String getRequesUrl(String endpoint, Options options, boolean globalApi) { | ||
|
||
StringBuilder sb = new StringBuilder(); | ||
sb.append(getBaseURL()); | ||
sb.append(API_BASE_URL); | ||
sb.append(PATH_DIV); | ||
sb.append(getApiPath()); | ||
sb.append(API_PATH); | ||
sb.append(PATH_DIV); | ||
sb.append(getApiVersion()); | ||
sb.append(API_VERSION); | ||
if (!globalApi) { | ||
sb.append(PATH_DIV); | ||
sb.append("app"); | ||
|
@@ -486,4 +489,12 @@ private <T> String objectToJson(T obj) throws IOException { | |
} | ||
} | ||
} | ||
|
||
/** | ||
* Copied from the Intellij code analysis: | ||
* A static inner class does not keep an implicit reference to its enclosing instance. | ||
* This prevents a common cause of memory leaks and uses less memory per instance of the class. | ||
*/ | ||
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. Apparently a potential source of memory leaks. |
||
private static class TokenHelperTypeReference extends TypeReference<Credentials.TokenHelper> { | ||
} | ||
} |
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
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
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
Oops, something went wrong.
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.
It used to be that the responseCode remained 0, which requires users to read the actual error message before knowing what's wrong.