qobuz_api_rust/api/content/
labels_and_articles.rs

1use crate::{
2    api::service::QobuzApiService,
3    errors::QobuzApiError::{self},
4    models::{Label, SearchResult},
5};
6
7impl QobuzApiService {
8    /// Searches for articles using the specified query.
9    ///
10    /// This method allows you to search for articles on the Qobuz platform using a text query.
11    /// The results can be paginated and limited to a specific number of entries.
12    ///
13    /// ## Parameters
14    ///
15    /// - `query`: The search query string to match against article titles, descriptions, and content
16    /// - `limit`: Optional maximum number of results to return (defaults to 50 if not specified)
17    /// - `offset`: Optional offset for pagination (defaults to 0 if not specified)
18    /// - `with_auth`: Optional flag to execute the search with user authentication (defaults to false)
19    ///
20    /// ## Returns
21    ///
22    /// - `Ok(SearchResult)`: Contains the search results including articles that match the query
23    /// - `Err(QobuzApiError)`: If the API request fails due to network issues, authentication problems, or invalid parameters
24    ///
25    /// ## Examples
26    ///
27    /// Basic search for articles:
28    ///
29    /// ```rust
30    /// # use qobuz_api_rust::{QobuzApiService, QobuzApiError};
31    /// # async fn example() -> Result<(), QobuzApiError> {
32    /// # let api = QobuzApiService::new().await?;
33    /// let results = api.search_articles("classical music", None, None, None).await?;
34    /// println!("Found {} articles", results.articles.as_ref().map(|a| a.total.unwrap_or(0)).unwrap_or(0));
35    /// # Ok(())
36    /// # }
37    /// ```
38    ///
39    /// Search with custom limit and offset for pagination:
40    ///
41    /// ```rust
42    /// # use qobuz_api_rust::{QobuzApiService, QobuzApiError};
43    /// # async fn example() -> Result<(), QobuzApiError> {
44    /// # let api = QobuzApiService::new().await?;
45    /// let results = api.search_articles("jazz", Some(10), Some(20), None).await?;
46    /// // Gets 10 articles starting from the 20th result
47    /// # Ok(())
48    /// # }
49    /// ```
50    pub async fn search_articles(
51        &self,
52        query: &str,
53        limit: Option<i32>,
54        offset: Option<i32>,
55        with_auth: Option<bool>,
56    ) -> Result<SearchResult, QobuzApiError> {
57        let params = vec![
58            ("query".to_string(), query.to_string()),
59            ("limit".to_string(), limit.unwrap_or(50).to_string()),
60            ("offset".to_string(), offset.unwrap_or(0).to_string()),
61        ];
62
63        let _use_auth = with_auth.unwrap_or(false);
64
65        self.get("/article/search", &params).await
66    }
67
68    /// Gets Label with the specified label ID.
69    ///
70    /// This method retrieves detailed information about a specific music label using its unique ID.
71    /// Additional related content can be included in the response based on the `extra` parameter.
72    ///
73    /// ## Parameters
74    ///
75    /// - `label_id`: The unique identifier of the label to retrieve
76    /// - `with_auth`: Optional flag to execute the request with user authentication (defaults to false)
77    /// - `extra`: Optional string specifying additional data to include (e.g., "albums", "news", "articles")
78    /// - `limit`: Optional maximum number of extra results to return (defaults to 25 if not specified)
79    /// - `offset`: Optional offset for pagination of extra results (defaults to 0 if not specified)
80    ///
81    /// ## Returns
82    ///
83    /// - `Ok(Label)`: Contains the detailed information about the requested label
84    /// - `Err(QobuzApiError)`: If the API request fails due to network issues, authentication problems, or invalid parameters
85    ///
86    /// ## Examples
87    ///
88    /// Basic label retrieval:
89    ///
90    /// ```rust
91    /// # use qobuz_api_rust::{QobuzApiService, QobuzApiError};
92    /// # async fn example() -> Result<(), QobuzApiError> {
93    /// # let api = QobuzApiService::new().await?;
94    /// let label = api.get_label("12345", None, None, None, None).await?;
95    /// println!("Label name: {:?}", label.name);
96    /// # Ok(())
97    /// # }
98    /// ```
99    ///
100    /// Get label with additional albums:
101    ///
102    /// ```rust
103    /// # use qobuz_api_rust::{QobuzApiService, QobuzApiError};
104    /// # async fn example() -> Result<(), QobuzApiError> {
105    /// # let api = QobuzApiService::new().await?;
106    /// let label = api.get_label("12345", None, Some("albums"), Some(10), Some(0)).await?;
107    /// // Gets label info with up to 10 associated albums
108    /// # Ok(())
109    /// # }
110    /// ```
111    pub async fn get_label(
112        &self,
113        label_id: &str,
114        with_auth: Option<bool>,
115        extra: Option<&str>,
116        limit: Option<i32>,
117        offset: Option<i32>,
118    ) -> Result<Label, QobuzApiError> {
119        let mut params = vec![("label_id".to_string(), label_id.to_string())];
120
121        if let Some(extra_val) = extra {
122            params.push(("extra".to_string(), extra_val.to_string()));
123        }
124
125        params.push(("limit".to_string(), limit.unwrap_or(25).to_string()));
126        params.push(("offset".to_string(), offset.unwrap_or(0).to_string()));
127
128        let _use_auth = with_auth.unwrap_or(false);
129
130        self.get("/label/get", &params).await
131    }
132}