mirror of
https://codeberg.org/demostf/api-client.git
synced 2026-06-03 16:44:09 +02:00
add listing by uploader
This commit is contained in:
parent
65c0f8ebb4
commit
7b484c5753
2 changed files with 71 additions and 0 deletions
46
src/lib.rs
46
src/lib.rs
|
|
@ -402,6 +402,52 @@ impl ApiClient {
|
|||
.await?)
|
||||
}
|
||||
|
||||
/// List demos uploaded by a user with the provided options
|
||||
///
|
||||
/// note that the pages start counting at 1
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// use demostf_client::{ListOrder, ListParams};
|
||||
/// # use demostf_client::ApiClient;
|
||||
///
|
||||
/// # #[tokio::main]
|
||||
/// # async fn main() -> Result<(), demostf_client::Error> {
|
||||
/// # use steamid_ng::SteamID;
|
||||
/// 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);
|
||||
/// }
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
pub async fn list_uploads(
|
||||
&self,
|
||||
uploader: SteamID,
|
||||
params: ListParams,
|
||||
page: u32,
|
||||
) -> Result<Vec<Demo>, Error> {
|
||||
if page == 0 {
|
||||
return Err(Error::InvalidPage);
|
||||
}
|
||||
|
||||
let mut url = self.base_url.clone();
|
||||
url.set_path(&format!("/uploads/{}", u64::from(uploader)));
|
||||
Ok(self
|
||||
.client
|
||||
.get(url)
|
||||
.query(&[("page", page)])
|
||||
.query(¶ms)
|
||||
.send()
|
||||
.await?
|
||||
.json()
|
||||
.await?)
|
||||
}
|
||||
|
||||
/// Get the data for a single demo
|
||||
///
|
||||
/// # Example
|
||||
|
|
|
|||
|
|
@ -210,3 +210,28 @@ async fn test_get_demo_not_found() {
|
|||
Error::DemoNotFound(999)
|
||||
));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_list_upload() {
|
||||
let client = test_client().await;
|
||||
|
||||
let demos = client
|
||||
.list_uploads(
|
||||
SteamID::from(76561198024494987),
|
||||
ListParams::default().with_order(ListOrder::Ascending),
|
||||
1,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(demos.len(), 0);
|
||||
|
||||
let demos = client
|
||||
.list_uploads(
|
||||
SteamID::from(76561198024494988),
|
||||
ListParams::default().with_order(ListOrder::Ascending),
|
||||
1,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(demos[0].id, 1);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue