Expand description
This module contains structs and functions these can be used
for working with the serverinfo
API request.
§Examples
use scpsl_api::server_info::{get, RequestParameters, Response};
use std::env::var;
use url::Url;
#[tokio::main]
async fn main() {
let account_id = var("ACCOUNT_ID")
.expect("Expected an account id in the environment")
.parse::<u64>()
.unwrap();
let api_key = var("API_KEY").expect("Expected an account id in the environment");
let parameters = RequestParameters::builder()
.url(Url::parse("https://api.scpslgame.com/serverinfo.php").unwrap())
.id(account_id)
.key(api_key)
.players(true)
.build();
if let Response::Success(response) = get(¶meters).await.unwrap() {
println!(
"Total players on your servers: {}",
response
.servers()
.iter()
.map(|server| server.players_count().unwrap().current_players())
.sum::<u32>()
)
}
}
Modules§
- raw
- This module contains structs and functions these can be used for
deserializing and serializing
serverinfo
API responses.
May be useful if you want to create your local API proxy or something like that.
Structs§
- Error
Response - A struct representing an unsuccessful API response for the
serverinfo
request. - Player
- A struct representing a player on the server.
- Players
Count - A struct representing the server’s players count.
- Request
Parameters - A struct representing a parameters for the
serverinfo
request. - Request
Parameters Builder - A struct representing a builder for the
RequestParameters
. - Server
Info - A struct representing a server info for the
serverinfo
request. - Success
Response - A struct representing a successful API response for the
serverinfo
request.
Enums§
- Response
- An enum representing a parsed API response for the
serverinfo
request.
Functions§
- get
- Returns info about own servers. See official API reference.