spotify_cli/spotify/
client.rs

1use reqwest::blocking::Client as HttpClient;
2
3use crate::error::Result;
4use crate::spotify::albums::AlbumsClient;
5use crate::spotify::artists::ArtistsClient;
6use crate::spotify::auth::AuthService;
7use crate::spotify::devices::DevicesClient;
8use crate::spotify::playback::PlaybackClient;
9use crate::spotify::playlists::PlaylistsClient;
10use crate::spotify::search::SearchClient;
11use crate::spotify::track::TrackClient;
12
13/// Top-level Spotify API client factory.
14#[derive(Debug, Clone)]
15pub struct SpotifyClient {
16    http: HttpClient,
17    auth: AuthService,
18}
19
20impl SpotifyClient {
21    pub fn new(auth: AuthService) -> Result<Self> {
22        let http = HttpClient::builder().build()?;
23        Ok(Self { http, auth })
24    }
25
26    pub fn playback(&self) -> PlaybackClient {
27        PlaybackClient::new(self.http.clone(), self.auth.clone())
28    }
29
30    pub fn albums(&self) -> AlbumsClient {
31        AlbumsClient::new(self.http.clone(), self.auth.clone())
32    }
33
34    pub fn artists(&self) -> ArtistsClient {
35        ArtistsClient::new(self.http.clone(), self.auth.clone())
36    }
37
38    pub fn devices(&self) -> DevicesClient {
39        DevicesClient::new(self.http.clone(), self.auth.clone())
40    }
41
42    pub fn playlists(&self) -> PlaylistsClient {
43        PlaylistsClient::new(self.http.clone(), self.auth.clone())
44    }
45
46    pub fn search(&self) -> SearchClient {
47        SearchClient::new(self.http.clone(), self.auth.clone())
48    }
49
50    pub fn track(&self) -> TrackClient {
51        TrackClient::new(self.http.clone(), self.auth.clone())
52    }
53}