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
89
use serde::Serialize;

use crate::{
    auth::{AuthFlow, Verifier},
    error::Result,
    model::{
        category::{Categories, Category},
        Page,
    },
};

use super::{Builder, Endpoint, Limit};

impl Endpoint for BrowseCategoryEndpoint {}
impl Endpoint for BrowseCategoriesEndpoint {}

#[derive(Clone, Debug, Default, Serialize)]
pub struct BrowseCategoryEndpoint {
    #[serde(skip)]
    pub(crate) id: String,
    pub(crate) country: Option<String>,
    pub(crate) locale: Option<String>,
}

impl<F: AuthFlow, V: Verifier> Builder<'_, F, V, BrowseCategoryEndpoint> {
    #[doc = include_str!("../docs/country.md")]
    pub fn country(mut self, country: impl Into<String>) -> Self {
        self.endpoint.country = Some(country.into());
        self
    }

    #[doc = include_str!("../docs/locale.md")]
    pub fn locale(mut self, locale: impl Into<String>) -> Self {
        self.endpoint.locale = Some(locale.into());
        self
    }

    #[doc = include_str!("../docs/send.md")]
    pub async fn get(self) -> Result<Category> {
        self.spotify
            .get(
                format!("/browse/categories/{}", self.endpoint.id),
                self.endpoint,
            )
            .await
    }
}

#[derive(Clone, Debug, Default, Serialize)]
pub struct BrowseCategoriesEndpoint {
    pub(crate) country: Option<String>,
    pub(crate) locale: Option<String>,
    pub(crate) limit: Option<Limit>,
    pub(crate) offset: Option<u32>,
}

impl<F: AuthFlow, V: Verifier> Builder<'_, F, V, BrowseCategoriesEndpoint> {
    #[doc = include_str!("../docs/country.md")]
    pub fn country(mut self, country: impl Into<String>) -> Self {
        self.endpoint.country = Some(country.into());
        self
    }

    #[doc = include_str!("../docs/locale.md")]
    pub fn locale(mut self, locale: impl Into<String>) -> Self {
        self.endpoint.locale = Some(locale.into());
        self
    }

    #[doc = include_str!("../docs/limit.md")]
    pub fn limit(mut self, limit: u32) -> Self {
        self.endpoint.limit = Some(Limit::new(limit));
        self
    }

    #[doc = include_str!("../docs/offset.md")]
    pub fn offset(mut self, offset: u32) -> Self {
        self.endpoint.offset = Some(offset);
        self
    }

    #[doc = include_str!("../docs/send.md")]
    pub async fn get(self) -> Result<Page<Category>> {
        self.spotify
            .get("/browse/categories".to_owned(), self.endpoint)
            .await
            .map(|c: Categories| c.categories)
    }
}