use super::{Error, client};
use crate::models::*;
use serde::{Deserialize, Serialize};
use reqwest;
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct ArtistsTrackProvidersResourceMeta {
#[serde(rename = "numberOfTracks")]
pub number_of_tracks: i64,
}
impl client::TidalClient {
pub async fn artist_list(
&self,
include: Option<Vec<String>>,
collapse_by: Option<String>,
filter_handle: Option<Vec<String>>,
filter_id: Option<Vec<String>>,
) -> Result<MultiResource<artist::Artist>, Error> {
let p_include = include;
let p_filter_handle = filter_handle;
let p_filter_id = filter_id;
let p_collapse_by = collapse_by;
let uri_str = format!("{}/artists", 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_collapse_by {
req_builder = req_builder.query(&[("collapseBy", ¶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_handle {
req_builder = req_builder.query(
¶m_value
.iter()
.map(|p| ("filter[handle]".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)>>(),
);
}
self.execute_request(req_builder).await
}
pub async fn artist_get(
&self,
id: &str,
include: Option<Vec<String>>,
collapse_by: Option<String>,
) -> Result<Resource<artist::Artist>, Error> {
let p_id = id;
let p_include = include;
let p_collapse_by = collapse_by;
let uri_str = format!(
"{}/artists/{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_collapse_by {
req_builder = req_builder.query(&[("collapseBy", ¶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)>>(),
);
}
self.execute_request(req_builder).await
}
pub async fn artist_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!(
"{}/artists/{id}/relationships/albums",
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", "albums")]);
self.execute_request(req_builder).await
}
pub async fn artist_biography(&self, id: &str) -> Result<Relationship, Error> {
let p_id = id;
let uri_str = format!(
"{}/artists/{id}/relationships/biography",
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", "biography")]);
self.execute_request(req_builder).await
}
pub async fn artist_owners(
&self,
id: &str,
include: Option<Vec<String>>,
page_cursor: Option<&str>,
) -> Result<MultiRelationship<ResourceIdentifier>, Error> {
let p_id = id;
let p_include = include;
let p_page_cursor = page_cursor;
let uri_str = format!(
"{}/artists/{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);
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_page_cursor {
req_builder = req_builder.query(&[("page[cursor]", ¶m_value.to_string())]);
}
self.execute_request(req_builder).await
}
pub async fn artist_profile_art(
&self,
id: &str,
include: Option<Vec<String>>,
page_cursor: Option<&str>,
) -> Result<MultiRelationship<ResourceIdentifier>, Error> {
let p_id = id;
let p_include = include;
let p_page_cursor = page_cursor;
let uri_str = format!(
"{}/artists/{id}/relationships/profileArt",
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)>>(),
);
}
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 artist_radio(
&self,
id: &str,
page_cursor: Option<&str>,
include: Option<Vec<String>>,
) -> Result<MultiRelationship<ResourceIdentifier>, Error> {
let p_id = id;
let p_page_cursor = page_cursor;
let p_include = include;
let uri_str = format!(
"{}/artists/{id}/relationships/radio",
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())]);
}
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 artist_roles(
&self,
id: &str,
include: Option<Vec<String>>,
page_cursor: Option<&str>,
) -> Result<MultiRelationship<ResourceIdentifier>, Error> {
let p_id = id;
let p_include = include;
let p_page_cursor = page_cursor;
let uri_str = format!(
"{}/artists/{id}/relationships/roles",
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(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_page_cursor {
req_builder = req_builder.query(&[("page[cursor]", ¶m_value.to_string())]);
}
self.execute_request(req_builder).await
}
pub async fn artist_similar_artists(
&self,
id: &str,
page_cursor: Option<&str>,
include: Option<Vec<String>>,
) -> Result<MultiRelationship<ResourceIdentifier>, Error> {
let p_id = id;
let p_page_cursor = page_cursor;
let p_include = include;
let uri_str = format!(
"{}/artists/{id}/relationships/similarArtists",
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())]);
}
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 artist_track_providers(
&self,
id: &str,
page_cursor: Option<&str>,
include: Option<Vec<String>>,
) -> Result<MultiRelationship<ResourceIdentifier<ArtistsTrackProvidersResourceMeta>>, Error>
{
let p_id = id;
let p_page_cursor = page_cursor;
let p_include = include;
let uri_str = format!(
"{}/artists/{id}/relationships/trackProviders",
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(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)>>(),
);
}
self.execute_request(req_builder).await
}
pub async fn artist_tracks(
&self,
id: &str,
collapse_by: &str,
page_cursor: Option<&str>,
include: Option<Vec<String>>,
) -> Result<MultiRelationship<ResourceIdentifier>, Error> {
let p_id = id;
let p_collapse_by = collapse_by;
let p_page_cursor = page_cursor;
let p_include = include;
let uri_str = format!(
"{}/artists/{id}/relationships/tracks",
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(&[("collapseBy", &p_collapse_by.to_string())]);
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)>>(),
);
}
self.execute_request(req_builder).await
}
pub async fn artist_videos(
&self,
id: &str,
page_cursor: Option<&str>,
include: Option<Vec<String>>,
) -> Result<MultiRelationship<ResourceIdentifier>, Error> {
let p_id = id;
let p_page_cursor = page_cursor;
let p_include = include;
let uri_str = format!(
"{}/artists/{id}/relationships/videos",
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())]);
}
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
}
}