Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eve Scout Fix #3

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 32 additions & 8 deletions app/Client/EveScout/EveScout.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,44 @@ class EveScout extends Client\AbstractApi implements EveScoutInterface {
/**
* @return RequestConfig
*/
protected function getTheraConnectionsRequest() : RequestConfig {
protected function getTheraConnectionsRequest(): RequestConfig {
return new RequestConfig(
WebClient::newRequest('GET', $this->getConfig()->getEndpoint(['wormholes', 'GET'])),
WebClient::newRequest('GET', $this->getConfig()->getEndpoint(['signatures', 'GET'])),
[],
function($body) : array {
function($body): array {
$connectionsData = [];
if(!$body->error){
foreach((array)$body as $data){
$connectionsData['connections'][(int)$data->id] = (new Mapper\Connection($data))->getData();
}
}else{
if(isset($body->error)){
$connectionsData['error'] = $body->error;
return $connectionsData;
}

foreach ($body as $data) {
$connectionId = (int)$data->id;
$wh_type = (string)$data->wh_type;
$target_region_id = (int)$data->in_region_id;
$target_region_name = (string)$data->in_region_name;
$outbound = (bool)$data->wh_exits_outward;
$remaining_hours = (int)$data->remaining_hours;


$connectionData = (new Mapper\Connection($data))->getData();
// Add connection data
$connectionsData['connections'][$connectionId] = $connectionData;

// Set End of Life status
$connectionsData['connections'][$connectionId]['eol'] = $remaining_hours <= 4 ? "critical" : "fresh";

// Determine wormhole types
$outboundSig = $outbound ? 'sourceSignature' : 'targetSignature';
$connectionsData['connections'][$connectionId][$outboundSig]['type'] = $wh_type;


// Need to fix iterator to handle nesting so for now pulling out the region
// 'in_region_id' => ['target' => ['region' => 'id']],
$connectionsData['connections'][$connectionId]['target']['region']['id'] = $target_region_id;
// 'in_region_name' => ['target' => ['region' => 'name']],
$connectionsData['connections'][$connectionId]['target']['region']['name'] = $target_region_name;
}
return $connectionsData;
}
);
Expand Down
4 changes: 2 additions & 2 deletions app/Config/EveScout/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class Config extends AbstractConfig {
* @var array
*/
protected static $spec = [
'wormholes' => [
'GET' => '/api/wormholes'
'signatures' => [
'GET' => 'v2/public/signatures'
]
];
}
36 changes: 18 additions & 18 deletions app/Mapper/EveScout/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@ class Connection extends AbstractIterator {
*/
protected static $map = [
'id' => 'id',
'type' => 'type',
'signature_type' => 'type',
'in_system_name' => 'name',
'completed' => ['state' => 'name'],
'updated_at' => ['state' => 'updated'],

'status' => ['state' => 'name'],
'statusUpdatedAt' => ['state' => 'updated'],
//Thera || Turner
'out_system_id' => ['source' => 'id'],
'out_system_name' => ['source' => 'name'],
'out_signature' => ['sourceSignature' => 'name'],

'sourceSolarSystem' => 'source',
'destinationSolarSystem' => 'target',
//Connection
'in_system_id' => ['target' => 'id'],
'in_system_name' => ['target' => 'name'],
'in_signature' => ['targetSignature' => 'name'],

'signatureId' => ['sourceSignature' => 'name'],
'sourceWormholeType' => ['sourceSignature' => 'type'],

'expires_at' => ['wormhole' => 'estimatedEol'],

'wormholeDestinationSignatureId' => ['targetSignature' => 'name'],
'destinationWormholeType' => ['targetSignature' => 'type'],
'created_at' => 'created',
'updated_at' => 'updated',

'wormholeMass' => ['wormhole' => 'mass'],
'wormholeEol' => ['wormhole' => 'eol'],
'wormholeEstimatedEol' => ['wormhole' => 'estimatedEol'],

'createdAt' => 'created',
'updatedAt' => 'updated',

'createdById' => ['character' => 'id'],
'createdBy' => ['character' => 'name']
'created_by_id' => ['character' => 'id'],
'created_by_name' => ['character' => 'name']
];
}