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
 import uk.co.md87.evetool.api.parser.ApiResult;
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
  * @author chris
34
  * @author chris
31
  */
35
  */
32
 public class ApiResponse<T> {
36
 public class ApiResponse<T> {
33
 
37
 
38
+    /** The wrapper object (after a successful response). */
34
     private final T result;
39
     private final T result;
40
+
41
+    /** The error message (after an unsuccessful response). */
35
     private final String error;
42
     private final String error;
43
+
44
+    /** The raw result from the API. */
36
     private final ApiResult apiResult;
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
     public ApiResponse(final T result, final ApiResult apiResult) {
53
     public ApiResponse(final T result, final ApiResult apiResult) {
39
         this.result = result;
54
         this.result = result;
40
         this.error = null;
55
         this.error = null;
41
         this.apiResult = apiResult;
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
     public ApiResponse(final String error, final ApiResult apiResult) {
65
     public ApiResponse(final String error, final ApiResult apiResult) {
45
         this.result = null;
66
         this.result = null;
46
         this.error = error;
67
         this.error = error;
47
         this.apiResult = apiResult;
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
     public boolean wasSuccessful() {
76
     public boolean wasSuccessful() {
51
         return result != null && error == null;
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
     public T getResult() {
85
     public T getResult() {
55
         return result;
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
     public String getError() {
94
     public String getError() {
59
         return error;
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
     public ApiResult getApiResult() {
103
     public ApiResult getApiResult() {
63
         return apiResult;
104
         return apiResult;
64
     }
105
     }
65
 
106
 
107
+    /** {@inheritDoc} */
66
     @Override
108
     @Override
67
     public String toString() {
109
     public String toString() {
68
         return "[ApiResponse - " + (wasSuccessful() ? "success" : "failure")
110
         return "[ApiResponse - " + (wasSuccessful() ? "success" : "failure")

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

43
 import uk.co.md87.evetool.api.wrappers.SkillList;
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
  * @author chris
48
  * @author chris
49
  */
49
  */
50
 public class EveApi {
50
 public class EveApi {
51
 
51
 
52
+    /** SQL tables required by the API. */
52
     private static final String[] TABLES = {"PageCache"};
53
     private static final String[] TABLES = {"PageCache"};
53
 
54
 
55
+    /** Logger to use for this class. */
54
     private static final Logger LOGGER = Logger.getLogger(EveApi.class.getName());
56
     private static final Logger LOGGER = Logger.getLogger(EveApi.class.getName());
55
 
57
 
58
+    /** Date format for dates returned by the API. */
56
     public static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
59
     public static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
57
 
60
 
61
+    /** The database connection to use. */
58
     private final Connection conn;
62
     private final Connection conn;
63
+
64
+    /** The downloader to use. */
59
     private final ApiDownloader downloader;
65
     private final ApiDownloader downloader;
66
+    
67
+    /** The client's user ID, if specified. */
60
     private String userID;
68
     private String userID;
69
+
70
+    /** The client's character ID, if specified. */
61
     private String charID;
71
     private String charID;
72
+
73
+    /** The client's API key, if specified. */
62
     private String apiKey;
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
     public EveApi(final Connection sqlConnection) {
82
     public EveApi(final Connection sqlConnection) {
65
         this.conn = sqlConnection;
83
         this.conn = sqlConnection;
66
         checkTables();
84
         checkTables();
68
         this.downloader = new ApiDownloader(new DBCache(conn), new ApiParser());
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
     public void setApiKey(final String apiKey) {
94
     public void setApiKey(final String apiKey) {
72
         this.apiKey = apiKey;
95
         this.apiKey = apiKey;
73
         downloader.setApiKey(apiKey);
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
     public void setCharID(final String charID) {
104
     public void setCharID(final String charID) {
77
         this.charID = charID;
105
         this.charID = charID;
78
         downloader.setCharID(charID);
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
     public void setUserID(final String userID) {
114
     public void setUserID(final String userID) {
82
         this.userID = userID;
115
         this.userID = userID;
83
         downloader.setUserID(userID);
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
     public ApiResponse<CharacterList> getCharacterList() {
125
     public ApiResponse<CharacterList> getCharacterList() {
87
         return getResponse("/account/Characters.xml.aspx", CharacterList.class, true, false);
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
     public ApiResponse<SkillInTraining> getSkillInTraining() {
135
     public ApiResponse<SkillInTraining> getSkillInTraining() {
91
         return getResponse("/char/SkillInTraining.xml.aspx", SkillInTraining.class, true, true);
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
     public ApiResponse<SkillList> getSkillTree() {
145
     public ApiResponse<SkillList> getSkillTree() {
95
         return getResponse("/eve/SkillTree.xml.aspx ", SkillList.class, false, true);
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
     protected <T> ApiResponse<T> getResponse(final String method, final Class<T> type,
160
     protected <T> ApiResponse<T> getResponse(final String method, final Class<T> type,
99
             final boolean needKey, final boolean needChar) {
161
             final boolean needKey, final boolean needChar) {
100
         // TODO: Require userid + apikey
162
         // TODO: Require userid + apikey
116
 
178
 
117
     // TODO: Abstract db maintenance
179
     // TODO: Abstract db maintenance
118
     // TODO: Version tables somehow
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
     protected void createTable(final String table) {
187
     protected void createTable(final String table) {
120
         LOGGER.log(Level.FINE, "Creating table " + table);
188
         LOGGER.log(Level.FINE, "Creating table " + table);
121
         final StringBuilder sql = new StringBuilder();
189
         final StringBuilder sql = new StringBuilder();
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
     protected void checkTables() {
220
     protected void checkTables() {
147
         LOGGER.log(Level.FINEST, "Checking that tables exist");
221
         LOGGER.log(Level.FINEST, "Checking that tables exist");
148
 
222
 
157
         LOGGER.log(Level.FINEST, "Done checking tables");
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
     protected List<String> getTables() {
239
     protected List<String> getTables() {
161
         final List<String> tables = new ArrayList<String>();
240
         final List<String> tables = new ArrayList<String>();
162
 
241
 

Loading…
Cancel
Save