Skip to content

Commit

Permalink
Merge pull request #10 from exodus4d/develop
Browse files Browse the repository at this point in the history
v1.2.3
  • Loading branch information
exodus4d authored Apr 7, 2018
2 parents e46f7f4 + 7327377 commit dd066bc
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 2 deletions.
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,25 @@
# pathfinder_esi
### [_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`

8 changes: 8 additions & 0 deletions app/ApiInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions app/Config/ESIConf.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ class ESIConf extends \Prefab {
'GET' => '/v3/universe/types/{x}/'
]
],
'routes' => [
'GET' => '/v1/route/{x}/{x}/'
],
'ui' => [
'autopilot' => [
'waypoint' => [
Expand Down
55 changes: 55 additions & 0 deletions app/ESI.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/Lib/WebClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down

0 comments on commit dd066bc

Please sign in to comment.