projects
/
m6w6
/
seekat
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
|
github
raw
|
inline
| side by side
PHP8
[m6w6/seekat]
/
lib
/
API
/
Call
/
Result.php
diff --git
a/lib/API/Call/Result.php
b/lib/API/Call/Result.php
index 6e1d8f818f0251196d7d6cf158b6a76917ee485a..c1cee55e6a32edcb02ee6304ee37f38699afde48 100644
(file)
--- a/
lib/API/Call/Result.php
+++ b/
lib/API/Call/Result.php
@@
-7,25
+7,31
@@
use http\Header;
use seekat\API;
use seekat\Exception\RequestException;
use seekat\API;
use seekat\Exception\RequestException;
-final class Result
-{
+final class Result {
private $api;
function __construct(API $api) {
$this->api = $api;
}
private $api;
function __construct(API $api) {
$this->api = $api;
}
+ /**
+ * @param Response $response
+ * @return API
+ * @throws RequestException
+ */
function __invoke(Response $response) : API {
function __invoke(Response $response) : API {
- $hit = $response->getHeader("X-Cache-Time") ? "cached" : "enqueued";
- $this->api->getLogger()->info("$hit -> response", [
- "url" => (string) $this->api->getUrl(),
- "info" => $response->getInfo(),
- ]);
-
$links = $this->checkResponseMeta($response);
$type = $this->checkResponseType($response);
$data = $this->checkResponseBody($response, $type);
$links = $this->checkResponseMeta($response);
$type = $this->checkResponseType($response);
$data = $this->checkResponseBody($response, $type);
+ $this->api->getLogger()->info("response -> info", [
+ "type" => $type->getType(),
+ "links" => $links->getRelations(),
+ ]);
+ $this->api->getLogger()->debug("response -> data", [
+ "data" => $data,
+ ]);
+
return $this->api = $this->api->with(compact("type", "data", "links"));
}
return $this->api = $this->api->with(compact("type", "data", "links"));
}
@@
-52,6
+58,11
@@
final class Result
return new API\Links($link);
}
return new API\Links($link);
}
+ /**
+ * @param Response $response
+ * @return API\ContentType
+ * @throws RequestException
+ */
private function checkResponseType(Response $response) {
if (!($type = $response->getHeader("Content-Type", Header::class))) {
$e = new RequestException($response);
private function checkResponseType(Response $response) {
if (!($type = $response->getHeader("Content-Type", Header::class))) {
$e = new RequestException($response);
@@
-63,12
+74,18
@@
final class Result
throw $e;
}
throw $e;
}
- return new API\ContentType($t
yp
e);
+ return new API\ContentType($t
his->api->getVersion(), $type->valu
e);
}
}
+ /**
+ * @param Response $response
+ * @param API\ContentType $type
+ * @return mixed
+ * @throws \Exception
+ */
private function checkResponseBody(Response $response, API\ContentType $type) {
try {
private function checkResponseBody(Response $response, API\ContentType $type) {
try {
- $data = $type->
parseBody
($response->getBody());
+ $data = $type->
decode
($response->getBody());
} catch (\Exception $e) {
$this->api->getLogger()->error("response -> error: ".$e->getMessage(), [
"url" => (string) $this->api->getUrl(),
} catch (\Exception $e) {
$this->api->getLogger()->error("response -> error: ".$e->getMessage(), [
"url" => (string) $this->api->getUrl(),