Skip to content

Instantly share code, notes, and snippets.

@JoaoVagner
Created May 7, 2013 18:10
Show Gist options
  • Save JoaoVagner/5534798 to your computer and use it in GitHub Desktop.
Save JoaoVagner/5534798 to your computer and use it in GitHub Desktop.
<?php
Class API extends \CI_Model {
public $auth = array(
'appID' => 'web-based',
'secret' => 'secret'
);
public $permission;
public $urlAPI;
public function __construct() {
//$this->_auth($this->auth['appID'], $this->auth['secret']);
parent::__construct();
$this->setUrlAPI();
}
public function setUrlAPI() {
if (ENVIRONMENT == 'development') {
$this->urlAPI = 'http://core.beautyq/index.php/api/';
}
//enviroment production
if (ENVIRONMENT == 'production') {
$this->urlAPI = 'http://core.beautyq/index.php/api/';
}
}
public function getUrlAPI() {
return $this->urlAPI;
}
public function getAuth() {
return $this->auth;
}
public function getPermission() {
return $this->permission;
}
/**
*
* @param string $action
* @param array $data
* @param string $typeReturn
* @param bool $debug
* @return mixed
*/
public function get_action($action, $data = false, $typeReturn = 'json', $debug = false) {
//debug get action url
if ($debug === true) {
$pathComplete = $this->getUrlAPI() . $action . '.' . $typeReturn;
if ($data AND \is_array($data)) {
$request = $this->curl->simple_post($action, $data);
} else {
$request = $this->curl->simple_get($action);
//var_dump($request);
}
echo "<pre>URL Completa: {$pathComplete}
<br /> Tipo de retorno: {$typeReturn}
<br /> Dados: " . \print_r($data) . "
<br /> Returno: " . \print_r($request);
echo "</pre>";
exit();
die('acabou debug');
}
if ($action) {
$path = $this->getUrlAPI() . $action . '.json';
$action = $path;
if ($data AND \is_array($data)) {
$request = $this->curl->simple_post($action, $data);
} else {
$request = $this->curl->simple_get($action);
}
return \json_decode($request);
}
}
private function _auth($appID, $secret) {
$getHash = $this->get_action('/auth/authorize', array('app_id' => $appID, 'secret' => $secret));
$this->session->set_userdata('API', array('hash' => $getHash->data->hash));
}
public function test() {
\var_dump($this->session->userdata('API'));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment