Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: feat(crates-io): add the downloads API #13972

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions crates/crates-io/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ pub struct Warnings {
pub other: Vec<String>,
}

#[derive(Deserialize)]
pub struct VersionDownload {
pub version: i32,
pub downloads: i32,
pub date: String,
}

#[derive(Deserialize)]
pub struct VersionDownloads {
pub version_downloads: Vec<VersionDownload>,
}

#[derive(Deserialize)]
struct R {
ok: bool,
Expand Down Expand Up @@ -370,6 +382,11 @@ impl Registry {
Ok(())
}

pub fn downloads(&mut self, krate: &str, version: &str) -> Result<VersionDownloads> {
let body = self.get(&format!("/crates/{}/{}/downloads", krate, version))?;
Ok(serde_json::from_str::<VersionDownloads>(&body)?)
}

fn put(&mut self, path: &str, b: &[u8]) -> Result<String> {
self.handle.put(true)?;
self.req(path, Some(b), Auth::Authorized)
Expand Down