1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
use crate::{
client::{
TidalClient,
models::search::{
SearchResultsFull, SearchSuggestionsFull,
config::{SearchConfig, SearchSuggestionsConfig},
},
},
error::TidalError,
};
impl TidalClient {
/// Searches for content on Tidal with configurable options
///
/// # Example
///
/// ```no_run
/// # use tidlers::TidalClient;
/// # use tidlers::auth::init::TidalAuth;
/// # use tidlers::client::models::search::config::{SearchConfig, SearchType};
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
/// # let auth = TidalAuth::with_oauth();
/// # let client = TidalClient::new(&auth);
/// let config = SearchConfig {
/// query: "Daft Punk".to_string(),
/// types: vec![SearchType::Artists, SearchType::Tracks],
/// limit: 10,
/// ..Default::default()
/// };
///
/// let results = client.search(config).await?;
/// if let Some(artists) = results.artists {
/// for artist in artists.items {
/// println!("Artist: {}", artist.name);
/// }
/// }
/// # Ok(())
/// # }
/// ```
pub async fn search(&self, config: SearchConfig) -> Result<SearchResultsFull, TidalError> {
let types_string = config
.types
.iter()
.map(|t| t.to_api_params())
.collect::<Vec<&str>>()
.join(",");
self.request(reqwest::Method::GET, "/search")
.with_country_code()
.with_locale()
.with_param("query", config.query)
.with_param(
"includeContributors",
config.include_contributors.to_string(),
)
.with_param("includeDidYouMean", config.include_did_you_mean.to_string())
.with_param(
"includeUserPlaylists",
config.include_user_playlists.to_string(),
)
.with_param(
"includeUserPlaylists",
config.include_user_playlists.to_string(),
)
.with_param("supportsUserData", config.supports_user_data.to_string())
.with_param("types", types_string)
.with_param("limit", config.limit.to_string())
.with_param("offset", config.offset.to_string())
.with_base_url(TidalClient::WEB_API_V2_LOCATION)
.send()
.await
}
/// Gets search suggestions for a query
pub async fn search_suggestion(
&self,
config: SearchSuggestionsConfig,
) -> Result<SearchSuggestionsFull, TidalError> {
self.request(reqwest::Method::GET, "/suggestions")
.with_country_code()
.with_param("query", config.query)
.with_param("explicit", config.explicit.to_string())
.with_param("hybrid", config.hybrid.to_string())
.with_base_url(TidalClient::WEB_API_V2_LOCATION)
.send()
.await
}
}