/** * The main entry point for V1 of the API engine * * @return string The JSON encoded string for the loader to parse */ public function action_index() { // Set up our APIRequest object if (is_array($setup = \V1\APIRequest::setup())) { return $this->response_format(); } // Validate the request if (is_array($validate_request = \V1\ValidateRequest::run())) { return $this->response_format($validate_request); } // Validate a Data Call if (\V1\APIRequest::get('data-call', false) !== false) { if (is_array($data_call = \V1\Call\DataCall::run()) || is_string($data_call)) { // HTML only Data Calls if (\Session::get('response_format', false) === 'html' && is_string($data_call)) { return $data_call; } // Non-HTML Data Calls return $this->response_format($data_call); } } // Are we processing an API call? if (\V1\APIRequest::get('api', false) !== false) { $runcall = new \V1\RunCall(); if (is_array($response = $runcall->ignite())) { return $this->response_format($response); } } // Nothing happened, so return an error. return $this->response_format(\Utility::format_error(500)); }
public function test_setup() { $bad_call = array(serialize('test')); // Use a Data Call so we can specify the post data. \Session::set('data_call', true); // Bad call setup \Session::set('posted_data', $bad_call); $this->assertInternalType('array', \V1\APIRequest::setup()); // Correct call setup \Session::set('posted_data', $this->call_data); $this->assertSame(true, \V1\APIRequest::setup()); }