//handles fetching a list of craft from KerbalX, processes the response for certain craft attributes and //assembles a Dictionary which is passed into the callback. private void fetch_craft_list(string path, CraftListCallback callback) { HTTP.get(url_to(path)).send(this, (resp, status_code) => { if (status_code == 200) { callback(process_craft_data( resp, "id", "name", "version", "url", "type", "part_count", "crew_capacity", "cost", "mass", "stages", "created_at", "updated_at", "description" ), status_code); } else { callback(null, status_code); } }); }
//Internal Authentication POST requests //make request to site to authenticate username and password and get token back internal void login(string username, string password, RequestCallback callback) { KXAPI.log("Logging into KerbalX.com..."); NameValueCollection data = new NameValueCollection() { { "username", username }, { "password", password } }; RequestHandler.show_401_message = false; //don't show standard 401 error dialog HTTP.post(url_to("api/login"), data).send(this, (resp, code) => { if (code == 200) { KXAPI.log("Logged in"); var resp_data = JSON.Parse(resp); KerbalXAPI.token = resp_data["token"]; KerbalXAPI.save_token(resp_data["token"]); KerbalXAPI.kx_username = resp_data["username"]; } callback(resp, code); }, false); }
public void upload_geo_cache(WWWForm geo_cache_data, RequestCallback callback) { HTTP.post(url_to("api/geo_caches"), geo_cache_data).send(this, callback); }
public void fetch_geo_cache(int geo_cache_id, RequestCallback callback) { HTTP.get(url_to("api/geo_caches/" + geo_cache_id)).send(this, callback); }
//GeoCache GET requests public void fetch_geo_cache_list(RequestCallback callback) { HTTP.get(url_to("api/geo_caches.json")).send(this, callback); }
//Does exactly what is says on the tin, it fetches a craft by ID from KerbalX. //Just to note though, the ID must be for a craft that is either in the users download queue, has been downloaded before or is one of the users craft public void download_craft(int id, RequestCallback callback) { HTTP.get(url_to("api/craft/" + id)).send(this, callback); }
//Remove a craft from the list of craft the user has tagged for download public void remove_from_queue(int craft_id, RequestCallback callback) { HTTP.get(url_to("api/remove_from_queue/" + craft_id)).send(this, callback); }
public void check_for_updates(RequestCallback callback) { HTTP.get(url_to("api/mod_update_available")).send(this, callback); }
public void enable_deferred_downloads(RequestCallback callback) { HTTP.post(url_to("api/enable_deferred_downloads")).send(this, callback); }
public void deferred_downloads_enabled(RequestCallback callback) { HTTP.get(url_to("api/deferred_downloads_enabled")).send(this, callback); }
//General requests //Tells KerbalX not to bug this user about the current minor/patch version update available //There is no callback for this request. public void dismiss_current_update_notification() { HTTP.post(url_to("api/dismiss_update_notification")).send(this, (resp, code) => { }); }
//test public void test_connection(RequestCallback callback) { HTTP.get(url_to("api/test_connection")).send(this, callback); }