Module server_info

Module server_info 

Source
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(&parameters).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§

ErrorResponse
A struct representing an unsuccessful API response for the serverinfo request.
Player
A struct representing a player on the server.
PlayersCount
A struct representing the server’s players count.
RequestParameters
A struct representing a parameters for the serverinfo request.
RequestParametersBuilder
A struct representing a builder for the RequestParameters.
ServerInfo
A struct representing a server info for the serverinfo request.
SuccessResponse
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.