aboutsummaryrefslogtreecommitdiffstats
path: root/main/src
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2011-09-22 23:52:04 +0200
committerSamuel Tardieu <sam@rfc1149.net>2011-09-26 08:55:08 +0200
commitf29a5ef2fbe59b607692561bfc7ddcc1271c3132 (patch)
treebb146961058e263564b3e3eac0886d7dda70aa20 /main/src
parent1246ee08e243bfb7aa876af9b2a206e6c2d485d3 (diff)
downloadcgeo-f29a5ef2fbe59b607692561bfc7ddcc1271c3132.zip
cgeo-f29a5ef2fbe59b607692561bfc7ddcc1271c3132.tar.gz
cgeo-f29a5ef2fbe59b607692561bfc7ddcc1271c3132.tar.bz2
Return a JSONObject from requestJSON()
Diffstat (limited to 'main/src')
-rw-r--r--main/src/cgeo/geocaching/cgBase.java11
-rw-r--r--main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java9
2 files changed, 9 insertions, 11 deletions
diff --git a/main/src/cgeo/geocaching/cgBase.java b/main/src/cgeo/geocaching/cgBase.java
index fa3ec7c..747b3f6 100644
--- a/main/src/cgeo/geocaching/cgBase.java
+++ b/main/src/cgeo/geocaching/cgBase.java
@@ -3822,7 +3822,7 @@ public class cgBase {
return ins;
}
- public static String requestJSON(String host, String path, String params) {
+ public static JSONObject requestJSON(String host, String path, String params) {
final HttpClient client = new DefaultHttpClient();
final Uri uri = buildURI(false, host, path, params);
final HttpGet request = new HttpGet(uri.toString());
@@ -3845,13 +3845,13 @@ public class cgBase {
final String paramsLog = params.replaceAll(passMatch, "password=***");
Log.i(cgSettings.tag + " | JSON", "[POST " + (int) (params.length() / 1024) + "k | " + statusCode + " | " + (int) (buffer.length() / 1024) + "k] Downloaded " + "http://" + host + path + "?" + paramsLog);
- return replaceWhitespace(buffer);
+ return new JSONObject(buffer.toString());
} catch (Exception e) {
Log.e(cgSettings.tag, "cgeoBase.requestJSON", e);
}
}
- return "";
+ return null;
}
public static boolean deleteDirectory(File path) {
@@ -4339,13 +4339,12 @@ public class cgBase {
String.format((Locale) null, "%.6f", coords.getLatitude()) + "," +
String.format((Locale) null, "%.6f", coords.getLongitude());
- final String data = requestJSON(host, path, params);
+ final JSONObject response = requestJSON(host, path, params);
- if (StringUtils.isBlank(data)) {
+ if (response == null) {
return null;
}
- JSONObject response = new JSONObject(data);
String status = response.getString("status");
if (status == null || status.equalsIgnoreCase("OK") == false) {
diff --git a/main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java b/main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java
index e9dcded..ae9d869 100644
--- a/main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java
+++ b/main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java
@@ -59,9 +59,9 @@ final public class OkapiClient {
public static cgCache getCache(final String geoCode) {
final String params = "cache_code=" + geoCode + "&" + SERVICE_CACHE_FIELDS;
- final String data = request(geoCode, SERVICE_CACHE, params, 1);
+ final JSONObject data = request(geoCode, SERVICE_CACHE, params, 1);
- if (StringUtils.isBlank(data)) {
+ if (data == null) {
return null;
}
@@ -73,10 +73,9 @@ final public class OkapiClient {
return cache;
}
- private static cgCache parseCache(final String data) {
+ private static cgCache parseCache(final JSONObject response) {
final cgCache cache = new cgCache();
try {
- final JSONObject response = new JSONObject(data);
cache.geocode = response.getString(CACHE_CODE);
cache.name = response.getString(CACHE_NAME);
// not used: names
@@ -246,7 +245,7 @@ final public class OkapiClient {
return "other";
}
- private static String request(final String geoCode, final String service, final String params, final int level) {
+ private static JSONObject request(final String geoCode, final String service, final String params, final int level) {
final IConnector connector = ConnectorFactory.getConnector(geoCode);
if (connector == null) {
return null;