use super::{Error, client};
use crate::models::*;
use serde::{Deserialize, Serialize};
use reqwest;
impl client::TidalClient {
pub async fn album_list(
&self,
page_cursor: Option<&str>,
include: Option<Vec<String>>,
filter_owners_period_id: Option<Vec<String>>,
filter_id: Option<Vec<String>>,
filter_barcode_id: Option<Vec<String>>,
) -> Result<MultiResource<album::Album>, Error> {
let p_page_cursor = page_cursor;
let p_include = include;
let p_filter_owners_period_id = filter_owners_period_id;
let p_filter_id = filter_id;
let p_filter_barcode_id = filter_barcode_id;
let uri_str = format!("{}/albums", self.base_path_api);
let mut req_builder = self.client.request(reqwest::Method::GET, &uri_str);
if let Some(country_code) = &self.country_code {
req_builder = req_builder.query(&[("countryCode", country_code.clone())]);
}
if let Some(ref param_value) = p_page_cursor {
req_builder = req_builder.query(&[("page[cursor]", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_include {
req_builder = req_builder.query(
¶m_value
.iter()
.map(|p| ("include".to_owned(), p.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
);
}
if let Some(ref param_value) = p_filter_owners_period_id {
req_builder = req_builder.query(
¶m_value
.iter()
.map(|p| ("filter[owners.id]".to_owned(), p.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
);
}
if let Some(ref param_value) = p_filter_id {
req_builder = req_builder.query(
¶m_value
.iter()
.map(|p| ("filter[id]".to_owned(), p.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
);
}
if let Some(ref param_value) = p_filter_barcode_id {
req_builder = req_builder.query(
¶m_value
.iter()
.map(|p| ("filter[barcodeId]".to_owned(), p.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
);
}
self.execute_request(req_builder).await
}
pub async fn album_get(
&self,
id: &str,
include: Option<Vec<String>>,
) -> Result<Resource<album::Album>, Error> {
let p_id = id;
let p_include = include;
let uri_str = format!(
"{}/albums/{id}",
self.base_path_api,
id = crate::apis::urlencode(p_id)
);
let mut req_builder = self.client.request(reqwest::Method::GET, &uri_str);
if let Some(country_code) = &self.country_code {
req_builder = req_builder.query(&[("countryCode", country_code.clone())]);
}
if let Some(ref param_value) = p_include {
req_builder = req_builder.query(
¶m_value
.iter()
.map(|p| ("include".to_owned(), p.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
);
}
self.execute_request(req_builder).await
}
pub async fn album_artists(
&self,
id: &str,
page_cursor: Option<&str>,
) -> Result<MultiRelationship<ResourceIdentifier>, Error> {
let p_id = id;
let p_page_cursor = page_cursor;
let uri_str = format!(
"{}/albums/{id}/relationships/artists",
self.base_path_api,
id = crate::apis::urlencode(p_id)
);
let mut req_builder = self.client.request(reqwest::Method::GET, &uri_str);
if let Some(country_code) = &self.country_code {
req_builder = req_builder.query(&[("countryCode", country_code.clone())]);
}
if let Some(ref param_value) = p_page_cursor {
req_builder = req_builder.query(&[("page[cursor]", ¶m_value.to_string())]);
}
req_builder = req_builder.query(&[("include", "artists")]);
self.execute_request(req_builder).await
}
pub async fn album_cover_art(
&self,
id: &str,
page_cursor: Option<&str>,
) -> Result<MultiRelationship<ResourceIdentifier>, Error> {
let p_id = id;
let p_page_cursor = page_cursor;
let uri_str = format!(
"{}/albums/{id}/relationships/coverArt",
self.base_path_api,
id = crate::apis::urlencode(p_id)
);
let mut req_builder = self.client.request(reqwest::Method::GET, &uri_str);
if let Some(country_code) = &self.country_code {
req_builder = req_builder.query(&[("countryCode", country_code.clone())]);
}
if let Some(ref param_value) = p_page_cursor {
req_builder = req_builder.query(&[("page[cursor]", ¶m_value.to_string())]);
}
req_builder = req_builder.query(&[("include", "coverArt")]);
self.execute_request(req_builder).await
}
pub async fn album_items(
&self,
id: &str,
page_cursor: Option<&str>,
) -> Result<MultiRelationship<ResourceIdentifier<album::AlbumsItemsResourceMeta>>, Error> {
let p_id = id;
let p_page_cursor = page_cursor;
let uri_str = format!(
"{}/albums/{id}/relationships/items",
self.base_path_api,
id = crate::apis::urlencode(p_id)
);
let mut req_builder = self.client.request(reqwest::Method::GET, &uri_str);
if let Some(country_code) = &self.country_code {
req_builder = req_builder.query(&[("countryCode", country_code.clone())]);
}
if let Some(ref param_value) = p_page_cursor {
req_builder = req_builder.query(&[("page[cursor]", ¶m_value.to_string())]);
}
req_builder = req_builder.query(&[("include", "items")]);
self.execute_request(req_builder).await
}
pub async fn album_owners(
&self,
id: &str,
page_cursor: Option<&str>,
) -> Result<MultiRelationship<ResourceIdentifier>, Error> {
let p_id = id;
let p_page_cursor = page_cursor;
let uri_str = format!(
"{}/albums/{id}/relationships/owners",
self.base_path_api,
id = crate::apis::urlencode(p_id)
);
let mut req_builder = self.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("include", "owners")]);
if let Some(ref param_value) = p_page_cursor {
req_builder = req_builder.query(&[("page[cursor]", ¶m_value.to_string())]);
}
self.execute_request(req_builder).await
}
pub async fn album_providers(
&self,
id: &str,
page_cursor: Option<&str>,
) -> Result<MultiRelationship<ResourceIdentifier>, Error> {
let p_id = id;
let p_page_cursor = page_cursor;
let uri_str = format!(
"{}/albums/{id}/relationships/providers",
self.base_path_api,
id = crate::apis::urlencode(p_id)
);
let mut req_builder = self.client.request(reqwest::Method::GET, &uri_str);
if let Some(country_code) = &self.country_code {
req_builder = req_builder.query(&[("countryCode", country_code.clone())]);
}
req_builder = req_builder.query(&[("include", "providers")]);
if let Some(ref param_value) = p_page_cursor {
req_builder = req_builder.query(&[("page[cursor]", ¶m_value.to_string())]);
}
self.execute_request(req_builder).await
}
pub async fn album_similar_albums(
&self,
id: &str,
page_cursor: Option<&str>,
) -> Result<MultiRelationship<ResourceIdentifier>, Error> {
let p_id = id;
let p_page_cursor = page_cursor;
let uri_str = format!(
"{}/albums/{id}/relationships/similarAlbums",
self.base_path_api,
id = crate::apis::urlencode(p_id)
);
let mut req_builder = self.client.request(reqwest::Method::GET, &uri_str);
if let Some(country_code) = &self.country_code {
req_builder = req_builder.query(&[("countryCode", country_code.clone())]);
}
if let Some(ref param_value) = p_page_cursor {
req_builder = req_builder.query(&[("page[cursor]", ¶m_value.to_string())]);
}
req_builder = req_builder.query(&[("include", "similarAlbums")]);
self.execute_request(req_builder).await
}
}