Skip to main content

open_library_api_rs/api/
history.rs

1// v0.0.1
2use crate::client::OpenLibraryClient;
3use crate::error::{Error, Result};
4use crate::models::query::HistoryEntry;
5
6impl OpenLibraryClient {
7    /// Fetch the revision history for any Open Library resource.
8    ///
9    /// `key` is an absolute path like `/works/OL45804W` or `/books/OL7353617M`.
10    pub async fn get_resource_history(&self, key: &str) -> Result<Vec<HistoryEntry>> {
11        if key.is_empty() {
12            return Err(Error::InvalidInput("resource key must not be empty".into()));
13        }
14        // Strip leading slash so url::Url::join treats it as a relative path.
15        let stripped = key.trim_start_matches('/');
16        let mut url = self.base_url.join(&format!("{stripped}.json"))?;
17        url.query_pairs_mut().append_pair("m", "history");
18        self.get_json(url).await
19    }
20}