tidalv2 0.3.0

Rust client library for TIDAL's v2 JSON:API - type-safe access to TIDAL's music catalog and streaming services
Documentation
/*
 * TIDAL API - Beta
 *
 * TIDAL API is a [JSON:API](https://jsonapi.org/) Web API that gives access to TIDAL functionality and data.
 *
 * The version of the OpenAPI document: 0.1.76
 *
 * Generated by: https://openapi-generator.tech
 */

use super::{Error, client};
use crate::models::*;

use reqwest;

impl client::TidalClient {
    /// Get search suggestions by query.
    ///
    /// TIDAL returns a collection containing exactly one search-suggestions resource.
    pub async fn search_suggestion_get(
        &self,
        query: &str,
        explicit_filter: Option<&str>,
        include: Option<Vec<String>>,
    ) -> Result<Resource<search_suggestions::SearchSuggestion>, Error> {
        let uri_str = format!("{}/searchSuggestions", self.base_path_api);
        let mut req_builder = self.client.request(reqwest::Method::GET, &uri_str);

        req_builder = req_builder.query(&[("filter[query]", query)]);
        if let Some(country_code) = &self.country_code {
            req_builder = req_builder.query(&[("countryCode", country_code.clone())]);
        }
        if let Some(ref param_value) = explicit_filter {
            req_builder = req_builder.query(&[("explicitFilter", &param_value.to_string())]);
        }
        if let Some(ref param_value) = include {
            req_builder = req_builder.query(
                &param_value
                    .iter()
                    .map(|p| ("include".to_owned(), p.to_string()))
                    .collect::<Vec<(std::string::String, std::string::String)>>(),
            );
        }

        let collection: MultiResource<search_suggestions::SearchSuggestion> =
            self.execute_request(req_builder).await?;
        collection.into_singleton()
    }

    /// Retrieves directHits relationship.
    ///
    /// # Parameters
    /// * `id` - Opaque search-suggestions identifier from a searchSuggestions collection response
    /// * `explicit_filter` - Explicit filter (e.g. "INCLUDE/EXCLUDE")
    /// * `page_cursor` - Server-generated cursor value pointing a certain page of items. Optional, targets first page if not specified
    pub async fn search_suggestion_direct_hits(
        &self,
        id: &str,
        explicit_filter: Option<&str>,
        page_cursor: Option<&str>,
    ) -> Result<MultiRelationship<ResourceIdentifier>, Error> {
        // add a prefix to parameters to efficiently prevent name collisions
        let p_id = id;
        let p_explicit_filter = explicit_filter;
        let p_page_cursor = page_cursor;

        let uri_str = format!(
            "{}/searchSuggestions/{id}/relationships/directHits",
            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_explicit_filter {
            req_builder = req_builder.query(&[("explicitFilter", &param_value.to_string())]);
        }
        req_builder = req_builder.query(&[("include", "directHits")]);
        if let Some(ref param_value) = p_page_cursor {
            req_builder = req_builder.query(&[("page[cursor]", &param_value.to_string())]);
        }

        self.execute_request(req_builder).await
    }
}