1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
package cgeo.geocaching.connector.oc;
import cgeo.geocaching.Geocache;
import cgeo.geocaching.SearchResult;
import cgeo.geocaching.connector.capability.ISearchByGeocode;
import cgeo.geocaching.network.Parameters;
import cgeo.geocaching.utils.CancellableHandler;
import cgeo.geocaching.utils.CryptUtils;
import org.apache.commons.lang3.StringUtils;
public class OCApiConnector extends OCConnector implements ISearchByGeocode {
// Levels of Okapi we support
// oldapi is around rev 500
// current is from rev 798 onwards
public enum ApiSupport {
oldapi,
current
}
// Levels of OAuth-Authentication we support
public enum OAuthLevel {
Level1,
Level3
}
private final String cK;
private final ApiSupport apiSupport;
private final String licenseString;
public OCApiConnector(String name, String host, String prefix, String cK, String licenseString, ApiSupport apiSupport) {
super(name, host, prefix);
this.cK = cK;
this.apiSupport = apiSupport;
this.licenseString = licenseString;
}
public void addAuthentication(final Parameters params) {
params.put(CryptUtils.rot13("pbafhzre_xrl"), CryptUtils.rot13(cK));
}
@Override
public String getLicenseText(final Geocache cache) {
// NOT TO BE TRANSLATED
return "© " + cache.getOwnerDisplayName() + ", <a href=\"" + getCacheUrl(cache) + "\">" + getName() + "</a>, " + licenseString;
}
@Override
public SearchResult searchByGeocode(final String geocode, final String guid, final CancellableHandler handler) {
final Geocache cache = OkapiClient.getCache(geocode);
if (cache == null) {
return null;
}
return new SearchResult(cache);
}
@Override
public boolean isActivated() {
// currently always active, but only for details download
return true;
}
@SuppressWarnings("static-method")
public OAuthLevel getSupportedAuthLevel() {
return OAuthLevel.Level1;
}
public String getCK() {
return CryptUtils.rot13(cK);
}
@SuppressWarnings("static-method")
public String getCS() {
return StringUtils.EMPTY;
}
public ApiSupport getApiSupport() {
return apiSupport;
}
@SuppressWarnings("static-method")
public int getTokenPublicPrefKeyId() {
return 0;
}
@SuppressWarnings("static-method")
public int getTokenSecretPrefKeyId() {
return 0;
}
}
|