Skip to content

Commit

Permalink
Merge pull request #14 from exodus4d/develop
Browse files Browse the repository at this point in the history
v1.3.1
  • Loading branch information
exodus4d authored May 7, 2019
2 parents 34859f0 + f961a0f commit 392cb81
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/Client/AbstractApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ protected function initStack(HandlerStack &$stack) : void {

if($this->getAcceptType() == 'json'){
// json middleware prepares request and response for JSON data
$stack->push( GuzzleJsonMiddleware::factory(), 'json');
$stack->push(GuzzleJsonMiddleware::factory(), 'json');
}

// error log middleware logs all request errors
Expand Down
68 changes: 63 additions & 5 deletions app/Client/ESI.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ public function getServerStatus() : array {
$serverStatus['status'] = (new Mapper\ServerStatus($response))->getData();
}else{
$serverStatus['error'] = $response->error;

}

return $serverStatus;
Expand Down Expand Up @@ -124,6 +123,27 @@ public function getCharacterData(int $characterId) : array {
return $characterData;
}

/**
* @param int $characterId
* @param string $accessToken
* @return array
*/
public function getCharacterClonesData(int $characterId, string $accessToken) : array {
$uri = $this->getEndpointURI(['characters', 'clones', 'GET'], [$characterId]);
$clonesData = [];

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

if(!$response->error){
$clonesData['home'] = (new Mapper\CharacterClone($response->home_location))->getData();
}else{
$clonesData['error'] = $response->error;
}

return $clonesData;
}

/**
* @param int $characterId
* @param string $accessToken
Expand Down Expand Up @@ -240,8 +260,8 @@ public function getCorporationRoles(int $corporationId, string $accessToken) : a
$response = $this->request('GET', $uri, $requestOptions)->getContents();

if(!$response->error){
foreach((array)$response as $characterRuleData){
$rolesData['roles'][(int)$characterRuleData->character_id] = array_map('strtolower', (array)$characterRuleData->roles);
foreach((array)$response as $characterRoleData){
$rolesData['roles'][(int)$characterRoleData->character_id] = array_map('strtolower', (array)$characterRoleData->roles);
}
}else{
$rolesData['error'] = $response->error;
Expand All @@ -250,6 +270,44 @@ public function getCorporationRoles(int $corporationId, string $accessToken) : a
return $rolesData;
}

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

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

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

return $factionData;
}

/**
* @param int $factionId
* @return array
*/
public function getUniverseFactionData(int $factionId) : array {
$factionDataAll = $this->getUniverseFactions();
$factionData = [];

if(isset($factionDataAll['error'])){
$factionData = $factionDataAll;
}elseif(is_array($factionDataAll['factions']) && array_key_exists($factionId, $factionDataAll['factions'])){
$factionData = $factionDataAll['factions'][$factionId];
}

return $factionData;
}

/**
* @return array
*/
Expand Down Expand Up @@ -288,7 +346,7 @@ public function getUniverseRegionData(int $regionId) : array {
/**
* @return array
*/
public function getUniverseConstellations() : array{
public function getUniverseConstellations() : array {
$uri = $this->getEndpointURI(['universe', 'constellations', 'list', 'GET']);
$constellationData = [];

Expand Down Expand Up @@ -323,7 +381,7 @@ public function getUniverseConstellationData(int $constellationId) : array {
/**
* @return array
*/
public function getUniverseSystems() : array{
public function getUniverseSystems() : array {
$uri = $this->getEndpointURI(['universe', 'systems', 'list', 'GET']);
$systemData = [];

Expand Down
7 changes: 7 additions & 0 deletions app/Client/EsiInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ public function getCharacterAffiliationData(array $characterIds) : array;
*/
public function getCharacterData(int $characterId) : array;

/**
* @param int $characterId
* @param string $accessToken
* @return array
*/
public function getCharacterClonesData(int $characterId, string $accessToken) : array;

/**
* @param int $characterId
* @param string $accessToken
Expand Down
8 changes: 8 additions & 0 deletions app/Config/ESIConf.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class ESIConf extends \Prefab {
'affiliation' => [
'POST' => '/v1/characters/affiliation/'
],
'clones' => [
'GET' => '/v3/characters/{x}/clones/'
],
'location' => [
'GET' => '/v1/characters/{x}/location/'
],
Expand All @@ -54,6 +57,11 @@ class ESIConf extends \Prefab {
'names' => [
'POST' => '/v3/universe/names/'
],
'factions' => [
'list' => [
'GET' => '/v2/universe/factions/'
]
],
'system_jumps' => [
'GET' => '/v1/universe/system_jumps/'
],
Expand Down
17 changes: 17 additions & 0 deletions app/Mapper/CharacterClone.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php


namespace Exodus4D\ESI\Mapper;

use data\mapper;

class CharacterClone extends mapper\AbstractIterator {

/**
* @var array
*/
protected static $map = [
'location_id' => ['location' => 'id'],
'location_type' => ['location' => 'type']
];
}
26 changes: 26 additions & 0 deletions app/Mapper/Universe/Faction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* Created by PhpStorm.
* User: Exodus 4D
* Date: 30.03.2019
* Time: 10:57
*/

namespace Exodus4D\ESI\Mapper\Universe;

use data\mapper;

class Faction extends mapper\AbstractIterator {

/**
* @var array
*/
protected static $map = [
'faction_id' => 'id',
'name' => 'name',
'description' => 'description',
'size_factor' => 'sizeFactor',
'station_count' => 'stationCount',
'station_system_count' => 'stationSystemCount'
];
}

0 comments on commit 392cb81

Please sign in to comment.