GeoCaches - Sujimichi/KXAPI GitHub Wiki
GeoCache Interface
A geo_cache on KerbalX has the following attributes:
Modifiable Attributes:
name
- string | name of the geo cache *required
coordinates
- string | long/lat values (format to be defined)
contents
- string | JSON string containing information about the geo_cache
file
- binary | the content of the geo cache ConfigNode file used to define a geo cache *required
System Attributes:
id
- integer | databased ID
user_id
- integer | database ID of the user who created the geo cache *required
created_at
- DateTime | Date and Time the geo cache was created
updated_at
- DateTime | Date and Time the geo cache was last updated
API Methods
search_geo_caches
KerbalX.api.search_geo_caches(WWWForm search_params, RequestCallback callback)
returns a JSON string with basic information about geo caches which match search paramiters.
Takes a WWWForm which can define a number of fields that will be used to search for geo caches. Currently only name
is supported but more fields will be added.
Example usage:
WWWForm search_params = new WWWForm();
search_params.AddField("name", "foo");
KerbalX.api.search_geo_caches(search_params, (resp, code) => {
Debug.Log(resp);
});
Example response:
[
{
"id": 1,
"name": "foo",
"coordinates": "not set",
"created_at": "2018-10-06 10:50:37 UTC"
},
{
"id": 4,
"name": "foobar",
"coordinates": "someplace",
"created_at": "2018-10-06 22:38:53 UTC"
}
]
fetch_geo_cache_list
KerbalX.api.fetch_geo_cache_list(RequestCallback callback)
returns a JSON string with basic information about all geo caches. It is not recommended to use this method, it is just included for testing purposes and will likely be deprecated.
Example usage:
KerbalX.api.fetch_geo_cache_list((resp, code) => {
Debug.Log(resp);
});
Example response: (same as above).
fetch_geo_cache
KerbalX.api.fetch_geo_cache(int geo_cache_id, RequestCallback callback)
Returns the geo cache file, as a string, for a given ID. The response can be parsed by ConfigNode.
Example usage:
int geo_cache_id = 42;
KerbalX.api.fetch_geo_cache(geo_cache_id, (geo_cache, code) => {
if(code == 200){
ConfigNode geo = ConfigNode.Parse(geo_cache);
}
});
upload_geo_cache
KerbalX.api.upload_geo_cache(WWWForm geo_cache_data, RequestCallback callback)
create a new geo cache on KerbalX and populate with it's file and other attributes. Takes a WWWForm populated with fields for the geo_cache.
Example Usage:
//get or create ConfigNode object for geo cache
ConfigNode geo_cache = new ConfigNode();
geo_cache.name = "GEO_CACHE";
geo_cache.AddValue("some attr", "some value");
geo_cache.AddValue("some other attr", "some other value");
//prepare upload data
WWWForm form = new WWWForm();
form.AddField("name", "foobar");
form.AddField("coordinates", "someplace");
form.AddField("file", geo_cache.ToString());
//upload geo cache data to KerbalX
KerbalX.api.upload_geo_cache(form, (resp, code) => {
if(code == 200){
//example resp: "{\"created\":true,\"id\":8}"
int database_id = int.Parse(JSON.Parse(resp)["id"]);
}else if(code == 422){ //unable to save geo_cache (ie invalid data).
//example resp: "{\"created\":false,\"errors\":\"unable to save because reasons\"}"
Debug.Log(JSON.Parse(resp)["errors"]);
}else{
Debug.Log("unknown error: " + resp);
}
});
update_geo_cache
KerbalX.api.update_geo_cache(int geo_cache_id, WWWForm geo_cache_data, RequestCallback callback)
Update an existing geo cache on KerbalX. Takes the ID of a geo_cache on KerbalX and a WWWForm populated with fields to update.
note: If the currently logged in user is the user who created the geo_cache (owner) then they can update all the modifiable attributes of the geo_cache. If the geo_cache was created by another user, then only the file
attribute can be updated. If other attributes are included in the WWWForm they will be ignored.
Example usage:
//get or create ConfigNode object for geo cache
ConfigNode geo_cache = new ConfigNode();
geo_cache.name = "GEO_CACHE";
geo_cache.AddValue("some attr", "some updated value");
geo_cache.AddValue("some other attr", "some other updated value");
//prepare upload data
WWWForm form = new WWWForm();
form.AddField("name", "new foobar");
form.AddField("coordinates", "some new place");
form.AddField("file", geo_cache.ToString());
//upload to KerbalX
int geo_cache_id = 42;
KerbalX.api.update_geo_cache(geo_cache_id, form, (resp, code) => {
if(code == 200){
//example response: "{\"updated\":true,\"id\":8}"
}else if(code == 422){
//example resp: "{\"updated\":false,\"errors\":\"unable to update because reasons\"}"
}else{
Debug.Log("unknown error: " + resp);
}
});
destroy_geo_cache
KerbalX.api.destroy_geo_cache(int geo_cache_id, RequestCallback callback)
Delete a geo_cache from KerbalX. Takes the integer ID of the geo_cache to be deleted.
note: a geo_cache can only be deleted by the user who created it.
Example usage:
int geo_cache_id = 42;
KerbalX.api.destroy_geo_cache(geo_cache_id, (resp, code) => {
if(code == 200){
//example response: "{\"deleted\":true}"
}else if(code == 422){
//example resp: "{\"deleted\":false,\"errors\":\"unable to delete\"}"
}
});