/** * Class constructor. Called on every page load. * @param $keyID integer * @param $vCode string * @param $user object/integer * @param $db PDO object */ public function __construct($keyID, $vCode, $user, $db) { /** Saving the database into the db param */ $this->_db = $db; /** Determining if we're live or a cronjob -- */ if (is_object($user)) { /** We're dealing with a live user */ $this->_userID = $user->getUserID(); } else { $this->_userID = $user; } /** Saving the API key keyID and vCode */ $this->_keyID = $keyID; $this->_vCode = $vCode; /** Creating a new Phealng object */ $pheal = new Pheal($keyID, $vCode, 'account'); /** Starting a Phealng lookup */ try { $response = $pheal->APIKeyInfo(); /** Checking to see if we received a valid response */ if (!isset($response->code) && $response->key->accessMask & MINIMUM_API_MASK) { $this->_keyStatus = 1; $this->_accessMask = $response->key->accessMask; $this->_keyExpiration = $response->key->expires; $this->_keyType = $response->key->type; if ($response->key->expires == null) { $this->_keyExpiration = 'No Expiration'; } else { $this->_keyExpiration = $response->key->expires; } $response2 = $pheal->AccountStatus(); if ($response2->paidUntil == null) { $this->_accountStatus = "Account Unsubscribed"; } else { $this->_accountStatus = $response2->paidUntil; } $i = 1; foreach ($response->key->characters as $character) { if ($character->allianceID == "0") { $allianceID = 0; $allianceName = "No Alliance"; } else { $allianceID = $character->allianceID; $allianceName = $character->allianceName; } $this->_characters[$i] = array('characterName' => $character->characterName, 'characterID' => $character->characterID, 'corporationName' => $character->corporationName, 'corporationID' => $character->corporationID, 'allianceName' => $allianceName, 'allianceID' => $allianceID); $i++; } } else { $this->_keyStatus = 0; $this->keyError = $this->parseKeyError($response->code, 'code'); } } catch (\Pheal\Exceptions\PhealException $e) { $this->keyError = $this->parseKeyError($e, 'exception'); $this->_keyStatus = 0; $_SESSION['alert'] = new Alert('danger', 'API Key Error', $e->getMessage()); } }
public function __construct($keyID, $vcode, $user, $db) { $this->db = $db; if (is_object($user)) { $this->uid = $user->getUID(); } else { $this->uid = $user; } $this->keyID = $keyID; $this->vcode = $vcode; $pheal = new Pheal($keyID, $vcode, 'account'); try { $response = $pheal->APIKeyInfo(); if (!isset($response->code) and $response->key->accessMask & MINIMUM_API) { $this->keyStatus = 1; $this->accessMask = $response->key->accessMask; $this->expires = $response->key->expires; $this->keyType = $response->key->type; if ($response->key->expires == NULL) { $this->expires = 'No Expiration'; } else { $this->expires = $response->key->expires; } $response2 = $pheal->AccountStatus(); if ($response2->paidUntil == NULL) { $this->accountStatus = "Account Unsubscribed"; } else { $this->accountStatus = $response2->paidUntil; } $i = 1; foreach ($response->key->characters as $character) { if ($character->allianceID == "0") { $allianceID = 0; $allianceName = "No Alliance"; } else { $allianceID = $character->allianceID; $allianceName = $character->allianceName; } $this->characters[$i] = array('characterName' => $character->characterName, 'characterID' => $character->characterID, 'corporationName' => $character->corporationName, 'corporationID' => $character->corporationID, 'allianceName' => $allianceName, 'allianceID' => $allianceID); $i++; } } else { $this->keyStatus = 0; $this->keyError = $this->parseKeyError($response->code, 'code'); } } catch (\Pheal\Exceptions\PhealException $e) { $this->keyError = $this->parseKeyError($e, 'exception'); $this->keyStatus = 0; setAlert('danger', 'API Key Error', $e->getMessage()); } }