spotify_rs/endpoint/
search.rs1use serde::Serialize;
2
3use crate::{
4 auth::AuthFlow,
5 error::Result,
6 model::search::{Item, SearchQuery, SearchResults},
7 query_list,
8};
9
10use super::{Client, Endpoint};
11
12impl Endpoint for SearchEndpoint {}
13
14pub fn search(query: impl Into<SearchQuery>, item_types: &[Item]) -> SearchEndpoint {
19 let r#type = query_list(item_types);
20 let query = query.into().to_string();
21
22 SearchEndpoint {
23 query,
24 r#type,
25 ..Default::default()
26 }
27}
28
29#[derive(Clone, Debug, Default, Serialize)]
30pub struct SearchEndpoint {
31 #[serde(rename = "q")]
32 pub(crate) query: String,
33 pub(crate) r#type: String,
34 #[serde(skip_serializing_if = "Option::is_none")]
35 pub(crate) market: Option<String>,
36 #[serde(skip_serializing_if = "Option::is_none")]
37 pub(crate) limit: Option<u32>,
38 #[serde(skip_serializing_if = "Option::is_none")]
39 pub(crate) offset: Option<u32>,
40 #[serde(skip_serializing_if = "Option::is_none")]
41 pub(crate) include_external: Option<bool>,
42}
43
44impl SearchEndpoint {
45 #[doc = include_str!("../docs/market.md")]
46 pub fn market(mut self, market: impl Into<String>) -> Self {
47 self.market = Some(market.into());
48 self
49 }
50
51 #[doc = include_str!("../docs/limit.md")]
52 pub fn limit(mut self, limit: u32) -> Self {
53 self.limit = Some(limit);
54 self
55 }
56
57 #[doc = include_str!("../docs/offset.md")]
58 pub fn offset(mut self, offset: u32) -> Self {
59 self.offset = Some(offset);
60 self
61 }
62
63 pub fn include_external(mut self, include_external: bool) -> Self {
68 self.include_external = Some(include_external);
69 self
70 }
71
72 pub fn item_types(mut self, item_types: &[Item]) -> Self {
74 self.r#type = query_list(item_types);
75 self
76 }
77
78 #[doc = include_str!("../docs/send.md")]
79 pub async fn get(self, spotify: &Client<impl AuthFlow>) -> Result<SearchResults> {
80 spotify.get("/search".to_owned(), self).await
81 }
82}