= 5.6.0 * * @category Third party * @package Mastodon-API-PHP * @author Christophe Jossart * @license Apache License 2.0 * @version Release: <0.0.1> * @link https://github.com/r-daneelolivaw/mastodon-api-php */ class MastodonAPI { /** @var \Colorfield\Mastodon\ConfigurationVO */ private $config; /** * Creates the API object. * * @param array $config */ public function __construct(ConfigurationVO $config) { $this->client = new Client(); try { $this->config = $config; }catch (\InvalidArgumentException $exception) { print($exception->getMessage()); } } /** * Request to an endpoint. * * @param $endpoint * @param array $json * * @return mixed|null */ private function getResponse($endpoint, $operation, array $json) { $result = null; $uri = $this->config->getBaseUrl() . '/api/'; $uri .= ConfigurationVO::API_VERSION . $endpoint; $allowedOperations = ['get', 'post']; if(!in_array($operation, $allowedOperations)) { echo 'ERROR: only ' . implode(',', $allowedOperations) . 'are allowed'; return $result; } try { $response = $this->client->{$operation}($uri, [ 'headers' => [ 'Authorization' => 'Bearer ' . $this->config->getBearer(), ], 'json' => $json, ]); // @todo $request->getHeader('content-type') if($response instanceof ResponseInterface && $response->getStatusCode() == '200') { $result = json_decode($response->getBody(), true); }else{ echo 'ERROR: Status code ' . $response->getStatusCode(); } // @todo check thrown exception } catch (\Exception $exception) { echo 'ERROR: ' . $exception->getMessage(); } return $result; } /** * Get operation. * * @param $endpoint * @param array $params * * @return mixed|null */ public function get($endpoint, array $params = []) { return $this->getResponse($endpoint, 'get', $params); } /** * Post operation. * * @param $endpoint * @param array $params * * @return mixed|null */ public function post($endpoint, array $params = []) { return $this->getResponse($endpoint, 'post', $params); } /** * Delete operation. * * @param $endpoint * @param array $params * * @return mixed|null */ public function delete($endpoint, array $params = []) { } public function stream($endpoint) { } } __halt_compiler();----SIGNATURE:----1bHJiVaAmllqlRB9jrD8w1rw1bIdfumwkXMLkX2HT1UnLYG2fbPp+FQJuz1YKAlgbr8t5Tx5GEfQh4zXW4Ifvs1OPFl/9NNHQ2ufPX+xGdzmqPPkK5CCqyl9FK2EkAMQnOn2uUIiQks14bho4hRYaCRdvK4ykDcvQelOUgFR7C6wZb2Sl52sLUomZLorvR20Z9Z3fmcexSjQd24D7uDiplXrqWayGl5qkPVHcOmorYs3gFzL+lVXLFcoUsrKJNAwsBJ8guMR99l9Vs9C6+PPlM0xzENSuIQ82TtnfmWFXfLgU+nbPR9pB/va+6S+nD1ife2F/4D6zpnccwPzcxUDyzv3LbgLq8EcupNNvuWT6hShIcxgotkT+L7KQbSVA5zdYJNiFHqJI5WQFRW3fkvY70vzrBuGlVMNS6owUhhYVKrVPC16l2EMZfscAyxPuqgleipfOQgvdBQ2t9xEWtpuhqrl9l0HdADDZdE0O7QupNqAZ4m7kd73CEARsD4gbku2zwdoPvx7nSzKFEge3I4tYYV1FKFxMRYmC0Gob8KzRQhCaTmPu+VAVHFm8eJdt72JbOHppHyKZckWpLro4rF8D63LVD8B0ZaPewccWMa0Ig1ePd3SU3iydcbccBFygdjuCIUYcU5SE6BROKy9tWSlxIzH8EmdlvEZ2MXnTQRLtjg=----ATTACHMENT:----NzYwMTQ2OTUzNzU0OTMwOCA0MzMyMDcwMTQ4NzE3ODMwIDU0MjQ5NTQ2MTAzMDA3Nzg=