Struct demostf_client::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
sourceimpl ApiClient
impl ApiClient
pub const DEMOS_TF_BASE_URL: &'static str = "https://api.demos.tf/"
sourcepub fn with_base_url(base_url: impl IntoUrl) -> Result<Self, Error>
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
sourcepub fn with_base_url_and_timeout(
base_url: impl IntoUrl,
timeout: Duration
) -> Result<Self, Error>
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
sourcepub async fn list(
&self,
params: ListParams,
page: u32
) -> Result<Vec<Demo>, Error>
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);
}
sourcepub async fn list_uploads(
&self,
uploader: SteamID,
params: ListParams,
page: u32
) -> Result<Vec<Demo>, Error>
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);
}
sourcepub async fn get(&self, demo_id: u32) -> Result<Demo, Error>
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);
}
sourcepub async fn get_user(&self, user_id: u32) -> Result<User, Error>
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());
sourcepub async fn search_users(&self, name: &str) -> Result<Vec<User>, Error>
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());
}
sourcepub async fn get_chat(&self, demo_id: u32) -> Result<Vec<ChatMessage>, Error>
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);
}
pub async fn set_url(
&self,
demo_id: u32,
backend: &str,
path: &str,
url: &str,
hash: [u8; 16],
key: &str
) -> Result<(), Error>
pub async fn upload_demo(
&self,
file_name: String,
body: Vec<u8>,
red: String,
blue: String,
key: String
) -> Result<u32, Error>
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for ApiClient
impl Send for ApiClient
impl Sync for ApiClient
impl Unpin for ApiClient
impl !UnwindSafe for ApiClient
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more