open-library-api-rs 0.1.0

Async Rust client for the Open Library API
Documentation
// v0.0.1
use crate::client::OpenLibraryClient;
use crate::error::Result;
use crate::models::common::ReadingShelf;
use crate::models::reading_log::ReadingLog;
use crate::validation::validate_username;

impl OpenLibraryClient {
    /// Fetch a user's public reading log for the given shelf.
    async fn get_reading_log_shelf(
        &self,
        username: &str,
        shelf: ReadingShelf,
    ) -> Result<ReadingLog> {
        validate_username(username)?;
        let url = self
            .base_url
            .join(&format!("people/{username}/books/{}.json", shelf.as_str()))?;
        self.get_json(url).await
    }

    /// Books on the user's "Want to Read" shelf.
    pub async fn get_want_to_read(&self, username: &str) -> Result<ReadingLog> {
        self.get_reading_log_shelf(username, ReadingShelf::WantToRead).await
    }

    /// Books the user is currently reading.
    pub async fn get_currently_reading(&self, username: &str) -> Result<ReadingLog> {
        self.get_reading_log_shelf(username, ReadingShelf::CurrentlyReading).await
    }

    /// Books the user has already read.
    pub async fn get_already_read(&self, username: &str) -> Result<ReadingLog> {
        self.get_reading_log_shelf(username, ReadingShelf::AlreadyRead).await
    }
}