/** * runs through all api keys registered, testing them for validity, * will up failcount if failed * @param array $options * @return void */ public function key_check(array $options) { $keys = Kingboard_EveApiKey::find(); foreach ($keys as $key) { $this->cli->message("testing {$key['userid']}"); $pheal = new Pheal($key['userid'], $key['apikey']); try { $pheal->Characters(); $this->cli->positive('ok'); } catch (PhealApiException $e) { $this->cli->error('failed'); if (!isset($key['failed'])) { $key->failed = 0; } $key->failed++; $key->save(); } } }
public function create(array $params) { if (!Kingboard_BattleCreate_Form::validate($_POST)) { // @todo handle invalid die; } $user = Kingboard_Auth::getUser(); list($key, $character) = explode('|', $_POST['character']); $key = $user["keys"][$key]; $pheal = new Pheal($key['apiuserid'], $key['apikey'], 'corp'); $contacts = $pheal->ContactList(array('characterID' => $character)); $positives = array(); foreach ($contacts->corporateContactList as $contact) { // accumulate postive standings if ($contact->standing > 0) { $positives[$contact->contactID] = $contact->contactName; } } // alliance standings override corp standings foreach ($contacts->allianceContactList as $contact) { if ($contact->standing > 0) { $positives[$contact->contactID] = $contact->contactName; } else { // negative standings, we only need those if corp has positive, but alliance negative if (isset($positives[$contact->contactID])) { unset($positives[$contact->contactID]); } } } $battleSetting = new Kingboard_BattleSettings(); $battleSetting->startdate = new MongoDate(strtotime($_POST['startdate'])); $battleSetting->user = $user->_id; $battleSetting->enddate = new MongoDate(strtotime($_POST['enddate'])); $battleSetting->system = $_POST['system']; $battleSetting->key = $key; $battleSetting->character = $character; $battleSetting->positives = $positives; $battleSetting->runs = 0; $battleSetting->nextRun = new MongoDate(time()); $battleSetting->save(); // we are done here, lets redirect to the battle! $this->redirect("/battle/" . $battleSetting->_id); }
/** * static method to close open http connections. * example: force closing keep-alive connections that are no longer needed. * @static * @return void */ public static function disconnect() { if (is_resource(self::$curl) && get_resource_type(self::$curl) == 'curl') { curl_close(self::$curl); } self::$curl = null; }
public function api_import(array $options) { $this->cli->message("import running"); $newkills = 0; $oldkills = 0; $errors = 0; $keys = Kingboard_EveApiKey::find(); foreach ($keys as $key) { $pheal = new Pheal($key['userid'], $key['apikey']); $pheal->scope = "account"; try { foreach ($pheal->Characters()->characters as $char) { try { $this->cli->message('trying corp import on ' . $char->name . "..."); $pheal->scope = 'corp'; $kills = $pheal->Killlog(array('characterID' => $char->characterID))->kills; } catch (PhealAPIException $e) { $this->cli->message('corp failed, trying char import now..'); $pheal->scope = 'char'; try { $kills = $pheal->Killlog(array('characterID' => $char->characterID))->kills; } catch (PhealAPIException $e) { continue; } } $this->cli->message("fetch done, parsing now"); $kakp = new Kingboard_ApiKillParser(); $info = $kakp->parseKills($kills); $oldkills += $info['oldkills']; $newkills += $info['newkills']; $errors += $info['errors']; } } catch (PhealApiException $e) { if (!isset($key['failed'])) { $key->failed = 0; } $key->failed++; $key->save(); } catch (PhealException $pe) { $this->cli->message("PhealException caught, auch!"); continue; } } $totalkills = $oldkills + $newkills; $this->cli->message("found {$totalkills} kills, {$oldkills} where allready in database, {$newkills} added ( errors: {$errors})"); }
function getCorpInfo($id) { $pheal = new Pheal(); $pheal->scope = "corp"; try { $result = $pheal->CorporationSheet(array("corporationID" => $id)); } catch (PhealAPIException $e) { return array(); } return array('characterID' => -1, 'characterName' => $result->corporationName, 'corporationID' => $result->corporationID); }