From 600f0e6a847017ee46c67e885ffbe1acdcba1ded Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Thu, 30 Jan 2020 02:20:16 +0100 Subject: Add web-api --- src/main.rs | 44 +++++++++----------------------------------- 1 file changed, 9 insertions(+), 35 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 1bd3417..8b7af53 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,13 @@ +#![feature(proc_macro_hygiene, decl_macro)] + +#[macro_use] +extern crate rocket; use rspotify::spotify::client::Spotify; use rspotify::spotify::oauth2::{SpotifyClientCredentials, SpotifyOAuth}; use rspotify::spotify::util::get_token; +mod serve; + fn main() { // Set client_id and client_secret in .env file or // export CLIENT_ID="your client_id" @@ -14,39 +20,7 @@ fn main() { // .client_secret("this-is-my-client-secret") // .redirect_uri("http://localhost:8888/callback") // .build(); - - let mut spotify_oauth = SpotifyOAuth::default() - .scope("playlist-read-private, playlist-read-collaborative") - .build(); - match get_token(&mut spotify_oauth) { - 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(); - //this is my(samray's) user_id, so just change - // user_id to yours, or you will get a 403 forbidden error - let user_id = "d-kobert"; - let playlists = spotify.user_playlists(user_id, Some(10), None); - for playlist in playlists.unwrap().items { - println!("{:?}", playlist.name); - for track in spotify - .user_playlist_tracks(user_id, &playlist.id, None, Some(2), None, None) - .unwrap() - .items - { - println!("{:?}", track.track.name); - } - } - } - None => println!("auth failed"), - }; + rocket::ignite() + .mount("/", routes![serve::token, serve::get_tracks]) + .launch(); } -- cgit v1.2.3-54-g00ecf