Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added updatePlaylist method.

  • Loading branch information...
commit 1363c8f2442ae3541c82b6ddec631b267e947499 1 parent 946f090
@mptre authored
Showing with 51 additions and 0 deletions.
  1. +16 −0 README.md
  2. +35 −0 Services/Soundcloud.php
View
16 README.md
@@ -99,6 +99,22 @@ try {
// do something clever with $track. Save to file perhaps?</code></pre>
+### Update playlist
+
+Many found it difficult to update a existing playlist. Therefor a custom method is available to simplify this matter.
+
+``` php
+$playlistId = 2000;
+$trackIds = array(2001);
+$optionalFields = array('title' => 'My awesome playlist');
+
+try {
+ $playlist = $soundcloud->updatePlaylist($playlistId, $trackIds, $optionalFields);
+} catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) {
+ exit($e->getMessage());
+}
+```
+
## Feedback and questions
Found a bug or missing a feature? Don't hesitate to create a new issue here on GitHub. Or contact me [directly](https://github.com/mptre).
View
35 Services/Soundcloud.php
@@ -668,6 +668,41 @@ function download($trackId, $params = array(), $curlOptions = array())
}
/**
+ * Update a existing playlist
+ *
+ * @param integer $playlistId The playlist id
+ * @param array $trackIds Tracks to add to the playlist
+ * @param array $optionalPostData Optional playlist fields to update
+ *
+ * @return mixed
+ *
+ * @access public
+ * @see Soundcloud::_request()
+ */
+ public function updatePlaylist($playlistId, $trackIds, $optionalPostData = null)
+ {
+ $url = $this->_buildUrl('playlists/' . $playlistId);
+ $postData = array_map(function ($track) {
+ return 'playlist[tracks][][id]=' . $track;
+ }, $trackIds);
+
+ if (is_array($optionalPostData)) {
+ foreach ($optionalPostData as $key => $val) {
+ array_push($postData, 'playlist[' . $key . ']=' . $val);
+ }
+ }
+
+ $postData = implode('&', $postData);
+ $curlOptions = array(
+ CURLOPT_CUSTOMREQUEST => 'PUT',
+ CURLOPT_HTTPHEADER => array('Content-Length' => strlen($postData)),
+ CURLOPT_POSTFIELDS => $postData
+ );
+
+ return $this->_request($url, $curlOptions);
+ }
+
+ /**
* Construct default HTTP request headers
*
* @param boolean $includeAccessToken Include access token
Please sign in to comment.
Something went wrong with that request. Please try again.