summary history branches tags files
commit:52f2b5f69dbecc230e2591395fb370701de88bab
author:Trevor Bentley
committer:Trevor Bentley
date:Mon Apr 10 18:24:31 2017 +0200
parents:74c625aac1df3e1c94cf65ae88fabb990cb2016f
Action functions
diff --git a/src/main.rs b/src/main.rs
line changes: +10/-1
index 15be247..9e2f10f
--- a/src/main.rs
+++ b/src/main.rs
@@ -30,7 +30,16 @@ fn main() {
     };
     let mut spotify = connectr::SpotifyConnectr::new(settings);
     spotify.connect();
-    spotify.go();
+
+    let device_list = spotify.request_device_list();
+    let player_state = spotify.request_player_state();
+
+    for dev in device_list.devices {
+        println!("{:?}", dev);
+    }
+    println!("State: {:?}", player_state);
+
+    spotify.play_uri("spotify:user:mrmekon:playlist:4XqYlbPdDUsranzjicPCgf");
 
     //systray(player_state);
     //loop {}

diff --git a/src/webapi/mod.rs b/src/webapi/mod.rs
line changes: +8/-14
index 081b9ff..327d2e6
--- a/src/webapi/mod.rs
+++ b/src/webapi/mod.rs
@@ -84,22 +84,16 @@ impl SpotifyConnectr {
         self.access_token = access_token;
         self.refresh_token = refresh_token;
     }
-    pub fn request_device_list() {}
-    pub fn go(&self) {
+    pub fn request_device_list(&self) -> ConnectDeviceList {
         let json_response = http::http(spotify_api::DEVICES, "", http::HttpMethod::GET, Some(&self.access_token)).unwrap();
-        let device_list: ConnectDeviceList = json::decode(&json_response).unwrap();
-
+        json::decode(&json_response).unwrap()
+    }
+    pub fn request_player_state(&self) -> PlayerState {
         let json_response = http::http(spotify_api::PLAYER_STATE, "", http::HttpMethod::GET, Some(&self.access_token)).unwrap();
-        let player_state: PlayerState = json::decode(&json_response).unwrap();
-
-        println!("Auth Code: {}...", &self.auth_code[0..5]);
-        println!("Access: {}... / Refresh: {}...", &self.access_token[0..5], &self.refresh_token[0..5]);
-        for dev in device_list.devices {
-            println!("{:?}", dev);
-        }
-        println!("State: {:?}", player_state);
-
-        let query = format!("{{\"context_uri\": \"spotify:user:mrmekon:playlist:4XqYlbPdDUsranzjicPCgf\"}}");
+        json::decode(&json_response).unwrap()
+    }
+    pub fn play_uri(&self, uri: &str) {
+        let query = format!("{{\"context_uri\": \"{}\"}}", uri);
         let _ = http::http(spotify_api::PLAY, &query, http::HttpMethod::PUT, Some(&self.access_token));
     }
 }