diff --git a/README.md b/README.md index efac0d15..fe3197ba 100644 --- a/README.md +++ b/README.md @@ -7,49 +7,44 @@ ## Disclaimer -This crate is heavily inspired by [spotipy](https://github.com/plamere/spotipy)- A spotify api wrapper implemented in Python +This crate is heavily inspired by [spotipy](https://github.com/plamere/spotipy) - A Spotify API wrapper implemented in Python. ## Description -Rspotify is a lightweight wrapper for the [Spotify Web API](https://developer.spotify.com/web-api/) It includes helper functions for -**all Spotify's endpoints**, such as fetching metadata (search and look-up of albums, artists, tracks, playlists, new releases) and user's information (follow -users, artists and playlists, and saved tracks management). +Rspotify is a lightweight wrapper for the [Spotify Web API](https://developer.spotify.com/web-api/) It includes helper functions for **all Spotify's endpoints**, such as fetching metadata (search and look-up of albums, artists, tracks, playlists, new releases) and user's information (follow users, artists and playlists, and saved tracks management). ## Features -*rspotify* supports all of the features of the Spotify Web API including access to all end points, and support for user authorization, notes that before accessing to any end points, you need to be authorized. For details on the capabilities you are encouraged to review the [Spotify Web Endpoint Reference](https://developer.spotify.com/web-api/endpoint-reference/) documentation. +*Rspotify* supports all the features of the Spotify Web API, including access to all endpoints, and support for user authorization. Note that before accessing to any endpoints, you need to be authorized. For details on the capabilities you are encouraged to review the [Spotify Web Endpoint Reference](https://developer.spotify.com/web-api/endpoint-reference/) documentation. -Nowaday, thanks to [`reqwest`](https://docs.rs/reqwest/0.10.1/reqwest/#proxies), `rspotify` now supports system proxy by default. `Reqwest` System proxies look in environment variables to set HTTP or HTTPS proxies. `HTTP_PROXY` or `http_proxy` provide http proxies for http connections while `HTTPS_PROXY` or `https_proxy` provide HTTPS proxies for HTTPS connections.(~~Notes that `reqwest` system proxy doesn't support socks proxy for now,~~ check [this issue](https://github.com/seanmonstar/reqwest/issues/790) for more details) +Nowadays, thanks to [`reqwest`](https://docs.rs/reqwest/0.10.1/reqwest/#proxies), `rspotify` supports system proxy by default. `reqwest` system proxies look in environment variables to set HTTP or HTTPS proxies. `HTTP_PROXY` or `http_proxy` provide HTTP proxies for HTTP connections while `HTTPS_PROXY` or `https_proxy` provide HTTPS proxies for HTTPS connections (~~note that `reqwest` system proxy doesn't support socks proxy for now,~~ check [this issue](https://github.com/seanmonstar/reqwest/issues/790) for more details). ## Usage -Add this to your `Cargo.toml` +Add this to your `Cargo.toml`: ``` toml [dependencies] rspotify = "0.10.0" ``` -Or you could get it from [github](https://github.com/samrayleung/rspotify) +Or you could get it from [GitHub](https://github.com/samrayleung/rspotify). ## Getting Started ### Authorization -Since all methods require user authorization now, you will need to generate an authorization token that indicates that the user has granted permission for your application to perform the given task. You will need to register your app to get the credentials necessary to make authorized calls. +Since all methods require user authorization now, you will need to generate an authorization token that indicates that the user has granted permission for your application to perform the given task. You will need to register your app to get the credentials necessary to make authorized calls. Even if your script does not have an accessible URL you need to specify one when registering your application where the spotify authentication API will redirect to after successful login. The URL doesn't need to work or be accessible, you can specify "http://localhost/", after successful login you just need to copy the "http://localhost/?code=..." URL from your browser and paste it to the console where your application is running. For example: + ![](./doc/images/rspotify.gif) -In order to help other developers to get used to `rspotify`, I registerd a Spotify account with temporary email. Your guys could test `rspotify` with this account's `CLIENT_ID` and `CLIENT_SECRET`, check [.env file](./.env) for more details. +In order to help other developers to get used to `rspotify`, I registered a Spotify account with temporary email. Your can test `rspotify` with this account's `CLIENT_ID` and `CLIENT_SECRET`, check the [`.env` file](./.env) for more details. ### Examples -If you have a use case you are interested in, you could check the -[examples](./examples), which has all kinds of detailed examples. For example, -If you want to get recently played history, you could check -[current_user_recently_played](./examples/current_user_recently_played.rs). This is -the example code: +If you have a use case you are interested in, you could check the [examples](./examples), which has all kinds of detailed examples. For example, If you want to get recently played history, you could check [current_user_recently_played](./examples/current_user_recently_played.rs). This is the example code: ``` toml [dependencies] @@ -139,7 +134,7 @@ fn main() { + Browse: - [Get a List of Categories](./examples/categories.rs) -+ Track: ++ Tracks: - [Get a Track](./examples/track.rs) - [Get several tracks](./examples/tracks.rs) - [Get current user's currently playing track](./examples/current_user_playing_track.rs) @@ -153,7 +148,7 @@ fn main() { - [Get audio features for several tracks](./examples/audios_features.rs) - [Get audio analysis for a track](./examples/audio_analysis.rs) -+ Player ++ Player: - [Get current user's available devices](./examples/device.rs) - [Get information about current user's current playback](./examples/current_playback.rs) - [Get current user's currently playing track](./examples/current_playing.rs) @@ -168,7 +163,7 @@ fn main() { - [Toggle shuffle for current user's playback](./examples/shuffle.rs) - [Add an item to the end of current user's playback queue](#) -+ Show: ++ Shows: - [Save shows for current user](./examples/save_shows.rs) - [Get a list of saved shows](./examples/save_shows.rs) - [Get a show](./examples/get_a_show.rs) @@ -176,7 +171,7 @@ fn main() { - [Check current user's saved shows](./examples/check_users_saved_shows.rs) - [Remove current user's saved shows](./examples/remove_users_saved_shows.rs) -+ Episodes ++ Episodes: - [Get a show's episodes](./examples/get_shows_episodes.rs) - [Get an Episode](./examples/get_an_episode.rs) - [Get seversal episodes](./examples/get_several_episodes.rs) @@ -195,9 +190,8 @@ fn main() { - [Get current user's profile](./examples/me.rs) - [Current User follow users](./examples/user_follow_users.rs) - [Current User unfollow users](./examples/user_unfollow_users.rs) - -+ Playlist: ++ Playlists: - [Get a Playlist](./examples/playlist.rs) - [Get a List of a User's Playlist](./examples/user_playlists.rs) - [Get a Playlists's tracks](./examples/user_playlist_tracks.rs) @@ -213,23 +207,22 @@ fn main() { - [Check user following playlist](./examples/user_playlist_check_follow.rs) - [Get a list of Spotify featured playlists](./examples/featured_playlists.rs) -+ Misc ++ Misc: - [Get list new releases](./examples/new_releases.rs) - [Get list categories](./examples/categories.rs) - - [get recommendtions](./examples/recommendations.rs) + - [Get recommendtions](./examples/recommendations.rs) ## API Documentation -For more API information, you could check [rspotify Api documentation](https://docs.rs/crate/rspotify) +For more API information, check the [Rspotify API documentation](https://docs.rs/crate/rspotify). ## CHANGELOG -Please see the [CHANGELOG](./CHANGELOG.md) for a release history. +Please see the [changelog](./CHANGELOG.md) for a release history. ## Contribution -If you find any problem or have suggestions about this crate, please submit an -issue. Moreover, any pull request ,code review and feedback are welcome. +If you find any problems or have suggestions about this crate, please submit an issue. Moreover, any pull request, code review and feedback are welcome. ## License diff --git a/examples/add_to_queue.rs b/examples/add_to_queue.rs index 8f1def97..bd6ecfc8 100644 --- a/examples/add_to_queue.rs +++ b/examples/add_to_queue.rs @@ -16,7 +16,7 @@ async fn main() { let client_credential = SpotifyClientCredentials::default() .token_info(token_info) .build(); - // instantiate the Spotify client + // Instantiate the Spotify client let spotify = Spotify::default() .client_credentials_manager(client_credential) .build(); diff --git a/examples/next_playback.rs b/examples/next_playback.rs index 7873d2b6..497dfd19 100644 --- a/examples/next_playback.rs +++ b/examples/next_playback.rs @@ -34,7 +34,7 @@ async fn main() { let spotify = Spotify::default() .client_credentials_manager(client_credential) .build(); - // this is the example device_id from spotify website, + // This is the example device_id from spotify website, // so it will raise a 403 error, just change this device_id to yours let device_id = String::from("74ASZWbe4lXaubB36ztrGX"); match spotify.next_track(Some(device_id)).await { diff --git a/examples/previous_playback.rs b/examples/previous_playback.rs index e38b4395..f2807305 100644 --- a/examples/previous_playback.rs +++ b/examples/previous_playback.rs @@ -34,7 +34,7 @@ async fn main() { let spotify = Spotify::default() .client_credentials_manager(client_credential) .build(); - // this is the example device_id from spotify website, + // This is the example device_id from spotify website, // so it will raise a 403 error, just change this device_id to yours let device_id = String::from("74ASZWbe4lXaubB36ztrGX"); match spotify.previous_track(Some(device_id)).await { diff --git a/src/blocking/client.rs b/src/blocking/client.rs index c126f9db..cae9de48 100644 --- a/src/blocking/client.rs +++ b/src/blocking/client.rs @@ -9,7 +9,7 @@ use serde::de::Deserialize; use serde_json::map::Map; use serde_json::Value; -// built-in battery +// Built-in battery use std::borrow::Cow; use std::collections::HashMap; use std::fmt; @@ -185,7 +185,7 @@ impl Spotify { let mut response = { let builder = CLIENT.request(method, &url.into_owned()).headers(headers); - // only add body if necessary + // Only add body if necessary // spotify rejects GET requests that have a body with a 400 response let builder = if let Some(json) = payload { builder.json(json) @@ -223,24 +223,24 @@ impl Spotify { } } - ///send post request + /// Send post request fn post(&self, url: &str, payload: &Value) -> Result { self.internal_call(Method::POST, url, Some(payload)) } - ///send put request + /// Send put request fn put(&self, url: &str, payload: &Value) -> Result { self.internal_call(Method::PUT, url, Some(payload)) } - /// send delete request + /// Send delete request fn delete(&self, url: &str, payload: &Value) -> Result { self.internal_call(Method::DELETE, url, Some(payload)) } - ///[get-track](https://developer.spotify.com/web-api/get-track/) - ///returns a single track given the track's ID, URI or URL - ///Parameters: - ///- track_id - a spotify URI, URL or ID + /// [get-track](https://developer.spotify.com/web-api/get-track/) + /// returns a single track given the track's ID, URI or URL + /// Parameters: + /// - track_id - a spotify URI, URL or ID pub fn track(&self, track_id: &str) -> Result { let trid = self.get_id(Type::Track, track_id); let url = format!("tracks/{}", trid); @@ -248,11 +248,11 @@ impl Spotify { self.convert_result::(&result) } - ///[get-several-tracks](https://developer.spotify.com/web-api/get-several-tracks/) - ///returns a list of tracks given a list of track IDs, URIs, or URLs - ///Parameters: - ///- track_ids - a list of spotify URIs, URLs or IDs - ///- market - an ISO 3166-1 alpha-2 country code. + /// [get-several-tracks](https://developer.spotify.com/web-api/get-several-tracks/) + /// returns a list of tracks given a list of track IDs, URIs, or URLs + /// Parameters: + /// - track_ids - a list of spotify URIs, URLs or IDs + /// - market - an ISO 3166-1 alpha-2 country code. pub fn tracks( &self, track_ids: Vec<&str>, @@ -273,10 +273,10 @@ impl Spotify { self.convert_result::(&result) } - ///[get-artist](https://developer.spotify.com/web-api/get-artist/) - ///returns a single artist given the artist's ID, URI or URL - ///Parameters: - ///- artist_id - an artist ID, URI or URL + /// [get-artist](https://developer.spotify.com/web-api/get-artist/) + /// returns a single artist given the artist's ID, URI or URL + /// Parameters: + /// - artist_id - an artist ID, URI or URL pub fn artist(&self, artist_id: &str) -> Result { let trid = self.get_id(Type::Artist, artist_id); let url = format!("artists/{}", trid); @@ -285,10 +285,10 @@ impl Spotify { self.convert_result::(&result) } - ///[get-several-artists](https://developer.spotify.com/web-api/get-several-artists/) - ///returns a list of artists given the artist IDs, URIs, or URLs - ///Parameters: - ///- artist_ids - a list of artist IDs, URIs or URLs + /// [get-several-artists](https://developer.spotify.com/web-api/get-several-artists/) + /// returns a list of artists given the artist IDs, URIs, or URLs + /// Parameters: + /// - artist_ids - a list of artist IDs, URIs or URLs pub fn artists(&self, artist_ids: Vec) -> Result { let mut ids: Vec = vec![]; for artist_id in artist_ids { @@ -300,8 +300,8 @@ impl Spotify { self.convert_result::(&result) } - ///[get-artists-albums](https://developer.spotify.com/web-api/get-artists-albums/) - /// Get Spotify catalog information about an artist's albums + /// [get-artists-albums](https://developer.spotify.com/web-api/get-artists-albums/) + /// Get Spotify catalog information about an artist's albums /// - artist_id - the artist ID, URI or URL /// - album_type - 'album', 'single', 'appears_on', 'compilation' /// - country - limit the response to one particular country. @@ -336,11 +336,11 @@ impl Spotify { self.convert_result::>(&result) } - ///[get artists to tracks](https://developer.spotify.com/web-api/get-artists-top-tracks/) + /// [get artists to tracks](https://developer.spotify.com/web-api/get-artists-top-tracks/) /// Get Spotify catalog information about an artist's top 10 tracks by country. - /// Parameters: - /// - artist_id - the artist ID, URI or URL - /// - country - limit the response to one particular country. + /// Parameters: + /// - artist_id - the artist ID, URI or URL + /// - country - limit the response to one particular country. pub fn artist_top_tracks>>( &self, artist_id: &str, @@ -373,12 +373,12 @@ impl Spotify { // } } - ///[get related artists](https://developer.spotify.com/web-api/get-related-artists/) - ///Get Spotify catalog information about artists similar to an - ///identified artist. Similarity is based on analysis of the - ///Spotify community's listening history. - ///Parameters: - ///- artist_id - the artist ID, URI or URL + /// [get related artists](https://developer.spotify.com/web-api/get-related-artists/) + /// Get Spotify catalog information about artists similar to an + /// identified artist. Similarity is based on analysis of the + /// Spotify community's listening history. + /// Parameters: + /// - artist_id - the artist ID, URI or URL pub fn artist_related_artists(&self, artist_id: &str) -> Result { let trid = self.get_id(Type::Artist, artist_id); let url = format!("artists/{}/related-artists", trid); @@ -388,10 +388,10 @@ impl Spotify { self.convert_result::(&result) } - ///[get album](https://developer.spotify.com/web-api/get-album/) - ///returns a single album given the album's ID, URIs or URL - ///Parameters: - ///- album_id - the album ID, URI or URL + /// [get album](https://developer.spotify.com/web-api/get-album/) + /// returns a single album given the album's ID, URIs or URL + /// Parameters: + /// - album_id - the album ID, URI or URL pub fn album(&self, album_id: &str) -> Result { let trid = self.get_id(Type::Album, album_id); let url = format!("albums/{}", trid); @@ -400,10 +400,10 @@ impl Spotify { self.convert_result::(&result) } - ///[get several albums](https://developer.spotify.com/web-api/get-several-albums/) - ///returns a list of albums given the album IDs, URIs, or URLs - ///Parameters: - ///- albums_ids - a list of album IDs, URIs or URLs + /// [get several albums](https://developer.spotify.com/web-api/get-several-albums/) + /// returns a list of albums given the album IDs, URIs, or URLs + /// Parameters: + /// - albums_ids - a list of album IDs, URIs or URLs pub fn albums(&self, album_ids: Vec) -> Result { let mut ids: Vec = vec![]; for album_id in album_ids { @@ -415,17 +415,17 @@ impl Spotify { self.convert_result::(&result) } - ///[search for items](https://developer.spotify.com/web-api/search-item/) - ///Search for an Item - ///Get Spotify catalog information about artists, albums, tracks or - /// playlists that match a keyword string. - /// Parameters: - ///- q - the search query - ///- limit - the number of items to return - ///- offset - the index of the first item to return - ///- type - the type of item to return. One of 'artist', 'album', - ///'track' or 'playlist' - ///- market - An ISO 3166-1 alpha-2 country code or the string from_token. + /// [search for items](https://developer.spotify.com/web-api/search-item/) + /// Search for an Item + /// Get Spotify catalog information about artists, albums, tracks or + /// playlists that match a keyword string. + /// Parameters: + /// - q - the search query + /// - limit - the number of items to return + /// - offset - the index of the first item to return + /// - type - the type of item to return. One of 'artist', 'album', + /// 'track' or 'playlist' + /// - market - An ISO 3166-1 alpha-2 country code or the string from_token. pub fn search>, O: Into>>( &self, q: &str, @@ -456,12 +456,12 @@ impl Spotify { self.convert_result::(&result) } - ///[get albums tracks](https://developer.spotify.com/web-api/get-albums-tracks/) - ///Get Spotify catalog information about an album's tracks - ///Parameters: - ///- album_id - the album ID, URI or URL - ///- limit - the number of items to return - ///- offset - the index of the first item to return + /// [get albums tracks](https://developer.spotify.com/web-api/get-albums-tracks/) + /// Get Spotify catalog information about an album's tracks + /// Parameters: + /// - album_id - the album ID, URI or URL + /// - limit - the number of items to return + /// - offset - the index of the first item to return pub fn album_track>, O: Into>>( &self, album_id: &str, @@ -479,21 +479,21 @@ impl Spotify { self.convert_result::>(&result) } - ///[get users profile](https://developer.spotify.com/web-api/get-users-profile/) - ///Gets basic profile information about a Spotify User - ///Parameters: - ///- user - the id of the usr + /// [get users profile](https://developer.spotify.com/web-api/get-users-profile/) + /// Gets basic profile information about a Spotify User + /// Parameters: + /// - user - the id of the usr pub fn user(&self, user_id: &str) -> Result { let url = format!("users/{}", user_id); let result = self.get(&url, &mut HashMap::new())?; self.convert_result::(&result) } - ///[get playlist](https://developer.spotify.com/documentation/web-api/reference/playlists/get-playlist/) - ///Get full details about Spotify playlist - ///Parameters: - ///- playlist_id - the id of the playlist - ///- market - an ISO 3166-1 alpha-2 country code. + /// [get playlist](https://developer.spotify.com/documentation/web-api/reference/playlists/get-playlist/) + /// Get full details about Spotify playlist + /// Parameters: + /// - playlist_id - the id of the playlist + /// - market - an ISO 3166-1 alpha-2 country code. pub fn playlist( &self, playlist_id: &str, @@ -514,11 +514,11 @@ impl Spotify { self.convert_result::(&result) } - ///[get users playlists](https://developer.spotify.com/web-api/get-a-list-of-current-users-playlists/) - ///Get current user playlists without required getting his profile - ///Parameters: - ///- limit - the number of items to return - ///- offset - the index of the first item to return + /// [get users playlists](https://developer.spotify.com/web-api/get-a-list-of-current-users-playlists/) + /// Get current user playlists without required getting his profile + /// Parameters: + /// - limit - the number of items to return + /// - offset - the index of the first item to return pub fn current_user_playlists>, O: Into>>( &self, limit: L, @@ -533,12 +533,12 @@ impl Spotify { self.convert_result::>(&result) } - ///[get list users playlists](https://developer.spotify.com/web-api/get-list-users-playlists/) - ///Gets playlists of a user - ///Parameters: - ///- user_id - the id of the usr - ///- limit - the number of items to return - ///- offset - the index of the first item to return + /// [get list users playlists](https://developer.spotify.com/web-api/get-list-users-playlists/) + /// Gets playlists of a user + /// Parameters: + /// - user_id - the id of the usr + /// - limit - the number of items to return + /// - offset - the index of the first item to return pub fn user_playlists>, O: Into>>( &self, user_id: &str, @@ -553,12 +553,12 @@ impl Spotify { self.convert_result::>(&result) } - ///[get list users playlists](https://developer.spotify.com/web-api/get-list-users-playlists/) - ///Gets playlist of a user - ///Parameters: - ///- user_id - the id of the user - ///- playlist_id - the id of the playlist - ///- fields - which fields to return + /// [get list users playlists](https://developer.spotify.com/web-api/get-list-users-playlists/) + /// Gets playlist of a user + /// Parameters: + /// - user_id - the id of the user + /// - playlist_id - the id of the playlist + /// - fields - which fields to return pub fn user_playlist( &self, user_id: &str, @@ -588,15 +588,15 @@ impl Spotify { } } - ///[get playlists tracks](https://developer.spotify.com/web-api/get-playlists-tracks/) - ///Get full details of the tracks of a playlist owned by a user - ///Parameters: - ///- user_id - the id of the user - ///- playlist_id - the id of the playlist - ///- fields - which fields to return - ///- limit - the maximum number of tracks to return - ///- offset - the index of the first track to return - ///- market - an ISO 3166-1 alpha-2 country code. + /// [get playlists tracks](https://developer.spotify.com/web-api/get-playlists-tracks/) + /// Get full details of the tracks of a playlist owned by a user + /// Parameters: + /// - user_id - the id of the user + /// - playlist_id - the id of the playlist + /// - fields - which fields to return + /// - limit - the maximum number of tracks to return + /// - offset - the index of the first track to return + /// - market - an ISO 3166-1 alpha-2 country code. pub fn user_playlist_tracks>, O: Into>>( &self, user_id: &str, @@ -621,13 +621,13 @@ impl Spotify { self.convert_result::>(&result) } - ///[create playlist](https://developer.spotify.com/web-api/create-playlist/) - ///Creates a playlist for a user - ///Parameters: - ///- user_id - the id of the user - ///- name - the name of the playlist - ///- public - is the created playlist public - ///- description - the description of the playlist + /// [create playlist](https://developer.spotify.com/web-api/create-playlist/) + /// Creates a playlist for a user + /// Parameters: + /// - user_id - the id of the user + /// - name - the name of the playlist + /// - public - is the created playlist public + /// - description - the description of the playlist pub fn user_playlist_create>, D: Into>>( &self, user_id: &str, @@ -647,15 +647,15 @@ impl Spotify { self.convert_result::(&result) } - ///[change playlists details](https://developer.spotify.com/web-api/change-playlist-details/) - ///Changes a playlist's name and/or public/private state - ///Parameters: - ///- user_id - the id of the user - ///- playlist_id - the id of the playlist - ///- name - optional name of the playlist - ///- public - optional is the playlist public - ///- collaborative - optional is the playlist collaborative - ///- description - optional description of the playlist + /// [change playlists details](https://developer.spotify.com/web-api/change-playlist-details/) + /// Changes a playlist's name and/or public/private state + /// Parameters: + /// - user_id - the id of the user + /// - playlist_id - the id of the playlist + /// - name - optional name of the playlist + /// - public - optional is the playlist public + /// - collaborative - optional is the playlist collaborative + /// - description - optional description of the playlist pub fn user_playlist_change_detail( &self, user_id: &str, @@ -682,11 +682,11 @@ impl Spotify { self.put(&url, &Value::Object(params)) } - ///[unfollow playlist](https://developer.spotify.com/web-api/unfollow-playlist/) - ///Unfollows (deletes) a playlist for a user - ///Parameters: - ///- user_id - the id of the user - ///- playlist_id - the id of the playlist + /// [unfollow playlist](https://developer.spotify.com/web-api/unfollow-playlist/) + /// Unfollows (deletes) a playlist for a user + /// Parameters: + /// - user_id - the id of the user + /// - playlist_id - the id of the playlist pub fn user_playlist_unfollow( &self, user_id: &str, @@ -696,13 +696,13 @@ impl Spotify { self.delete(&url, &json!({})) } - ///[add tracks to playlist](https://developer.spotify.com/web-api/add-tracks-to-playlist/) - ///Adds tracks to a playlist - ///Parameters: - ///- user_id - the id of the user - ///- playlist_id - the id of the playlist - ///- track_ids - a list of track URIs, URLs or IDs - ///- position - the position to add the tracks + /// [add tracks to playlist](https://developer.spotify.com/web-api/add-tracks-to-playlist/) + /// Adds tracks to a playlist + /// Parameters: + /// - user_id - the id of the user + /// - playlist_id - the id of the playlist + /// - track_ids - a list of track URIs, URLs or IDs + /// - position - the position to add the tracks pub fn user_playlist_add_tracks( &self, user_id: &str, @@ -724,13 +724,13 @@ impl Spotify { let result = self.post(&url, &Value::Object(params))?; self.convert_result::(&result) } - ///[replaced playlists tracks](https://developer.spotify.com/web-api/replace-playlists-tracks/) - ///Replace all tracks in a playlist - ///Parameters: - ///- user - the id of the user - ///- playlist_id - the id of the playlist - ///- tracks - the list of track ids to add to the playlist + /// [replaced playlists tracks](https://developer.spotify.com/web-api/replace-playlists-tracks/) + /// Replace all tracks in a playlist + /// Parameters: + /// - user - the id of the user + /// - playlist_id - the id of the playlist + /// - tracks - the list of track ids to add to the playlist pub fn user_playlist_replace_tracks( &self, user_id: &str, @@ -752,15 +752,15 @@ impl Spotify { } } - ///[reorder playlists tracks](https://developer.spotify.com/web-api/reorder-playlists-tracks/) - ///Reorder tracks in a playlist - ///Parameters: - ///- user_id - the id of the user - ///- playlist_id - the id of the playlist - ///- range_start - the position of the first track to be reordered - ///- range_length - optional the number of tracks to be reordered (default: 1) - ///- insert_before - the position where the tracks should be inserted - ///- snapshot_id - optional playlist's snapshot ID + /// [reorder playlists tracks](https://developer.spotify.com/web-api/reorder-playlists-tracks/) + /// Reorder tracks in a playlist + /// Parameters: + /// - user_id - the id of the user + /// - playlist_id - the id of the playlist + /// - range_start - the position of the first track to be reordered + /// - range_length - optional the number of tracks to be reordered (default: 1) + /// - insert_before - the position where the tracks should be inserted + /// - snapshot_id - optional playlist's snapshot ID pub fn user_playlist_recorder_tracks>>( &self, user_id: &str, @@ -784,13 +784,13 @@ impl Spotify { self.convert_result::(&result) } - ///[remove tracks playlist](https://developer.spotify.com/web-api/remove-tracks-playlist/) - ///Removes all occurrences of the given tracks from the given playlist - ///Parameters: - ///- user_id - the id of the user - ///- playlist_id - the id of the playlist - ///- track_ids - the list of track ids to add to the playlist - ///- snapshot_id - optional id of the playlist snapshot + /// [remove tracks playlist](https://developer.spotify.com/web-api/remove-tracks-playlist/) + /// Removes all occurrences of the given tracks from the given playlist + /// Parameters: + /// - user_id - the id of the user + /// - playlist_id - the id of the playlist + /// - track_ids - the list of track ids to add to the playlist + /// - snapshot_id - optional id of the playlist snapshot pub fn user_playlist_remove_all_occurrences_of_tracks( &self, user_id: &str, @@ -819,16 +819,16 @@ impl Spotify { self.convert_result::(&result) } - ///[remove tracks playlist](https://developer.spotify.com/web-api/remove-tracks-playlist/) - ///Removes all occurrences of the given tracks from the given playlist - ///Parameters: - ///- user_id - the id of the user - ///- playlist_id - the id of the playlist - ///- tracks - an array of map containing Spotify URIs of the tracks - /// to remove with their current positions in the playlist. For example: - ///{ "tracks": [{ "uri": "spotify:track:4iV5W9uYEdYUVa79Axb7Rh", "positions": [0,3] },{ - ///"uri": "spotify:track:1301WleyT98MSxVHPZCA6M", "positions": [7] }] } - ///- snapshot_id - optional id of the playlist snapshot + /// [remove tracks playlist](https://developer.spotify.com/web-api/remove-tracks-playlist/) + /// Removes all occurrences of the given tracks from the given playlist + /// Parameters: + /// - user_id - the id of the user + /// - playlist_id - the id of the playlist + /// - tracks - an array of map containing Spotify URIs of the tracks + /// to remove with their current positions in the playlist. For example: + /// { "tracks": [{ "uri": "spotify:track:4iV5W9uYEdYUVa79Axb7Rh", "positions": [0,3] },{ + /// "uri": "spotify:track:1301WleyT98MSxVHPZCA6M", "positions": [7] }] } + /// - snapshot_id - optional id of the playlist snapshot pub fn user_playlist_remove_specific_occurrenes_of_tracks( &self, user_id: &str, @@ -859,11 +859,11 @@ impl Spotify { self.convert_result::(&result) } - ///[follow playlist](https://developer.spotify.com/web-api/follow-playlist/) - ///Add the current authenticated user as a follower of a playlist. - ///Parameters: - ///- playlist_owner_id - the user id of the playlist owner - ///- playlist_id - the id of the playlist + /// [follow playlist](https://developer.spotify.com/web-api/follow-playlist/) + /// Add the current authenticated user as a follower of a playlist. + /// Parameters: + /// - playlist_owner_id - the user id of the playlist owner + /// - playlist_id - the id of the playlist pub fn user_playlist_follow_playlist>>( &self, playlist_owner_id: &str, @@ -883,13 +883,13 @@ impl Spotify { } } - ///[check user following playlist](https://developer.spotify.com/web-api/check-user-following-playlist/) - ///Check to see if the given users are following the given playlist - ///Parameters: - ///- playlist_owner_id - the user id of the playlist owner - ///- playlist_id - the id of the playlist - ///- user_ids - the ids of the users that you want to - ///check to see if they follow the playlist. Maximum: 5 ids. + /// [check user following playlist](https://developer.spotify.com/web-api/check-user-following-playlist/) + /// Check to see if the given users are following the given playlist + /// Parameters: + /// - playlist_owner_id - the user id of the playlist owner + /// - playlist_id - the id of the playlist + /// - user_ids - the ids of the users that you want to + /// check to see if they follow the playlist. Maximum: 5 ids. pub fn user_playlist_check_follow( &self, playlist_owner_id: &str, @@ -909,17 +909,17 @@ impl Spotify { let result = self.get(&url, &mut dumb)?; self.convert_result::>(&result) } - ///[get current users profile](https://developer.spotify.com/web-api/get-current-users-profile/) - ///Get detailed profile information about the current user. - ///An alias for the 'current_user' method. + /// [get current users profile](https://developer.spotify.com/web-api/get-current-users-profile/) + /// Get detailed profile information about the current user. + /// An alias for the 'current_user' method. pub fn me(&self) -> Result { let mut dumb: HashMap = HashMap::new(); let url = String::from("me/"); let result = self.get(&url, &mut dumb)?; self.convert_result::(&result) } - ///Get detailed profile information about the current user. - ///An alias for the 'me' method. + /// Get detailed profile information about the current user. + /// An alias for the 'me' method. pub fn current_user(&self) -> Result { self.me() } @@ -941,13 +941,13 @@ impl Spotify { } } - ///[get user saved albums](https://developer.spotify.com/web-api/get-users-saved-albums/) - ///Gets a list of the albums saved in the current authorized user's - ///"Your Music" library - ///Parameters: - ///- limit - the number of albums to return - ///- offset - the index of the first album to return - ///- market - Provide this parameter if you want to apply Track Relinking. + /// [get user saved albums](https://developer.spotify.com/web-api/get-users-saved-albums/) + /// Gets a list of the albums saved in the current authorized user's + /// "Your Music" library + /// Parameters: + /// - limit - the number of albums to return + /// - offset - the index of the first album to return + /// - market - Provide this parameter if you want to apply Track Relinking. pub fn current_user_saved_albums>, O: Into>>( &self, limit: L, @@ -962,11 +962,11 @@ impl Spotify { let result = self.get(&url, &mut params)?; self.convert_result::>(&result) } - ///[get users saved tracks](https://developer.spotify.com/web-api/get-users-saved-tracks/) - ///Parameters: - ///- limit - the number of tracks to return - ///- offset - the index of the first track to return - ///- market - Provide this parameter if you want to apply Track Relinking. + /// [get users saved tracks](https://developer.spotify.com/web-api/get-users-saved-tracks/) + /// Parameters: + /// - limit - the number of tracks to return + /// - offset - the index of the first track to return + /// - market - Provide this parameter if you want to apply Track Relinking. pub fn current_user_saved_tracks>, O: Into>>( &self, limit: L, @@ -981,11 +981,11 @@ impl Spotify { let result = self.get(&url, &mut params)?; self.convert_result::>(&result) } - ///[get followed artists](https://developer.spotify.com/web-api/get-followed-artists/) - ///Gets a list of the artists followed by the current authorized user - ///Parameters: - ///- limit - the number of tracks to return - ///- after - ghe last artist ID retrieved from the previous request + /// [get followed artists](https://developer.spotify.com/web-api/get-followed-artists/) + /// Gets a list of the artists followed by the current authorized user + /// Parameters: + /// - limit - the number of tracks to return + /// - after - ghe last artist ID retrieved from the previous request pub fn current_user_followed_artists>>( &self, limit: L, @@ -1003,11 +1003,11 @@ impl Spotify { self.convert_result::(&result) } - ///[remove tracks users](https://developer.spotify.com/web-api/remove-tracks-user/) - ///Remove one or more tracks from the current user's - ///"Your Music" library. - ///Parameters: - ///- track_ids - a list of track URIs, URLs or IDs + /// [remove tracks users](https://developer.spotify.com/web-api/remove-tracks-user/) + /// Remove one or more tracks from the current user's + /// "Your Music" library. + /// Parameters: + /// - track_ids - a list of track URIs, URLs or IDs pub fn current_user_saved_tracks_delete( &self, track_ids: &[String], @@ -1023,11 +1023,11 @@ impl Spotify { } } - ///[check users saved tracks](https://developer.spotify.com/web-api/check-users-saved-tracks/) - ///Check if one or more tracks is already saved in - ///the current Spotify user’s “Your Music” library. - ///Parameters: - ///- track_ids - a list of track URIs, URLs or IDs + /// [check users saved tracks](https://developer.spotify.com/web-api/check-users-saved-tracks/) + /// Check if one or more tracks is already saved in + /// the current Spotify user’s “Your Music” library. + /// Parameters: + /// - track_ids - a list of track URIs, URLs or IDs pub fn current_user_saved_tracks_contains( &self, track_ids: &[String], @@ -1042,11 +1042,11 @@ impl Spotify { self.convert_result::>(&result) } - ///[save tracks user ](https://developer.spotify.com/web-api/save-tracks-user/) - ///Save one or more tracks to the current user's - ///"Your Music" library. - ///Parameters: - ///- track_ids - a list of track URIs, URLs or IDs + /// [save tracks user ](https://developer.spotify.com/web-api/save-tracks-user/) + /// Save one or more tracks to the current user's + /// "Your Music" library. + /// Parameters: + /// - track_ids - a list of track URIs, URLs or IDs pub fn current_user_saved_tracks_add( &self, track_ids: &[String], @@ -1062,13 +1062,12 @@ impl Spotify { } } - ///[get users top artists and tracks](https://developer.spotify.com/web-api/get-users-top-artists-and-tracks/) - ///Get the current user's top artists - ///Parameters: - ///- limit - the number of entities to return - ///- offset - the index of the first entity to return - ///- time_range - Over what time frame are the affinities computed - + /// [get users top artists and tracks](https://developer.spotify.com/web-api/get-users-top-artists-and-tracks/) + /// Get the current user's top artists + /// Parameters: + /// - limit - the number of entities to return + /// - offset - the index of the first entity to return + /// - time_range - Over what time frame are the affinities computed pub fn current_user_top_artists< L: Into>, O: Into>, @@ -1091,12 +1090,12 @@ impl Spotify { self.convert_result::>(&result) } - ///[get users top artists and tracks](https://developer.spotify.com/web-api/get-users-top-artists-and-tracks/) - ///Get the current user's top tracks - ///Parameters: - ///- limit - the number of entities to return - ///- offset - the index of the first entity to return - ///- time_range - Over what time frame are the affinities computed + /// [get users top artists and tracks](https://developer.spotify.com/web-api/get-users-top-artists-and-tracks/) + /// Get the current user's top tracks + /// Parameters: + /// - limit - the number of entities to return + /// - offset - the index of the first entity to return + /// - time_range - Over what time frame are the affinities computed pub fn current_user_top_tracks< L: Into>, O: Into>, @@ -1119,10 +1118,10 @@ impl Spotify { self.convert_result::>(&result) } - ///[get recently played](https://developer.spotify.com/web-api/web-api-personalization-endpoints/get-recently-played/) - ///Get the current user's recently played tracks - ///Parameters: - ///- limit - the number of entities to return + /// [get recently played](https://developer.spotify.com/web-api/web-api-personalization-endpoints/get-recently-played/) + /// Get the current user's recently played tracks + /// Parameters: + /// - limit - the number of entities to return pub fn current_user_recently_played>>( &self, limit: L, @@ -1135,11 +1134,11 @@ impl Spotify { self.convert_result::>(&result) } - ///[save albums user](https://developer.spotify.com/web-api/save-albums-user/) - ///Add one or more albums to the current user's - ///"Your Music" library. - ///Parameters: - ///- album_ids - a list of album URIs, URLs or IDs + /// [save albums user](https://developer.spotify.com/web-api/save-albums-user/) + /// Add one or more albums to the current user's + /// "Your Music" library. + /// Parameters: + /// - album_ids - a list of album URIs, URLs or IDs pub fn current_user_saved_albums_add( &self, album_ids: &[String], @@ -1155,11 +1154,11 @@ impl Spotify { } } - ///[remove albums user](https://developer.spotify.com/documentation/web-api/reference/library/remove-albums-user/) - ///Remove one or more albums from the current user's - ///"Your Music" library. - ///Parameters: - ///- album_ids - a list of album URIs, URLs or IDs + /// [remove albums user](https://developer.spotify.com/documentation/web-api/reference/library/remove-albums-user/) + /// Remove one or more albums from the current user's + /// "Your Music" library. + /// Parameters: + /// - album_ids - a list of album URIs, URLs or IDs pub fn current_user_saved_albums_delete( &self, album_ids: &[String], @@ -1175,11 +1174,11 @@ impl Spotify { } } - ///[check users saved albums](https://developer.spotify.com/documentation/web-api/reference/library/check-users-saved-albums/) - ///Check if one or more albums is already saved in - ///the current Spotify user’s “Your Music” library. - ///Parameters: - ///- album_ids - a list of album URIs, URLs or IDs + /// [check users saved albums](https://developer.spotify.com/documentation/web-api/reference/library/check-users-saved-albums/) + /// Check if one or more albums is already saved in + /// the current Spotify user’s “Your Music” library. + /// Parameters: + /// - album_ids - a list of album URIs, URLs or IDs pub fn current_user_saved_albums_contains( &self, album_ids: &[String], @@ -1194,10 +1193,10 @@ impl Spotify { self.convert_result::>(&result) } - ///[follow artists users](https://developer.spotify.com/web-api/follow-artists-users/) - ///Follow one or more artists - ///Parameters: - ///- artist_ids - a list of artist IDs + /// [follow artists users](https://developer.spotify.com/web-api/follow-artists-users/) + /// Follow one or more artists + /// Parameters: + /// - artist_ids - a list of artist IDs pub fn user_follow_artists(&self, artist_ids: &[String]) -> Result<(), failure::Error> { let url = format!("me/following?type=artist&ids={}", artist_ids.join(",")); match self.put(&url, &json!({})) { @@ -1206,10 +1205,10 @@ impl Spotify { } } - ///[unfollow artists users](https://developer.spotify.com/documentation/web-api/reference/follow/unfollow-artists-users/) - ///Unfollow one or more artists - ///Parameters: - ///- artist_ids - a list of artist IDs + /// [unfollow artists users](https://developer.spotify.com/documentation/web-api/reference/follow/unfollow-artists-users/) + /// Unfollow one or more artists + /// Parameters: + /// - artist_ids - a list of artist IDs pub fn user_unfollow_artists(&self, artist_ids: &[String]) -> Result<(), failure::Error> { let url = format!("me/following?type=artist&ids={}", artist_ids.join(",")); match self.delete(&url, &json!({})) { @@ -1218,11 +1217,11 @@ impl Spotify { } } - ///[check user following - ///artists](https://developer.spotify.com/web-api/checkcurrent-user-follows/) - ///Check to see if the given users are following the given artists - ///Parameters: - ///- artist_ids - the ids of the users that you want to + /// [check user following + /// artists](https://developer.spotify.com/web-api/checkcurrent-user-follows/) + /// Check to see if the given users are following the given artists + /// Parameters: + /// - artist_ids - the ids of the users that you want to pub fn user_artist_check_follow( &self, artsit_ids: &[String], @@ -1236,10 +1235,10 @@ impl Spotify { self.convert_result::>(&result) } - ///[follow artists users](https://developer.spotify.com/web-api/follow-artists-users/) - ///Follow one or more users - ///Parameters: - ///- user_ids - a list of artist IDs + /// [follow artists users](https://developer.spotify.com/web-api/follow-artists-users/) + /// Follow one or more users + /// Parameters: + /// - user_ids - a list of artist IDs pub fn user_follow_users(&self, user_ids: &[String]) -> Result<(), failure::Error> { let url = format!("me/following?type=user&ids={}", user_ids.join(",")); match self.put(&url, &json!({})) { @@ -1248,10 +1247,10 @@ impl Spotify { } } - ///[unfollow artists users](https://developer.spotify.com/documentation/web-api/reference/follow/unfollow-artists-users/) - ///Unfollow one or more users - ///Parameters: - ///- user_ids - a list of artist IDs + /// [unfollow artists users](https://developer.spotify.com/documentation/web-api/reference/follow/unfollow-artists-users/) + /// Unfollow one or more users + /// Parameters: + /// - user_ids - a list of artist IDs pub fn user_unfollow_users(&self, user_ids: &[String]) -> Result<(), failure::Error> { let url = format!("me/following?type=user&ids={}", user_ids.join(",")); match self.delete(&url, &json!({})) { @@ -1260,22 +1259,22 @@ impl Spotify { } } - ///[get list featured playlists](https://developer.spotify.com/web-api/get-list-featured-playlists/) - ///Get a list of Spotify featured playlists - ///Parameters: - ///- locale - The desired language, consisting of a lowercase ISO - ///639 language code and an uppercase ISO 3166-1 alpha-2 country - ///code, joined by an underscore. - ///- country - An ISO 3166-1 alpha-2 country code. - ///- timestamp - A timestamp in ISO 8601 format: - ///yyyy-MM-ddTHH:mm:ss. Use this parameter to specify the user's - ///local time to get results tailored for that specific date and - ///time in the day - ///- limit - The maximum number of items to return. Default: 20. - ///Minimum: 1. Maximum: 50 - ///- offset - The index of the first item to return. Default: 0 - ///(the first object). Use with limit to get the next set of - ///items. + /// [get list featured playlists](https://developer.spotify.com/web-api/get-list-featured-playlists/) + /// Get a list of Spotify featured playlists + /// Parameters: + /// - locale - The desired language, consisting of a lowercase ISO + /// 639 language code and an uppercase ISO 3166-1 alpha-2 country + /// code, joined by an underscore. + /// - country - An ISO 3166-1 alpha-2 country code. + /// - timestamp - A timestamp in ISO 8601 format: + /// yyyy-MM-ddTHH:mm:ss. Use this parameter to specify the user's + /// local time to get results tailored for that specific date and + /// time in the day + /// - limit - The maximum number of items to return. Default: 20. + /// Minimum: 1. Maximum: 50 + /// - offset - The index of the first item to return. Default: 0 + /// (the first object). Use with limit to get the next set of + /// items. pub fn featured_playlists>, O: Into>>( &self, locale: Option, @@ -1303,15 +1302,15 @@ impl Spotify { self.convert_result::(&result) } - ///[get list new releases](https://developer.spotify.com/web-api/get-list-new-releases/) - ///Get a list of new album releases featured in Spotify - ///Parameters: - ///- country - An ISO 3166-1 alpha-2 country code. - ///- limit - The maximum number of items to return. Default: 20. - ///Minimum: 1. Maximum: 50 - ///- offset - The index of the first item to return. Default: 0 - ///(the first object). Use with limit to get the next set of - ///items. + /// [get list new releases](https://developer.spotify.com/web-api/get-list-new-releases/) + /// Get a list of new album releases featured in Spotify + /// Parameters: + /// - country - An ISO 3166-1 alpha-2 country code. + /// - limit - The maximum number of items to return. Default: 20. + /// Minimum: 1. Maximum: 50 + /// - offset - The index of the first item to return. Default: 0 + /// (the first object). Use with limit to get the next set of + /// items. pub fn new_releases>, O: Into>>( &self, country: Option, @@ -1331,18 +1330,18 @@ impl Spotify { self.convert_result::(&result) } - ///[get list categories](https://developer.spotify.com/web-api/get-list-categories/) - ///Get a list of new album releases featured in Spotify - ///Parameters: - ///- country - An ISO 3166-1 alpha-2 country code. - ///- locale - The desired language, consisting of an ISO 639 - ///language code and an ISO 3166-1 alpha-2 country code, joined - ///by an underscore. - ///- limit - The maximum number of items to return. Default: 20. - ///Minimum: 1. Maximum: 50 - ///- offset - The index of the first item to return. Default: 0 - ///(the first object). Use with limit to get the next set of - ///items. + /// [get list categories](https://developer.spotify.com/web-api/get-list-categories/) + /// Get a list of new album releases featured in Spotify + /// Parameters: + /// - country - An ISO 3166-1 alpha-2 country code. + /// - locale - The desired language, consisting of an ISO 639 + /// language code and an ISO 3166-1 alpha-2 country code, joined + /// by an underscore. + /// - limit - The maximum number of items to return. Default: 20. + /// Minimum: 1. Maximum: 50 + /// - offset - The index of the first item to return. Default: 0 + /// (the first object). Use with limit to get the next set of + /// items. pub fn categories>, O: Into>>( &self, locale: Option, @@ -1366,19 +1365,19 @@ impl Spotify { self.convert_result::(&result) } - ///[get recommendtions](https://developer.spotify.com/web-api/get-recommendations/) - ///Get Recommendations Based on Seeds - /// Parameters: - /// - seed_artists - a list of artist IDs, URIs or URLs - /// - seed_tracks - a list of artist IDs, URIs or URLs - /// - seed_genres - a list of genre names. Available genres for - /// - country - An ISO 3166-1 alpha-2 country code. If provided, all - /// results will be playable in this country. - /// - limit - The maximum number of items to return. Default: 20. - /// Minimum: 1. Maximum: 100 - /// - min/max/target_ - For the tuneable track attributes listed - /// in the documentation, these values provide filters and targeting on - /// results. + /// [get recommendtions](https://developer.spotify.com/web-api/get-recommendations/) + /// Get Recommendations Based on Seeds + /// Parameters: + /// - seed_artists - a list of artist IDs, URIs or URLs + /// - seed_tracks - a list of artist IDs, URIs or URLs + /// - seed_genres - a list of genre names. Available genres for + /// - country - An ISO 3166-1 alpha-2 country code. If provided, all + /// results will be playable in this country. + /// - limit - The maximum number of items to return. Default: 20. + /// Minimum: 1. Maximum: 100 + /// - min/max/target_ - For the tuneable track attributes listed + /// in the documentation, these values provide filters and targeting on + /// results. pub fn recommendations>>( &self, seed_artists: Option>, @@ -1448,9 +1447,9 @@ impl Spotify { let result = self.get(&url, &mut params)?; self.convert_result::(&result) } - ///[get audio features](https://developer.spotify.com/web-api/get-audio-features/) - ///Get audio features for a track - ///- track - track URI, URL or ID + /// [get audio features](https://developer.spotify.com/web-api/get-audio-features/) + /// Get audio features for a track + /// - track - track URI, URL or ID pub fn audio_features(&self, track: &str) -> Result { let track_id = self.get_id(Type::Track, track); let url = format!("audio-features/{}", track_id); @@ -1459,9 +1458,9 @@ impl Spotify { self.convert_result::(&result) } - ///[get several audio features](https://developer.spotify.com/web-api/get-several-audio-features/) - ///Get Audio Features for Several Tracks - /// -tracks a list of track URIs, URLs or IDs + /// [get several audio features](https://developer.spotify.com/web-api/get-several-audio-features/) + /// Get Audio Features for Several Tracks + /// -tracks a list of track URIs, URLs or IDs pub fn audios_features( &self, tracks: &[String], @@ -1484,10 +1483,10 @@ impl Spotify { } } - ///[get audio analysis](https://developer.spotify.com/web-api/get-audio-analysis/) - ///Get Audio Analysis for a Track - ///Parameters: - ///- track_id - a track URI, URL or ID + /// [get audio analysis](https://developer.spotify.com/web-api/get-audio-analysis/) + /// Get Audio Analysis for a Track + /// Parameters: + /// - track_id - a track URI, URL or ID pub fn audio_analysis(&self, track: &str) -> Result { let trid = self.get_id(Type::Track, track); let url = format!("audio-analysis/{}", trid); @@ -1496,8 +1495,8 @@ impl Spotify { self.convert_result::(&result) } - ///[get a users available devices](https://developer.spotify.com/web-api/get-a-users-available-devices/) - ///Get a User’s Available Devices + /// [get a users available devices](https://developer.spotify.com/web-api/get-a-users-available-devices/) + /// Get a User’s Available Devices pub fn device(&self) -> Result { let url = String::from("me/player/devices"); let mut dumb = HashMap::new(); @@ -1505,11 +1504,11 @@ impl Spotify { self.convert_result::(&result) } - ///[get informatation about the users current playback](https://developer.spotify.com/web-api/get-information-about-the-users-current-playback/) - ///Get Information About The User’s Current Playback - /// Parameters: - /// - market: Optional. an ISO 3166-1 alpha-2 country code. - /// - additional_types: Optional. A comma-separated list of item types that your client supports besides the default track type. Valid types are: `track` and `episode`. + /// [get informatation about the users current playback](https://developer.spotify.com/web-api/get-information-about-the-users-current-playback/) + /// Get Information About The User’s Current Playback + /// Parameters: + /// - market: Optional. an ISO 3166-1 alpha-2 country code. + /// - additional_types: Optional. A comma-separated list of item types that your client supports besides the default track type. Valid types are: `track` and `episode`. pub fn current_playback( &self, market: Option, @@ -1542,11 +1541,11 @@ impl Spotify { } } - ///[get the users currently playing track](https://developer.spotify.com/web-api/get-the-users-currently-playing-track/) - /// Get the User’s Currently Playing Track - /// Query Parameters: - /// - market: Optional. an ISO 3166-1 alpha-2 country code. - /// - additional_types: Optional. A comma-separated list of item types that your client supports besides the default track type. Valid types are: `track` and `episode`. + /// [get the users currently playing track](https://developer.spotify.com/web-api/get-the-users-currently-playing-track/) + /// Get the User’s Currently Playing Track + /// Query Parameters: + /// - market: Optional. an ISO 3166-1 alpha-2 country code. + /// - additional_types: Optional. A comma-separated list of item types that your client supports besides the default track type. Valid types are: `track` and `episode`. pub fn current_playing( &self, market: Option, @@ -1578,14 +1577,14 @@ impl Spotify { Err(e) => Err(e), } } - ///[transfer a users playback](https://developer.spotify.com/web-api/transfer-a-users-playback/) - ///Transfer a User’s Playback - ///Note: Although an array is accepted, only a single device_id is currently - /// supported. Supplying more than one will return 400 Bad Request - /// Parameters: - ///- device_id - transfer playback to this device - ///- force_play - true: after transfer, play. false: - ///keep current state. + /// [transfer a users playback](https://developer.spotify.com/web-api/transfer-a-users-playback/) + /// Transfer a User’s Playback + /// Note: Although an array is accepted, only a single device_id is currently + /// supported. Supplying more than one will return 400 Bad Request + /// Parameters: + /// - device_id - transfer playback to this device + /// - force_play - true: after transfer, play. false: + /// keep current state. pub fn transfer_playback>>( &self, device_id: &str, @@ -1603,23 +1602,23 @@ impl Spotify { } } - ///[start a users playback](https://developer.spotify.com/web-api/start-a-users-playback/) - ///Start/Resume a User’s Playback - ///Provide a `context_uri` to start playback or a album, - ///artist, or playlist. + /// [start a users playback](https://developer.spotify.com/web-api/start-a-users-playback/) + /// Start/Resume a User’s Playback + /// Provide a `context_uri` to start playback or a album, + /// artist, or playlist. /// - ///Provide a `uris` list to start playback of one or more - ///tracks. + /// Provide a `uris` list to start playback of one or more + /// tracks. /// - ///Provide `offset` as {"position": } or {"uri": ""} - ///to start playback at a particular offset. + /// Provide `offset` as {"position": } or {"uri": ""} + /// to start playback at a particular offset. /// - ///Parameters: - ///- device_id - device target for playback - ///- context_uri - spotify context uri to play - ///- uris - spotify track uris - ///- offset - offset into context by index or track - ///- position_ms - Indicates from what position to start playback. + /// Parameters: + /// - device_id - device target for playback + /// - context_uri - spotify context uri to play + /// - uris - spotify track uris + /// - offset - offset into context by index or track + /// - position_ms - Indicates from what position to start playback. pub fn start_playback( &self, device_id: Option, @@ -1659,10 +1658,10 @@ impl Spotify { } } - ///[pause a users playback](https://developer.spotify.com/web-api/pause-a-users-playback/) - ///Pause a User’s Playback - ///Parameters: - ///- device_id - device target for playback + /// [pause a users playback](https://developer.spotify.com/web-api/pause-a-users-playback/) + /// Pause a User’s Playback + /// Parameters: + /// - device_id - device target for playback pub fn pause_playback(&self, device_id: Option) -> Result<(), failure::Error> { let url = self.append_device_id("me/player/pause", device_id); match self.put(&url, &json!({})) { @@ -1671,10 +1670,10 @@ impl Spotify { } } - ///[skip users playback to the next track](https://developer.spotify.com/web-api/skip-users-playback-to-next-track/) - ///Skip User’s Playback To Next Track - /// Parameters: - /// - device_id - device target for playback + /// [skip users playback to the next track](https://developer.spotify.com/web-api/skip-users-playback-to-next-track/) + /// Skip User’s Playback To Next Track + /// Parameters: + /// - device_id - device target for playback pub fn next_track(&self, device_id: Option) -> Result<(), failure::Error> { let url = self.append_device_id("me/player/next", device_id); match self.post(&url, &json!({})) { @@ -1685,7 +1684,7 @@ impl Spotify { ///[skip users playback to previous track](https://developer.spotify.com/web-api/skip-users-playback-to-previous-track/) ///Skip User’s Playback To Previous Track - /// Parameters: + /// Parameters: /// - device_id - device target for playback pub fn previous_track(&self, device_id: Option) -> Result<(), failure::Error> { let url = self.append_device_id("me/player/previous", device_id); @@ -1695,11 +1694,11 @@ impl Spotify { } } - ///[seek-to-position-in-currently-playing-track/](https://developer.spotify.com/web-api/seek-to-position-in-currently-playing-track/) - ///Seek To Position In Currently Playing Track - /// Parameters: - /// - position_ms - position in milliseconds to seek to - /// - device_id - device target for playback + /// [seek-to-position-in-currently-playing-track/](https://developer.spotify.com/web-api/seek-to-position-in-currently-playing-track/) + /// Seek To Position In Currently Playing Track + /// Parameters: + /// - position_ms - position in milliseconds to seek to + /// - device_id - device target for playback pub fn seek_track( &self, position_ms: u32, @@ -1715,11 +1714,11 @@ impl Spotify { } } - ///[set repeat mode on users playback](https://developer.spotify.com/web-api/set-repeat-mode-on-users-playback/) - ///Set Repeat Mode On User’s Playback - /// Parameters: - /// - state - `track`, `context`, or `off` - /// - device_id - device target for playback + /// [set repeat mode on users playback](https://developer.spotify.com/web-api/set-repeat-mode-on-users-playback/) + /// Set Repeat Mode On User’s Playback + /// Parameters: + /// - state - `track`, `context`, or `off` + /// - device_id - device target for playback pub fn repeat( &self, state: RepeatState, @@ -1735,11 +1734,11 @@ impl Spotify { } } - ///[set-volume-for-users-playback](https://developer.spotify.com/web-api/set-volume-for-users-playback/) - ///Set Volume For User’s Playback - /// Parameters: - ///- volume_percent - volume between 0 and 100 - ///- device_id - device target for playback + /// [set-volume-for-users-playback](https://developer.spotify.com/web-api/set-volume-for-users-playback/) + /// Set Volume For User’s Playback + /// Parameters: + /// - volume_percent - volume between 0 and 100 + /// - device_id - device target for playback pub fn volume( &self, volume_percent: u8, @@ -1758,11 +1757,11 @@ impl Spotify { } } - ///[toggle shuffle for user playback](https://developer.spotify.com/web-api/toggle-shuffle-for-users-playback/) - ///Toggle Shuffle For User’s Playback - /// Parameters: - /// - state - true or false - /// - device_id - device target for playback + /// [toggle shuffle for user playback](https://developer.spotify.com/web-api/toggle-shuffle-for-users-playback/) + /// Toggle Shuffle For User’s Playback + /// Parameters: + /// - state - true or false + /// - device_id - device target for playback pub fn shuffle(&self, state: bool, device_id: Option) -> Result<(), failure::Error> { let url = self.append_device_id(&format!("me/player/shuffle?state={}", state), device_id); match self.put(&url, &json!({})) { @@ -1771,12 +1770,12 @@ impl Spotify { } } - ///[Add an item to the end fo the user's current playback queue](https://developer.spotify.com/console/post-queue/) + /// [Add an item to the end fo the user's current playback queue](https://developer.spotify.com/console/post-queue/) /// Add and item to the end of the user's playback queue - /// Parameters: + /// Parameters: /// - uri - THe uri of the item to add, Track or Episode /// - device id - The id of the device targeting - /// - If no device ID provided the user's currently active device is targeted + /// - If no device ID provided the user's currently active device is targeted pub fn add_item_to_queue( &self, item: String, @@ -1983,7 +1982,7 @@ impl Spotify { } } - ///Append device ID to API path. + /// Append device ID to API path. fn append_device_id(&self, path: &str, device_id: Option) -> String { let mut new_path = path.to_string(); if let Some(_device_id) = device_id { @@ -2003,7 +2002,7 @@ impl Spotify { uri.push_str(&self.get_id(_type, _id)); uri } - /// get spotify id by type and id + /// Get spotify id by type and id fn get_id(&self, _type: Type, id: &str) -> String { let mut _id = id.to_owned(); let fields: Vec<&str> = _id.split(':').collect(); @@ -2043,26 +2042,26 @@ mod tests { use super::*; #[test] fn test_get_id() { - // assert artist + // Assert artist let spotify = Spotify::default().access_token("test-access").build(); let mut artist_id = String::from("spotify:artist:2WX2uTcsvV5OnS0inACecP"); let id = spotify.get_id(Type::Artist, &mut artist_id); assert_eq!("2WX2uTcsvV5OnS0inACecP", &id); - // assert album + // Assert album let mut artist_id_a = String::from("spotify/album/2WX2uTcsvV5OnS0inACecP"); assert_eq!( "2WX2uTcsvV5OnS0inACecP", &spotify.get_id(Type::Album, &mut artist_id_a) ); - // mismatch type + // Mismatch type let mut artist_id_b = String::from("spotify:album:2WX2uTcsvV5OnS0inACecP"); assert_eq!( "spotify:album:2WX2uTcsvV5OnS0inACecP", &spotify.get_id(Type::Artist, &mut artist_id_b) ); - // could not split + // Could not split let mut artist_id_c = String::from("spotify-album-2WX2uTcsvV5OnS0inACecP"); assert_eq!( "spotify-album-2WX2uTcsvV5OnS0inACecP", diff --git a/src/blocking/oauth2.rs b/src/blocking/oauth2.rs index 62fc0a13..d56898ff 100644 --- a/src/blocking/oauth2.rs +++ b/src/blocking/oauth2.rs @@ -6,7 +6,7 @@ use percent_encoding::{utf8_percent_encode, PATH_SEGMENT_ENCODE_SET}; use reqwest::blocking::Client; use serde_json; -// use built-in library +// Use built-in library use std::collections::{HashMap, HashSet}; use std::env; use std::fs::File; @@ -15,7 +15,7 @@ use std::io::prelude::*; use std::iter::FromIterator; use std::path::{Path, PathBuf}; -// use customized library +// Use customized library use super::util::{convert_map_to_string, datetime_to_timestamp, generate_random_string}; /// Client credentials object for spotify @@ -91,7 +91,7 @@ impl TokenInfo { } impl SpotifyClientCredentials { - /// build default SpotifyClientCredentials + /// Build default SpotifyClientCredentials pub fn default() -> SpotifyClientCredentials { dotenv().ok(); let client_id = env::var("CLIENT_ID").unwrap_or_default(); @@ -140,7 +140,7 @@ impl SpotifyClientCredentials { } self } - /// get access token from self.token_info, if self.token_info is none or is + /// Get access token from self.token_info, if self.token_info is none or is /// expired. fetch token info by HTTP request pub fn get_access_token(&self) -> String { let access_token = match self.token_info { @@ -192,7 +192,7 @@ impl SpotifyClientCredentials { } impl SpotifyOAuth { - // spotify token example: + // Spotify token example: // { // "access_token": "NgCXRK...MzYjw", // "token_type": "Bearer", @@ -302,7 +302,7 @@ impl SpotifyOAuth { } } } - /// gets the access_token for the app with given the code without caching token. + /// Gets the access_token for the app with given the code without caching token. pub fn get_access_token_without_cache(&self, code: &str) -> Option { let mut payload: HashMap<&str, &str> = HashMap::new(); @@ -313,7 +313,7 @@ impl SpotifyOAuth { payload.insert("state", &self.state); return self.fetch_access_token(&self.client_id, &self.client_secret, &payload); } - /// gets the access_token for the app with given the code + /// Gets the access_token for the app with given the code pub fn get_access_token(&self, code: &str) -> Option { if let Some(token_info) = self.get_access_token_without_cache(code) { match serde_json::to_string(&token_info) { @@ -333,7 +333,7 @@ impl SpotifyOAuth { None } } - /// fetch access_token + /// Fetch access_token fn fetch_access_token( &self, client_id: &str, @@ -376,7 +376,7 @@ impl SpotifyOAuth { authorize_url } - /// refresh token without caching token. + /// Refresh token without caching token. pub fn refresh_access_token_without_cache(&self, refresh_token: &str) -> Option { let mut payload = HashMap::new(); payload.insert("refresh_token", refresh_token); @@ -384,7 +384,7 @@ impl SpotifyOAuth { return self.fetch_access_token(&self.client_id, &self.client_secret, &payload); } - /// after refresh access_token, the response may be empty + /// After refresh access_token, the response may be empty /// when refresh_token again pub fn refresh_access_token(&self, refresh_token: &str) -> Option { if let Some(token_info) = self.refresh_access_token_without_cache(refresh_token) { diff --git a/src/blocking/util.rs b/src/blocking/util.rs index 1c9e650e..3179890c 100644 --- a/src/blocking/util.rs +++ b/src/blocking/util.rs @@ -1,4 +1,4 @@ -//! utils function +//! Utils function use chrono::prelude::*; use rand::distributions::Alphanumeric; use rand::{self, Rng}; @@ -12,12 +12,12 @@ use std::string::ToString; use super::oauth2::{SpotifyOAuth, TokenInfo}; -/// convert datetime to unix timestampe +/// Convert datetime to unix timestampe pub fn datetime_to_timestamp(elapsed: u32) -> i64 { let utc: DateTime = Utc::now(); utc.timestamp() + i64::from(elapsed) } -/// generate `length` random chars +/// Generate `length` random chars pub fn generate_random_string(length: usize) -> String { rand::thread_rng() .sample_iter(&Alphanumeric) @@ -25,7 +25,7 @@ pub fn generate_random_string(length: usize) -> String { .collect() } -/// convert map to `query_string`, for example: +/// Convert map to `query_string`, for example: /// convert /// `{"redirect_uri":"my_uri", /// "state":"my-state" @@ -51,7 +51,7 @@ pub fn convert_map_to_string< string } -/// convert query string to map, for example: +/// Convert query string to map, for example: /// convert /// `redirect_uri=my_uri&state=my-state&scope=test-scope` /// to @@ -97,7 +97,7 @@ pub fn process_token_without_cache( } } -/// get tokenInfo by Authorization +/// Get tokenInfo by Authorization pub fn get_token(spotify_oauth: &mut SpotifyOAuth) -> Option { match spotify_oauth.get_cached_token() { Some(token_info) => Some(token_info), @@ -113,7 +113,7 @@ pub fn get_token(spotify_oauth: &mut SpotifyOAuth) -> Option { } } -/// get tokenInfo by Authorization without cache. +/// Get tokenInfo by Authorization without cache. pub fn get_token_without_cache(spotify_oauth: &mut SpotifyOAuth) -> Option { request_token(spotify_oauth); println!("Enter the URL you were redirected to: "); @@ -124,7 +124,7 @@ pub fn get_token_without_cache(spotify_oauth: &mut SpotifyOAuth) -> Option Option { spotify_oauth.get_access_token(&code) } @@ -151,7 +151,7 @@ mod tests { map.insert("state", "my-state"); map.insert("scope", "test-scope"); let result = convert_map_to_string(&map); - // hashmap is not sorted, so the order of key-value-pairs will not + // Hashmap is not sorted, so the order of key-value-pairs will not // follow the insert order assert!(result.contains("redirect_uri=my_uri&")); assert!(result.contains("state=my-state&")); diff --git a/src/client.rs b/src/client.rs index 4fee4d6e..4338aa33 100644 --- a/src/client.rs +++ b/src/client.rs @@ -9,7 +9,7 @@ use serde::de::Deserialize; use serde_json::map::Map; use serde_json::Value; -// built-in battery +// Built-in battery use std::borrow::Cow; use std::collections::HashMap; use std::fmt; @@ -209,7 +209,7 @@ impl Spotify { )) } } - ///send get request + /// Send get request async fn get( &self, url: &str, @@ -227,11 +227,11 @@ impl Spotify { } } - ///send post request + /// Send post request async fn post(&self, url: &str, payload: &Value) -> Result { self.internal_call(Method::POST, url, Some(payload)).await } - ///send put request + /// Send put request async fn put(&self, url: &str, payload: &Value) -> Result { self.internal_call(Method::PUT, url, Some(payload)).await } @@ -240,10 +240,10 @@ impl Spotify { self.internal_call(Method::DELETE, url, Some(payload)).await } - ///[get-track](https://developer.spotify.com/web-api/get-track/) - ///returns a single track given the track's ID, URI or URL - ///Parameters: - ///- track_id - a spotify URI, URL or ID + /// [get-track](https://developer.spotify.com/web-api/get-track/) + /// returns a single track given the track's ID, URI or URL + /// Parameters: + /// - track_id - a spotify URI, URL or ID pub async fn track(&self, track_id: &str) -> Result { let trid = self.get_id(Type::Track, track_id); let url = format!("tracks/{}", trid); @@ -251,11 +251,11 @@ impl Spotify { self.convert_result::(&result) } - ///[get-several-tracks](https://developer.spotify.com/web-api/get-several-tracks/) - ///returns a list of tracks given a list of track IDs, URIs, or URLs - ///Parameters: - ///- track_ids - a list of spotify URIs, URLs or IDs - ///- market - an ISO 3166-1 alpha-2 country code. + /// [get-several-tracks](https://developer.spotify.com/web-api/get-several-tracks/) + /// returns a list of tracks given a list of track IDs, URIs, or URLs + /// Parameters: + /// - track_ids - a list of spotify URIs, URLs or IDs + /// - market - an ISO 3166-1 alpha-2 country code. pub async fn tracks( &self, track_ids: Vec<&str>, @@ -275,10 +275,10 @@ impl Spotify { self.convert_result::(&result) } - ///[get-artist](https://developer.spotify.com/web-api/get-artist/) - ///returns a single artist given the artist's ID, URI or URL - ///Parameters: - ///- artist_id - an artist ID, URI or URL + /// [get-artist](https://developer.spotify.com/web-api/get-artist/) + /// returns a single artist given the artist's ID, URI or URL + /// Parameters: + /// - artist_id - an artist ID, URI or URL pub async fn artist(&self, artist_id: &str) -> Result { let trid = self.get_id(Type::Artist, artist_id); let url = format!("artists/{}", trid); @@ -286,10 +286,10 @@ impl Spotify { self.convert_result::(&result) } - ///[get-several-artists](https://developer.spotify.com/web-api/get-several-artists/) - ///returns a list of artists given the artist IDs, URIs, or URLs - ///Parameters: - ///- artist_ids - a list of artist IDs, URIs or URLs + /// [get-several-artists](https://developer.spotify.com/web-api/get-several-artists/) + /// returns a list of artists given the artist IDs, URIs, or URLs + /// Parameters: + /// - artist_ids - a list of artist IDs, URIs or URLs pub async fn artists(&self, artist_ids: Vec) -> Result { let mut ids: Vec = vec![]; for artist_id in artist_ids { @@ -300,8 +300,8 @@ impl Spotify { self.convert_result::(&result) } - ///[get-artists-albums](https://developer.spotify.com/web-api/get-artists-albums/) - /// Get Spotify catalog information about an artist's albums + /// [get-artists-albums](https://developer.spotify.com/web-api/get-artists-albums/) + /// Get Spotify catalog information about an artist's albums /// - artist_id - the artist ID, URI or URL /// - album_type - 'album', 'single', 'appears_on', 'compilation' /// - country - limit the response to one particular country. @@ -334,9 +334,9 @@ impl Spotify { self.convert_result::>(&result) } - ///[get artists to tracks](https://developer.spotify.com/web-api/get-artists-top-tracks/) + /// [get artists to tracks](https://developer.spotify.com/web-api/get-artists-top-tracks/) /// Get Spotify catalog information about an artist's top 10 tracks by country. - /// Parameters: + /// Parameters: /// - artist_id - the artist ID, URI or URL /// - country - limit the response to one particular country. pub async fn artist_top_tracks>>( @@ -358,12 +358,12 @@ impl Spotify { self.convert_result::(&result) } - ///[get related artists](https://developer.spotify.com/web-api/get-related-artists/) - ///Get Spotify catalog information about artists similar to an - ///identified artist. Similarity is based on analysis of the - ///Spotify community's listening history. - ///Parameters: - ///- artist_id - the artist ID, URI or URL + /// [get related artists](https://developer.spotify.com/web-api/get-related-artists/) + /// Get Spotify catalog information about artists similar to an + /// identified artist. Similarity is based on analysis of the + /// Spotify community's listening history. + /// Parameters: + /// - artist_id - the artist ID, URI or URL pub async fn artist_related_artists( &self, artist_id: &str, @@ -374,10 +374,10 @@ impl Spotify { self.convert_result::(&result) } - ///[get album](https://developer.spotify.com/web-api/get-album/) - ///returns a single album given the album's ID, URIs or URL - ///Parameters: - ///- album_id - the album ID, URI or URL + /// [get album](https://developer.spotify.com/web-api/get-album/) + /// returns a single album given the album's ID, URIs or URL + /// Parameters: + /// - album_id - the album ID, URI or URL pub async fn album(&self, album_id: &str) -> Result { let trid = self.get_id(Type::Album, album_id); let url = format!("albums/{}", trid); @@ -385,10 +385,10 @@ impl Spotify { self.convert_result::(&result) } - ///[get several albums](https://developer.spotify.com/web-api/get-several-albums/) - ///returns a list of albums given the album IDs, URIs, or URLs - ///Parameters: - ///- albums_ids - a list of album IDs, URIs or URLs + /// [get several albums](https://developer.spotify.com/web-api/get-several-albums/) + /// returns a list of albums given the album IDs, URIs, or URLs + /// Parameters: + /// - albums_ids - a list of album IDs, URIs or URLs pub async fn albums(&self, album_ids: Vec) -> Result { let mut ids: Vec = vec![]; for album_id in album_ids { @@ -399,18 +399,18 @@ impl Spotify { self.convert_result::(&result) } - ///[search for items](https://developer.spotify.com/web-api/search-item/) - ///Search for an Item - ///Get Spotify catalog information about artists, albums, tracks or + /// [search for items](https://developer.spotify.com/web-api/search-item/) + /// Search for an Item + /// Get Spotify catalog information about artists, albums, tracks or /// playlists that match a keyword string. /// Parameters: - ///- q - the search query - ///- limit - the number of items to return - ///- offset - the index of the first item to return - ///- type - the type of item to return. One of 'artist', 'album', 'track', - /// 'playlist', 'show' or 'episode' - ///- market - An ISO 3166-1 alpha-2 country code or the string from_token. - ///- include_external: Optional.Possible values: audio. If include_external=audio is specified the response will include any relevant audio content that is hosted externally. + /// - q - the search query + /// - limit - the number of items to return + /// - offset - the index of the first item to return + /// - type - the type of item to return. One of 'artist', 'album', 'track', + /// 'playlist', 'show' or 'episode' + /// - market - An ISO 3166-1 alpha-2 country code or the string from_token. + /// - include_external: Optional.Possible values: audio. If include_external=audio is specified the response will include any relevant audio content that is hosted externally. pub async fn search>, O: Into>>( &self, q: &str, @@ -441,12 +441,12 @@ impl Spotify { self.convert_result::(&result) } - ///[get albums tracks](https://developer.spotify.com/web-api/get-albums-tracks/) - ///Get Spotify catalog information about an album's tracks - ///Parameters: - ///- album_id - the album ID, URI or URL - ///- limit - the number of items to return - ///- offset - the index of the first item to return + /// [get albums tracks](https://developer.spotify.com/web-api/get-albums-tracks/) + /// Get Spotify catalog information about an album's tracks + /// Parameters: + /// - album_id - the album ID, URI or URL + /// - limit - the number of items to return + /// - offset - the index of the first item to return pub async fn album_track>, O: Into>>( &self, album_id: &str, @@ -472,11 +472,11 @@ impl Spotify { self.convert_result::(&result) } - ///[get playlist](https://developer.spotify.com/documentation/web-api/reference/playlists/get-playlist/) - ///Get full details about Spotify playlist - ///Parameters: - ///- playlist_id - the id of the playlist - ///- market - an ISO 3166-1 alpha-2 country code. + /// [get playlist](https://developer.spotify.com/documentation/web-api/reference/playlists/get-playlist/) + /// Get full details about Spotify playlist + /// Parameters: + /// - playlist_id - the id of the playlist + /// - market - an ISO 3166-1 alpha-2 country code. pub async fn playlist( &self, playlist_id: &str, @@ -497,11 +497,11 @@ impl Spotify { self.convert_result::(&result) } - ///[get users playlists](https://developer.spotify.com/web-api/get-a-list-of-current-users-playlists/) - ///Get current user playlists without required getting his profile - ///Parameters: - ///- limit - the number of items to return - ///- offset - the index of the first item to return + /// [get users playlists](https://developer.spotify.com/web-api/get-a-list-of-current-users-playlists/) + /// Get current user playlists without required getting his profile + /// Parameters: + /// - limit - the number of items to return + /// - offset - the index of the first item to return pub async fn current_user_playlists>, O: Into>>( &self, limit: L, @@ -516,12 +516,12 @@ impl Spotify { self.convert_result::>(&result) } - ///[get list users playlists](https://developer.spotify.com/web-api/get-list-users-playlists/) - ///Gets playlists of a user - ///Parameters: - ///- user_id - the id of the usr - ///- limit - the number of items to return - ///- offset - the index of the first item to return + /// [get list users playlists](https://developer.spotify.com/web-api/get-list-users-playlists/) + /// Gets playlists of a user + /// Parameters: + /// - user_id - the id of the usr + /// - limit - the number of items to return + /// - offset - the index of the first item to return pub async fn user_playlists>, O: Into>>( &self, user_id: &str, @@ -536,12 +536,12 @@ impl Spotify { self.convert_result::>(&result) } - ///[get list users playlists](https://developer.spotify.com/web-api/get-list-users-playlists/) - ///Gets playlist of a user - ///Parameters: - ///- user_id - the id of the user - ///- playlist_id - the id of the playlist - ///- fields - which fields to return + /// [get list users playlists](https://developer.spotify.com/web-api/get-list-users-playlists/) + /// Gets playlist of a user + /// Parameters: + /// - user_id - the id of the user + /// - playlist_id - the id of the playlist + /// - fields - which fields to return pub async fn user_playlist( &self, user_id: &str, @@ -571,15 +571,15 @@ impl Spotify { } } - ///[get playlists tracks](https://developer.spotify.com/web-api/get-playlists-tracks/) - ///Get full details of the tracks of a playlist owned by a user - ///Parameters: - ///- user_id - the id of the user - ///- playlist_id - the id of the playlist - ///- fields - which fields to return - ///- limit - the maximum number of tracks to return - ///- offset - the index of the first track to return - ///- market - an ISO 3166-1 alpha-2 country code. + /// [get playlists tracks](https://developer.spotify.com/web-api/get-playlists-tracks/) + /// Get full details of the tracks of a playlist owned by a user + /// Parameters: + /// - user_id - the id of the user + /// - playlist_id - the id of the playlist + /// - fields - which fields to return + /// - limit - the maximum number of tracks to return + /// - offset - the index of the first track to return + /// - market - an ISO 3166-1 alpha-2 country code. pub async fn user_playlist_tracks>, O: Into>>( &self, user_id: &str, @@ -604,13 +604,13 @@ impl Spotify { self.convert_result::>(&result) } - ///[create playlist](https://developer.spotify.com/web-api/create-playlist/) - ///Creates a playlist for a user - ///Parameters: - ///- user_id - the id of the user - ///- name - the name of the playlist - ///- public - is the created playlist public - ///- description - the description of the playlist + /// [create playlist](https://developer.spotify.com/web-api/create-playlist/) + /// Creates a playlist for a user + /// Parameters: + /// - user_id - the id of the user + /// - name - the name of the playlist + /// - public - is the created playlist public + /// - description - the description of the playlist pub async fn user_playlist_create>, D: Into>>( &self, user_id: &str, @@ -630,15 +630,15 @@ impl Spotify { self.convert_result::(&result) } - ///[change playlists details](https://developer.spotify.com/web-api/change-playlist-details/) - ///Changes a playlist's name and/or public/private state - ///Parameters: - ///- user_id - the id of the user - ///- playlist_id - the id of the playlist - ///- name - optional name of the playlist - ///- public - optional is the playlist public - ///- collaborative - optional is the playlist collaborative - ///- description - optional description of the playlist + /// [change playlists details](https://developer.spotify.com/web-api/change-playlist-details/) + /// Changes a playlist's name and/or public/private state + /// Parameters: + /// - user_id - the id of the user + /// - playlist_id - the id of the playlist + /// - name - optional name of the playlist + /// - public - optional is the playlist public + /// - collaborative - optional is the playlist collaborative + /// - description - optional description of the playlist pub async fn user_playlist_change_detail( &self, user_id: &str, @@ -665,11 +665,11 @@ impl Spotify { self.put(&url, &Value::Object(params)).await } - ///[unfollow playlist](https://developer.spotify.com/web-api/unfollow-playlist/) - ///Unfollows (deletes) a playlist for a user - ///Parameters: - ///- user_id - the id of the user - ///- playlist_id - the id of the playlist + /// [unfollow playlist](https://developer.spotify.com/web-api/unfollow-playlist/) + /// Unfollows (deletes) a playlist for a user + /// Parameters: + /// - user_id - the id of the user + /// - playlist_id - the id of the playlist pub async fn user_playlist_unfollow( &self, user_id: &str, @@ -679,13 +679,13 @@ impl Spotify { self.delete(&url, &json!({})).await } - ///[add tracks to playlist](https://developer.spotify.com/web-api/add-tracks-to-playlist/) - ///Adds tracks to a playlist - ///Parameters: - ///- user_id - the id of the user - ///- playlist_id - the id of the playlist - ///- track_ids - a list of track URIs, URLs or IDs - ///- position - the position to add the tracks + /// [add tracks to playlist](https://developer.spotify.com/web-api/add-tracks-to-playlist/) + /// Adds tracks to a playlist + /// Parameters: + /// - user_id - the id of the user + /// - playlist_id - the id of the playlist + /// - track_ids - a list of track URIs, URLs or IDs + /// - position - the position to add the tracks pub async fn user_playlist_add_tracks( &self, user_id: &str, @@ -713,7 +713,6 @@ impl Spotify { ///- user - the id of the user ///- playlist_id - the id of the playlist ///- tracks - the list of track ids to add to the playlist - pub async fn user_playlist_replace_tracks( &self, user_id: &str, @@ -735,15 +734,15 @@ impl Spotify { } } - ///[reorder playlists tracks](https://developer.spotify.com/web-api/reorder-playlists-tracks/) - ///Reorder tracks in a playlist - ///Parameters: - ///- user_id - the id of the user - ///- playlist_id - the id of the playlist - ///- range_start - the position of the first track to be reordered - ///- range_length - optional the number of tracks to be reordered (default: 1) - ///- insert_before - the position where the tracks should be inserted - ///- snapshot_id - optional playlist's snapshot ID + /// [reorder playlists tracks](https://developer.spotify.com/web-api/reorder-playlists-tracks/) + /// Reorder tracks in a playlist + /// Parameters: + /// - user_id - the id of the user + /// - playlist_id - the id of the playlist + /// - range_start - the position of the first track to be reordered + /// - range_length - optional the number of tracks to be reordered (default: 1) + /// - insert_before - the position where the tracks should be inserted + /// - snapshot_id - optional playlist's snapshot ID pub async fn user_playlist_recorder_tracks>>( &self, user_id: &str, @@ -767,13 +766,13 @@ impl Spotify { self.convert_result::(&result) } - ///[remove tracks playlist](https://developer.spotify.com/web-api/remove-tracks-playlist/) - ///Removes all occurrences of the given tracks from the given playlist - ///Parameters: - ///- user_id - the id of the user - ///- playlist_id - the id of the playlist - ///- track_ids - the list of track ids to add to the playlist - ///- snapshot_id - optional id of the playlist snapshot + /// [remove tracks playlist](https://developer.spotify.com/web-api/remove-tracks-playlist/) + /// Removes all occurrences of the given tracks from the given playlist + /// Parameters: + /// - user_id - the id of the user + /// - playlist_id - the id of the playlist + /// - track_ids - the list of track ids to add to the playlist + /// - snapshot_id - optional id of the playlist snapshot pub async fn user_playlist_remove_all_occurrences_of_tracks( &self, user_id: &str, @@ -802,16 +801,16 @@ impl Spotify { self.convert_result::(&result) } - ///[remove tracks playlist](https://developer.spotify.com/web-api/remove-tracks-playlist/) - ///Removes specfic occurrences of the given tracks from the given playlist - ///Parameters: - ///- user_id - the id of the user - ///- playlist_id - the id of the playlist - ///- tracks - an array of map containing Spotify URIs of the tracks - /// to remove with their current positions in the playlist. For example: - ///{ "tracks": [{ "uri": "spotify:track:4iV5W9uYEdYUVa79Axb7Rh", "positions": [0,3] },{ - ///"uri": "spotify:track:1301WleyT98MSxVHPZCA6M", "positions": [7] }] } - ///- snapshot_id - optional id of the playlist snapshot + /// [remove tracks playlist](https://developer.spotify.com/web-api/remove-tracks-playlist/) + /// Removes specfic occurrences of the given tracks from the given playlist + /// Parameters: + /// - user_id - the id of the user + /// - playlist_id - the id of the playlist + /// - tracks - an array of map containing Spotify URIs of the tracks + /// to remove with their current positions in the playlist. For example: + /// { "tracks": [{ "uri": "spotify:track:4iV5W9uYEdYUVa79Axb7Rh", "positions": [0,3] },{ + /// "uri": "spotify:track:1301WleyT98MSxVHPZCA6M", "positions": [7] }] } + /// - snapshot_id - optional id of the playlist snapshot pub async fn user_playlist_remove_specific_occurrenes_of_tracks( &self, user_id: &str, @@ -842,11 +841,11 @@ impl Spotify { self.convert_result::(&result) } - ///[follow playlist](https://developer.spotify.com/web-api/follow-playlist/) - ///Add the current authenticated user as a follower of a playlist. - ///Parameters: - ///- playlist_owner_id - the user id of the playlist owner - ///- playlist_id - the id of the playlist + /// [follow playlist](https://developer.spotify.com/web-api/follow-playlist/) + /// Add the current authenticated user as a follower of a playlist. + /// Parameters: + /// - playlist_owner_id - the user id of the playlist owner + /// - playlist_id - the id of the playlist pub async fn user_playlist_follow_playlist>>( &self, playlist_owner_id: &str, @@ -866,13 +865,13 @@ impl Spotify { } } - ///[check user following playlist](https://developer.spotify.com/web-api/check-user-following-playlist/) - ///Check to see if the given users are following the given playlist - ///Parameters: - ///- playlist_owner_id - the user id of the playlist owner - ///- playlist_id - the id of the playlist - ///- user_ids - the ids of the users that you want to - ///check to see if they follow the playlist. Maximum: 5 ids. + /// [check user following playlist](https://developer.spotify.com/web-api/check-user-following-playlist/) + /// Check to see if the given users are following the given playlist + /// Parameters: + /// - playlist_owner_id - the user id of the playlist owner + /// - playlist_id - the id of the playlist + /// - user_ids - the ids of the users that you want to + /// check to see if they follow the playlist. Maximum: 5 ids. pub async fn user_playlist_check_follow( &self, playlist_owner_id: &str, @@ -892,23 +891,23 @@ impl Spotify { let result = self.get(&url, &mut dumb).await?; self.convert_result::>(&result) } - ///[get current users profile](https://developer.spotify.com/web-api/get-current-users-profile/) - ///Get detailed profile information about the current user. - ///An alias for the 'current_user' method. + /// [get current users profile](https://developer.spotify.com/web-api/get-current-users-profile/) + /// Get detailed profile information about the current user. + /// An alias for the 'current_user' method. pub async fn me(&self) -> Result { let mut dumb: HashMap = HashMap::new(); let url = String::from("me/"); let result = self.get(&url, &mut dumb).await?; self.convert_result::(&result) } - ///Get detailed profile information about the current user. - ///An alias for the 'me' method. + /// Get detailed profile information about the current user. + /// An alias for the 'me' method. pub async fn current_user(&self) -> Result { self.me().await } - /// [get the users currently playing track](https://developer.spotify.com/web-api/get-the-users-currently-playing-track/) - /// Get information about the current users currently playing track. + /// [get the users currently playing track](https://developer.spotify.com/web-api/get-the-users-currently-playing-track/) + /// Get information about the current users currently playing track. pub async fn current_user_playing_track(&self) -> Result, failure::Error> { let mut dumb = HashMap::new(); let url = String::from("me/player/currently-playing"); @@ -924,13 +923,13 @@ impl Spotify { } } - ///[get user saved albums](https://developer.spotify.com/web-api/get-users-saved-albums/) - ///Gets a list of the albums saved in the current authorized user's - ///"Your Music" library - ///Parameters: - ///- limit - the number of albums to return - ///- offset - the index of the first album to return - ///- market - Provide this parameter if you want to apply Track Relinking. + /// [get user saved albums](https://developer.spotify.com/web-api/get-users-saved-albums/) + /// Gets a list of the albums saved in the current authorized user's + /// "Your Music" library + /// Parameters: + /// - limit - the number of albums to return + /// - offset - the index of the first album to return + /// - market - Provide this parameter if you want to apply Track Relinking. pub async fn current_user_saved_albums>, O: Into>>( &self, limit: L, @@ -986,11 +985,11 @@ impl Spotify { self.convert_result::(&result) } - ///[remove tracks users](https://developer.spotify.com/web-api/remove-tracks-user/) - ///Remove one or more tracks from the current user's - ///"Your Music" library. - ///Parameters: - ///- track_ids - a list of track URIs, URLs or IDs + /// [remove tracks users](https://developer.spotify.com/web-api/remove-tracks-user/) + /// Remove one or more tracks from the current user's + /// "Your Music" library. + /// Parameters: + /// - track_ids - a list of track URIs, URLs or IDs pub async fn current_user_saved_tracks_delete( &self, track_ids: &[String], @@ -1006,11 +1005,11 @@ impl Spotify { } } - ///[check users saved tracks](https://developer.spotify.com/web-api/check-users-saved-tracks/) - ///Check if one or more tracks is already saved in - ///the current Spotify user’s “Your Music” library. - ///Parameters: - ///- track_ids - a list of track URIs, URLs or IDs + /// [check users saved tracks](https://developer.spotify.com/web-api/check-users-saved-tracks/) + /// Check if one or more tracks is already saved in + /// the current Spotify user’s “Your Music” library. + /// Parameters: + /// - track_ids - a list of track URIs, URLs or IDs pub async fn current_user_saved_tracks_contains( &self, track_ids: &[String], @@ -1025,11 +1024,11 @@ impl Spotify { self.convert_result::>(&result) } - ///[save tracks user ](https://developer.spotify.com/web-api/save-tracks-user/) - ///Save one or more tracks to the current user's - ///"Your Music" library. - ///Parameters: - ///- track_ids - a list of track URIs, URLs or IDs + /// [save tracks user ](https://developer.spotify.com/web-api/save-tracks-user/) + /// Save one or more tracks to the current user's + /// "Your Music" library. + /// Parameters: + /// - track_ids - a list of track URIs, URLs or IDs pub async fn current_user_saved_tracks_add( &self, track_ids: &[String], @@ -1045,12 +1044,12 @@ impl Spotify { } } - ///[get users top artists and tracks](https://developer.spotify.com/web-api/get-users-top-artists-and-tracks/) - ///Get the current user's top artists - ///Parameters: - ///- limit - the number of entities to return - ///- offset - the index of the first entity to return - ///- time_range - Over what time frame are the affinities computed + /// [get users top artists and tracks](https://developer.spotify.com/web-api/get-users-top-artists-and-tracks/) + /// Get the current user's top artists + /// Parameters: + /// - limit - the number of entities to return + /// - offset - the index of the first entity to return + /// - time_range - Over what time frame are the affinities computed pub async fn current_user_top_artists< L: Into>, O: Into>, @@ -1073,12 +1072,12 @@ impl Spotify { self.convert_result::>(&result) } - ///[get users top artists and tracks](https://developer.spotify.com/web-api/get-users-top-artists-and-tracks/) - ///Get the current user's top tracks - ///Parameters: - ///- limit - the number of entities to return - ///- offset - the index of the first entity to return - ///- time_range - Over what time frame are the affinities computed + /// [get users top artists and tracks](https://developer.spotify.com/web-api/get-users-top-artists-and-tracks/) + /// Get the current user's top tracks + /// Parameters: + /// - limit - the number of entities to return + /// - offset - the index of the first entity to return + /// - time_range - Over what time frame are the affinities computed pub async fn current_user_top_tracks< L: Into>, O: Into>, @@ -1101,10 +1100,10 @@ impl Spotify { self.convert_result::>(&result) } - ///[get recently played](https://developer.spotify.com/web-api/web-api-personalization-endpoints/get-recently-played/) - ///Get the current user's recently played tracks - ///Parameters: - ///- limit - the number of entities to return + /// [get recently played](https://developer.spotify.com/web-api/web-api-personalization-endpoints/get-recently-played/) + /// Get the current user's recently played tracks + /// Parameters: + /// - limit - the number of entities to return pub async fn current_user_recently_played>>( &self, limit: L, @@ -1117,11 +1116,11 @@ impl Spotify { self.convert_result::>(&result) } - ///[save albums user](https://developer.spotify.com/web-api/save-albums-user/) - ///Add one or more albums to the current user's - ///"Your Music" library. - ///Parameters: - ///- album_ids - a list of album URIs, URLs or IDs + /// [save albums user](https://developer.spotify.com/web-api/save-albums-user/) + /// Add one or more albums to the current user's + /// "Your Music" library. + /// Parameters: + /// - album_ids - a list of album URIs, URLs or IDs pub async fn current_user_saved_albums_add( &self, album_ids: &[String], @@ -1137,11 +1136,11 @@ impl Spotify { } } - ///[remove albums user](https://developer.spotify.com/documentation/web-api/reference/library/remove-albums-user/) - ///Remove one or more albums from the current user's - ///"Your Music" library. - ///Parameters: - ///- album_ids - a list of album URIs, URLs or IDs + /// [remove albums user](https://developer.spotify.com/documentation/web-api/reference/library/remove-albums-user/) + /// Remove one or more albums from the current user's + /// "Your Music" library. + /// Parameters: + /// - album_ids - a list of album URIs, URLs or IDs pub async fn current_user_saved_albums_delete( &self, album_ids: &[String], @@ -1157,11 +1156,11 @@ impl Spotify { } } - ///[check users saved albums](https://developer.spotify.com/documentation/web-api/reference/library/check-users-saved-albums/) - ///Check if one or more albums is already saved in - ///the current Spotify user’s “Your Music” library. - ///Parameters: - ///- album_ids - a list of album URIs, URLs or IDs + /// [check users saved albums](https://developer.spotify.com/documentation/web-api/reference/library/check-users-saved-albums/) + /// Check if one or more albums is already saved in + /// the current Spotify user’s “Your Music” library. + /// Parameters: + /// - album_ids - a list of album URIs, URLs or IDs pub async fn current_user_saved_albums_contains( &self, album_ids: &[String], @@ -1176,10 +1175,10 @@ impl Spotify { self.convert_result::>(&result) } - ///[follow artists users](https://developer.spotify.com/web-api/follow-artists-users/) - ///Follow one or more artists - ///Parameters: - ///- artist_ids - a list of artist IDs + /// [follow artists users](https://developer.spotify.com/web-api/follow-artists-users/) + /// Follow one or more artists + /// Parameters: + /// - artist_ids - a list of artist IDs pub async fn user_follow_artists(&self, artist_ids: &[String]) -> Result<(), failure::Error> { let url = format!("me/following?type=artist&ids={}", artist_ids.join(",")); match self.put(&url, &json!({})).await { @@ -1188,10 +1187,10 @@ impl Spotify { } } - ///[unfollow artists users](https://developer.spotify.com/documentation/web-api/reference/follow/unfollow-artists-users/) - ///Unfollow one or more artists - ///Parameters: - ///- artist_ids - a list of artist IDs + /// [unfollow artists users](https://developer.spotify.com/documentation/web-api/reference/follow/unfollow-artists-users/) + /// Unfollow one or more artists + /// Parameters: + /// - artist_ids - a list of artist IDs pub async fn user_unfollow_artists(&self, artist_ids: &[String]) -> Result<(), failure::Error> { let url = format!("me/following?type=artist&ids={}", artist_ids.join(",")); match self.delete(&url, &json!({})).await { @@ -1200,11 +1199,11 @@ impl Spotify { } } - ///[check user following - ///artists](https://developer.spotify.com/web-api/checkcurrent-user-follows/) - ///Check to see if the given users are following the given artists - ///Parameters: - ///- artist_ids - the ids of the users that you want to + /// [check user following + /// artists](https://developer.spotify.com/web-api/checkcurrent-user-follows/) + /// Check to see if the given users are following the given artists + /// Parameters: + /// - artist_ids - the ids of the users that you want to pub async fn user_artist_check_follow( &self, artsit_ids: &[String], @@ -1218,10 +1217,10 @@ impl Spotify { self.convert_result::>(&result) } - ///[follow artists users](https://developer.spotify.com/web-api/follow-artists-users/) - ///Follow one or more users - ///Parameters: - ///- user_ids - a list of artist IDs + /// [follow artists users](https://developer.spotify.com/web-api/follow-artists-users/) + /// Follow one or more users + /// Parameters: + /// - user_ids - a list of artist IDs pub async fn user_follow_users(&self, user_ids: &[String]) -> Result<(), failure::Error> { let url = format!("me/following?type=user&ids={}", user_ids.join(",")); match self.put(&url, &json!({})).await { @@ -1230,10 +1229,10 @@ impl Spotify { } } - ///[unfollow artists users](https://developer.spotify.com/documentation/web-api/reference/follow/unfollow-artists-users/) - ///Unfollow one or more users - ///Parameters: - ///- user_ids - a list of artist IDs + /// [unfollow artists users](https://developer.spotify.com/documentation/web-api/reference/follow/unfollow-artists-users/) + /// Unfollow one or more users + /// Parameters: + /// - user_ids - a list of artist IDs pub async fn user_unfollow_users(&self, user_ids: &[String]) -> Result<(), failure::Error> { let url = format!("me/following?type=user&ids={}", user_ids.join(",")); match self.delete(&url, &json!({})).await { @@ -1242,22 +1241,22 @@ impl Spotify { } } - ///[get list featured playlists](https://developer.spotify.com/web-api/get-list-featured-playlists/) - ///Get a list of Spotify featured playlists - ///Parameters: - ///- locale - The desired language, consisting of a lowercase ISO - ///639 language code and an uppercase ISO 3166-1 alpha-2 country - ///code, joined by an underscore. - ///- country - An ISO 3166-1 alpha-2 country code. - ///- timestamp - A timestamp in ISO 8601 format: - ///yyyy-MM-ddTHH:mm:ss. Use this parameter to specify the user's - ///local time to get results tailored for that specific date and - ///time in the day - ///- limit - The maximum number of items to return. Default: 20. - ///Minimum: 1. Maximum: 50 - ///- offset - The index of the first item to return. Default: 0 - ///(the first object). Use with limit to get the next set of - ///items. + /// [get list featured playlists](https://developer.spotify.com/web-api/get-list-featured-playlists/) + /// Get a list of Spotify featured playlists + /// Parameters: + /// - locale - The desired language, consisting of a lowercase ISO + /// 639 language code and an uppercase ISO 3166-1 alpha-2 country + /// code, joined by an underscore. + /// - country - An ISO 3166-1 alpha-2 country code. + /// - timestamp - A timestamp in ISO 8601 format: + /// yyyy-MM-ddTHH:mm:ss. Use this parameter to specify the user's + /// local time to get results tailored for that specific date and + /// time in the day + /// - limit - The maximum number of items to return. Default: 20. + /// Minimum: 1. Maximum: 50 + /// - offset - The index of the first item to return. Default: 0 + /// (the first object). Use with limit to get the next set of + /// items. pub async fn featured_playlists>, O: Into>>( &self, locale: Option, @@ -1285,15 +1284,15 @@ impl Spotify { self.convert_result::(&result) } - ///[get list new releases](https://developer.spotify.com/web-api/get-list-new-releases/) - ///Get a list of new album releases featured in Spotify - ///Parameters: - ///- country - An ISO 3166-1 alpha-2 country code. - ///- limit - The maximum number of items to return. Default: 20. - ///Minimum: 1. Maximum: 50 - ///- offset - The index of the first item to return. Default: 0 - ///(the first object). Use with limit to get the next set of - ///items. + /// [get list new releases](https://developer.spotify.com/web-api/get-list-new-releases/) + /// Get a list of new album releases featured in Spotify + /// Parameters: + /// - country - An ISO 3166-1 alpha-2 country code. + /// - limit - The maximum number of items to return. Default: 20. + /// Minimum: 1. Maximum: 50 + /// - offset - The index of the first item to return. Default: 0 + /// (the first object). Use with limit to get the next set of + /// items. pub async fn new_releases>, O: Into>>( &self, country: Option, @@ -1313,18 +1312,18 @@ impl Spotify { self.convert_result::(&result) } - ///[get list categories](https://developer.spotify.com/web-api/get-list-categories/) - ///Get a list of new album releases featured in Spotify - ///Parameters: - ///- country - An ISO 3166-1 alpha-2 country code. - ///- locale - The desired language, consisting of an ISO 639 - ///language code and an ISO 3166-1 alpha-2 country code, joined - ///by an underscore. - ///- limit - The maximum number of items to return. Default: 20. - ///Minimum: 1. Maximum: 50 - ///- offset - The index of the first item to return. Default: 0 - ///(the first object). Use with limit to get the next set of - ///items. + /// [get list categories](https://developer.spotify.com/web-api/get-list-categories/) + /// Get a list of new album releases featured in Spotify + /// Parameters: + /// - country - An ISO 3166-1 alpha-2 country code. + /// - locale - The desired language, consisting of an ISO 639 + /// language code and an ISO 3166-1 alpha-2 country code, joined + /// by an underscore. + /// - limit - The maximum number of items to return. Default: 20. + /// Minimum: 1. Maximum: 50 + /// - offset - The index of the first item to return. Default: 0 + /// (the first object). Use with limit to get the next set of + /// items. pub async fn categories>, O: Into>>( &self, locale: Option, @@ -1348,9 +1347,9 @@ impl Spotify { self.convert_result::(&result) } - ///[get recommendtions](https://developer.spotify.com/web-api/get-recommendations/) - ///Get Recommendations Based on Seeds - /// Parameters: + /// [get recommendtions](https://developer.spotify.com/web-api/get-recommendations/) + /// Get Recommendations Based on Seeds + /// Parameters: /// - seed_artists - a list of artist IDs, URIs or URLs /// - seed_tracks - a list of artist IDs, URIs or URLs /// - seed_genres - a list of genre names. Available genres for @@ -1430,9 +1429,9 @@ impl Spotify { let result = self.get(&url, &mut params).await?; self.convert_result::(&result) } - ///[get audio features](https://developer.spotify.com/web-api/get-audio-features/) - ///Get audio features for a track - ///- track - track URI, URL or ID + /// [get audio features](https://developer.spotify.com/web-api/get-audio-features/) + /// Get audio features for a track + /// - track - track URI, URL or ID pub async fn audio_features(&self, track: &str) -> Result { let track_id = self.get_id(Type::Track, track); let url = format!("audio-features/{}", track_id); @@ -1441,9 +1440,9 @@ impl Spotify { self.convert_result::(&result) } - ///[get several audio features](https://developer.spotify.com/web-api/get-several-audio-features/) - ///Get Audio Features for Several Tracks - /// -tracks a list of track URIs, URLs or IDs + /// [get several audio features](https://developer.spotify.com/web-api/get-several-audio-features/) + /// Get Audio Features for Several Tracks + /// - tracks a list of track URIs, URLs or IDs pub async fn audios_features( &self, tracks: &[String], @@ -1466,10 +1465,10 @@ impl Spotify { } } - ///[get audio analysis](https://developer.spotify.com/web-api/get-audio-analysis/) - ///Get Audio Analysis for a Track - ///Parameters: - ///- track_id - a track URI, URL or ID + /// [get audio analysis](https://developer.spotify.com/web-api/get-audio-analysis/) + /// Get Audio Analysis for a Track + /// Parameters: + /// - track_id - a track URI, URL or ID pub async fn audio_analysis(&self, track: &str) -> Result { let trid = self.get_id(Type::Track, track); let url = format!("audio-analysis/{}", trid); @@ -1478,8 +1477,8 @@ impl Spotify { self.convert_result::(&result) } - ///[get a users available devices](https://developer.spotify.com/web-api/get-a-users-available-devices/) - ///Get a User’s Available Devices + /// [get a users available devices](https://developer.spotify.com/web-api/get-a-users-available-devices/) + /// Get a User’s Available Devices pub async fn device(&self) -> Result { let url = String::from("me/player/devices"); let mut dumb = HashMap::new(); @@ -1487,8 +1486,8 @@ impl Spotify { self.convert_result::(&result) } - ///[get informatation about the users current playback](https://developer.spotify.com/web-api/get-information-about-the-users-current-playback/) - ///Get Information About The User’s Current Playback + /// [get informatation about the users current playback](https://developer.spotify.com/web-api/get-information-about-the-users-current-playback/) + /// Get Information About The User’s Current Playback /// Parameters: /// - market: Optional. an ISO 3166-1 alpha-2 country code. /// - additional_types: Optional. A comma-separated list of item types that your client supports besides the default track type. Valid types are: `track` and `episode`. @@ -1524,7 +1523,7 @@ impl Spotify { } } - ///[get the users currently playing track](https://developer.spotify.com/web-api/get-the-users-currently-playing-track/) + /// [get the users currently playing track](https://developer.spotify.com/web-api/get-the-users-currently-playing-track/) /// Get the User’s Currently Playing Track /// Parameters: /// - market: Optional. an ISO 3166-1 alpha-2 country code. @@ -1560,14 +1559,14 @@ impl Spotify { Err(e) => Err(e), } } - ///[transfer a users playback](https://developer.spotify.com/web-api/transfer-a-users-playback/) - ///Transfer a User’s Playback - ///Note: Although an array is accepted, only a single device_id is currently + /// [transfer a users playback](https://developer.spotify.com/web-api/transfer-a-users-playback/) + /// Transfer a User’s Playback + /// Note: Although an array is accepted, only a single device_id is currently /// supported. Supplying more than one will return 400 Bad Request - /// Parameters: - ///- device_id - transfer playback to this device - ///- force_play - true: after transfer, play. false: - ///keep current state. + /// Parameters: + /// - device_id - transfer playback to this device + /// - force_play - true: after transfer, play. false: + /// keep current state. pub async fn transfer_playback>>( &self, device_id: &str, @@ -1585,23 +1584,23 @@ impl Spotify { } } - ///[start a users playback](https://developer.spotify.com/web-api/start-a-users-playback/) - ///Start/Resume a User’s Playback - ///Provide a `context_uri` to start playback or a album, - ///artist, or playlist. + /// [start a users playback](https://developer.spotify.com/web-api/start-a-users-playback/) + /// Start/Resume a User’s Playback + /// Provide a `context_uri` to start playback or a album, + /// artist, or playlist. /// - ///Provide a `uris` list to start playback of one or more - ///tracks. + /// Provide a `uris` list to start playback of one or more + /// tracks. /// - ///Provide `offset` as {"position": } or {"uri": ""} - ///to start playback at a particular offset. + /// Provide `offset` as {"position": } or {"uri": ""} + /// to start playback at a particular offset. /// - ///Parameters: - ///- device_id - device target for playback - ///- context_uri - spotify context uri to play - ///- uris - spotify track uris - ///- offset - offset into context by index or track - ///- position_ms - Indicates from what position to start playback. + /// Parameters: + /// - device_id - device target for playback + /// - context_uri - spotify context uri to play + /// - uris - spotify track uris + /// - offset - offset into context by index or track + /// - position_ms - Indicates from what position to start playback. pub async fn start_playback( &self, device_id: Option, @@ -1641,10 +1640,10 @@ impl Spotify { } } - ///[pause a users playback](https://developer.spotify.com/web-api/pause-a-users-playback/) - ///Pause a User’s Playback - ///Parameters: - ///- device_id - device target for playback + /// [pause a users playback](https://developer.spotify.com/web-api/pause-a-users-playback/) + /// Pause a User’s Playback + /// Parameters: + /// - device_id - device target for playback pub async fn pause_playback(&self, device_id: Option) -> Result<(), failure::Error> { let url = self.append_device_id("me/player/pause", device_id); match self.put(&url, &json!({})).await { @@ -1653,9 +1652,9 @@ impl Spotify { } } - ///[skip users playback to the next track](https://developer.spotify.com/web-api/skip-users-playback-to-next-track/) - ///Skip User’s Playback To Next Track - /// Parameters: + /// [skip users playback to the next track](https://developer.spotify.com/web-api/skip-users-playback-to-next-track/) + /// Skip User’s Playback To Next Track + /// Parameters: /// - device_id - device target for playback pub async fn next_track(&self, device_id: Option) -> Result<(), failure::Error> { let url = self.append_device_id("me/player/next", device_id); @@ -1665,9 +1664,9 @@ impl Spotify { } } - ///[skip users playback to previous track](https://developer.spotify.com/web-api/skip-users-playback-to-previous-track/) - ///Skip User’s Playback To Previous Track - /// Parameters: + /// [skip users playback to previous track](https://developer.spotify.com/web-api/skip-users-playback-to-previous-track/) + /// Skip User’s Playback To Previous Track + /// Parameters: /// - device_id - device target for playback pub async fn previous_track(&self, device_id: Option) -> Result<(), failure::Error> { let url = self.append_device_id("me/player/previous", device_id); @@ -1677,9 +1676,9 @@ impl Spotify { } } - ///[seek-to-position-in-currently-playing-track/](https://developer.spotify.com/web-api/seek-to-position-in-currently-playing-track/) - ///Seek To Position In Currently Playing Track - /// Parameters: + /// [seek-to-position-in-currently-playing-track/](https://developer.spotify.com/web-api/seek-to-position-in-currently-playing-track/) + /// Seek To Position In Currently Playing Track + /// Parameters: /// - position_ms - position in milliseconds to seek to /// - device_id - device target for playback pub async fn seek_track( @@ -1697,11 +1696,11 @@ impl Spotify { } } - ///[set repeat mode on users playback](https://developer.spotify.com/web-api/set-repeat-mode-on-users-playback/) - ///Set Repeat Mode On User’s Playback - /// Parameters: - /// - state - `track`, `context`, or `off` - /// - device_id - device target for playback + /// [set repeat mode on users playback](https://developer.spotify.com/web-api/set-repeat-mode-on-users-playback/) + /// Set Repeat Mode On User’s Playback + /// Parameters: + /// - state - `track`, `context`, or `off` + /// - device_id - device target for playback pub async fn repeat( &self, state: RepeatState, @@ -1717,11 +1716,11 @@ impl Spotify { } } - ///[set-volume-for-users-playback](https://developer.spotify.com/web-api/set-volume-for-users-playback/) - ///Set Volume For User’s Playback - /// Parameters: - ///- volume_percent - volume between 0 and 100 - ///- device_id - device target for playback + /// [set-volume-for-users-playback](https://developer.spotify.com/web-api/set-volume-for-users-playback/) + /// Set Volume For User’s Playback + /// Parameters: + /// - volume_percent - volume between 0 and 100 + /// - device_id - device target for playback pub async fn volume( &self, volume_percent: u8, @@ -1740,9 +1739,9 @@ impl Spotify { } } - ///[toggle shuffle for user playback](https://developer.spotify.com/web-api/toggle-shuffle-for-users-playback/) - ///Toggle Shuffle For User’s Playback - /// Parameters: + /// [toggle shuffle for user playback](https://developer.spotify.com/web-api/toggle-shuffle-for-users-playback/) + /// Toggle Shuffle For User’s Playback + /// Parameters: /// - state - true or false /// - device_id - device target for playback pub async fn shuffle( @@ -1757,12 +1756,12 @@ impl Spotify { } } - ///[Add an item to the end fo the user's current playback queue](https://developer.spotify.com/console/post-queue/) + /// [Add an item to the end fo the user's current playback queue](https://developer.spotify.com/console/post-queue/) /// Add an item to the end of the user's playback queue - /// Parameters: + /// Parameters: /// - uri - THe uri of the item to add, Track or Episode /// - device id - The id of the device targeting - /// - If no device ID provided the user's currently active device is targeted + /// - If no device ID provided the user's currently active device is targeted pub async fn add_item_to_queue( &self, item: String, @@ -1972,7 +1971,7 @@ impl Spotify { Ok(result) } - ///Append device ID to API path. + /// Append device ID to API path. fn append_device_id(&self, path: &str, device_id: Option) -> String { let mut new_path = path.to_string(); if let Some(_device_id) = device_id { @@ -1992,7 +1991,7 @@ impl Spotify { uri.push_str(&self.get_id(_type, _id)); uri } - /// get spotify id by type and id + /// Get spotify id by type and id fn get_id(&self, _type: Type, id: &str) -> String { let mut _id = id.to_owned(); let fields: Vec<&str> = _id.split(':').collect(); @@ -2032,26 +2031,26 @@ mod tests { use super::*; #[test] fn test_get_id() { - // assert artist + // Assert artist let spotify = Spotify::default().access_token("test-access").build(); let mut artist_id = String::from("spotify:artist:2WX2uTcsvV5OnS0inACecP"); let id = spotify.get_id(Type::Artist, &mut artist_id); assert_eq!("2WX2uTcsvV5OnS0inACecP", &id); - // assert album + // Assert album let mut artist_id_a = String::from("spotify/album/2WX2uTcsvV5OnS0inACecP"); assert_eq!( "2WX2uTcsvV5OnS0inACecP", &spotify.get_id(Type::Album, &mut artist_id_a) ); - // mismatch type + // Mismatch type let mut artist_id_b = String::from("spotify:album:2WX2uTcsvV5OnS0inACecP"); assert_eq!( "spotify:album:2WX2uTcsvV5OnS0inACecP", &spotify.get_id(Type::Artist, &mut artist_id_b) ); - // could not split + // Could not split let mut artist_id_c = String::from("spotify-album-2WX2uTcsvV5OnS0inACecP"); assert_eq!( "spotify-album-2WX2uTcsvV5OnS0inACecP", diff --git a/src/lib.rs b/src/lib.rs index ec717770..26180199 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,9 +7,9 @@ //! albums, artists, tracks, playlists, new releases) and user's information (follow //! users, artists and playlists, and saved tracks management). //! ## Features -//! *rspotify* supports all of the features of the Spotify Web API including access -//! to all end points, and support for user authorization, notes that before -//! accessing to any end points, you need to be authorized. For details on the +//! *rspotify* supports all the features of the Spotify Web API including access +//! to all endpoints, and support for user authorization. Note that before +//! accessing to any endpoints, you need to be authorized. For details on the //! capabilities you are encouraged to review the [Spotify Web Endpoint //! Reference](https://developer.spotify.com/web-api/endpoint-reference/) //! documentation @@ -18,20 +18,20 @@ //! ### Authorization //! Since all methods require user authorization now, you will need to //! generate an authorization token that indicates that the user has granted -//! permission for your application to perform the given task. You will need to +//! permission for your application to perform the given task. You will need to //! register your app to get the credentials necessary to make authorized calls. //! //! Even if your script does not have an accessible URL you need to specify one when //! registering your application where the spotify authentication API will redirect //! to after successful login. The URL doesn't need to work or be accessible, you -//! can specify "http://localhost/", after successful login you just need to copy -//! the "http://localhost/?code=..." URL from your browser and paste it to the -//! console where your application is running. +//! can specify "http://localhost/", and after a successful login you just need +//! to copy the "http://localhost/?code=..." URL from your browser and paste it +//! to the console where your application is running. //! //! ## Examples //! If you have a use case you are intertested in, you could check the //! [examples](./examples), which has all kinds of detailed examples. For example, -//! If you want to get recently played history, you could check +//! if you want to get recently played history, you could check //! [current_user_recently_played](https://github.com/samrayleung/rspotify/blob/master/examples/current_user_recently_played.rs). This is //! the example code: //! ``` rust @@ -43,39 +43,39 @@ //! //! #[tokio::main] //! async fn main() { -//! // Set client_id and client_secret in .env file or -//! // export CLIENT_ID="your client_id" -//! // export CLIENT_SECRET="secret" -//! // export REDIRECT_URI=your-direct-uri +//! // Set client_id and client_secret in .env file or +//! // export CLIENT_ID="your client_id" +//! // export CLIENT_SECRET="secret" +//! // export REDIRECT_URI=your-direct-uri //! -//! // Or set client_id, client_secret,redirect_uri explictly -//! // let oauth = SpotifyOAuth::default() -//! // .client_id("this-is-my-client-id") -//! // .client_secret("this-is-my-client-secret") -//! // .redirect_uri("http://localhost:8888/callback") -//! // .build(); +//! // Or set client_id, client_secret,redirect_uri explictly +//! // let oauth = SpotifyOAuth::default() +//! // .client_id("this-is-my-client-id") +//! // .client_secret("this-is-my-client-secret") +//! // .redirect_uri("http://localhost:8888/callback") +//! // .build(); //! -//! let mut oauth = SpotifyOAuth::default() -//! .scope("user-read-recently-played") -//! .build(); -//! match get_token(&mut oauth).await { -//! Some(token_info) => { -//! let client_credential = SpotifyClientCredentials::default() -//! .token_info(token_info) -//! .build(); -//! // Or set client_id and client_secret explictly -//! // let client_credential = SpotifyClientCredentials::default() -//! // .client_id("this-is-my-client-id") -//! // .client_secret("this-is-my-client-secret") -//! // .build(); -//! let spotify = Spotify::default() -//! .client_credentials_manager(client_credential) -//! .build(); -//! let history = spotify.current_user_recently_played(10).await; -//! println!("{:?}", history); -//! } -//! None => println!("auth failed"), -//! }; +//! let mut oauth = SpotifyOAuth::default() +//! .scope("user-read-recently-played") +//! .build(); +//! match get_token(&mut oauth).await { +//! Some(token_info) => { +//! let client_credential = SpotifyClientCredentials::default() +//! .token_info(token_info) +//! .build(); +//! // Or set client_id and client_secret explictly +//! // let client_credential = SpotifyClientCredentials::default() +//! // .client_id("this-is-my-client-id") +//! // .client_secret("this-is-my-client-secret") +//! // .build(); +//! let spotify = Spotify::default() +//! .client_credentials_manager(client_credential) +//! .build(); +//! let history = spotify.current_user_recently_played(10).await; +//! println!("{:?}", history); +//! } +//! None => println!("auth failed"), +//! }; //! } //! //! ``` diff --git a/src/model/album.rs b/src/model/album.rs index 4b0c8053..48aa72e1 100644 --- a/src/model/album.rs +++ b/src/model/album.rs @@ -9,7 +9,7 @@ use super::page::Page; use super::track::SimplifiedTrack; use crate::senum::{AlbumType, Type}; -///[link to album object simplified](https://developer.spotify.com/web-api/object-model/#album-object-simplified) +/// [link to album object simplified](https://developer.spotify.com/web-api/object-model/#album-object-simplified) /// Simplified Album Object #[derive(Clone, Debug, Serialize, Deserialize)] pub struct SimplifiedAlbum { @@ -41,7 +41,7 @@ pub struct Restrictions { pub reason: String, } -///[link to album object full](https://developer.spotify.com/web-api/object-model/#album-object-full) +/// [link to album object full](https://developer.spotify.com/web-api/object-model/#album-object-full) /// Full Album Object #[derive(Clone, Debug, Serialize, Deserialize)] pub struct FullAlbum { @@ -71,14 +71,14 @@ pub struct FullAlbums { pub albums: Vec, } -///[link to get list new releases](https://developer.spotify.com/web-api/get-list-new-releases/) +/// [link to get list new releases](https://developer.spotify.com/web-api/get-list-new-releases/) /// Simplified Albums wrapped by Page object #[derive(Clone, Debug, Serialize, Deserialize)] pub struct PageSimpliedAlbums { pub albums: Page, } -///[link to save album object](https://developer.spotify.com/web-api/object-model/#save-album-object) +/// [link to save album object](https://developer.spotify.com/web-api/object-model/#save-album-object) /// Saved Album object #[derive(Clone, Debug, Serialize, Deserialize)] pub struct SavedAlbum { diff --git a/src/model/artist.rs b/src/model/artist.rs index 83dc8b0e..bce6d76f 100644 --- a/src/model/artist.rs +++ b/src/model/artist.rs @@ -5,7 +5,7 @@ use super::page::CursorBasedPage; use crate::senum::Type; use serde_json::Value; use std::collections::HashMap; -///[artist object simplified](https://developer.spotify.com/web-api/object-model/#artist-object-simplified) +/// [artist object simplified](https://developer.spotify.com/web-api/object-model/#artist-object-simplified) /// Simplified Artist Object #[derive(Clone, Debug, Serialize, Deserialize)] pub struct SimplifiedArtist { @@ -18,7 +18,7 @@ pub struct SimplifiedArtist { pub uri: Option, } -///[artist object full](https://developer.spotify.com/web-api/object-model/#artist-object-full) +/// [artist object full](https://developer.spotify.com/web-api/object-model/#artist-object-full) /// Full Artist Object #[derive(Clone, Debug, Serialize, Deserialize)] pub struct FullArtist { diff --git a/src/model/audio.rs b/src/model/audio.rs index 06ff8321..7cf62c73 100644 --- a/src/model/audio.rs +++ b/src/model/audio.rs @@ -1,6 +1,6 @@ //! All objects related to artist defined by Spotify API -///[audio feature object](https://developer.spotify.com/web-api/object-model/#audio-features-object) +/// [audio feature object](https://developer.spotify.com/web-api/object-model/#audio-features-object) /// Audio Feature object #[derive(Clone, Debug, Serialize, Deserialize)] pub struct AudioFeatures { @@ -32,7 +32,7 @@ pub struct AudioFeaturesPayload { } /// Audio Analysis Object -///[audio analysis](https://developer.spotify.com/web-api/get-audio-analysis/) +/// [audio analysis](https://developer.spotify.com/web-api/get-audio-analysis/) #[derive(Clone, Debug, Serialize, Deserialize)] pub struct AudioAnalysis { pub bars: Vec, @@ -44,7 +44,7 @@ pub struct AudioAnalysis { pub track: AudioAnalysisTrack, } -///[audio analysis](https://developer.spotify.com/web-api/get-audio-analysis/) +/// [audio analysis](https://developer.spotify.com/web-api/get-audio-analysis/) #[derive(Clone, Debug, Serialize, Deserialize)] pub struct AudioAnalysisMeasure { pub start: f32, @@ -52,7 +52,7 @@ pub struct AudioAnalysisMeasure { pub confidence: f32, } -///[audio analysis](https://developer.spotify.com/web-api/get-audio-analysis/) +/// [audio analysis](https://developer.spotify.com/web-api/get-audio-analysis/) #[derive(Clone, Debug, Serialize, Deserialize)] pub struct AudioAnalysisSection { pub start: f32, @@ -69,7 +69,7 @@ pub struct AudioAnalysisSection { pub time_signature_confidence: f32, } -///[audio analysis](https://developer.spotify.com/web-api/get-audio-analysis/) +/// [audio analysis](https://developer.spotify.com/web-api/get-audio-analysis/) #[derive(Clone, Debug, Serialize, Deserialize)] pub struct AudioAnalysisMeta { pub analyzer_version: String, @@ -94,7 +94,7 @@ pub struct AudioAnalysisSegment { pub timbre: Vec, } -///[audio analysis](https://developer.spotify.com/web-api/get-audio-analysis/) +/// [audio analysis](https://developer.spotify.com/web-api/get-audio-analysis/) #[derive(Clone, Debug, Serialize, Deserialize)] pub struct AudioAnalysisTrack { pub num_samples: u32, diff --git a/src/model/category.rs b/src/model/category.rs index 5bb3d5e8..27c1d40e 100644 --- a/src/model/category.rs +++ b/src/model/category.rs @@ -2,7 +2,7 @@ use super::image::Image; use super::page::Page; /// category object -///[category object](https://developer.spotify.com/web-api/get-list-categories/#categoryobject) +/// [category object](https://developer.spotify.com/web-api/get-list-categories/#categoryobject) #[derive(Clone, Debug, Serialize, Deserialize)] pub struct Category { pub href: String, @@ -12,7 +12,7 @@ pub struct Category { } /// Categories wrapped by page object -///[get list categories](https://developer.spotify.com/web-api/get-list-categories/) +/// [get list categories](https://developer.spotify.com/web-api/get-list-categories/) #[derive(Clone, Debug, Serialize, Deserialize)] pub struct PageCategory { pub categories: Page, diff --git a/src/model/context.rs b/src/model/context.rs index d9369ba0..39178280 100644 --- a/src/model/context.rs +++ b/src/model/context.rs @@ -6,7 +6,7 @@ use super::track::FullTrack; use super::PlayingItem; use crate::senum::{CurrentlyPlayingType, DisallowKey, RepeatState, Type}; /// Context object -///[get the users currently playing track](https://developer.spotify.com/web-api/get-the-users-currently-playing-track/) +/// [get the users currently playing track](https://developer.spotify.com/web-api/get-the-users-currently-playing-track/) #[derive(Clone, Debug, Serialize, Deserialize)] pub struct Context { pub uri: String, @@ -17,7 +17,7 @@ pub struct Context { } /// Full playing context -///[get information about the users current playback](https://developer.spotify.com/web-api/get-information-about-the-users-current-playback/) +/// [get information about the users current playback](https://developer.spotify.com/web-api/get-information-about-the-users-current-playback/) #[derive(Clone, Debug, Serialize, Deserialize)] pub struct FullPlayingContext { pub device: Device, @@ -30,7 +30,7 @@ pub struct FullPlayingContext { pub item: Option, } -///[get the users currently playing track](https://developer.spotify.com/web-api/get-the-users-currently-playing-track/) +/// [Get the users currently playing track](https://developer.spotify.com/web-api/get-the-users-currently-playing-track/) #[derive(Clone, Debug, Serialize, Deserialize)] pub struct SimplifiedPlayingContext { pub context: Option, @@ -66,7 +66,7 @@ pub struct CurrentlyPlaybackContext { pub actions: Actions, } -/// [actions](https://developer.spotify.com/documentation/web-api/reference/player/get-the-users-currently-playing-track/) +/// [Actions](https://developer.spotify.com/documentation/web-api/reference/player/get-the-users-currently-playing-track/) #[derive(Clone, Debug, Serialize, Deserialize)] pub struct Actions { pub disallows: HashMap, diff --git a/src/model/cud_result.rs b/src/model/cud_result.rs index ce515604..5fc84218 100644 --- a/src/model/cud_result.rs +++ b/src/model/cud_result.rs @@ -1,4 +1,4 @@ -//! the result of post/put/delete request +//! The result of post/put/delete request #[derive(Clone, Debug, Serialize, Deserialize)] pub struct CUDResult { pub snapshot_id: String, diff --git a/src/model/device.rs b/src/model/device.rs index 6aacd704..fb9cc30c 100644 --- a/src/model/device.rs +++ b/src/model/device.rs @@ -1,5 +1,5 @@ /// All objects related to device -///[get a users available devices](https://developer.spotify.com/web-api/get-a-users-available-devices/) +/// [get a users available devices](https://developer.spotify.com/web-api/get-a-users-available-devices/) use crate::senum::DeviceType; #[derive(Clone, Debug, Serialize, Deserialize)] pub struct Device { diff --git a/src/model/image.rs b/src/model/image.rs index a7cd7501..06c54293 100644 --- a/src/model/image.rs +++ b/src/model/image.rs @@ -1,5 +1,5 @@ //! Image object -///[image object](https://developer.spotify.com/web-api/object-model/#image-object) +/// [image object](https://developer.spotify.com/web-api/object-model/#image-object) #[derive(Clone, Debug, Serialize, Deserialize)] pub struct Image { pub height: Option, diff --git a/src/model/offset.rs b/src/model/offset.rs index 7edec6fd..1dc90ecd 100644 --- a/src/model/offset.rs +++ b/src/model/offset.rs @@ -1,5 +1,5 @@ //! Offset object -///[offset object](https://developer.spotify.com/documentation/web-api/reference/player/start-a-users-playback/) +/// [offset object](https://developer.spotify.com/documentation/web-api/reference/player/start-a-users-playback/) #[derive(Clone, Debug, Serialize, Deserialize)] pub struct Offset { pub position: Option, diff --git a/src/model/page.rs b/src/model/page.rs index 63130c0a..c8ed82f3 100644 --- a/src/model/page.rs +++ b/src/model/page.rs @@ -1,6 +1,6 @@ //! All kinds of page object -///Basic page -///ppaging abject(https://developer.spotify.com/web-api/object-model/#paging-object) +/// Basic page +/// ppaging abject(https://developer.spotify.com/web-api/object-model/#paging-object) #[derive(Clone, Debug, Serialize, Deserialize)] pub struct Page { pub href: String, @@ -11,8 +11,8 @@ pub struct Page { pub previous: Option, pub total: u32, } -/// cursor based page -///[cursor based paging object](https://developer.spotify.com/web-api/object-model/#cursor-based-paging-object) +/// Cursor based page +/// [cursor based paging object](https://developer.spotify.com/web-api/object-model/#cursor-based-paging-object) #[derive(Clone, Debug, Serialize, Deserialize)] pub struct CursorBasedPage { pub href: String, @@ -24,8 +24,8 @@ pub struct CursorBasedPage { /// Spotify document says pub total: Option, } -///Cursor object -///[cursor object](https://developer.spotify.com/web-api/object-model/#cursor-object) +/// Cursor object +/// [cursor object](https://developer.spotify.com/web-api/object-model/#cursor-object) #[derive(Clone, Debug, Serialize, Deserialize)] pub struct Cursor { pub after: Option, diff --git a/src/model/playing.rs b/src/model/playing.rs index ec826e0e..6637a5e5 100644 --- a/src/model/playing.rs +++ b/src/model/playing.rs @@ -4,8 +4,8 @@ use chrono::prelude::*; use super::context::Context; use super::track::FullTrack; use super::track::SimplifiedTrack; -/// current playing track -///[get the users currently playing track](https://developer.spotify.com/web-api/get-the-users-currently-playing-track/) +/// Current playing track +/// [get the users currently playing track](https://developer.spotify.com/web-api/get-the-users-currently-playing-track/) #[derive(Clone, Debug, Serialize, Deserialize)] pub struct Playing { pub context: Option, @@ -15,8 +15,8 @@ pub struct Playing { pub item: Option, } -/// playing history -///[play history object](https://developer.spotify.com/web-api/object-model/#play-history-object) +/// Playing history +/// [play history object](https://developer.spotify.com/web-api/object-model/#play-history-object) #[derive(Clone, Debug, Serialize, Deserialize)] pub struct PlayHistory { pub track: SimplifiedTrack, diff --git a/src/model/playlist.rs b/src/model/playlist.rs index 893d9a9c..1f003f3e 100644 --- a/src/model/playlist.rs +++ b/src/model/playlist.rs @@ -8,7 +8,8 @@ use super::page::Page; use super::track::FullTrack; use super::user::PublicUser; use crate::senum::Type; -///[playlist object simplified](https://developer.spotify.com/web-api/object-model/#playlist-object-simplified) + +///[Playlist object simplified](https://developer.spotify.com/web-api/object-model/#playlist-object-simplified) #[derive(Clone, Debug, Serialize, Deserialize)] pub struct SimplifiedPlaylist { pub collaborative: bool, @@ -45,7 +46,7 @@ pub struct FullPlaylist { pub uri: String, } -///[playlist track object](https://developer.spotify.com/web-api/object-model/#playlist-track-object) +/// [Playlist track object](https://developer.spotify.com/web-api/object-model/#playlist-track-object) #[derive(Clone, Debug, Serialize, Deserialize)] pub struct PlaylistTrack { pub added_at: DateTime, @@ -53,7 +54,7 @@ pub struct PlaylistTrack { pub is_local: bool, pub track: Option, } -///[get list featured playlists](https://developer.spotify.com/web-api/get-list-featured-playlists/) +/// [Get list featured playlists](https://developer.spotify.com/web-api/get-list-featured-playlists/) #[derive(Clone, Debug, Serialize, Deserialize)] pub struct FeaturedPlaylists { pub message: String, diff --git a/src/model/recommend.rs b/src/model/recommend.rs index 6fcf3df5..4b0229dc 100644 --- a/src/model/recommend.rs +++ b/src/model/recommend.rs @@ -1,12 +1,12 @@ //! All objects related to recommendation use super::track::SimplifiedTrack; -///[recommendations object](https://developer.spotify.com/web-api/object-model/#recommendations-object) +/// [Recommendations object](https://developer.spotify.com/web-api/object-model/#recommendations-object) #[derive(Clone, Debug, Serialize, Deserialize)] pub struct Recommendations { pub seeds: Vec, pub tracks: Vec, } -///[recommendations seed object](https://developer.spotify.com/web-api/object-model/#recommendations-seed-object) +/// [Recommendations seed object](https://developer.spotify.com/web-api/object-model/#recommendations-seed-object) #[derive(Clone, Debug, Serialize, Deserialize)] pub struct RecommendationsSeed { #[serde(rename = "afterFilteringSize")] diff --git a/src/model/search.rs b/src/model/search.rs index 23d0a9fc..c725826f 100644 --- a/src/model/search.rs +++ b/src/model/search.rs @@ -5,34 +5,35 @@ use super::page::Page; use super::playlist::SimplifiedPlaylist; use super::show::{SimplifiedEpisode, SimplifiedShow}; use super::track::FullTrack; -///[search item](https://developer.spotify.com/web-api/search-item/); + +///[Search item](https://developer.spotify.com/web-api/search-item/); #[derive(Clone, Debug, Serialize, Deserialize)] pub struct SearchPlaylists { pub playlists: Page, } -///[search item](https://developer.spotify.com/web-api/search-item/) +///[Search item](https://developer.spotify.com/web-api/search-item/) #[derive(Clone, Debug, Serialize, Deserialize)] pub struct SearchAlbums { pub albums: Page, } -///[search item](https://developer.spotify.com/web-api/search-item/) +///[Search item](https://developer.spotify.com/web-api/search-item/) #[derive(Clone, Debug, Serialize, Deserialize)] pub struct SearchArtists { pub artists: Page, } -///[search item](https://developer.spotify.com/web-api/search-item/) +///[Search item](https://developer.spotify.com/web-api/search-item/) #[derive(Clone, Debug, Serialize, Deserialize)] pub struct SearchTracks { pub tracks: Page, } -///[search item](https://developer.spotify.com/web-api/search-item/) +/// [Search item](https://developer.spotify.com/web-api/search-item/) #[derive(Clone, Debug, Serialize, Deserialize)] pub struct SearchShows { pub shows: Page, } -///[search item](https://developer.spotify.com/web-api/search-item/) +/// [Search item](https://developer.spotify.com/web-api/search-item/) #[derive(Clone, Debug, Serialize, Deserialize)] pub struct SearchEpisodes { pub episodes: Page, diff --git a/src/model/show.rs b/src/model/show.rs index bf7178de..99dad4cf 100644 --- a/src/model/show.rs +++ b/src/model/show.rs @@ -112,7 +112,7 @@ pub struct SeveralEpisodes { pub episodes: Vec, } -/// [](https://developer.spotify.com/documentation/web-api/reference/object-model/#resume-point-object) +/// [Resume point object](https://developer.spotify.com/documentation/web-api/reference/object-model/#resume-point-object) #[derive(Clone, Debug, Serialize, Deserialize)] pub struct ResumePoint { pub fully_played: bool, diff --git a/src/model/track.rs b/src/model/track.rs index 24e228f2..82e6b527 100644 --- a/src/model/track.rs +++ b/src/model/track.rs @@ -7,7 +7,8 @@ use super::album::Restrictions; use super::album::SimplifiedAlbum; use super::artist::SimplifiedArtist; use crate::senum::Type; -///[track object full](https://developer.spotify.com/web-api/object-model/#track-object-full) + +/// [Track object full](https://developer.spotify.com/web-api/object-model/#track-object-full) #[derive(Clone, Debug, Serialize, Deserialize)] pub struct FullTrack { pub album: SimplifiedAlbum, @@ -37,9 +38,8 @@ pub struct FullTrack { pub uri: String, } -/// [link to track link] https://developer.spotify.com/documentation/web-api/reference/object-model/#track-link +/// [Link to track link] https://developer.spotify.com/documentation/web-api/reference/object-model/#track-link /// Track Link - #[derive(Clone, Debug, Serialize, Deserialize)] pub struct TrackLink { pub external_urls: HashMap, @@ -54,7 +54,7 @@ pub struct TrackLink { pub struct FullTracks { pub tracks: Vec, } -///[track object simplified](https://developer.spotify.com/web-api/object-model/#track-object-simplified) +/// [track object simplified](https://developer.spotify.com/web-api/object-model/#track-object-simplified) #[derive(Clone, Debug, Serialize, Deserialize)] pub struct SimplifiedTrack { pub artists: Vec, @@ -75,7 +75,7 @@ pub struct SimplifiedTrack { pub uri: String, } -///[saved track object](https://developer.spotify.com/web-api/object-model/#saved-track-object) +/// [Saved track object](https://developer.spotify.com/web-api/object-model/#saved-track-object) #[derive(Clone, Debug, Serialize, Deserialize)] pub struct SavedTrack { pub added_at: DateTime, diff --git a/src/model/user.rs b/src/model/user.rs index 62c658f8..7607506a 100644 --- a/src/model/user.rs +++ b/src/model/user.rs @@ -6,7 +6,7 @@ use std::collections::HashMap; use super::image::Image; use crate::senum::Type; -///[public user object](https://developer.spotify.com/web-api/object-model/#user-object-public) +/// [Public user object](https://developer.spotify.com/web-api/object-model/#user-object-public) #[derive(Clone, Debug, Serialize, Deserialize)] pub struct PublicUser { pub display_name: Option, @@ -20,7 +20,7 @@ pub struct PublicUser { pub uri: String, } -///[private user object](https://developer.spotify.com/web-api/object-model/#user-object-private) +/// [Private user object](https://developer.spotify.com/web-api/object-model/#user-object-private) #[derive(Clone, Debug, Serialize, Deserialize)] pub struct PrivateUser { pub birthdate: Option, diff --git a/src/oauth2.rs b/src/oauth2.rs index 5f59db56..27d156ef 100644 --- a/src/oauth2.rs +++ b/src/oauth2.rs @@ -1,11 +1,11 @@ //! The module contains function about authorization and client-credential -// use 3rd party library +// Use 3rd party library use chrono::prelude::*; use dotenv::dotenv; use percent_encoding::{utf8_percent_encode, PATH_SEGMENT_ENCODE_SET}; use reqwest::Client; -// use built-in library +// Use built-in library use std::collections::{HashMap, HashSet}; use std::env; use std::fs::File; @@ -14,7 +14,7 @@ use std::io::prelude::*; use std::iter::FromIterator; use std::path::{Path, PathBuf}; -// use customized library +// Use customized library use super::util::{convert_map_to_string, datetime_to_timestamp, generate_random_string}; /// Client credentials object for spotify @@ -90,7 +90,7 @@ impl TokenInfo { } impl SpotifyClientCredentials { - /// build default SpotifyClientCredentials + /// Build default SpotifyClientCredentials pub fn default() -> SpotifyClientCredentials { dotenv().ok(); let client_id = env::var("CLIENT_ID").unwrap_or_default(); @@ -139,7 +139,7 @@ impl SpotifyClientCredentials { } self } - /// get access token from self.token_info, if self.token_info is none or is + /// Get access token from self.token_info, if self.token_info is none or is /// expired. fetch token info by HTTP request pub async fn get_access_token(&self) -> String { let access_token = match self.token_info { @@ -192,7 +192,7 @@ impl SpotifyClientCredentials { } impl SpotifyOAuth { - // spotify token example: + // Spotify token example: // { // "access_token": "NgCXRK...MzYjw", // "token_type": "Bearer", @@ -302,7 +302,7 @@ impl SpotifyOAuth { } } } - /// gets the access_token for the app with the given code without caching(without saving token to `cache_path`) + /// Gets the access_token for the app with the given code without caching(without saving token to `cache_path`) pub async fn get_access_token_without_cache(&self, code: &str) -> Option { let mut payload: HashMap<&str, &str> = HashMap::new(); payload.insert("redirect_uri", &self.redirect_uri); @@ -314,7 +314,7 @@ impl SpotifyOAuth { .await } - /// gets the access_token for the app with given the code + /// Gets the access_token for the app with given the code pub async fn get_access_token(&self, code: &str) -> Option { if let Some(token_info) = self.get_access_token_without_cache(code).await { match serde_json::to_string(&token_info) { @@ -334,7 +334,7 @@ impl SpotifyOAuth { None } } - /// fetch access_token + /// Fetch access_token async fn fetch_access_token( &self, client_id: &str,