From 11fdfe9d3601b45a75100343ebb2492fa3d1f8a7 Mon Sep 17 00:00:00 2001 From: Victor Westerlund Date: Mon, 2 Oct 2023 11:54:06 +0200 Subject: [PATCH] wip: 2023-10-02T11:22:18+0200 (1696238538) --- src/Reflect/Method.php | 13 +++++++++++++ src/Reflect/Response.php | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 src/Reflect/Method.php create mode 100644 src/Reflect/Response.php diff --git a/src/Reflect/Method.php b/src/Reflect/Method.php new file mode 100644 index 0000000..00d4c67 --- /dev/null +++ b/src/Reflect/Method.php @@ -0,0 +1,13 @@ +status, $this->body] = $response; + + $this->ok = $this->is_ok(); + } + + // A boolean indicating whether the response was successful (status in the range 200 – 299) or not + public function is_ok(): bool { + return $this->status >= 200 && $this->status < 300; + } + + // Parse JSON from response body and return as PHP array + public function json(bool $assoc = true): array { + return json_decode($this->body, $assoc); + } + + // Return response body as-is + public function text() { + return $this->body; + } + } \ No newline at end of file