Skip to content

Commit

Permalink
Merge pull request #15 from exodus4d/develop
Browse files Browse the repository at this point in the history
v1.3.2
  • Loading branch information
exodus4d authored Oct 8, 2019
2 parents 392cb81 + cb5ace2 commit 7eecfe2
Show file tree
Hide file tree
Showing 32 changed files with 408 additions and 82 deletions.
182 changes: 154 additions & 28 deletions app/Client/ESI.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace Exodus4D\ESI\Client;

use Exodus4D\ESI\Config;
use Exodus4D\ESI\Mapper;
use Exodus4D\ESI\Mapper\Esi as Mapper;

class ESI extends AbstractCcp implements EsiInterface {

Expand Down Expand Up @@ -74,7 +74,7 @@ public function getServerStatus() : array {
$response = $this->request('GET', $uri, $requestOptions)->getContents();

if(!$response->error){
$serverStatus['status'] = (new Mapper\ServerStatus($response))->getData();
$serverStatus['status'] = (new Mapper\Status\Status($response))->getData();
}else{
$serverStatus['error'] = $response->error;
}
Expand All @@ -95,7 +95,7 @@ public function getCharacterAffiliationData(array $characterIds) : array {

if(!$response->error){
foreach((array)$response as $affiliationData){
$characterAffiliationData[] = (new Mapper\CharacterAffiliation($affiliationData))->getData();
$characterAffiliationData[] = (new Mapper\Character\Affiliation($affiliationData))->getData();
}
}

Expand All @@ -114,7 +114,7 @@ public function getCharacterData(int $characterId) : array {
$response = $this->request('GET', $uri, $requestOptions)->getContents();

if(!$response->error){
$characterData = (new Mapper\Character($response))->getData();
$characterData = (new Mapper\Character\Character($response))->getData();
if( !empty($characterData) ){
$characterData['id'] = $characterId;
}
Expand All @@ -136,7 +136,7 @@ public function getCharacterClonesData(int $characterId, string $accessToken) :
$response = $this->request('GET', $uri, $requestOptions)->getContents();

if(!$response->error){
$clonesData['home'] = (new Mapper\CharacterClone($response->home_location))->getData();
$clonesData['home'] = (new Mapper\Character\CharacterClone($response->home_location))->getData();
}else{
$clonesData['error'] = $response->error;
}
Expand All @@ -157,7 +157,7 @@ public function getCharacterLocationData(int $characterId, string $accessToken)
$response = $this->request('GET', $uri, $requestOptions)->getContents();

if(!$response->error){
$locationData = (new Mapper\Location($response))->getData();
$locationData = (new Mapper\Character\Location($response))->getData();
}

return $locationData;
Expand All @@ -176,7 +176,7 @@ public function getCharacterShipData(int $characterId, string $accessToken) : ar
$response = $this->request('GET', $uri, $requestOptions)->getContents();

if(!$response->error){
$shipData = (new Mapper\Ship($response))->getData();
$shipData = (new Mapper\Character\Ship($response))->getData();
}

return $shipData;
Expand All @@ -195,7 +195,7 @@ public function getCharacterOnlineData(int $characterId, string $accessToken) :
$response = $this->request('GET', $uri, $requestOptions)->getContents();

if(!$response->error){
$onlineData = (new Mapper\Online($response))->getData();
$onlineData = (new Mapper\Character\Online($response))->getData();
}

return $onlineData;
Expand All @@ -213,10 +213,12 @@ public function getCorporationData(int $corporationId) : array {
$response = $this->request('GET', $uri, $requestOptions)->getContents();

if(!$response->error){
$corporationData = (new Mapper\Corporation($response))->getData();
$corporationData = (new Mapper\Corporation\Corporation($response))->getData();
if( !empty($corporationData) ){
$corporationData['id'] = $corporationId;
}
}else{
$corporationData['error'] = $response->error;
}

return $corporationData;
Expand All @@ -234,10 +236,12 @@ public function getAllianceData(int $allianceId) : array {
$response = $this->request('GET', $uri, $requestOptions)->getContents();

if(!$response->error){
$allianceData = (new Mapper\Alliance($response))->getData();
$allianceData = (new Mapper\Alliance\Alliance($response))->getData();
if( !empty($allianceData) ){
$allianceData['id'] = $allianceId;
}
}else{
$allianceData['error'] = $response->error;
}

return $allianceData;
Expand Down Expand Up @@ -280,12 +284,12 @@ public function getUniverseFactions() : array {
$requestOptions = $this->getRequestOptions();
$response = $this->request('GET', $uri, $requestOptions)->getContents();

if(!$response->error){
if($response->error){
$factionData['error'] = $response->error;
}else{
foreach((array)$response as $data){
$factionData['factions'][(int)$data->faction_id] = (new Mapper\Universe\Faction($data))->getData();
}
}else{
$factionData['error'] = $response->error;
}

return $factionData;
Expand All @@ -308,6 +312,44 @@ public function getUniverseFactionData(int $factionId) : array {
return $factionData;
}

/**
* @return array
*/
public function getUniverseRaces() : array {
$uri = $this->getEndpointURI(['universe', 'races', 'list', 'GET']);
$raceData = [];

$requestOptions = $this->getRequestOptions();
$response = $this->request('GET', $uri, $requestOptions)->getContents();

if($response->error){
$raceData['error'] = $response->error;
}else{
foreach((array)$response as $data){
$raceData['races'][(int)$data->race_id] = (new Mapper\Universe\Race($data))->getData();
}
}

return $raceData;
}

/**
* @param int $raceId
* @return array
*/
public function getUniverseRaceData(int $raceId) : array {
$raceDataAll = $this->getUniverseRaces();
$raceData = [];

if(isset($raceDataAll['error'])){
$raceData = $raceDataAll;
}elseif(is_array($raceDataAll['races']) && array_key_exists($raceId, $raceDataAll['races'])){
$raceData = $raceDataAll['races'][$raceId];
}

return $raceData;
}

/**
* @return array
*/
Expand Down Expand Up @@ -337,7 +379,7 @@ public function getUniverseRegionData(int $regionId) : array {
$response = $this->request('GET', $uri, $requestOptions)->getContents();

if(!$response->error){
$regionData = (new Mapper\Region($response))->getData();
$regionData = (new Mapper\Universe\Region($response))->getData();
}

return $regionData;
Expand Down Expand Up @@ -372,7 +414,7 @@ public function getUniverseConstellationData(int $constellationId) : array {
$response = $this->request('GET', $uri, $requestOptions)->getContents();

if(!$response->error){
$constellationData = (new Mapper\Constellation($response))->getData();
$constellationData = (new Mapper\Universe\Constellation($response))->getData();
}

return $constellationData;
Expand Down Expand Up @@ -407,7 +449,7 @@ public function getUniverseSystemData(int $systemId) : array {
$response = $this->request('GET', $uri, $requestOptions)->getContents();

if(!$response->error){
$systemData = (new Mapper\System($response))->getData();
$systemData = (new Mapper\Universe\System($response))->getData();
}

return $systemData;
Expand Down Expand Up @@ -487,20 +529,20 @@ public function getUniverseNamesData(array $universeIds) : array {
$category = $data->category;
switch($category){
case 'character':
$categoryData = (new Mapper\Character($data))->getData();
$categoryData = (new Mapper\Character\Character($data))->getData();
break;
case 'alliance':
$categoryData = (new Mapper\Alliance($data))->getData();
$categoryData = (new Mapper\Alliance\Alliance($data))->getData();
break;
case 'corporation':
$categoryData = (new Mapper\Corporation($data))->getData();
$categoryData = (new Mapper\Corporation\Corporation($data))->getData();
break;
case 'station':
$categoryData = (new Mapper\Station($data))->getData();
$categoryData = (new Mapper\Universe\Station($data))->getData();
break;
case 'solar_system':
$category = 'system';
$categoryData = (new Mapper\System($data))->getData();
$categoryData = (new Mapper\Universe\System($data))->getData();
break;
case 'inventory_type':
$category = 'inventoryType';
Expand Down Expand Up @@ -650,7 +692,9 @@ public function getUniverseStructureData(int $structureId, string $accessToken)
$requestOptions = $this->getRequestOptions($accessToken);
$response = $this->request('GET', $uri, $requestOptions)->getContents();

if(!$response->error){
if($response->error){
$structureData['error'] = $response->error;
}else{
$structureData = (new Mapper\Universe\Structure($response))->getData();
if( !empty($structureData) ){
$structureData['id'] = $structureId;
Expand All @@ -660,6 +704,26 @@ public function getUniverseStructureData(int $structureId, string $accessToken)
return $structureData;
}

/**
* @param int $stationId
* @return array
*/
public function getUniverseStationData(int $stationId) : array {
$uri = $this->getEndpointURI(['universe', 'stations', 'GET'], [$stationId]);
$stationData = [];

$requestOptions = $this->getRequestOptions();
$response = $this->request('GET', $uri, $requestOptions)->getContents();

if($response->error){
$stationData['error'] = $response->error;
}else{
$stationData = (new Mapper\Universe\Station($response))->getData();
}

return $stationData;
}

/**
* @param int $typeId
* @return array
Expand All @@ -678,6 +742,47 @@ public function getUniverseTypesData(int $typeId) : array {
return $typesData;
}

/**
* @param int $attributeId
* @return array
*/
public function getDogmaAttributeData(int $attributeId) : array {
$uri = $this->getEndpointURI(['dogma', 'attributes', 'GET'], [$attributeId]);
$attributeData = [];

$requestOptions = $this->getRequestOptions();
$response = $this->request('GET', $uri, $requestOptions)->getContents();

if($response->error){
$attributeData['error'] = $response->error;
}else{
$attributeData = (new Mapper\Dogma\Attribute($response))->getData();
}

return $attributeData;
}

/**
* @return array
*/
public function getFactionWarSystems() : array {
$uri = $this->getEndpointURI(['fw', 'systems', 'GET']);
$systemsData = [];

$requestOptions = $this->getRequestOptions();
$response = $this->request('GET', $uri, $requestOptions)->getContents();

if($response->error){
$systemsData['error'] = $response->error;
}else{
foreach((array)$response as $data){
$systemsData['systems'][(int)$data->solar_system_id] = (new Mapper\FactionWarfare\System($data))->getData();
}
}

return $systemsData;
}

/**
* @param int $sourceId
* @param int $targetId
Expand Down Expand Up @@ -721,26 +826,26 @@ public function getRouteData(int $sourceId, int $targetId, array $options = [])
}

/**
* @param int $systemId
* @param int $destinationId
* @param string $accessToken
* @param array $options
* @return array
*/
public function setWaypoint(int $systemId, string $accessToken, array $options = []) : array {
public function setWaypoint(int $destinationId, string $accessToken, array $options = []) : array {
$uri = $this->getEndpointURI(['ui', 'autopilot', 'waypoint', 'POST']);
$waypointData = [];

$query = [
'add_to_beginning' => var_export( (bool)$options['addToBeginning'], true),
'clear_other_waypoints' => var_export( (bool)$options['clearOtherWaypoints'], true),
'destination_id' => $systemId
'destination_id' => $destinationId
];

$requestOptions = $this->getRequestOptions($accessToken, null, $query);
$response = $this->request('POST', $uri, $requestOptions)->getContents();

// "null" === success => There is no response body send...
if( $response->error ){
if($response->error){
$waypointData['error'] = self::ERROR_ESI_WAYPOINT;
}

Expand Down Expand Up @@ -771,6 +876,27 @@ public function openWindow(int $targetId, string $accessToken) : array {
return $return;
}

/**
* @return array
*/
public function getSovereigntyMap() : array {
$uri = $this->getEndpointURI(['sovereignty', 'map', 'GET']);
$sovData = [];

$requestOptions = $this->getRequestOptions();
$response = $this->request('GET', $uri, $requestOptions)->getContents();

if(!$response->error){
foreach((array)$response as $data){
$sovData['map'][(int)$data->system_id] = (new Mapper\Sovereignty\Map($data))->getData();
}
}else{
$sovData['error'] = $response->error;
}

return $sovData;
}

/**
* @param array $categories
* @param string $search
Expand All @@ -797,7 +923,7 @@ public function search(array $categories, string $search, bool $strict = false)
if($response->error){
$searchData['error'] = $response->error;
}else{
$searchData = (new Mapper\Search($response))->getData();
$searchData = (new Mapper\Search\Search($response))->getData();
}

return $searchData;
Expand All @@ -821,7 +947,7 @@ public function getStatus(string $version = 'last') : array {

if(!$response->error){
foreach((array)$response as $status){
$statusData['status'][] = (new Mapper\EsiStatus($status))->getData();
$statusData['status'][] = (new Mapper\Status($status))->getData();
}
}else{
$statusData['error'] = $response->error;
Expand Down
Loading

0 comments on commit 7eecfe2

Please sign in to comment.