Skip to content

Commit

Permalink
feat: Add crate_reverse_dependency_count()
Browse files Browse the repository at this point in the history
Add method to get just the total count of reverse dependencies of a
given crate.

Closes #31.
  • Loading branch information
theduke committed Jan 29, 2022
1 parent b6b0885 commit a5151a3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/async_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ impl Client {
Ok(deps)
}

/// Get the total count of reverse dependencies for a given crate.
pub async fn crate_reverse_dependency_count(&self, crate_name: &str) -> Result<u64, Error> {
let page = self.crate_reverse_dependencies_page(crate_name, 1).await?;
Ok(page.meta.total)
}

/// Retrieve the authors for a crate version.
pub async fn crate_authors(&self, name: &str, version: &str) -> Result<Authors, Error> {
let url = self
Expand Down Expand Up @@ -402,7 +408,6 @@ mod test {
Ok(())
}


#[tokio::test]
async fn test_user_get_async() -> Result<(), Error> {
let client = build_test_client();
Expand Down Expand Up @@ -434,4 +439,15 @@ mod test {

Ok(())
}

#[tokio::test]
async fn test_crate_reverse_dependency_count() -> Result<(), Error> {
let client = build_test_client();
let count = client
.crate_reverse_dependency_count("crates_io_api")
.await?;
assert!(count > 0);

Ok(())
}
}
15 changes: 15 additions & 0 deletions src/sync_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ impl SyncClient {
Ok(deps)
}

/// Get the total count of reverse dependencies for a given crate.
pub fn crate_reverse_dependency_count(&self, crate_name: &str) -> Result<u64, Error> {
let page = self.crate_reverse_dependencies_page(crate_name, 1)?;
Ok(page.meta.total)
}

/// Retrieve the authors for a crate version.
pub fn crate_authors(&self, name: &str, version: &str) -> Result<Authors, Error> {
let url = self
Expand Down Expand Up @@ -395,4 +401,13 @@ mod test {

Ok(())
}

#[test]
fn test_crate_reverse_dependency_count() -> Result<(), Error> {
let client = build_test_client();
let count = client.crate_reverse_dependency_count("crates_io_api")?;
assert!(count > 0);

Ok(())
}
}

0 comments on commit a5151a3

Please sign in to comment.