示例#1
0
 /**
  * Starting point
  */
 public function index()
 {
     // Instantiate the API service
     $api_service = new Api_Service();
     // Run the service
     $api_service->run_service();
     // Avoid caching
     header("Cache-Control: no-cache, must-revalidate");
     // HTTP/1.1
     header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
     // Date in the pas
     if ($api_service->get_response_type() == 'xml') {
         header("Content-type: text/xml");
     }
     print $api_service->get_response();
 }
示例#2
0
 /**
  * Starting point
  */
 public function index()
 {
     // Disables CSRF validation for API requests
     Validation::$is_api_request = TRUE;
     // Instantiate the API service
     $api_service = new Api_Service();
     // Run the service
     $api_service->run_service();
     // Avoid caching
     header("Cache-Control: no-cache, must-revalidate");
     // HTTP/1.1
     header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
     // Date in the pas
     if ($api_service->get_response_type() == 'xml') {
         header("Content-type: text/xml");
     } else {
         header("Content-type: application/json; charset=utf-8");
     }
     print $api_service->get_response();
 }
示例#3
0
 /**
  * Response
  * 
  * @param int ret_value
  * @param string response_type = XML or JSON
  * @param string error_message - The error message to display
  * 
  * @return string
  */
 protected function response($ret_value, $error_messages = '')
 {
     $response = array();
     // Set the record count to zero where the value of @param ret_val <> 0
     $this->record_count = $ret_value != 0 ? 0 : 1;
     if ($ret_value == 0) {
         $response = array("payload" => array("domain" => $this->domain, "success" => "true"), "error" => $this->api_service->get_error_msg(0));
     } elseif ($ret_value == 1) {
         $response = array("payload" => array("domain" => $this->domain, "success" => "false"), "error" => $this->api_service->get_error_msg(03, '', $error_messages));
     } elseif ($ret_value == 2) {
         // Authentication Failed. Invalid User or App Key
         $response = array("payload" => array("domain" => $this->domain, "success" => "false"), "error" => $this->api_service->get_error_msg(05));
     } elseif ($ret_value == 4) {
         // No results got from the database query
         $response = array("payload" => array("domain" => $this->domain, "success" => "true"), "error" => $this->api_service->get_error_msg(07));
     } else {
         $response = array("payload" => array("domain" => $this->domain, "success" => "false"), "error" => $this->api_service->get_error_msg(04));
     }
     return $this->response_type == 'json' ? $this->array_as_json($response) : $this->array_as_xml($response, array());
 }
示例#4
0
 /**
  * Starting point
  */
 public function index()
 {
     // Disables CSRF validation for API requests
     Validation::$is_api_request = TRUE;
     // Reset session for API requests - since they don't get CSRF checked
     // AJAX requests are ok - they skip CSRF anyway.
     if (!request::is_ajax()) {
         // Reset the session - API should be stateless
         $_SESSION = array();
         // Especially reset auth
         Session::instance()->set(Kohana::config('auth.session_key'), null);
         // Re-authenticate
         $this->auth->http_auth_login();
     }
     // Instantiate the API service
     $api_service = new Api_Service();
     // Run the service
     $api_service->run_service();
     // Avoid caching
     header("Cache-Control: no-cache, must-revalidate");
     // HTTP/1.1
     header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
     // Date in the past
     $resp = '';
     if ($api_service->get_response_type() == 'jsonp') {
         header("Content-type: application/json; charset=utf-8");
         $resp = $_GET['callback'] . '(' . $api_service->get_response() . ')';
     } elseif ($api_service->get_response_type() == 'xml') {
         header("Content-type: text/xml");
         $resp = $api_service->get_response();
     } else {
         header("Content-type: application/json; charset=utf-8");
         $resp = $api_service->get_response();
     }
     print $resp;
 }