Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactoring: move getRequestLogged/postRequestlogged into Login

  • Loading branch information...
commit b65d9bb009e1afbd2aba1f775368a343c0ac7801 1 parent 8074ce7
@samueltardieu samueltardieu authored
View
8 main/src/cgeo/geocaching/cgBase.java
@@ -1359,7 +1359,7 @@ private static SearchResult searchByAny(final cgSearchThread thread, final Cache
final String uri = "http://www.geocaching.com/seek/nearest.aspx";
final String fullUri = uri + "?" + addFToParams(params, false, true);
- final String page = Network.getRequestLogged(uri, addFToParams(params, my, true));
+ final String page = Login.getRequestLogged(uri, addFToParams(params, my, true));
if (StringUtils.isBlank(page)) {
Log.e("cgeoBase.searchByAny: No data from server");
@@ -1439,7 +1439,7 @@ public static cgTrackable searchTrackable(final String geocode, final String gui
params.put("id", id);
}
- final String page = Network.getRequestLogged("http://www.geocaching.com/track/details.aspx", params);
+ final String page = Login.getRequestLogged("http://www.geocaching.com/track/details.aspx", params);
if (StringUtils.isBlank(page)) {
Log.e("cgeoBase.searchTrackable: No data from server");
@@ -1691,7 +1691,7 @@ public static StatusCode postLogTrackable(final String tbid, final String tracki
*/
public static int addToWatchlist(final cgCache cache) {
final String uri = "http://www.geocaching.com/my/watchlist.aspx?w=" + cache.getCacheId();
- String page = Network.postRequestLogged(uri);
+ String page = Login.postRequestLogged(uri);
if (StringUtils.isBlank(page)) {
Log.e("cgBase.addToWatchlist: No data from server");
@@ -1717,7 +1717,7 @@ public static int addToWatchlist(final cgCache cache) {
*/
public static int removeFromWatchlist(final cgCache cache) {
final String uri = "http://www.geocaching.com/my/watchlist.aspx?ds=1&action=rem&id=" + cache.getCacheId();
- String page = Network.postRequestLogged(uri);
+ String page = Login.postRequestLogged(uri);
if (StringUtils.isBlank(page)) {
Log.e("cgBase.removeFromWatchlist: No data from server");
View
4 main/src/cgeo/geocaching/connector/gc/GCConnector.java
@@ -9,7 +9,7 @@
import cgeo.geocaching.connector.AbstractConnector;
import cgeo.geocaching.enumerations.StatusCode;
import cgeo.geocaching.geopoint.Viewport;
-import cgeo.geocaching.network.Network;
+import cgeo.geocaching.network.Login;
import cgeo.geocaching.network.Parameters;
import cgeo.geocaching.utils.CancellableHandler;
import cgeo.geocaching.utils.Log;
@@ -104,7 +104,7 @@ public SearchResult searchByGeocode(final String geocode, final String guid, fin
cgBase.sendLoadProgressDetail(handler, R.string.cache_dialog_loading_details_status_loadpage);
- final String page = Network.getRequestLogged("http://www.geocaching.com/seek/cache_details.aspx", params);
+ final String page = Login.getRequestLogged("http://www.geocaching.com/seek/cache_details.aspx", params);
if (StringUtils.isEmpty(page)) {
final SearchResult search = new SearchResult();
View
41 main/src/cgeo/geocaching/network/Login.java
@@ -378,4 +378,45 @@ public static void transferViewstates(final String page, final Parameters params
putViewstates(params, getViewstates(page));
}
+ /**
+ * POST HTTP request. Do the request a second time if the user is not logged in
+ *
+ * @param uri
+ * @return
+ */
+ public static String postRequestLogged(final String uri) {
+ HttpResponse response = Network.postRequest(uri, null);
+ String data = Network.getResponseData(response);
+
+ if (!getLoginStatus(data)) {
+ if (login() == StatusCode.NO_ERROR) {
+ response = Network.postRequest(uri, null);
+ data = Network.getResponseData(response);
+ } else {
+ Log.i("Working as guest.");
+ }
+ }
+ return data;
+ }
+
+ /**
+ * GET HTTP request. Do the request a second time if the user is not logged in
+ *
+ * @param uri
+ * @param params
+ * @return
+ */
+ public static String getRequestLogged(final String uri, final Parameters params) {
+ final String data = Network.getResponseData(Network.getRequest(uri, params));
+
+ if (!getLoginStatus(data)) {
+ if (login() == StatusCode.NO_ERROR) {
+ return Network.getResponseData(Network.getRequest(uri, params));
+ } else {
+ Log.i("Working as guest.");
+ }
+ }
+ return data;
+ }
+
}
View
45 main/src/cgeo/geocaching/network/Network.java
@@ -1,6 +1,5 @@
package cgeo.geocaching.network;
-import cgeo.geocaching.enumerations.StatusCode;
import cgeo.geocaching.files.LocalStorage;
import cgeo.geocaching.utils.BaseUtils;
import cgeo.geocaching.utils.Log;
@@ -40,7 +39,6 @@
import java.net.URLEncoder;
import java.util.zip.GZIPInputStream;
-
public abstract class Network {
static class GzipDecompressingEntity extends HttpEntityWrapper {
@@ -289,54 +287,13 @@ public static String getResponseData(final HttpResponse response) {
return Network.getResponseData(response, true);
}
- static public String getResponseData(final HttpResponse response, boolean replaceWhitespace) {
+ public static String getResponseData(final HttpResponse response, boolean replaceWhitespace) {
if (!isSuccess(response)) {
return null;
}
return getResponseDataNoError(response, replaceWhitespace);
}
- /**
- * POST HTTP request. Do the request a second time if the user is not logged in
- *
- * @param uri
- * @return
- */
- public static String postRequestLogged(final String uri) {
- HttpResponse response = postRequest(uri, null);
- String data = getResponseData(response);
-
- if (!Login.getLoginStatus(data)) {
- if (Login.login() == StatusCode.NO_ERROR) {
- response = postRequest(uri, null);
- data = getResponseData(response);
- } else {
- Log.i("Working as guest.");
- }
- }
- return data;
- }
-
- /**
- * GET HTTP request. Do the request a second time if the user is not logged in
- *
- * @param uri
- * @param params
- * @return
- */
- public static String getRequestLogged(final String uri, final Parameters params) {
- final String data = getResponseData(getRequest(uri, params));
-
- if (!Login.getLoginStatus(data)) {
- if (Login.login() == StatusCode.NO_ERROR) {
- return getResponseData(getRequest(uri, params));
- } else {
- Log.i("Working as guest.");
- }
- }
- return data;
- }
-
public static String urlencode_rfc3986(String text) {
return StringUtils.replace(URLEncoder.encode(text).replace("+", "%20"), "%7E", "~");
}
Please sign in to comment.
Something went wrong with that request. Please try again.