-
Notifications
You must be signed in to change notification settings - Fork 29
/
ParseGeneric.java
82 lines (72 loc) · 3.42 KB
/
ParseGeneric.java
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
/*
* Copyright (C) 2012-2017 Aubort Jean-Baptiste (Rorist)
* Licensed under GNU's GPL 3, see README
*/
package ch.fixme.status;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.HashMap;
public class ParseGeneric {
protected HashMap<String, Object> mResult = new HashMap<>();
protected JSONObject mApi;
protected static final String API_NAME = "space";
protected static final String API_LON = "lon";
protected static final String API_LOCATION = "location";
protected static final String API_LAT = "lat";
protected static final String API_URL = "url";
protected static final String API_LEVEL = "api";
protected static final String API_STATE = "state";
protected static final String API_STATE_MESSAGE = "message";
protected static final String API_STATUS_TXT = "status";
protected static final String API_EXT_DURATION = "ext_duration";
protected static final String API_ADDRESS = "address";
protected static final String API_CONTACT = "contact";
protected static final String API_EMAIL = "email";
protected static final String API_IRC = "irc";
protected static final String API_JABBER = "jabber";
protected static final String API_PHONE = "phone";
protected static final String API_SIP = "sip";
protected static final String API_TWITTER = "twitter";
protected static final String API_IDENTICA = "identica";
protected static final String API_FOURSQUARE = "foursquare";
protected static final String API_ML = "ml";
protected static final String API_STREAM = "stream";
protected static final String API_CAM = "cam";
protected static final String API_SENSORS = "sensors";
protected static final String API_EXT = "ext_";
protected static final String API_RADIATION = "radiation";
// Sensors
protected static final String API_SENSOR_VALUE = "value";
protected static final String API_SENSOR_UNIT = "unit";
protected static final String API_SENSOR_LOCATION = "location";
protected static final String API_SENSOR_NAME = "name";
protected static final String API_SENSOR_DESCRIPTION = "description";
protected static final String API_SENSOR_MACHINES = "machines";
protected static final String API_SENSOR_NAMES = "names";
protected static final String API_SENSOR_PROPERTIES = "properties";
// State
protected static final String API_DEFAULT = "https://fixme.ch/status.json";
protected static final String API_ICON = "icon";
protected static final String API_ICON_OPEN = "open";
protected static final String API_ICON_CLOSED = "closed";
protected static final String API_LOGO = "logo";
protected static final String API_STATUS = "open";
protected static final String API_LASTCHANGE = "lastchange";
public ParseGeneric(JSONObject jsonObject) {
mApi = jsonObject;
}
public ParseGeneric(String jsonString) throws JSONException {
mApi = new JSONObject(jsonString);
}
public HashMap<String, Object> getData() throws JSONException {
if ("0.13".equals(mApi.getString(ParseGeneric.API_LEVEL))) {
mResult = new Parse13(mApi).parse();
} else if ("0.12".equals(mApi.getString(ParseGeneric.API_LEVEL))) {
mResult = new Parse12(mApi).parse();
} else {
throw new JSONException("API LEVEL NOT SUPPORTED: "
+ mApi.getString(ParseGeneric.API_LEVEL));
}
return mResult;
}
}