Skip to main content

open_library_api_rs/api/
partner.rs

1// v0.0.1
2use crate::client::OpenLibraryClient;
3use crate::error::{Error, Result};
4use crate::models::common::VolumeIdType;
5use crate::models::partner::VolumesResponse;
6
7impl OpenLibraryClient {
8    /// Look up a single volume by identifier type and value.
9    ///
10    /// Example: `read_volume(VolumeIdType::Isbn, "0451450523")`.
11    pub async fn read_volume(
12        &self,
13        id_type: VolumeIdType,
14        id_value: &str,
15    ) -> Result<VolumesResponse> {
16        if id_value.is_empty() {
17            return Err(Error::InvalidInput("id_value must not be empty".into()));
18        }
19        let path = format!("api/volumes/brief/{}/{}.json", id_type.as_str(), id_value);
20        let url = self.base_url.join(&path)?;
21        self.get_json(url).await
22    }
23
24    /// Batch-look up multiple volumes.
25    ///
26    /// `requests` is a list of `"type/value"` strings, e.g. `["isbn/0451450523", "oclc/45883427"]`.
27    pub async fn read_volumes_batch(
28        &self,
29        requests: &[String],
30    ) -> Result<VolumesResponse> {
31        if requests.is_empty() {
32            return Err(Error::InvalidInput("requests list must not be empty".into()));
33        }
34        let joined = requests.join("|");
35        let path = format!("api/volumes/brief/json/{}", joined);
36        let url = self.base_url.join(&path)?;
37        self.get_json(url).await
38    }
39}