return $status;
}
-/**
- * Returns the remaining number of API requests available to the user before the API limit is reached.
- *
- * @param string $type Return type (atom, rss, xml, json)
- *
- * @return array|string
- * @throws Exception
- */
-function api_account_rate_limit_status($type)
-{
- if ($type == "xml") {
- $hash = [
- 'remaining-hits' => '150',
- '@attributes' => ["type" => "integer"],
- 'hourly-limit' => '150',
- '@attributes2' => ["type" => "integer"],
- 'reset-time' => DateTimeFormat::utc('now + 1 hour', DateTimeFormat::ATOM),
- '@attributes3' => ["type" => "datetime"],
- 'reset_time_in_seconds' => strtotime('now + 1 hour'),
- '@attributes4' => ["type" => "integer"],
- ];
- } else {
- $hash = [
- 'reset_time_in_seconds' => strtotime('now + 1 hour'),
- 'remaining_hits' => '150',
- 'hourly_limit' => '150',
- 'reset_time' => api_date(DateTimeFormat::utc('now + 1 hour', DateTimeFormat::ATOM)),
- ];
- }
-
- return BaseApi::formatData('hash', $type, ['hash' => $hash]);
-}
-
-/// @TODO move to top of file or somewhere better
-api_register_func('api/account/rate_limit_status', 'api_account_rate_limit_status', true);
-
/**
* Returns all lists the user subscribes to.
*
`type`, `height`, `width`, `datasize`, `profile`, `allow_cid`, `deny_cid`, `allow_gid`, `deny_gid`,
MIN(`scale`) AS `minscale`, MAX(`scale`) AS `maxscale`
FROM `photo` WHERE `uid` = ? AND `resource-id` = ? $scale_sql GROUP BY
- `resource-id`, `created`, `edited`, `title`, `desc`, `album`, `filename`,
- `type`, `height`, `width`, `datasize`, `profile`, `allow_cid`, `deny_cid`, `allow_gid`, `deny_gid`",
+ `resource-id`, `created`, `edited`, `title`, `desc`, `album`, `filename`,
+ `type`, `height`, `width`, `datasize`, `profile`, `allow_cid`, `deny_cid`, `allow_gid`, `deny_gid`",
local_user(),
$photo_id
));
--- /dev/null
+<?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\Friendica\Account;
+
+use Friendica\Module\BaseApi;
+use Friendica\Util\DateTimeFormat;
+
+/**
+ * API endpoint: /api/account/rate_limit_status
+ */
+class RateLimitStatus extends BaseApi
+{
+ public static function rawContent(array $parameters = [])
+ {
+ if (!empty($parameters['extension']) && ($parameters['extension'] == 'xml')) {
+ $hash = [
+ 'remaining-hits' => '150',
+ '@attributes' => ["type" => "integer"],
+ 'hourly-limit' => '150',
+ '@attributes2' => ["type" => "integer"],
+ 'reset-time' => DateTimeFormat::utc('now + 1 hour', DateTimeFormat::ATOM),
+ '@attributes3' => ["type" => "datetime"],
+ 'reset_time_in_seconds' => strtotime('now + 1 hour'),
+ '@attributes4' => ["type" => "integer"],
+ ];
+ } else {
+ $hash = [
+ 'reset_time_in_seconds' => strtotime('now + 1 hour'),
+ 'remaining_hits' => '150',
+ 'hourly_limit' => '150',
+ 'reset_time' => api_date(DateTimeFormat::utc('now + 1 hour', DateTimeFormat::ATOM)),
+ ];
+ }
+
+ self::exit('hash', ['hash' => $hash], $parameters['extension'] ?? null);
+ }
+}
*
* @return int User ID
*/
- protected static function getCurrentUserID()
+ public static function getCurrentUserID()
{
$uid = OAuth::getCurrentUserID();
if (is_bool($item)) {
$item = ($item ? 'true' : 'false');
}
-
+
if (substr($key, 0, 10) == 'statusnet_') {
$key = 'statusnet:'.substr($key, 10);
} elseif (substr($key, 0, 10) == 'friendica_') {
}
return true;
}
-
+
/**
* Creates the XML from a JSON style array
*
$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\Index::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\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]],
],
'/blocks/list[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [R::GET ]],
*/
public function testApiAccountRateLimitStatus()
{
- $result = api_account_rate_limit_status('json');
- self::assertEquals(150, $result['hash']['remaining_hits']);
- self::assertEquals(150, $result['hash']['hourly_limit']);
- self::assertIsInt($result['hash']['reset_time_in_seconds']);
+ // @todo How to test the new API?
+ // $result = api_account_rate_limit_status('json');
+ // self::assertEquals(150, $result['hash']['remaining_hits']);
+ // self::assertEquals(150, $result['hash']['hourly_limit']);
+ // self::assertIsInt($result['hash']['reset_time_in_seconds']);
}
/**
*/
public function testApiAccountRateLimitStatusWithXml()
{
- $result = api_account_rate_limit_status('xml');
- self::assertXml($result, 'hash');
+ // @todo How to test the new API?
+ // $result = api_account_rate_limit_status('xml');
+ // self::assertXml($result, 'hash');
}
/**