public function PrintOuput(ApiHandler $api) { $this->SetHeaderContentType(); try { $val = $api->ExecuteApi(); } catch (ApiException $e) { // If something goes wrong, set the proper header $temp_arr = $e->getArrayMessage(); header($temp_arr["header"]); // Ouput the error JSONized without the header info unset($temp_arr["header"]); die($this->FormatOuput($temp_arr)); } echo $this->FormatOuput($val); }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { $item = \ApiHandler::parseSingle($this->model, $id)->getResult(); return \Fractal::item($item, $this->transformer)->getArray(); }
<?php // echo phpversion(); // echo "<br>"; // header('Content-Type: text/plain'); // require_once('settings.inc'); require_once 'modules/api_handler.inc'; require_once 'modules/GoogleAPI.php'; require_once 'twitteroauth/twitteroauth.php'; require_once 'twitteroauth/config.php'; require_once dirname(__DIR__) . '/vendor/recurly_lib/recurly.php'; require_once 'modules/simple_html_dom.php'; Recurly_Client::$subdomain = RECURLY_SUB_DOMAIN; Recurly_Client::$apiKey = RECURLY_API_KEY; $api = new ApiHandler(); // Try to setup our session // Utilities::eClincherSetupUserSession(); // For analytics/backtracing $bt = debug_backtrace(); $log_response_to_ec_error_handler = false; array_shift($bt); $ajax_time_started = microtime(TRUE); $ajax_label = 'Unknown'; if ($log_response_to_ec_error_handler) { ob_start(); } // Detect and respond to our users that we're in maintenance mode > 1 if (ECConfig::get('MAINTENANCE_MODE') > 1) { // echo "Reload page"; echo file_get_contents(ROOT_PATH . '/web/maintenance.html'); exit;
/** * 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)); }
/** * If this a valid route? * * @param $route * * @return bool */ public static function ValidRoute($route) { return ApiHandler::GetName($route) != false ? true : false; }
$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)); });