/** * Make all the requests and push responses (as objects if success) to self::responses["public" or "oauth"] */ public static function run() { // Create Public and Oauth Clients self::$clientPublic = new Client(Endpoint::headers()); self::$clientOauth = new Client(Endpoint::headers(TRUE)); // Public $poolPublic = new Pool(self::$clientPublic, self::$requests["public"], ["concurrency" => 20, "fulfilled" => function (Response $response, $index) { // On success we json_decode response $data = json_decode($response->getBody()->getContents(), TRUE); // Create object and push it to responses success $factory = OpenCrest::getFactory(); $object = $factory->create(self::$objects["public"][$index], $data, $response); array_push(self::$responses["public"]["success"], $object); }, "rejected" => function ($reason, $index) { // On failure we push it to responses rejected array_push(self::$responses["public"]["rejected"], ["reason" => $reason, "index" => $index]); }]); self::$promise["public"] = $poolPublic->promise(); self::$promise["public"]->wait(); // Oauth $poolOauth = new Pool(self::$clientOauth, self::$requests["oauth"], ["concurrency" => 20, "fulfilled" => function (Response $response, $index) { // On success we json_decode response $data = json_decode($response->getBody()->getContents(), TRUE); // Create object and push it to responses success $factory = OpenCrest::getFactory(); $object = $factory->create(self::$objects["oauth"][$index], $data, $response); array_push(self::$responses["oauth"]["success"], $object); }, "rejected" => function ($reason, $index) { // On failure we push it to responses rejected array_push(self::$responses["oauth"]["rejected"], ["reason" => $reason, "index" => $index]); }]); self::$promise["oauth"] = $poolOauth->promise(); self::$promise["oauth"]->wait(); }
/** * Create Public and Auth headers for CREST * * @param bool $oauth * @return array */ public static function headers($oauth = false) { if ($oauth) { $headers = ['base_uri' => OpenCrest::getCrestBase(), 'headers' => ['User-Agent' => 'OpenCrest/' . OpenCrest::version(), 'Accept' => 'application/vnd.ccp.eve.Api-' . OpenCrest::getApiVersion() . '+json; charset=utf-8', 'Authorization' => 'Bearer ' . OpenCrest::getToken()]]; } else { $headers = ['base_uri' => OpenCrest::getCrestBase(), 'headers' => ['User-Agent' => 'OpenCrest/' . OpenCrest::version(), 'Accept' => 'application/vnd.ccp.eve.Api-' . OpenCrest::getApiVersion() . '+json; charset=utf-8']]; } return $headers; }
/** * Object constructor * * @param int $relationId */ public function __construct(int $relationId = null) { $this->relationId = $relationId; $this->endpoint = OpenCrest::getEndpoint($this); }