]> git.mxchange.org Git - friendica.git/commitdiff
Add response for JSON only
authorPhilipp <admin@philipp.info>
Sun, 5 Dec 2021 23:06:56 +0000 (00:06 +0100)
committerPhilipp <admin@philipp.info>
Sun, 5 Dec 2021 23:12:18 +0000 (00:12 +0100)
src/Module/Api/ApiResponse.php
src/Module/Api/Mastodon/Accounts/VerifyCredentials.php
tests/src/Module/Api/Mastodon/Accounts/StatusesTest.php

index c4b9b1e943162f4bbbd8475c65ebf0c9ff5727cc..a6a94ad81c559e209635013e2da2039b35eb1e73 100644 (file)
@@ -221,6 +221,16 @@ class ApiResponse extends Response
                $this->addContent($return);
        }
 
+       /**
+        * Wrapper around exit() for JSON only responses
+        *
+        * @param array $data
+        */
+       public function exitWithJson(array $data)
+       {
+               $this->exit('content', ['content' => $data], static::TYPE_JSON);
+       }
+
        /**
         * Quit execution with the message that the endpoint isn't implemented
         *
index 4318fac7b5b29debb53ffc5eb0b7617f09da2403..058a52f630895d37a9ed32c9d23f02b3fa656a2e 100644 (file)
@@ -52,6 +52,6 @@ class VerifyCredentials extends BaseApi
 
                // @todo Support the source property,
                $account = DI::mstdnAccount()->createFromContactId($cdata['user'], $uid);
-               $this->response->exit('account', ['account' => $account->toArray()]);
+               $this->response->exitWithJson($account->toArray());
        }
 }
index 0c6aab8867a4bf1e8d34fd665cedb9dbeaf51437..f2a709531cdf9a0381d6995f873f3492b31a5af7 100644 (file)
@@ -14,7 +14,7 @@ class StatusesTest extends ApiTest
         */
        public function testApiStatusShowWithJson()
        {
-               self::markTestIncomplete('Needs Stastuses to not set header during call (like at BaseApi::setLinkHeader');
+               self::markTestIncomplete('Needs Statuses to not set header during call (like at BaseApi::setLinkHeader');
 
                // $result = api_status_show('json', 1);
                // self::assertStatus($result['status']);
@@ -25,7 +25,7 @@ class StatusesTest extends ApiTest
         */
        public function testApiStatusShowWithXml()
        {
-               self::markTestIncomplete('Needs Stastuses to not set header during call (like at BaseApi::setLinkHeader');
+               self::markTestIncomplete('Needs Statuses to not set header during call (like at BaseApi::setLinkHeader');
 
                // $result = api_status_show('xml', 1);
                // self::assertXml($result, 'statuses');