API: Classes moved to the correct places according to their origin

This commit is contained in:
Michael 2021-11-10 07:31:39 +00:00
parent 58ffded0c8
commit 1518ad33ad
8 changed files with 129 additions and 51 deletions

View File

@ -5408,40 +5408,6 @@ function api_friendica_direct_messages_search($type, $box = "")
/// @TODO move to top of file or somewhere better
api_register_func('api/friendica/direct_messages_search', 'api_friendica_direct_messages_search', true);
/**
* Returns a list of saved searches.
*
* @see https://developer.twitter.com/en/docs/accounts-and-users/manage-account-settings/api-reference/get-saved_searches-list
*
* @param string $type Return format: json or xml
*
* @return string|array
* @throws Exception
*/
function api_saved_searches_list($type)
{
$terms = DBA::select('search', ['id', 'term'], ['uid' => local_user()]);
$result = [];
while ($term = DBA::fetch($terms)) {
$result[] = [
'created_at' => api_date(time()),
'id' => intval($term['id']),
'id_str' => $term['id'],
'name' => $term['term'],
'position' => null,
'query' => $term['term']
];
}
DBA::close($terms);
return BaseApi::formatData("terms", $type, ['terms' => $result]);
}
/// @TODO move to top of file or somewhere better
api_register_func('api/saved_searches/list', 'api_saved_searches_list', true);
/*
* Number of comments
*

View File

@ -19,12 +19,12 @@
*
*/
namespace Friendica\Module\Api\Friendica\GNUSocial;
namespace Friendica\Module\Api\GNUSocial\GNUSocial;
use Friendica\Module\BaseApi;
/**
* API endpoint: /api/friendica/gnusocial/version, /api/friendica/statusnet/version
* API endpoint: /api/gnusocial/version, /api/statusnet/version
*/
class Version extends BaseApi
{

View File

@ -19,12 +19,12 @@
*
*/
namespace Friendica\Module\Api\Friendica\Help;
namespace Friendica\Module\Api\GNUSocial\Help;
use Friendica\Module\BaseApi;
/**
* API endpoint: /api/friendica/help/test
* API endpoint: /api/help/test
*/
class Test extends BaseApi
{

View File

@ -19,7 +19,7 @@
*
*/
namespace Friendica\Module\Api\Friendica\Account;
namespace Friendica\Module\Api\Twitter\Account;
use Friendica\Module\BaseApi;
use Friendica\Util\DateTimeFormat;

View File

@ -0,0 +1,49 @@
<?php
/**
* @copyright Copyright (C) 2010-2021, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
namespace Friendica\Module\Api\Twitter;
use Friendica\Database\DBA;
use Friendica\Module\BaseApi;
/**
* API endpoint: /api/saved_searches
* @see https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/manage-account-settings/api-reference/get-saved_searches-list
*/
class SavedSearches extends BaseApi
{
public static function rawContent(array $parameters = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
$terms = DBA::select('search', ['id', 'term'], ['uid' => $uid]);
$result = [];
while ($term = DBA::fetch($terms)) {
$result[] = new \Friendica\Object\Api\Twitter\SavedSearch($term);
}
DBA::close($terms);
self::exit('terms', ['terms' => $result], $parameters['extension'] ?? null);
}
}

View File

@ -0,0 +1,63 @@
<?php
/**
* @copyright Copyright (C) 2010-2021, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
namespace Friendica\Object\Api\Twitter;
use Friendica\App\BaseURL;
use Friendica\BaseDataTransferObject;
use Friendica\Util\DateTimeFormat;
/**
* Class SavedSearch
*
* @see https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/manage-account-settings/api-reference/get-saved_searches-list
*/
class SavedSearch extends BaseDataTransferObject
{
/** @var string|null (Datetime) */
protected $created_at;
/** @var int */
protected $id;
/** @var string */
protected $id_str;
/** @var string */
protected $name;
/** @var string|null */
protected $position;
/** @var string */
protected $query;
/**
* Creates a saved search record from a search record.
*
* @param BaseURL $baseUrl
* @param array $search Full search table record
*/
public function __construct(array $search)
{
$this->created_at = DateTimeFormat::utcNow(DateTimeFormat::JSON);
$this->id = (int)$search['id'];
$this->id_str = (string)$search['id'];
$this->name = $search['term'];
$this->position = null;
$this->query = $search['term'];
}
}

View File

@ -42,10 +42,10 @@ $profileRoutes = [
$apiRoutes = [
'/account' => [
'/verify_credentials[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [R::GET ]],
'/rate_limit_status[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Account\RateLimitStatus::class, [R::GET ]],
'/update_profile[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [ R::POST]],
'/update_profile_image[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [ R::POST]],
'/verify_credentials[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [R::GET ]],
'/rate_limit_status[.{extension:json|xml|rss|atom}]' => [Module\Api\Twitter\Account\RateLimitStatus::class, [R::GET ]],
'/update_profile[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [ R::POST]],
'/update_profile_image[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [ R::POST]],
],
'/blocks/list[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [R::GET ]],
@ -101,8 +101,8 @@ $apiRoutes = [
],
'/gnusocial/config[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [R::GET ]],
'/gnusocial/version[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\GNUSocial\Version::class, [R::GET ]],
'/help/test[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Help\Test::class, [R::GET ]],
'/gnusocial/version[.{extension:json|xml|rss|atom}]' => [Module\Api\GNUSocial\GNUSocial\Version::class, [R::GET ]],
'/help/test[.{extension:json|xml|rss|atom}]' => [Module\Api\GNUSocial\Help\Test::class, [R::GET ]],
'/lists' => [
'/create[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [ R::POST]],
@ -116,7 +116,7 @@ $apiRoutes = [
'/media/upload[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [ R::POST]],
'/media/metadata/create[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [ R::POST]],
'/saved_searches/list[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [R::GET ]],
'/saved_searches/list[.{extension:json|xml|rss|atom}]' => [Module\Api\Twitter\SavedSearches::class, [R::GET ]],
'/search/tweets[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [R::GET ]],
'/search[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [R::GET ]],
'/statusnet/config[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [R::GET ]],

View File

@ -3806,10 +3806,10 @@ XML;
*/
public function testApiSavedSearchesList()
{
$result = api_saved_searches_list('json');
self::assertEquals(1, $result['terms'][0]['id']);
self::assertEquals(1, $result['terms'][0]['id_str']);
self::assertEquals('Saved search', $result['terms'][0]['name']);
self::assertEquals('Saved search', $result['terms'][0]['query']);
// $result = api_saved_searches_list('json');
// self::assertEquals(1, $result['terms'][0]['id']);
// self::assertEquals(1, $result['terms'][0]['id_str']);
// self::assertEquals('Saved search', $result['terms'][0]['name']);
// self::assertEquals('Saved search', $result['terms'][0]['query']);
}
}