|
@@ -43,24 +43,42 @@ import uk.co.md87.evetool.api.wrappers.SkillInTraining;
|
43
|
43
|
import uk.co.md87.evetool.api.wrappers.SkillList;
|
44
|
44
|
|
45
|
45
|
/**
|
|
46
|
+ * Allows access to the EVE Api (see http://api.eve-online.com/).
|
46
|
47
|
*
|
47
|
|
- * TODO: Document
|
48
|
48
|
* @author chris
|
49
|
49
|
*/
|
50
|
50
|
public class EveApi {
|
51
|
51
|
|
|
52
|
+ /** SQL tables required by the API. */
|
52
|
53
|
private static final String[] TABLES = {"PageCache"};
|
53
|
54
|
|
|
55
|
+ /** Logger to use for this class. */
|
54
|
56
|
private static final Logger LOGGER = Logger.getLogger(EveApi.class.getName());
|
55
|
57
|
|
|
58
|
+ /** Date format for dates returned by the API. */
|
56
|
59
|
public static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
|
57
|
60
|
|
|
61
|
+ /** The database connection to use. */
|
58
|
62
|
private final Connection conn;
|
|
63
|
+
|
|
64
|
+ /** The downloader to use. */
|
59
|
65
|
private final ApiDownloader downloader;
|
|
66
|
+
|
|
67
|
+ /** The client's user ID, if specified. */
|
60
|
68
|
private String userID;
|
|
69
|
+
|
|
70
|
+ /** The client's character ID, if specified. */
|
61
|
71
|
private String charID;
|
|
72
|
+
|
|
73
|
+ /** The client's API key, if specified. */
|
62
|
74
|
private String apiKey;
|
63
|
75
|
|
|
76
|
+ /**
|
|
77
|
+ * Creates a new instance of the EVE API client using the specified database
|
|
78
|
+ * connection.
|
|
79
|
+ *
|
|
80
|
+ * @param sqlConnection A connection to a database to use
|
|
81
|
+ */
|
64
|
82
|
public EveApi(final Connection sqlConnection) {
|
65
|
83
|
this.conn = sqlConnection;
|
66
|
84
|
checkTables();
|
|
@@ -68,33 +86,77 @@ public class EveApi {
|
68
|
86
|
this.downloader = new ApiDownloader(new DBCache(conn), new ApiParser());
|
69
|
87
|
}
|
70
|
88
|
|
|
89
|
+ /**
|
|
90
|
+ * Sets the API key used by this client.
|
|
91
|
+ *
|
|
92
|
+ * @param apiKey The user's API key
|
|
93
|
+ */
|
71
|
94
|
public void setApiKey(final String apiKey) {
|
72
|
95
|
this.apiKey = apiKey;
|
73
|
96
|
downloader.setApiKey(apiKey);
|
74
|
97
|
}
|
75
|
98
|
|
|
99
|
+ /**
|
|
100
|
+ * Sets the character ID used by this client.
|
|
101
|
+ *
|
|
102
|
+ * @param charID The user's chosen character ID
|
|
103
|
+ */
|
76
|
104
|
public void setCharID(final String charID) {
|
77
|
105
|
this.charID = charID;
|
78
|
106
|
downloader.setCharID(charID);
|
79
|
107
|
}
|
80
|
108
|
|
|
109
|
+ /**
|
|
110
|
+ * Sets the user ID used by this client.
|
|
111
|
+ *
|
|
112
|
+ * @param userID The user's user ID
|
|
113
|
+ */
|
81
|
114
|
public void setUserID(final String userID) {
|
82
|
115
|
this.userID = userID;
|
83
|
116
|
downloader.setUserID(userID);
|
84
|
117
|
}
|
85
|
118
|
|
|
119
|
+ /**
|
|
120
|
+ * Retrieves the character list for the user's account.
|
|
121
|
+ * Requires a limited API key and user ID.
|
|
122
|
+ *
|
|
123
|
+ * @return The user's character list
|
|
124
|
+ */
|
86
|
125
|
public ApiResponse<CharacterList> getCharacterList() {
|
87
|
126
|
return getResponse("/account/Characters.xml.aspx", CharacterList.class, true, false);
|
88
|
127
|
}
|
89
|
128
|
|
|
129
|
+ /**
|
|
130
|
+ * Retrieves the skill that's currently in training.
|
|
131
|
+ * Requires a limited API key, user ID and character ID.
|
|
132
|
+ *
|
|
133
|
+ * @return The character's currently training skill
|
|
134
|
+ */
|
90
|
135
|
public ApiResponse<SkillInTraining> getSkillInTraining() {
|
91
|
136
|
return getResponse("/char/SkillInTraining.xml.aspx", SkillInTraining.class, true, true);
|
92
|
137
|
}
|
93
|
138
|
|
|
139
|
+ /**
|
|
140
|
+ * Retrieves the full skill tree for EVE.
|
|
141
|
+ * Does not require an API key.
|
|
142
|
+ *
|
|
143
|
+ * @return The complete EVE skill tree
|
|
144
|
+ */
|
94
|
145
|
public ApiResponse<SkillList> getSkillTree() {
|
95
|
146
|
return getResponse("/eve/SkillTree.xml.aspx ", SkillList.class, false, true);
|
96
|
147
|
}
|
97
|
148
|
|
|
149
|
+ /**
|
|
150
|
+ * Utility method to send a request to the API and manufacture the
|
|
151
|
+ * appropaite response objects.
|
|
152
|
+ *
|
|
153
|
+ * @param <T> The type of object that will be returned on success
|
|
154
|
+ * @param method The method (path) of the API being used
|
|
155
|
+ * @param type The class of object to return on success
|
|
156
|
+ * @param needKey Whether or not an API key is needed
|
|
157
|
+ * @param needChar Whether or not a character ID is needed
|
|
158
|
+ * @return An appropriate ApiResponse encapsulating the request
|
|
159
|
+ */
|
98
|
160
|
protected <T> ApiResponse<T> getResponse(final String method, final Class<T> type,
|
99
|
161
|
final boolean needKey, final boolean needChar) {
|
100
|
162
|
// TODO: Require userid + apikey
|
|
@@ -116,6 +178,12 @@ public class EveApi {
|
116
|
178
|
|
117
|
179
|
// TODO: Abstract db maintenance
|
118
|
180
|
// TODO: Version tables somehow
|
|
181
|
+ /**
|
|
182
|
+ * Creates the table with the specified name. SQL is read from the
|
|
183
|
+ * <code>db</code> package.
|
|
184
|
+ *
|
|
185
|
+ * @param table The table to be created
|
|
186
|
+ */
|
119
|
187
|
protected void createTable(final String table) {
|
120
|
188
|
LOGGER.log(Level.FINE, "Creating table " + table);
|
121
|
189
|
final StringBuilder sql = new StringBuilder();
|
|
@@ -143,6 +211,12 @@ public class EveApi {
|
143
|
211
|
}
|
144
|
212
|
}
|
145
|
213
|
|
|
214
|
+ /**
|
|
215
|
+ * Checks to ensure that all required tables exist. If any table is missing,
|
|
216
|
+ * it will be created.
|
|
217
|
+ *
|
|
218
|
+ * @see #createTable(java.lang.String)
|
|
219
|
+ */
|
146
|
220
|
protected void checkTables() {
|
147
|
221
|
LOGGER.log(Level.FINEST, "Checking that tables exist");
|
148
|
222
|
|
|
@@ -157,6 +231,11 @@ public class EveApi {
|
157
|
231
|
LOGGER.log(Level.FINEST, "Done checking tables");
|
158
|
232
|
}
|
159
|
233
|
|
|
234
|
+ /**
|
|
235
|
+ * Retrieves a list of tables that exist in the database.
|
|
236
|
+ *
|
|
237
|
+ * @return A list of table names that exist
|
|
238
|
+ */
|
160
|
239
|
protected List<String> getTables() {
|
161
|
240
|
final List<String> tables = new ArrayList<String>();
|
162
|
241
|
|