ampapi-rs


An API that allows you to communicate with AMP installations from within Rust.
Documentation for available API calls can be found by appending /API to the URL of any existing AMP installation.
Support:
Installation
cargo add ampapi
Examples
CommonAPI Example
use ampapi::modules::CommonAPI;
use ampapi::types::Status;
fn main() {
let api = CommonAPI::new(
String::from("http://localhost:8080/"),
String::from("admin"),
String::from("myfancypassword123"),
"".to_string(),
"".to_string()
);
let _ = api.Core.SendConsoleMessage("say Hello Everyone, this message was sent from the Rust API!".to_string());
let current_status: Status = api.Core.GetStatus().unwrap();
let cpu_usage_percent: f64 = current_status.Metrics.get("CPU Usage").unwrap().get("Percent").unwrap().as_f64().unwrap();
println!("Current CPU usage is: {}%", cpu_usage_percent);
}
Example using the ADS to manage an instance
use ampapi::modules::{ADS, Minecraft};
use ampapi::types::{IADSInstance, Status};
fn main() {
let api = ADS::new(
String::from("http://localhost:8080/"),
String::from("admin"),
String::from("myfancypassword123"),
"".to_string(),
"".to_string()
);
let instances_result = api.ADSModule.GetInstances().unwrap();
let targets: Vec<IADSInstance> = instances_result.result;
let hub_instance_id = targets[1].AvailableInstances.iter().find(|&x| x.InstanceName == "Hub").unwrap().InstanceID.clone();
let hub: Minecraft = api.instance_login(hub_instance_id, "Minecraft".to_string()).unwrap().into();
let current_status: Status = api.Core.GetStatus().unwrap();
let cpu_usage_percent: f64 = current_status.Metrics.get("CPU Usage").unwrap().get("Percent").unwrap().as_f64().unwrap();
let _ = hub.Core.SendConsoleMessage(format!("say Current CPU usage is: {}%", cpu_usage_percent)).unwrap();
}
CommonAPI Example, handling the sessionId and rememberMeToken manually (not recommended)
fn main() {
}