Example #1
0
 public function __construct($request, $origin)
 {
     $this->loadClasses();
     parent::__construct($request);
     // Abstracted out for example
     $APIKey = new PowaTagAPIKey();
     if (!Module::isInstalled('powatag') || !Module::isEnabled('powatag')) {
         throw new Exception('Module not enable');
     }
     /*
     		if (!array_key_exists('HTTP_HMAC', $_SERVER))
     			throw new Exception('No API Key provided');
     		else if (!$APIKey->verifyKey($_SERVER['HTTP_HMAC'], $this->data))
     			throw new Exception('Invalid API Key');
     */
     $this->data = Tools::jsonDecode($this->data);
 }
 /**
  * Constructor: __construct
  * Allow for CORS, assemble and pre-process the data
  */
 public function __construct($request)
 {
     header('Access-Control-Allow-Orgin: *');
     header('Access-Control-Allow-Methods: *');
     header('Content-Type: application/json; charset=utf-8');
     $this->args = explode('/', rtrim($request, '/'));
     $this->endpoint = array_shift($this->args);
     if (array_key_exists(0, $this->args) && !is_numeric($this->args[0])) {
         $this->verb = array_shift($this->args);
     }
     $this->method = $_SERVER['REQUEST_METHOD'];
     if ($this->method == 'POST' && array_key_exists('HTTP_X_HTTP_METHOD', $_SERVER)) {
         if ($_SERVER['HTTP_X_HTTP_METHOD'] == 'DELETE') {
             $this->method = 'DELETE';
         } else {
             if ($_SERVER['HTTP_X_HTTP_METHOD'] == 'PUT') {
                 $this->method = 'PUT';
             } else {
                 throw new Exception('Unexpected Header');
             }
         }
     }
     $this->data = Tools::file_get_contents('php://input');
     self::$api_log = Configuration::get('POWATAG_API_LOG');
     self::$request_log = Configuration::get('POWATAG_REQUEST_LOG');
     PowaTagRequestLogs::add(array('args' => $this->args, 'endpoint' => $this->endpoint, 'verb' => $this->verb, 'method' => $this->method, 'data' => $this->data));
     $this->module = Module::getInstanceByName('powatag');
 }