Example #1
0
File: API.php Project: m6w6/seekat
 /**
  * Import handler for the endpoint's underlying data
  *
  * \seekat\Call will call this when the request will have finished.
  *
  * @param Response $response
  * @return API self
  * @throws UnexpectedValueException
  * @throws RequestException
  * @throws \Exception
  */
 function import(Response $response) : API
 {
     $this->__log->info(__FUNCTION__ . ": " . $response->getInfo(), ["url" => (string) $this->__url]);
     if ($response->getResponseCode() >= 400) {
         $e = new RequestException($response);
         $this->__log->critical(__FUNCTION__ . ": " . $e->getMessage(), ["url" => (string) $this->__url]);
         throw $e;
     }
     if (!($type = $response->getHeader("Content-Type", Header::class))) {
         $e = new RequestException($response);
         $this->__log->error(__FUNCTION__ . ": Empty Content-Type -> " . $e->getMessage(), ["url" => (string) $this->__url]);
         throw $e;
     }
     try {
         $this->__type = new ContentType($type);
         $this->__data = $this->__type->parseBody($response->getBody());
         if ($link = $response->getHeader("Link", Header::class)) {
             $this->__links = new Links($link);
         }
     } catch (\Exception $e) {
         $this->__log->error(__FUNCTION__ . ": " . $e->getMessage(), ["url" => (string) $this->__url]);
         throw $e;
     }
     return $this;
 }