summary history branches tags files
commit:a05596a03904a8ac7e311983411dece23af5e035
author:Trevor Bentley
committer:Trevor Bentley
date:Tue Apr 11 17:27:48 2017 +0200
parents:c0f430f71f5e92b4b4a0fb86615db7e4c823393b
All actions implemented
diff --git a/src/lib.rs b/src/lib.rs
line changes: +6/-0
index 29381c7..96220b7
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -16,5 +16,11 @@ pub mod spotify_api {
     pub const PLAYER_STATE: &'static str = "https://api.spotify.com/v1/me/player";
     pub const PLAY: &'static str = "https://api.spotify.com/v1/me/player/play";
     pub const PAUSE: &'static str = "https://api.spotify.com/v1/me/player/pause";
+    pub const NEXT: &'static str = "https://api.spotify.com/v1/me/player/next";
+    pub const PREVIOUS: &'static str = "https://api.spotify.com/v1/me/player/previous";
     pub const SEEK: &'static str = "https://api.spotify.com/v1/me/player/seek";
+    pub const VOLUME: &'static str = "https://api.spotify.com/v1/me/player/volume";
+    pub const SHUFFLE: &'static str = "https://api.spotify.com/v1/me/player/shuffle";
+    pub const REPEAT: &'static str = "https://api.spotify.com/v1/me/player/repeat";
+    pub const PLAYER: &'static str = "https://api.spotify.com/v1/me/player";
 }

diff --git a/src/main.rs b/src/main.rs
line changes: +10/-0
index e8a2713..9ba1456
--- a/src/main.rs
+++ b/src/main.rs
@@ -53,5 +53,15 @@ fn main() {
     spotify.set_target_device(None);
     require(spotify.play(Some(&ctx)));
     require(spotify.pause());
+    require(spotify.next());
+    require(spotify.previous());
     require(spotify.seek(5000));
+    require(spotify.volume(10));
+    require(spotify.shuffle(true));
+    require(spotify.repeat(connectr::SpotifyRepeat::Context));
+    require(spotify.transfer_multi(vec!["1a793f2a23989a1c35d05b2fd1ff00e9a67e7134".to_string()], false));
+    require(spotify.transfer("1a793f2a23989a1c35d05b2fd1ff00e9a67e7134".to_string(), false));
+
+    let player_state = spotify.request_player_state();
+    println!("Final state:\n{}", player_state);
 }

diff --git a/src/webapi/mod.rs b/src/webapi/mod.rs
line changes: +58/-0
index 0f2cefb..dbc1e79
--- a/src/webapi/mod.rs
+++ b/src/webapi/mod.rs
@@ -199,6 +199,27 @@ impl QueryString {
 
 pub type SpotifyResponse = HttpResponse;
 
+pub enum SpotifyRepeat {
+    Off,
+    Track,
+    Context,
+}
+impl ToString for SpotifyRepeat {
+    fn to_string(&self) -> String {
+        match self {
+            &SpotifyRepeat::Off => "off".to_string(),
+            &SpotifyRepeat::Track => "track".to_string(),
+            &SpotifyRepeat::Context => "context".to_string(),
+        }
+    }
+}
+
+#[derive(RustcDecodable, RustcEncodable)]
+struct DeviceIdList {
+    device_ids: Vec<String>,
+    play: bool,
+}
+
 pub struct SpotifyConnectr {
     settings: settings::Settings,
     auth_code: String,
@@ -244,6 +265,14 @@ impl SpotifyConnectr {
         let query = QueryString::new().add_opt("device_id", self.device.clone()).build();
         http::http(spotify_api::PAUSE, &query, "", http::HttpMethod::PUT, Some(&self.access_token))
     }
+    pub fn next(&self) -> SpotifyResponse {
+        let query = QueryString::new().add_opt("device_id", self.device.clone()).build();
+        http::http(spotify_api::NEXT, &query, "", http::HttpMethod::POST, Some(&self.access_token))
+    }
+    pub fn previous(&self) -> SpotifyResponse {
+        let query = QueryString::new().add_opt("device_id", self.device.clone()).build();
+        http::http(spotify_api::PREVIOUS, &query, "", http::HttpMethod::POST, Some(&self.access_token))
+    }
     pub fn seek(&self, position: u32) -> SpotifyResponse {
         let query = QueryString::new()
             .add_opt("device_id", self.device.clone())
@@ -251,4 +280,33 @@ impl SpotifyConnectr {
             .build();
         http::http(spotify_api::SEEK, &query, "", http::HttpMethod::PUT, Some(&self.access_token))
     }
+    pub fn volume(&self, volume: u32) -> SpotifyResponse {
+        let query = QueryString::new()
+            .add_opt("device_id", self.device.clone())
+            .add("volume_percent", volume)
+            .build();
+        http::http(spotify_api::VOLUME, &query, "", http::HttpMethod::PUT, Some(&self.access_token))
+    }
+    pub fn shuffle(&self, shuffle: bool) -> SpotifyResponse {
+        let query = QueryString::new()
+            .add_opt("device_id", self.device.clone())
+            .add("state", shuffle)
+            .build();
+        http::http(spotify_api::SHUFFLE, &query, "", http::HttpMethod::PUT, Some(&self.access_token))
+    }
+    pub fn repeat(&self, repeat: SpotifyRepeat) -> SpotifyResponse {
+        let query = QueryString::new()
+            .add_opt("device_id", self.device.clone())
+            .add("state", repeat)
+            .build();
+        http::http(spotify_api::REPEAT, &query, "", http::HttpMethod::PUT, Some(&self.access_token))
+    }
+    pub fn transfer_multi(&self, devices: Vec<String>, play: bool) -> SpotifyResponse {
+        let body = json::encode(&DeviceIdList {device_ids: devices, play: play}).unwrap();
+        http::http(spotify_api::PLAYER, "", &body, http::HttpMethod::PUT, Some(&self.access_token))
+    }
+    pub fn transfer(&self, device: String, play: bool) -> SpotifyResponse {
+        let body = json::encode(&DeviceIdList {device_ids: vec![device], play: play}).unwrap();
+        http::http(spotify_api::PLAYER, "", &body, http::HttpMethod::PUT, Some(&self.access_token))
+    }
 }