add listing by uploader

This commit is contained in:
Robin Appelman 2020-12-09 23:11:41 +01:00
commit 7b484c5753
2 changed files with 71 additions and 0 deletions

View file

@ -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(&params)
.send()
.await?
.json()
.await?)
}
/// Get the data for a single demo
///
/// # Example

View file

@ -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);
}