Skip to content
Browse files

Moved the deprecated code into a separate branch.

  • Loading branch information...
1 parent 34ca5ea commit 7ebb510caa3c4dbf36e4499a95b0ad71c19ccf08 @mptre committed Jul 29, 2010
Showing with 0 additions and 297 deletions.
  1. +0 −185 deprecated/README.textile
  2. +0 −112 deprecated/soundcloud.php
View
185 deprecated/README.textile
@@ -1,185 +0,0 @@
-h1. SoundCloud PHP API wrapper
-
-A minimalistic API wrapper for "SoundCloud":http://soundcloud.com/ written in PHP.
-Inspired by "tcdent":http://github.com/tcdent "Twitter API class":http://github.com/tcdent/php-twitter/.
-
-So far the supported and tested methods are comments, users and tracks.
-All methods will be supported in the near future.
-
-h2. Example of usage
-
-All responses are XML-formated. I would recommend SimpleXMLElement to parse them.
-
-h3. Users
-
-<pre>
-<code>
-<?php
-$soundcloud = new Soundcloud('username', 'password');
-
-// Get the authenticated user.
-$soundcloud->me->basic();
-
-// Get the authenticated user comments.
-$soundcloud->me->comments();
-
-// Get the authenticated user contacts.
-$soundcloud->me->contacts();
-
-// Add a new contact.
-$soundcloud->me->contacts(
- array(
- 'contact_id' => 1,
- 'put' => TRUE
- )
-);
-
-// Delete a contact.
-$soundcloud->me->contacts(
- array(
- 'contact_id' => 1,
- 'delete' => TRUE
- )
-);
-
-// Get the authenticated user tracks.
-$soundcloud->me->tracks();
-
-// Get the authenticated user fans.
-$soundcloud->me->fans();
-
-// Get the authenticated user favorites.
-$soundcloud->me->favorites();
-
-// Add a new favorite track.
-$soundcloud->me->favorites(
- array(
- 'track_id' => 1,
- 'put' => TRUE
- )
-);
-
-// Delete a favorite track.
-$soundcloud->me->favorites(
- array(
- 'track_id' => 1,
- 'delete' => TRUE
- )
-);
-?>
-</code>
-</pre>
-Note that you can perform most of these actions with other users.
-This is done by replacing "me" with users and simply add the key "user_id" to the array of arguments.
-Here's an example.
-<pre>
-<code>
-<?php
-$soundcloud->users->tracks(
- array(
- 'user_id' => 1
- )
-);
-?>
-</code>
-</pre>
-
-h3. Tracks
-
-<pre>
-<code>
-<?php
-$soundcloud = new Soundcloud('username', 'password');
-
-// Search for tracks.
-$soundcloud->tracks->basic(
- array(
- 'query' => array(
- 'filter' => 'downloadable',
- 'orderby' => 'hotness'
- )
- )
-);
-
-// Get the given track.
-$soundcloud->tracks->basic(
- array(
- 'track_id' => 1
- )
-);
-
-// Upload a new track.
-$soundcloud->tracks->basic(
- array(
- 'post' => TRUE,
- 'fields' => array(
- 'track[title]' => 'API calling',
- 'track[asset_data]' => '@my_track.mp3'
- )
- )
-);
-
-// Update a track.
-$soundcloud->tracks->basic(
- array(
- 'put' => TRUE,
- 'track_id' => 1,
- 'fields' => array(
- 'track[downloadable]' => 'true'
- )
- )
-);
-
-// Delete a track.
-$soundcloud->tracks->basic(
- array(
- 'delete' => TRUE,
- 'track_id' => 1
- )
-);
-
-// Get a track comments.
-$soundcloud->tracks->comments(
- array(
- 'track_id' => 1
- )
-);
-
-// Post a new comment to the given track.
-$soundcloud->tracks->comments(
- array(
- 'post' => TRUE,
- 'track_id' => 1,
- 'fields' => array(
- 'comment[body]' => 'Awesome track!'
- )
- )
-);
-?>
-</code>
-</pre>
-
-h3. Comments
-
-<pre>
-<code>
-<?php
-$soundcloud = new Soundcloud('username', 'password');
-
-// Get the given comment.
-$soundcloud->comments->basic(
- array(
- 'comment_id' => 1
- )
-);
-
-// Delete the given comment.
-$soundcloud->comments->basic(
- array(
- 'delete' => TRUE,
- 'comment_id' => 1
- )
-);
-?>
-</code>
-</pre>
View
112 deprecated/soundcloud.php
@@ -1,112 +0,0 @@
-<?php
-/**
- * A minimalistic API wrapper for SoundCloud written in PHP.
- * For further reference and example of usage see link below.
- *
- * @link http://github.com/mptre/php-soundcloud/
- * @author Anton Lindqvist <anton@qvister.se>
- * @version 0.1.1
- */
-
-class Soundcloud {
- private $key;
- private $me;
- private $username;
- private $password;
- private $url;
-
- function __construct($username, $password, $key = NULL) {
- $this->username = $username;
- $this->password = $password;
- $this->key = $key;
- $this->me = ($key == 'me') ? TRUE : FALSE;
- $this->url = 'http://api.sandbox-soundcloud.com';
- }
-
- function __get($key) {
- return new Soundcloud($this->username, $this->password, $key);
- }
-
- function __call($method, $args) {
- $args = (count($args) && is_array($args)) ? $args[0] : array();
- $options = array(
- CURLOPT_RETURNTRANSFER => 1,
- CURLOPT_URL => sprintf('%s/%s/', $this->url, $this->key),
- CURLOPT_USERPWD => sprintf('%s:%s', $this->username, $this->password)
- );
-
- // Handle me and users method.
- if (!in_array($this->key, array('tracks'))) {
- $options[CURLOPT_URL] .= (isset($args['user_id']))
- ? $args['user_id'] .'/'
- : NULL;
- $options[CURLOPT_URL] .= ($method != 'basic')
- ? $method .'/'
- : NULL;
- }
-
- // Handle tracks search method.
- if (isset($args['query'])) {
- if (is_array($args['query'])) {
- $options[CURLOPT_URL] = preg_replace(
- '/\/$/',
- '?',
- $options[CURLOPT_URL]
- );
- $options[CURLOPT_URL] .= http_build_query($args['query']);
- }
- }
-
- // Handle POST, PUT and DELETE requests.
- foreach ($args as $key => $val) {
- if (in_array($key, array('delete', 'post', 'put'))) {
- if ($key == 'post') {
- $options[CURLOPT_POST] = 1;
- } else {
- $options[CURLOPT_CUSTOMREQUEST] = strtoupper($key);
- }
-
- $options[CURLOPT_POSTFIELDS] = (isset($args['fields']))
- ? $args['fields']
- : '';
- } elseif (preg_match('/[^[user]]{0}_id$/', $key)) {
- $options[CURLOPT_URL] .= $args[$key] .'/';
- }
- }
-
- if (in_array($this->key, array('tracks')) && $method != 'basic') {
- $options[CURLOPT_URL] .= $method;
- }
-
- $ch = curl_init();
- curl_setopt_array($ch, $options);
- $data = curl_exec($ch);
- $meta = curl_getinfo($ch);
-
- if (in_array($meta['http_code'], array(200, 201, 303))) {
- return (strlen($data) <= 1) ? TRUE : $data;
- } else {
- // Throw error.
- throw new SoundcloudException(
- sprintf(
- 'Response code: %d from %s',
- $meta['http_code'],
- $options[CURLOPT_URL]
- )
- );
- }
- }
-
- function __destruct() {
- $this->username = NULL;
- $this->password = NULL;
- $this->key = NULL;
- $this->me = NULL;
- $this->url = NULL;
- }
-}
-
-class SoundcloudException extends Exception {
- // Kthxbye.
-}
-?>

0 comments on commit 7ebb510

Please sign in to comment.
Something went wrong with that request. Please try again.