diff --git a/README.md b/README.md index a9c9dbf..478a079 100644 --- a/README.md +++ b/README.md @@ -1 +1,25 @@ -# pathfinder_esi \ No newline at end of file +### [_EVE-Online_](https://www.eveonline.com) - [_ESI_ API](https://esi.tech.ccp.is) client library for [_Pathfinder_](https://github.com/exodus4d/pathfinder) + +This ESI API client handles all _ESI_ API calls within _Pathfinder_ (`>= v.1.2.3`) and implements all required endpoints. + +#### Installation +This _ESI_ client is automatically installed through [_Composer_](https://getcomposer.org/) with all dependencies from your _Pathfinder_ project root. (see [composer.json](https://github.com/exodus4d/pathfinder/blob/master/composer.json)). + +A newer version of _Pathfinder_ **may** require a newer version of this client as well. So running `composer install` **after** a _Pathfinder_ update will upgrade/install a newer _ESI_ client. +Check the _Pathfinder_ [release](https://github.com/exodus4d/pathfinder/releases) notes for further information. + +#### Bug report +Issues can be tracked here: https://github.com/exodus4d/pathfinder/issues + +#### Development +If you are a developer you might have **both** repositories ([exodus4d/pathfinder](https://github.com/exodus4d/pathfinder), [exodus4d/pathfinder_esi](https://github.com/exodus4d/pathfinder_esi) ) checked out locally. + +In this case you probably want to _test_ changes in your **local** [exodus4d/pathfinder_esi](https://github.com/exodus4d/pathfinder_esi) repo using your **local** [exodus4d/pathfinder](https://github.com/exodus4d/pathfinder) installation. + +1. Clone/Checkout **both** repositories local next to each other +2. Make your changes in your pathfinder_esi repo and **commit** changes (no push!) +3. Switch to your pathfinder repo +4. Run _Composer_ with [`composer-dev.json`](https://github.com/exodus4d/pathfinder/blob/master/composer-dev.json), which installs pathfinder_esi from your **local** repository. + - Unix: `$set COMPOSER=composer-dev.json && composer update` + - Windows (PowerShell): `$env:COMPOSER="composer-dev.json"; composer update --no-suggest` + diff --git a/app/ApiInterface.php b/app/ApiInterface.php index 72f2572..63ac054 100644 --- a/app/ApiInterface.php +++ b/app/ApiInterface.php @@ -153,6 +153,14 @@ public function getUniverseTypesData(int $typeId, array $additionalOptions = []) */ public function openWindow(int $targetId, string $accessToken): array; + /** + * @param int $sourceId + * @param int $targetId + * @param array $options + * @return array + */ + public function getRouteData(int $sourceId, int $targetId, array $options = []): array; + /** * @param int $corporationId * @return bool diff --git a/app/Config/ESIConf.php b/app/Config/ESIConf.php index 7b743eb..babebd2 100644 --- a/app/Config/ESIConf.php +++ b/app/Config/ESIConf.php @@ -71,6 +71,9 @@ class ESIConf extends \Prefab { 'GET' => '/v3/universe/types/{x}/' ] ], + 'routes' => [ + 'GET' => '/v1/route/{x}/{x}/' + ], 'ui' => [ 'autopilot' => [ 'waypoint' => [ diff --git a/app/ESI.php b/app/ESI.php index 085fc9a..b737bd5 100644 --- a/app/ESI.php +++ b/app/ESI.php @@ -511,6 +511,42 @@ public function openWindow(int $targetId, string $accessToken): array{ return $return; } + /** + * @param int $sourceId + * @param int $targetId + * @param array $options + * @return array + */ + public function getRouteData(int $sourceId, int $targetId, array $options = []): array { + $urlParams = []; + if( !empty($options['avoid']) ){ + $urlParams['avoid'] = $options['avoid']; + } + if( !empty($options['connections']) ){ + $urlParams['connections'] = $options['connections']; + } + if( !empty($options['flag']) ){ + $urlParams['flag'] = $options['flag']; + } + + $urlParams = $this->formatUrlParams($urlParams, [ + 'connections' => [',', '|'], + 'avoid' => [','] + ]); + + $url = $this->getEndpointURL(['routes', 'GET'], [$sourceId, $targetId], $urlParams); + $routeData = []; + $response = $this->request($url, 'GET'); + + if($response->error){ + $routeData['error'] = $response->error; + }else{ + $routeData['route'] = array_unique( array_map('intval', $response) ); + } + + return $routeData; + } + /** * @param int $corporationId * @return bool @@ -535,6 +571,25 @@ protected function getNpcCorporations(): array{ return $npcCorporations; } + protected function formatUrlParams(array $urlParams = [], array $format = []) : array { + + $formatter = function(&$item, $key, $params) use (&$formatter) { + $params['depth'] = isset($params['depth']) ? ++$params['depth'] : 0; + $params['firstKey'] = isset($params['firstKey']) ? $params['firstKey'] : $key; + + if(is_array($item)){ + if($delimiter = $params[$params['firstKey']][$params['depth']]){ + array_walk($item, $formatter, $params); + $item = implode($delimiter, $item); + } + } + }; + + array_walk($urlParams, $formatter, $format); + + return $urlParams; + } + /** * get/build endpoint URL * @param array $path diff --git a/app/Lib/WebClient.php b/app/Lib/WebClient.php index 355665d..2241e87 100644 --- a/app/Lib/WebClient.php +++ b/app/Lib/WebClient.php @@ -349,7 +349,7 @@ public function request( $url, array $options = null, $additionalOptions = [], $ $parsedResponseHeaders = $this->parseHeaders($responseHeaders); // check response headers $this->checkResponseHeaders($parsedResponseHeaders, $url); - $statusCode = $this->getStatusCodeFromHeaders($responseHeaders); + $statusCode = $this->getStatusCodeFromHeaders($parsedResponseHeaders); $statusType = $this->getStatusType($statusCode); switch($statusType){