Small refactoring
This commit is contained in:
parent
4a3de9a51b
commit
5d69794e27
1 changed files with 34 additions and 35 deletions
|
@ -98,12 +98,10 @@ public class OsmBugsRemoteUtil implements OsmBugsUtil {
|
|||
return editingPOI(getUserDetailsApi(), GET, "validate_login", false);
|
||||
}
|
||||
|
||||
private OsmBugResult editingPOI(String url, String requestMethod, String userOperation,
|
||||
boolean anonymous) {
|
||||
private OsmBugResult editingPOI(String url, String requestMethod, String userOperation, boolean anonymous) {
|
||||
OsmOAuthAuthorizationAdapter authorizationAdapter = new OsmOAuthAuthorizationAdapter(app);
|
||||
OsmBugResult result = new OsmBugResult();
|
||||
if (!anonymous) {
|
||||
if (authorizationAdapter.isValidToken()) {
|
||||
if (authorizationAdapter.isValidToken() && !anonymous) {
|
||||
try {
|
||||
result = performOAuthRequest(url, requestMethod, userOperation, authorizationAdapter);
|
||||
} catch (InterruptedException e) {
|
||||
|
@ -118,7 +116,7 @@ public class OsmBugsRemoteUtil implements OsmBugsUtil {
|
|||
}
|
||||
} else {
|
||||
try {
|
||||
result = performBasicRequest(url, requestMethod);
|
||||
result = performBasicRequest(url, requestMethod, anonymous);
|
||||
} catch (FileNotFoundException | NullPointerException e) {
|
||||
// that's tricky case why NPE is thrown to fix that problem httpClient could be used
|
||||
String msg = app.getString(R.string.auth_failed);
|
||||
|
@ -132,19 +130,20 @@ public class OsmBugsRemoteUtil implements OsmBugsUtil {
|
|||
result.warning = e.getMessage() + " link unavailable";
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private OsmBugResult performBasicRequest(String url, String requestMethod) throws IOException {
|
||||
private OsmBugResult performBasicRequest(String url, String requestMethod, boolean anonymous) throws IOException {
|
||||
OsmBugResult result = new OsmBugResult();
|
||||
HttpURLConnection connection = NetworkUtils.getHttpURLConnection(url);
|
||||
log.info("Editing poi " + url);
|
||||
connection.setConnectTimeout(15000);
|
||||
connection.setRequestMethod(requestMethod);
|
||||
connection.setRequestProperty("User-Agent", Version.getFullVersion(app));
|
||||
if (!anonymous) {
|
||||
String token = settings.USER_NAME.get() + ":" + settings.USER_PASSWORD.get();
|
||||
connection.addRequestProperty("Authorization", "Basic " + Base64.encode(token.getBytes(StandardCharsets.UTF_8)));
|
||||
}
|
||||
connection.setDoInput(true);
|
||||
connection.connect();
|
||||
String msg = connection.getResponseMessage();
|
||||
|
|
Loading…
Reference in a new issue