/** * Run the Update * * @return mixed|void */ public function call() { $result = $this->setScope('account')->getPheal()->APIKeyInfo(); $key_info = ApiKeyInfoModel::firstOrNew(['keyID' => $this->api_info->key_id]); $key_info->fill(['accessMask' => $result->key->accessMask, 'type' => $result->key->type, 'expires' => strlen($result->key->expires) > 0 ? $result->key->expires : null]); $key_info->save(); // Lets process the characters for this API // Key. We need to be aware of the fact that it // is possible for characters to move around. foreach ($result->key->characters as $character) { $character_info = ApiKeyInfoCharacters::firstOrNew(['keyID' => $this->api_info->key_id, 'characterID' => $character->characterID]); $character_info->fill(['characterName' => $character->characterName, 'corporationID' => $character->corporationID, 'corporationName' => $character->corporationName]); $character_info->save(); } // Cleanup Characters no longer on this key ApiKeyInfoCharacters::where('keyID', $this->api_info->key_id)->whereNotIn('characterID', array_map(function ($character) { return $character->characterID; }, (array) $result->key->characters))->delete(); return; }
/** * Retreive a character name by character id * * @param int $character_id * * @return string */ public function getCharacterNameById(int $character_id) : string { return ApiKeyInfoCharacters::where('characterID', $character_id)->value('characterName'); }
/** * Returns the characters on a API Key * * @param $key_id * * @return mixed */ public function getCharactersOnApiKey($key_id) { return ApiKeyInfoCharacters::where('keyID', $key_id)->get(); }