use crate::api::prelude::*;
#[derive(Debug, Clone)]
pub struct GetSeveralAudiobooks {
pub ids: Vec<String>,
pub market: Option<Market>,
}
impl<T, I> From<I> for GetSeveralAudiobooks
where
I: IntoIterator<Item = T>,
T: Into<String>,
{
fn from(ids: I) -> Self {
Self {
ids: ids.into_iter().map(Into::into).collect(),
market: None,
}
}
}
impl Endpoint for GetSeveralAudiobooks {
fn method(&self) -> Method {
Method::GET
}
fn endpoint(&self) -> Cow<'static, str> {
"audiobooks".into()
}
fn parameters(&self) -> QueryParams<'_> {
let mut params = QueryParams::default();
params.push("ids", &self.ids.join(","));
params.push_opt("market", self.market.as_ref());
params
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::{
api::{self, Query as _},
test::client::{ExpectedUrl, SingleTestClient},
};
#[test]
fn test_get_several_audiobooks_endpoint() {
let endpoint = ExpectedUrl::builder()
.endpoint("audiobooks")
.add_query_params(&[(
"ids",
"18yVqkdbdRvS24c0Ilj2ci,1HGw3J3NxZO1TP1BTtVhpZ,7iHfbu1YPACw6oZPAFJtqe",
)])
.build();
let client = SingleTestClient::new_raw(endpoint, "");
let endpoint = GetSeveralAudiobooks::from([
"18yVqkdbdRvS24c0Ilj2ci",
"1HGw3J3NxZO1TP1BTtVhpZ",
"7iHfbu1YPACw6oZPAFJtqe",
]);
api::ignore(endpoint).query(&client).unwrap();
}
}