diff options
| -rw-r--r-- | main/src/cgeo/geocaching/connector/oc/OkapiClient.java | 21 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/files/LocParser.java | 6 | ||||
| -rw-r--r-- | send2cgeo/send2cgeo.user.js | 4 | ||||
| -rw-r--r-- | send2cgeo/send2cgeoOc.user.js | 78 | ||||
| -rw-r--r-- | tests/src/cgeo/geocaching/connector/oc/OkapiClientTest.java | 2 | ||||
| -rw-r--r-- | tests/src/cgeo/geocaching/files/LocParserTest.java | 6 |
6 files changed, 92 insertions, 25 deletions
diff --git a/main/src/cgeo/geocaching/connector/oc/OkapiClient.java b/main/src/cgeo/geocaching/connector/oc/OkapiClient.java index 9920e6f..3c99bc9 100644 --- a/main/src/cgeo/geocaching/connector/oc/OkapiClient.java +++ b/main/src/cgeo/geocaching/connector/oc/OkapiClient.java @@ -137,7 +137,6 @@ final public class OkapiClient { return parseCache(data); } - // Assumes level 3 OAuth public static List<Geocache> getCachesAround(final Geopoint center, OCApiConnector connector) { String centerString = GeopointFormatter.format(GeopointFormatter.Format.LAT_DECDEGREE_RAW, center) + SEPARATOR + GeopointFormatter.format(GeopointFormatter.Format.LON_DECDEGREE_RAW, center); final Parameters params = new Parameters("search_method", METHOD_SEARCH_NEAREST); @@ -145,12 +144,7 @@ final public class OkapiClient { valueMap.put("center", centerString); valueMap.put("limit", "20"); - if (connector.getSupportedAuthLevel() != OAuthLevel.Level3) { - Log.e("Calling OkapiClient.getCachesAround with wrong connector"); - return Collections.emptyList(); - } - - addFilterParams(valueMap); + addFilterParams(valueMap, connector); params.add("search_params", new JSONObject(valueMap).toString()); @@ -180,13 +174,7 @@ final public class OkapiClient { final Map<String, String> valueMap = new LinkedHashMap<String, String>(); valueMap.put("bbox", bboxString); - // FIXME Why is this testing level 3? The to be used service is level 1 only. - if (connector.getSupportedAuthLevel() != OAuthLevel.Level3) { - Log.e("Calling OkapiClient.getCachesBBox with wrong connector"); - return Collections.emptyList(); - } - - addFilterParams(valueMap); + addFilterParams(valueMap, connector); params.add("search_params", new JSONObject(valueMap).toString()); @@ -641,12 +629,11 @@ final public class OkapiClient { return "en"; } - // assumes level 3 oauth - private static void addFilterParams(final Map<String, String> valueMap) { + private static void addFilterParams(final Map<String, String> valueMap, OCApiConnector connector) { if (!Settings.isExcludeDisabledCaches()) { valueMap.put("status", "Available|Temporarily unavailable"); } - if (Settings.isExcludeMyCaches()) { + if (Settings.isExcludeMyCaches() && connector.getSupportedAuthLevel() == OAuthLevel.Level3) { valueMap.put("exclude_my_own", "true"); valueMap.put("found_status", "notfound_only"); } diff --git a/main/src/cgeo/geocaching/files/LocParser.java b/main/src/cgeo/geocaching/files/LocParser.java index 49b9d6e..1cfb2a3 100644 --- a/main/src/cgeo/geocaching/files/LocParser.java +++ b/main/src/cgeo/geocaching/files/LocParser.java @@ -76,7 +76,7 @@ public final class LocParser extends FileParser { if (StringUtils.isBlank(cache.getName())) { cache.setName(coord.getName()); } - cache.setOwnerDisplayName(coord.getOwnerDisplayName()); + cache.setOwnerUserId(coord.getOwnerUserId()); } static Map<String, Geocache> parseCoordinates(final String fileContent) { @@ -152,8 +152,8 @@ public final class LocParser extends FileParser { if (matcherName.find()) { final String name = matcherName.group(1).trim(); String ownerName = StringUtils.trim(StringUtils.substringAfterLast(name, NAME_OWNER_SEPARATOR)); - if (StringUtils.isEmpty(cache.getOwnerDisplayName()) && StringUtils.isNotEmpty(ownerName)) { - cache.setOwnerDisplayName(ownerName); + if (StringUtils.isEmpty(cache.getOwnerUserId()) && StringUtils.isNotEmpty(ownerName)) { + cache.setOwnerUserId(ownerName); } cache.setName(StringUtils.substringBeforeLast(name, NAME_OWNER_SEPARATOR).trim()); } else { diff --git a/send2cgeo/send2cgeo.user.js b/send2cgeo/send2cgeo.user.js index b309b58..bd20f3a 100644 --- a/send2cgeo/send2cgeo.user.js +++ b/send2cgeo/send2cgeo.user.js @@ -4,9 +4,10 @@ // @description Add button "Send to c:geo" to geocaching.com // @include http://www.geocaching.com/seek/cache_details* // @include http://www.geocaching.com/map/* +// @include http://www.geocaching.com/geocache/* // @icon http://send2.cgeo.org/content/images/logo.png // @updateURL http://send2.cgeo.org/send2cgeo.user.js -// @version 0.26 +// @version 0.27 // ==/UserScript== // Inserts javascript that will be called by the s2cgeo button. The closure @@ -81,6 +82,7 @@ s.textContent = '(' + function() { + '/>'; $('#Download p:last').append(html); + $('#Download dd:last').append(html); } } + ')();'; diff --git a/send2cgeo/send2cgeoOc.user.js b/send2cgeo/send2cgeoOc.user.js new file mode 100644 index 0000000..abf4707 --- /dev/null +++ b/send2cgeo/send2cgeoOc.user.js @@ -0,0 +1,78 @@ +// ==UserScript== +// @name Send to c:geo for opencaching +// @namespace http://send2.cgeo.org/ +// @description Add button "Send to c:geo" to opencaching.de +// @include http://www.opencaching.de/viewcache.php* +// @icon http://send2.cgeo.org/content/images/logo.png +// @version 0.1 +// ==/UserScript== + +// Inserts javascript that will be called by the s2cgeo button. The closure +// look strange, but avoids having to escape the code. Almost everything +// is put into that script element so that geocaching.com's jQuery may be +// accessed. + +var s = document.createElement('script'); +s.type = 'text/javascript'; +s.innerHTML = 'function s2cgeo(code) {\n' + + '// show the box and the "please wait" text\n' + + 'document.getElementById("send2cgeo").style.display="block";\n' + + 'document.getElementById("send2cgeo").childNodes[0].style.display="block";\n' + + '// hide iframe for now and wait for page to be loaded\n' + + 'document.getElementById("send2cgeo").childNodes[1]\n' + + ' .style.display="none";\n' + + 'document.getElementById("send2cgeo").childNodes[1]\n' + + ' .onload=function() {\n' + + ' document.getElementById(\'send2cgeo\').childNodes[0]\n' + + ' .style.display="none";\n' + + ' document.getElementById(\'send2cgeo\').childNodes[1]\n' + + ' .style.display="block";\n' + + ' // hide box after 3 seconds\n' + + ' setTimeout( function() {' + + ' document.getElementById(\'send2cgeo\').style.display="none";}, 3000);\n' + + ' };\n' + + 'document.getElementById("send2cgeo").childNodes[1]\n' + + ' .src="http://send2.cgeo.org/add.html?cache="+code;\n' + + '}'; + +// Inject Script. +document.getElementsByTagName("head")[0].appendChild(s); + + // Defines the elements to insert into the page ////////////////////////////// + var boxWidth = 20, + boxHeight = 7; + + var boxStyle = 'display:none; background:#1D1D1D; z-index:1000; left:50%;' + + 'box-shadow:0 0 0.5em #000; padding:0; border:0; ' + + 'position:fixed; top:0.5em; text-align:center; ' + + 'margin-left:-'+(boxWidth/2)+'em; line-height:'+boxHeight+'em;' + + 'width:'+boxWidth+'em; height:'+boxHeight+'em; color: #fff'; + var waitStyle = 'width: '+boxWidth+'em; color: #fff'; + var iframeStyle = 'border:0; width:'+boxWidth+'em; height: '+boxHeight+'em'; + + var b = document.createElement('div'); + b.id = "send2cgeo"; + b.setAttribute("style", boxStyle); + b.innerHTML = '<div style="'+waitStyle+'">Please wait…</div>' + + '<iframe style="'+iframeStyle+'"></iframe>'; + + document.getElementsByTagName("body")[0].appendChild(b); + + // Append to send2cgeo links/buttons ///////////////////////////////////////// + var oc = document.getElementById('SendToGPS').parentNode.parentNode; + + if(oc !== null) { + + var occode=oc.innerHTML; + occode = occode.substr(occode.indexOf('wp=')+3,6); + + var html = '<img src="resource2/ocstyle/images/viewcache/14x19-gps-device.png" class="icon16" alt="" />' + + '<a class="send-to-gps" ' + + 'href="#" ' + + 'onclick="s2cgeo(\''+occode+'\'); return false;" >' + + '<input id="SendToGPS" type="button" value="An c:geo senden"' + + 'name="SendToCgeo" /></a> ' + + '<br><br>'; + + oc.innerHTML = oc.innerHTML.replace('<br><br>', html); + }; diff --git a/tests/src/cgeo/geocaching/connector/oc/OkapiClientTest.java b/tests/src/cgeo/geocaching/connector/oc/OkapiClientTest.java index 50bf22a..410252f 100644 --- a/tests/src/cgeo/geocaching/connector/oc/OkapiClientTest.java +++ b/tests/src/cgeo/geocaching/connector/oc/OkapiClientTest.java @@ -25,7 +25,7 @@ public class OkapiClientTest extends CGeoTestCase { public static void testOCSearchMustWorkWithoutOAuthAccessTokens() { final String geoCode = "OC1234"; Geocache cache = OkapiClient.getCache(geoCode); - assertNotNull(cache); + assertNotNull("You must have a valid OKAPI key installed for running this test (but you do not need to set credentials in the app).", cache); assertEquals("Wupper-Schein", cache.getName()); } } diff --git a/tests/src/cgeo/geocaching/files/LocParserTest.java b/tests/src/cgeo/geocaching/files/LocParserTest.java index 6e00b35..3039a1f 100644 --- a/tests/src/cgeo/geocaching/files/LocParserTest.java +++ b/tests/src/cgeo/geocaching/files/LocParserTest.java @@ -36,7 +36,7 @@ public class LocParserTest extends AbstractResourceInstrumentationTestCase { assertNotNull(cache); assertEquals("OC5952", cache.getGeocode()); assertEquals("Die Schatzinsel / treasure island", cache.getName()); - assertEquals("Die unbesiegbaren Geo - Geparden", cache.getOwnerDisplayName()); + assertEquals("Die unbesiegbaren Geo - Geparden", cache.getOwnerUserId()); assertEquals(new Geopoint(48.85968, 9.18740), cache.getCoords()); } @@ -47,7 +47,7 @@ public class LocParserTest extends AbstractResourceInstrumentationTestCase { assertNotNull(cache); assertEquals("GC1BKP3", cache.getGeocode()); assertEquals("Die Schatzinsel / treasure island", cache.getName()); - assertEquals("Die unbesiegbaren Geo - Geparden", cache.getOwnerDisplayName()); + assertEquals("Die unbesiegbaren Geo - Geparden", cache.getOwnerUserId()); assertEquals(new Geopoint(48.859683, 9.1874), cache.getCoords()); assertEquals(1.0f, cache.getDifficulty()); assertEquals(5.0f, cache.getTerrain()); @@ -61,7 +61,7 @@ public class LocParserTest extends AbstractResourceInstrumentationTestCase { assertNotNull(waymark); assertEquals("WM7BK7", waymark.getGeocode()); assertEquals("Römerstrasse Kornwestheim", waymark.getName()); - assertEquals("travelling", waymark.getOwnerDisplayName()); + assertEquals("travelling", waymark.getOwnerUserId()); assertEquals(new Geopoint(48.856733, 9.197683), waymark.getCoords()); // links are not yet stored for single caches // assertEquals("http://www.waymarking.com/waymarks/WM7BK7_Rmerstrasse_Kornwestheim", waymark.getUrl()); |
