Struct ApiClient

Source
pub struct ApiClient { /* private fields */ }
Expand description

Api client for demos.tf

§Example

use demostf_client::{ListOrder, ListParams, ApiClient};

let client = ApiClient::new();

let demos = client.list(ListParams::default().with_order(ListOrder::Ascending), 1).await?;

for demo in demos {
    println!("{}: {}", demo.id, demo.name);
}

Implementations§

Source§

impl ApiClient

Source

pub const DEMOS_TF_BASE_URL: &'static str = "https://api.demos.tf/"

Source

pub fn new() -> Self

Create an api client for the default demos.tf endpoint

Source

pub fn with_base_url(base_url: impl IntoUrl) -> Result<Self, Error>

Create an api client using a different api endpoint

§Errors

Returns an error when the provided base_url is not a valid url

Source

pub fn with_base_url_and_timeout( base_url: impl IntoUrl, timeout: Duration, ) -> Result<Self, Error>

Create an api client using a different api endpoint and timeout

§Errors

Returns an error when the provided base_url is not a valid url

Source

pub fn set_access_key(&mut self, access_key: String)

Set access key used to access private demos

Source

pub async fn list( &self, params: ListParams, page: u32, ) -> Result<Vec<Demo>, Error>

List demos with the provided options

note that the pages start counting at 1

§Example
use demostf_client::{ListOrder, ListParams};

let demos = client.list(ListParams::default().with_order(ListOrder::Ascending), 1).await?;

for demo in demos {
    println!("{}: {}", demo.id, demo.name);
}
Source

pub async fn list_uploads( &self, uploader: SteamID, params: ListParams, page: u32, ) -> Result<Vec<Demo>, Error>

List demos uploaded by a user with the provided options

note that the pages start counting at 1

§Example
use demostf_client::{ListOrder, ListParams};

let client = ApiClient::default();
let demos = client.list_uploads(SteamID::from(76561198024494988), ListParams::default().with_order(ListOrder::Ascending), 1).await?;

for demo in demos {
    println!("{}: {}", demo.id, demo.name);
}
Source

pub async fn get(&self, demo_id: u32) -> Result<Demo, Error>

Get the data for a single demo

§Example
let demo = client.get(9).await?;

println!("{}: {}", demo.id, demo.name);
println!("players:");

for player in demo.players.unwrap_or_default() {
    println!("{}", player.user.name);
}
Source

pub async fn get_user(&self, user_id: u32) -> Result<User, Error>

Get user info by id

§Example
let user = client.get_user(1).await?;

println!("{} ({})", user.name, user.steam_id.steam3());
Source

pub async fn search_users(&self, name: &str) -> Result<Vec<User>, Error>

Search for players by name

§Example
let client = ApiClient::default();
let users = client.search_users("icewind").await?;

for user in users {
  println!("{} ({})", user.name, user.steam_id.steam3());
}
Source

pub async fn get_chat(&self, demo_id: u32) -> Result<Vec<ChatMessage>, Error>

List demos with the provided options

§Example
let chat = client.get_chat(447678).await?;

for message in chat {
    println!("{}: {}", message.user, message.message);
}
Source

pub async fn set_url( &self, demo_id: u32, backend: &str, path: &str, url: &str, hash: [u8; 16], key: &str, ) -> Result<(), Error>

Source

pub async fn upload_demo( &self, file_name: String, body: Vec<u8>, red: String, blue: String, key: String, ) -> Result<u32, Error>

Source

pub async fn upload_private_demo( &self, file_name: String, body: Vec<u8>, red: String, blue: String, key: String, ) -> Result<u32, Error>

Trait Implementations§

Source§

impl Clone for ApiClient

Source§

fn clone(&self) -> ApiClient

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ApiClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ApiClient

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T