From c204f1f206f4c4fab8af56b0155cb9aa7882d8ed Mon Sep 17 00:00:00 2001 From: ivan770 Date: Sat, 28 Sep 2019 17:34:49 +0300 Subject: [PATCH] Add request class --- src/Request.php | 104 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 src/Request.php diff --git a/src/Request.php b/src/Request.php new file mode 100644 index 0000000..3b8e6e3 --- /dev/null +++ b/src/Request.php @@ -0,0 +1,104 @@ +client = $client; + } + + /** + * Method getter + * + * @return string + */ + protected function getMethod() + { + return strtolower($this->method); + } + + /** + * Resource getter + * + * @return string + */ + protected function getResource() + { + return $this->resource; + } + + /** + * Attach builder properties on execution + * + * @param HttpClient $client + */ + protected function defaultAttach(HttpClient $client) + { + // + } + + /** + * Attach builder properties. HttpClient instance is passed into Closure + * + * @param \Closure $callback + * @return Request + */ + public function attach($callback) + { + $callback($this->client); + + return $this; + } + + /** + * Run request + * + * @return Response + */ + public function execute() + { + $this->defaultAttach($this->client); + + $method = $this->getMethod(); + + return $this->client->$method($this->getResource()); + } + + /** + * Run request, and retrieve response contents + * + * @return \Illuminate\Support\Collection|string + */ + public function get() + { + return $this->execute()->getContent(); + } +} \ No newline at end of file