/** * Register User * * @param string $username * @param string $password * @return status */ public function registerUser($username, $password) { $username = trim($username); if ($this->getDao()->getUserExistsByUsername($username)) { ApiHandler::sendResponse(200, array('error' => true, 'message' => 'User already exists')); return USER_ALREADY_EXISTS; } $password = md5($password); $created = date('Y-m-d H:i:s'); $api_key = md5($username . $created); return $this->getDao()->createUser(array($username, $password, $api_key, $created, $created)); }
$app->get('/api/v1/player/next', function () { $player = new Player(); $song = $player->playNextSong(); if ($song !== false) { ApiHandler::sendResponse(200, true, array('token' => $song)); } else { ApiHandler::sendResponse(200, false); } }); /** * Gets the stream token for a given song */ $app->get('/api/v1/player/stream/:token', function ($token) { $player = new Player(); ApiHandler::sendResponse(200, true, $player->getStream($token)); }); /** * Validates the song is playing with GrooveShark after 30 seconds */ $app->post('/api/v1/player/stream/validate', function () { $player = new Player(); $player->markSong30Seconds($_POST['streamKey'], $_POST['streamServerID']); ApiHandler::sendResponse(200, true); }); /** * Marks a song as played */ $app->post('/api/v1/song/:id/played', function ($id) use($base) { $player = new Player(); echo ApiHandler::sendResponse(200, $player->markSongComplete($id)); });