Skip to content

Commit

Permalink
closed #163 added CREST endpoint support for "waypoints"
Browse files Browse the repository at this point in the history
  • Loading branch information
exodus4d committed May 21, 2016
1 parent 46ea77d commit 1b4b8af
Show file tree
Hide file tree
Showing 9 changed files with 451 additions and 172 deletions.
47 changes: 43 additions & 4 deletions app/main/controller/api/system.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

namespace Controller\Api;
use Controller\Ccp\Sso;
use Data\Mapper as Mapper;
use Model;

Expand Down Expand Up @@ -318,10 +319,9 @@ public function constellationData(\Base $f3, $params){
$return->error = [];
$return->systemData = [];

$constellationId = 0;
$activeCharacter = $this->getCharacter();
if( $activeCharacter = $this->getCharacter() ){
$constellationId = 0;

if($activeCharacter){
// check for search parameter
if( isset($params['arg1']) ){
$constellationId = (int)$params['arg1'];
Expand All @@ -346,12 +346,51 @@ public function constellationData(\Base $f3, $params){
echo json_encode($return);
}

/**
* set destination for specific systemIds
* @param \Base $f3
*/
public function setDestination(\Base $f3){
$postData = (array)$f3->get('POST');

$return = (object) [];
$return->error = [];
$return->systemData = [];

if(
($activeCharacter = $this->getCharacter()) &&
!empty($postData['systemData'])
){
$return->clearOtherWaypoints = (bool)$postData['clearOtherWaypoints'];
$return->first = (bool)$postData['first'];

/**
* @var Sso $ssoController
*/
$ssoController = self::getController('Sso');
foreach($postData['systemData'] as $systemData){
$waypointData = $ssoController->setWaypoint($activeCharacter, $systemData['systemId'], [
'clearOtherWaypoints' => $return->clearOtherWaypoints,
'first' => $return->first,
]);
if($waypointData['systemId']){
$return->systemData[] = $systemData;
}elseif( isset($waypointData['error']) ){
$return->error[] = $waypointData['error'];
}
}
}

echo json_encode($return);
}


/**
* delete systems and all its connections
* @param \Base $f3
*/
public function delete(\Base $f3){
$systemIds = $f3->get('POST.systemIds');
$systemIds = (array)$f3->get('POST.systemIds');

if($activeCharacter = $this->getCharacter()){
/**
Expand Down
61 changes: 61 additions & 0 deletions app/main/controller/ccp/sso.php
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,67 @@ public function getCharacterLocationData($accessToken, $ttl = 10, $additionalOpt
return $locationData;
}

/**
* set new ingame waypoint
* @param Model\CharacterModel $character
* @param int $systemId
* @param array $options
* @return array
*/
public function setWaypoint( Model\CharacterModel $character, $systemId, $options = []){
$crestUrlParts = parse_url( self::getCrestEndpoint() );
$waypointData = [];

if( $crestUrlParts ){
$endpointUrl = self::getCrestEndpoint() . '/characters/' . $character->_id . '/navigation/waypoints/';
$systemEndpoint = self::getCrestEndpoint() . '/solarsystems/' . $systemId . '/';

// request body
$content = [
'clearOtherWaypoints' => (bool)$options['clearOtherWaypoints'],
'first' => (bool)$options['first'],
'solarSystem' => [
'href' => $systemEndpoint,
'id' => (int)$systemId
]
];

$requestOptions = [
'timeout' => self::CREST_TIMEOUT,
'method' => 'POST',
'user_agent' => $this->getUserAgent(),
'header' => [
'Scope: characterNavigationWrite',
'Authorization: Bearer ' . $character->getAccessToken(),
'Host: ' . $crestUrlParts['host'],
'Content-Type: application/vnd.ccp.eve.PostWaypoint-v1+json;charset=utf-8',
],
'content' => json_encode($content, JSON_UNESCAPED_SLASHES)
];

$apiResponse = Lib\Web::instance()->request($endpointUrl, $requestOptions);

if( isset($apiResponse['body']) ){
$responseData = json_decode($apiResponse['body']);

if( empty($responseData) ){
$waypointData['systemId'] = (int)$systemId;
}elseif(
isset($responseData->message) &&
isset($responseData->key)
){
// waypoint could not be set...
$error = (object) [];
$error->type = 'error';
$error->message = $responseData->key;
$waypointData['error'] = $error;
}
}
}

return $waypointData;
}

/**
* update character
* @param $characterData
Expand Down
Loading

0 comments on commit 1b4b8af

Please sign in to comment.