scpsl-api

Crates.ioscpsl-api
lib.rsscpsl-api
version0.1.0-alpha.10
sourcesrc
created_at2021-07-29 10:11:48.123541
updated_at2021-07-29 17:20:34.359601
descriptionA SCP: Secret Laboratory API wrapper
homepage
repositoryhttps://github.com/trickybestia/scpsl-api
max_upload_size
id428683
size37,929
trickybestia (trickybestia)

documentation

https://docs.rs/scpsl-api

README

scpsl-api

crates.io docs.rs

A SCP: Secret Laboratory API wrapper (see official API reference).

Example

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>()
        )
    }
}

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in scpsl-api by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Commit count: 17

cargo fmt