Update code style

Cleanup unused code
This commit is contained in:
alphayax 2016-06-25 14:23:07 +02:00
parent fe9fb2852b
commit 4bdc0c05d0
3 changed files with 17 additions and 29 deletions

View File

@ -43,9 +43,9 @@ class Authorize extends Service {
$this->application->loadAppToken();
if( ! $this->application->haveAppToken()){
$this->ask_authorization();
$this->askAuthorization();
while( in_array( $this->status, [self::STATUS_UNKNOWN, self::STATUS_PENDING])){
$this->get_authorization_status();
$this->getAuthorizationStatus();
if( $this->status == self::STATUS_GRANTED){
$this->application->setAppToken( $this->app_token);
$this->application->saveAppToken();
@ -68,7 +68,7 @@ class Authorize extends Service {
* Contact the freebox and ask for App auth
* @throws \Exception
*/
public function ask_authorization(){
public function askAuthorization(){
$rest = $this->getService( self::API_LOGIN_AUTHORIZE);
$rest->POST([
'app_id' => $this->application->getId(),
@ -77,29 +77,21 @@ class Authorize extends Service {
'device_name' => gethostname(),
]);
$response = $rest->getCurlResponse();
if( ! $rest->getSuccess()){
$this->application->getLogger()->addCritical( 'Freebox Error : '. $response['error_code'] .' - '. $response['msg']);
throw new \Exception( $response['msg'], $response['error_code']);
}
$this->app_token = $rest->getResult()['app_token'];
$this->track_id = $rest->getResult()['track_id'];
$this->application->getLogger()->addInfo( 'Authorization send to Freebox. Waiting for response...');
$this->app_token = $response['result']['app_token'];
$this->track_id = $response['result']['track_id'];
}
/**
* @throws \Exception
*/
public function get_authorization_status(){
public function getAuthorizationStatus(){
$rest = $this->getService( self::API_LOGIN_AUTHORIZE . $this->track_id);
$rest->GET();
$result = $rest->getResult();
$this->status = $result['status'];
$this->challenge = $result['challenge'];
$this->status = $rest->getResult()['status'];
$this->challenge = $rest->getResult()['challenge'];
$this->application->getLogger()->addInfo( 'Freebox authorization status : '. $this->status);
}

View File

@ -10,15 +10,16 @@ use alphayax\freebox\utils\Service;
*/
class Session extends Service {
/// APIs services
const API_LOGIN = '/api/v3/login/';
const API_LOGIN_SESSION = '/api/v3/login/session/';
/** @var string */
private $challenge = '';
/** @var string Password Salt */
private $password_salt = '';
/** @var bool Is the user logged */
private $logged_in = false;
/** @var array */
@ -30,30 +31,25 @@ class Session extends Service {
/**
* @throws \Exception
*/
public function ask_login_status(){
public function askLoginStatus(){
$rest = $this->getService( static::API_LOGIN);
$rest->GET();
$result = $rest->getCurlResponse()['result'];
$this->logged_in = $result['logged_in'];
$this->challenge = $result['challenge'];
$this->password_salt = $result['password_salt'];
$this->logged_in = $rest->getResult()['logged_in'];
$this->challenge = $rest->getResult()['challenge'];
$this->password_salt = $rest->getResult()['password_salt'];
}
/**
* @throws \Exception
*/
public function create_session(){
public function createSession(){
$rest = $this->getService( static::API_LOGIN_SESSION);
$rest->POST([
'app_id' => $this->application->getId(),
'password' => hash_hmac( 'sha1', $this->challenge, $this->application->getAppToken()),
]);
if( ! $rest->getSuccess()){
throw new \Exception( $rest->getCurlResponse()['error_code'] .' : '. $rest->getCurlResponse()['msg']);
}
$this->session_token = $rest->getResult()['session_token'];
$this->permissions = $rest->getResult()['permissions'];
}

View File

@ -84,8 +84,8 @@ class Application {
*/
public function openSession(){
$Login = new services\login\Session( $this);
$Login->ask_login_status();
$Login->create_session();
$Login->askLoginStatus();
$Login->createSession();
$this->permissions = $Login->getPermissions();
$this->session_token = $Login->getSessionToken();