From a94a9afdcc7e621a2840e7e9455e9a3e9aa066b7 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Wed, 3 Jun 2015 02:39:01 +0200 Subject: [PATCH] Create an API client class. This should make it easier to make API calls from the frontends. --- src/Api/Client.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/Api/Client.php diff --git a/src/Api/Client.php b/src/Api/Client.php new file mode 100644 index 000000000..6ef31b6d5 --- /dev/null +++ b/src/Api/Client.php @@ -0,0 +1,36 @@ +container = $container; + $this->actor = $actor; + } + + /** + * Execute the given API action class, pass the input and return its response. + * + * @param string $actionClass + * @param array $input + * @return object + */ + public function send($actionClass, array $input = []) + { + /** @var \Flarum\Api\Actions\JsonApiAction $action */ + $action = $this->container->make($actionClass); + + $response = $action->handle(new Request($input, $this->actor)); + + return json_decode($response->getBody()); + } +}