Browse Source

Javadoc

master
Chris Smith 15 years ago
parent
commit
49ffaf3512
2 changed files with 123 additions and 2 deletions
  1. 43
    1
      src/uk/co/md87/evetool/api/ApiResponse.java
  2. 80
    1
      src/uk/co/md87/evetool/api/EveApi.java

+ 43
- 1
src/uk/co/md87/evetool/api/ApiResponse.java View File

@@ -25,44 +25,86 @@ package uk.co.md87.evetool.api;
25 25
 import uk.co.md87.evetool.api.parser.ApiResult;
26 26
 
27 27
 /**
28
+ * Represents a response from the EVE API. A response can either be successful,
29
+ * in which case the ApiResponse object will contain one object from the
30
+ * <code>wrapper</code> package which encapsulates the retured data, or
31
+ * unsuccessful, in which case it contains a human-readable error message.
28 32
  *
29
- * TODO: Document
33
+ * @param <T> The type of wrapper that will be used for a successful response
30 34
  * @author chris
31 35
  */
32 36
 public class ApiResponse<T> {
33 37
 
38
+    /** The wrapper object (after a successful response). */
34 39
     private final T result;
40
+
41
+    /** The error message (after an unsuccessful response). */
35 42
     private final String error;
43
+
44
+    /** The raw result from the API. */
36 45
     private final ApiResult apiResult;
37 46
 
47
+    /**
48
+     * Creates a new successful ApiResponse.
49
+     *
50
+     * @param result The wrapper object containing the resulting data
51
+     * @param apiResult The raw API response
52
+     */
38 53
     public ApiResponse(final T result, final ApiResult apiResult) {
39 54
         this.result = result;
40 55
         this.error = null;
41 56
         this.apiResult = apiResult;
42 57
     }
43 58
 
59
+    /**
60
+     * Creates a new unsuccessful ApiResponse.
61
+     *
62
+     * @param error The human-readable error message
63
+     * @param apiResult The raw API response
64
+     */
44 65
     public ApiResponse(final String error, final ApiResult apiResult) {
45 66
         this.result = null;
46 67
         this.error = error;
47 68
         this.apiResult = apiResult;
48 69
     }
49 70
 
71
+    /**
72
+     * Determines if this response was successful or not.
73
+     *
74
+     * @return True if the response indicates a success, false otherwise
75
+     */
50 76
     public boolean wasSuccessful() {
51 77
         return result != null && error == null;
52 78
     }
53 79
 
80
+    /**
81
+     * Retrieves the wrapper object for this response.
82
+     *
83
+     * @return The wrapper object if successful, null otherwise
84
+     */
54 85
     public T getResult() {
55 86
         return result;
56 87
     }
57 88
 
89
+    /**
90
+     * Retrieves the error message for this response.
91
+     *
92
+     * @return The error message if unsuccessful, false otherwise
93
+     */
58 94
     public String getError() {
59 95
         return error;
60 96
     }
61 97
 
98
+    /**
99
+     * Retrieves the raw API result associated with this response.
100
+     *
101
+     * @return The raw {@link ApiResult} object.
102
+     */
62 103
     public ApiResult getApiResult() {
63 104
         return apiResult;
64 105
     }
65 106
 
107
+    /** {@inheritDoc} */
66 108
     @Override
67 109
     public String toString() {
68 110
         return "[ApiResponse - " + (wasSuccessful() ? "success" : "failure")

+ 80
- 1
src/uk/co/md87/evetool/api/EveApi.java View File

@@ -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
 

Loading…
Cancel
Save