mirror of
https://github.com/viq/NewsBlur.git
synced 2025-09-18 21:43:31 +00:00
Minor cleanup in APIManager.
This commit is contained in:
parent
14f65c0892
commit
5a666a6a9d
1 changed files with 10 additions and 14 deletions
|
@ -513,15 +513,11 @@ public class APIManager {
|
|||
int tryCount = 0;
|
||||
do {
|
||||
backoffSleep(tryCount++);
|
||||
response = get_single(urlString);
|
||||
response = get_single(urlString, HttpStatus.SC_OK);
|
||||
} while ((response.isError()) && (tryCount < AppConstants.MAX_API_TRIES));
|
||||
return response;
|
||||
}
|
||||
|
||||
private APIResponse get_single(final String urlString) {
|
||||
return get_single(urlString, HttpStatus.SC_OK);
|
||||
}
|
||||
|
||||
private APIResponse get_single(final String urlString, int expectedReturnCode) {
|
||||
if (!NetworkUtils.isOnline(context)) {
|
||||
return new APIResponse(context);
|
||||
|
@ -532,16 +528,20 @@ public class APIManager {
|
|||
}
|
||||
|
||||
Request.Builder requestBuilder = new Request.Builder().url(urlString);
|
||||
addCookieHeader(requestBuilder);
|
||||
requestBuilder.header("User-Agent", this.customUserAgent);
|
||||
|
||||
return new APIResponse(context, httpClient, requestBuilder.build(), expectedReturnCode);
|
||||
}
|
||||
|
||||
private void addCookieHeader(Request.Builder requestBuilder) {
|
||||
SharedPreferences preferences = context.getSharedPreferences(PrefConstants.PREFERENCES, 0);
|
||||
String cookie = preferences.getString(PrefConstants.PREF_COOKIE, null);
|
||||
if (cookie != null) {
|
||||
requestBuilder.header("Cookie", cookie);
|
||||
}
|
||||
requestBuilder.header("User-Agent", this.customUserAgent);
|
||||
|
||||
return new APIResponse(context, httpClient, requestBuilder.build(), expectedReturnCode);
|
||||
}
|
||||
|
||||
|
||||
private APIResponse get(final String urlString, final ContentValues values) {
|
||||
return this.get(urlString + "?" + builderGetParametersString(values));
|
||||
}
|
||||
|
@ -583,11 +583,7 @@ public class APIManager {
|
|||
}
|
||||
|
||||
Request.Builder requestBuilder = new Request.Builder().url(urlString);
|
||||
SharedPreferences preferences = context.getSharedPreferences(PrefConstants.PREFERENCES, 0);
|
||||
String cookie = preferences.getString(PrefConstants.PREF_COOKIE, null);
|
||||
if (cookie != null) {
|
||||
requestBuilder.header("Cookie", cookie);
|
||||
}
|
||||
addCookieHeader(requestBuilder);
|
||||
requestBuilder.post(formBody);
|
||||
|
||||
return new APIResponse(context, httpClient, requestBuilder.build());
|
||||
|
|
Loading…
Add table
Reference in a new issue