Skip to content

Commit

Permalink
Merge pull request #12 from exodus4d/develop
Browse files Browse the repository at this point in the history
v1.2.5
  • Loading branch information
exodus4d committed Jul 15, 2018
2 parents a9b7706 + f7bfa31 commit d7c5764
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
34 changes: 21 additions & 13 deletions app/ESI.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,18 @@ public function getAllianceData(int $allianceId) : array {
* @return array
*/
public function getCorporationRoles(int $corporationId, string $accessToken) : array {
// 403 'Character cannot grant roles' error
$additionalOptions['suppressHTTPLogging'] = [403];

$url = $this->getEndpointURL(['corporations', 'roles', 'GET'], [$corporationId]);
$rolesData = [];
$response = $this->request($url, 'GET', $accessToken);
$response = $this->request($url, 'GET', $accessToken, $additionalOptions);

if( !empty($response) ){
if($response->error){
$rolesData['error'] = $response->error;
}elseif( !empty($response) ){
foreach((array)$response as $characterRuleData){
$rolesData[(int)$characterRuleData->character_id] = array_map('strtolower', (array)$characterRuleData->roles);
$rolesData['roles'][(int)$characterRuleData->character_id] = array_map('strtolower', (array)$characterRuleData->roles);
}
}

Expand All @@ -315,7 +320,7 @@ public function getUniverseRegions() : array {
$regionData = [];
$response = $this->request($url, 'GET');

if( !empty($response) ){
if( !$response->error && !empty($response) ){
$regionData = array_unique( array_map('intval', $response) );
}

Expand All @@ -331,7 +336,7 @@ public function getUniverseRegionData(int $regionId) : array {
$regionData = [];
$response = $this->request($url, 'GET');

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

Expand All @@ -346,7 +351,7 @@ public function getUniverseConstellations() : array{
$constellationData = [];
$response = $this->request($url, 'GET');

if( !empty($response) ){
if( !$response->error && !empty($response) ){
$constellationData = array_unique( array_map('intval', $response) );
}

Expand All @@ -362,7 +367,7 @@ public function getUniverseConstellationData(int $constellationId) : array {
$constellationData = [];
$response = $this->request($url, 'GET');

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

Expand All @@ -377,7 +382,7 @@ public function getUniverseSystems() : array{
$systemData = [];
$response = $this->request($url, 'GET');

if( !empty($response) ){
if( !$response->error && !empty($response) ){
$systemData = array_unique( array_map('intval', $response) );
}

Expand All @@ -393,7 +398,7 @@ public function getUniverseSystemData(int $systemId) : array {
$systemData = [];
$response = $this->request($url, 'GET');

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

Expand All @@ -409,7 +414,7 @@ public function getUniverseStarData(int $starId) : array {
$starData = [];
$response = $this->request($url, 'GET');

if( !empty($response) ){
if( !$response->error && !empty($response) ){
$starData = (new namespace\Mapper\Universe\Star($response))->getData();
if( !empty($starData) ){
$starData['id'] = $starId;
Expand All @@ -428,7 +433,7 @@ public function getUniversePlanetData(int $planetId) : array {
$planetData = [];
$response = $this->request($url, 'GET');

if( !empty($response) ){
if( !$response->error && !empty($response) ){
$planetData = (new namespace\Mapper\Universe\Planet($response))->getData();
}

Expand All @@ -444,7 +449,7 @@ public function getUniverseStargateData(int $stargateId) : array {
$stargateData = [];
$response = $this->request($url, 'GET');

if( !empty($response) ){
if( !$response->error && !empty($response) ){
$stargateData = (new namespace\Mapper\Universe\Stargate($response))->getData();
}

Expand Down Expand Up @@ -659,6 +664,9 @@ public function getUniverseTypesData(int $typeId, array $additionalOptions = [])
* @return array
*/
public function getRouteData(int $sourceId, int $targetId, array $options = []) : array {
// 404 'No route found' error
$additionalOptions['suppressHTTPLogging'] = [404];

$urlParams = [];
if( !empty($options['avoid']) ){
$urlParams['avoid'] = $options['avoid'];
Expand All @@ -677,7 +685,7 @@ public function getRouteData(int $sourceId, int $targetId, array $options = [])

$url = $this->getEndpointURL(['routes', 'GET'], [$sourceId, $targetId], $urlParams);
$routeData = [];
$response = $this->request($url, 'GET');
$response = $this->request($url, 'GET', '', $additionalOptions);

if($response->error){
$routeData['error'] = $response->error;
Expand Down
16 changes: 9 additions & 7 deletions app/Lib/WebClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -383,13 +383,15 @@ public function request( $url, array $options = null, $additionalOptions = [], $
case 'ok': // HTTP 2xx
break;
case 'err_client': // HTTP 4xx
$errorMsg = $this->getErrorMessageFromJsonResponse(
$statusCode,
$options['method'],
$url,
$responseBody
);
$this->getLogger($statusType)->write($errorMsg);
if( !in_array($statusCode, (array)$additionalOptions['suppressHTTPLogging']) ){
$errorMsg = $this->getErrorMessageFromJsonResponse(
$statusCode,
$options['method'],
$url,
$responseBody
);
$this->getLogger($statusType)->write($errorMsg);
}
break;
case 'err_server': // HTTP 5xx
$retry = true;
Expand Down

0 comments on commit d7c5764

Please sign in to comment.