prawn 0.1.0

Rust Client for the Tidal API providing comprehensive API coverag, and easy OAuth management
Documentation
/*
 * TIDAL API
 *
 * The TIDAL API is a [JSON:API](https://jsonapi.org/)–compliant web API that exposes TIDAL’s music, metadata, and user-related functionality through a consistent, resource-oriented design. More information and API management are available at [developer.tidal.com](developer.tidal.com)
 *
 * The version of the OpenAPI document: 1.0.36
 *
 * Generated by: https://openapi-generator.tech
 */

use super::{configuration, Error};
use crate::apis::ContentType;
use crate::{apis::ResponseContent, models};
use async_trait::async_trait;
use reqwest;
use serde::{de::Error as _, Deserialize, Serialize};
use std::sync::Arc;

#[async_trait]
pub trait DynamicPagesApi: Send + Sync {
    /// GET /dynamicPages
    ///
    /// Retrieves multiple dynamicPages by available filters, or without if applicable.
    async fn get_dynamic_page<
        'client_version,
        'device_type,
        'platform,
        'refresh_id,
        'country_code,
        'locale,
        'include,
        'filter_left_square_bracket_page_type_right_square_bracket,
        'filter_left_square_bracket_subject_id_right_square_bracket,
    >(
        &self,
        client_version: &'client_version str,
        device_type: &'device_type str,
        platform: &'platform str,
        refresh_id: Option<i64>,
        country_code: Option<&'country_code str>,
        locale: Option<&'locale str>,
        include: Option<Vec<String>>,
        filter_left_square_bracket_page_type_right_square_bracket: Option<Vec<String>>,
        filter_left_square_bracket_subject_id_right_square_bracket: Option<Vec<String>>,
    ) -> Result<models::DynamicPagesMultiResourceDataDocument, Error<GetDynamicPageError>>;

    /// GET /dynamicPages/{id}/relationships/subject
    ///
    /// Retrieves subject relationship.
    async fn get_dynamic_pages_subject<'id, 'include>(
        &self,
        id: &'id str,
        include: Option<Vec<String>>,
    ) -> Result<
        models::DynamicPagesSingleRelationshipDataDocument,
        Error<GetDynamicPagesSubjectError>,
    >;
}

#[derive(Clone)]
pub struct DynamicPagesApiClient {
    configuration: Arc<configuration::Configuration>,
}

impl DynamicPagesApiClient {
    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
        Self { configuration }
    }
}

#[async_trait]
impl DynamicPagesApi for DynamicPagesApiClient {
    /// Retrieves multiple dynamicPages by available filters, or without if applicable.
    async fn get_dynamic_page<
        'client_version,
        'device_type,
        'platform,
        'refresh_id,
        'country_code,
        'locale,
        'include,
        'filter_left_square_bracket_page_type_right_square_bracket,
        'filter_left_square_bracket_subject_id_right_square_bracket,
    >(
        &self,
        client_version: &'client_version str,
        device_type: &'device_type str,
        platform: &'platform str,
        refresh_id: Option<i64>,
        country_code: Option<&'country_code str>,
        locale: Option<&'locale str>,
        include: Option<Vec<String>>,
        filter_left_square_bracket_page_type_right_square_bracket: Option<Vec<String>>,
        filter_left_square_bracket_subject_id_right_square_bracket: Option<Vec<String>>,
    ) -> Result<models::DynamicPagesMultiResourceDataDocument, Error<GetDynamicPageError>> {
        let local_var_configuration = &self.configuration;

        let local_var_client = &local_var_configuration.client;

        let local_var_uri_str = format!("{}/dynamicPages", local_var_configuration.base_path);
        let mut local_var_req_builder =
            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());

        local_var_req_builder =
            local_var_req_builder.query(&[("clientVersion", &client_version.to_string())]);
        local_var_req_builder =
            local_var_req_builder.query(&[("deviceType", &device_type.to_string())]);
        local_var_req_builder = local_var_req_builder.query(&[("platform", &platform.to_string())]);
        if let Some(ref param_value) = refresh_id {
            local_var_req_builder =
                local_var_req_builder.query(&[("refreshId", &param_value.to_string())]);
        }
        if let Some(ref param_value) = country_code {
            local_var_req_builder =
                local_var_req_builder.query(&[("countryCode", &param_value.to_string())]);
        }
        if let Some(ref param_value) = locale {
            local_var_req_builder =
                local_var_req_builder.query(&[("locale", &param_value.to_string())]);
        }
        if let Some(ref param_value) = include {
            local_var_req_builder = match "multi" {
                "multi" => local_var_req_builder.query(
                    &param_value
                        .into_iter()
                        .map(|p| ("include".to_owned(), p.to_string()))
                        .collect::<Vec<(std::string::String, std::string::String)>>(),
                ),
                _ => local_var_req_builder.query(&[(
                    "include",
                    &param_value
                        .into_iter()
                        .map(|p| p.to_string())
                        .collect::<Vec<String>>()
                        .join(",")
                        .to_string(),
                )]),
            };
        }
        if let Some(ref param_value) = filter_left_square_bracket_page_type_right_square_bracket {
            local_var_req_builder = match "multi" {
                "multi" => local_var_req_builder.query(
                    &param_value
                        .into_iter()
                        .map(|p| ("filter[pageType]".to_owned(), p.to_string()))
                        .collect::<Vec<(std::string::String, std::string::String)>>(),
                ),
                _ => local_var_req_builder.query(&[(
                    "filter[pageType]",
                    &param_value
                        .into_iter()
                        .map(|p| p.to_string())
                        .collect::<Vec<String>>()
                        .join(",")
                        .to_string(),
                )]),
            };
        }
        if let Some(ref param_value) = filter_left_square_bracket_subject_id_right_square_bracket {
            local_var_req_builder = match "multi" {
                "multi" => local_var_req_builder.query(
                    &param_value
                        .into_iter()
                        .map(|p| ("filter[subject.id]".to_owned(), p.to_string()))
                        .collect::<Vec<(std::string::String, std::string::String)>>(),
                ),
                _ => local_var_req_builder.query(&[(
                    "filter[subject.id]",
                    &param_value
                        .into_iter()
                        .map(|p| p.to_string())
                        .collect::<Vec<String>>()
                        .join(",")
                        .to_string(),
                )]),
            };
        }
        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
            local_var_req_builder = local_var_req_builder
                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
        }
        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
        };
        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
        };

        let local_var_req = local_var_req_builder.build()?;
        let local_var_resp = local_var_client.execute(local_var_req).await?;

        let local_var_status = local_var_resp.status();
        let local_var_content_type = local_var_resp
            .headers()
            .get("content-type")
            .and_then(|v| v.to_str().ok())
            .unwrap_or("application/octet-stream");
        let local_var_content_type = super::ContentType::from(local_var_content_type);
        let local_var_content = local_var_resp.text().await?;

        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
            match local_var_content_type {
                ContentType::Json => serde_path_to_error::deserialize(&mut serde_json::Deserializer::from_str(&local_var_content)).map_err(Error::from),
                ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DynamicPagesMultiResourceDataDocument`"))),
                ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `models::DynamicPagesMultiResourceDataDocument`")))),
            }
        } else {
            let local_var_entity: Option<GetDynamicPageError> =
                serde_json::from_str(&local_var_content).ok();
            let local_var_error = ResponseContent {
                status: local_var_status,
                content: local_var_content,
                entity: local_var_entity,
            };
            Err(Error::ResponseError(local_var_error))
        }
    }

    /// Retrieves subject relationship.
    async fn get_dynamic_pages_subject<'id, 'include>(
        &self,
        id: &'id str,
        include: Option<Vec<String>>,
    ) -> Result<
        models::DynamicPagesSingleRelationshipDataDocument,
        Error<GetDynamicPagesSubjectError>,
    > {
        let local_var_configuration = &self.configuration;

        let local_var_client = &local_var_configuration.client;

        let local_var_uri_str = format!(
            "{}/dynamicPages/{id}/relationships/subject",
            local_var_configuration.base_path,
            id = crate::apis::urlencode(id)
        );
        let mut local_var_req_builder =
            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());

        if let Some(ref param_value) = include {
            local_var_req_builder = match "multi" {
                "multi" => local_var_req_builder.query(
                    &param_value
                        .into_iter()
                        .map(|p| ("include".to_owned(), p.to_string()))
                        .collect::<Vec<(std::string::String, std::string::String)>>(),
                ),
                _ => local_var_req_builder.query(&[(
                    "include",
                    &param_value
                        .into_iter()
                        .map(|p| p.to_string())
                        .collect::<Vec<String>>()
                        .join(",")
                        .to_string(),
                )]),
            };
        }
        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
            local_var_req_builder = local_var_req_builder
                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
        }
        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
        };
        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
        };

        let local_var_req = local_var_req_builder.build()?;
        let local_var_resp = local_var_client.execute(local_var_req).await?;

        let local_var_status = local_var_resp.status();
        let local_var_content_type = local_var_resp
            .headers()
            .get("content-type")
            .and_then(|v| v.to_str().ok())
            .unwrap_or("application/octet-stream");
        let local_var_content_type = super::ContentType::from(local_var_content_type);
        let local_var_content = local_var_resp.text().await?;

        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
            match local_var_content_type {
                ContentType::Json => serde_path_to_error::deserialize(&mut serde_json::Deserializer::from_str(&local_var_content)).map_err(Error::from),
                ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DynamicPagesSingleRelationshipDataDocument`"))),
                ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `models::DynamicPagesSingleRelationshipDataDocument`")))),
            }
        } else {
            let local_var_entity: Option<GetDynamicPagesSubjectError> =
                serde_json::from_str(&local_var_content).ok();
            let local_var_error = ResponseContent {
                status: local_var_status,
                content: local_var_content,
                entity: local_var_entity,
            };
            Err(Error::ResponseError(local_var_error))
        }
    }
}

/// struct for typed errors of method [`DynamicPagesApi::get_dynamic_page`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetDynamicPageError {
    Status400(models::Default400ResponseBody),
    Status404(models::Default404ResponseBody),
    Status405(models::Default405ResponseBody),
    Status406(models::Default406ResponseBody),
    Status415(models::Default415ResponseBody),
    Status429(models::Default429ResponseBody),
    Status500(models::Default500ResponseBody),
    Status503(models::Default503ResponseBody),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`DynamicPagesApi::get_dynamic_pages_subject`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetDynamicPagesSubjectError {
    Status400(models::Default400ResponseBody),
    Status404(models::Default404ResponseBody),
    Status405(models::Default405ResponseBody),
    Status406(models::Default406ResponseBody),
    Status415(models::Default415ResponseBody),
    Status429(models::Default429ResponseBody),
    Status500(models::Default500ResponseBody),
    Status503(models::Default503ResponseBody),
    UnknownValue(serde_json::Value),
}