3 * StatusNet, the distributed open-source microblogging tool
5 * Dummy action that emulates Twitter's rate limit status API resource
9 * LICENCE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Brion Vibber <brion@pobox.com>
25 * @author Evan Prodromou <evan@status.net>
26 * @author Robin Millette <robin@millette.info>
27 * @author Siebrand Mazeland <s.mazeland@xs4all.nl>
28 * @author Zach Copley <zach@status.net>
29 * @copyright 2009 StatusNet, Inc.
30 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
31 * @link http://status.net/
34 if (!defined('GNUSOCIAL')) {
39 * We don't have a rate limit, but some clients check this method.
40 * It always returns the same thing: 150 hits left.
44 * @author Evan Prodromou <evan@status.net>
45 * @author Robin Millette <robin@millette.info>
46 * @author Zach Copley <zach@status.net>
47 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
48 * @link http://status.net/
50 class ApiAccountRateLimitStatusAction extends ApiBareAuthAction
53 * Return true if read only.
57 * @param array $args other arguments
59 * @return boolean is read only action?
61 public function isReadOnly($args)
69 * Return some Twitter-ish data about API limits
72 * @throws ClientException
74 protected function handle()
78 if (!in_array($this->format, ['xml', 'json'])) {
80 // TRANS: Client error displayed when coming across a non-supported API method.
81 _('API method not found.'),
87 $reset = new DateTime();
88 $reset->modify('+1 hour');
90 $this->initDocument($this->format);
92 if ($this->format == 'xml') {
93 $this->elementStart('hash');
94 $this->element('remaining-hits', ['type' => 'integer'], "150");
95 $this->element('hourly-limit', ['type' => 'integer'], "150");
98 ['type' => 'datetime'],
99 common_date_iso8601($reset->format('r'))
102 'reset_time_in_seconds',
103 ['type' => 'integer'],
106 $this->elementEnd('hash');
107 } elseif ($this->format == 'json') {
109 'reset_time_in_seconds' => strtotime('+1 hour'),
110 'remaining_hits' => 150,
111 'hourly_limit' => 150,
112 'reset_time' => common_date_rfc2822(
116 print json_encode($out);
119 $this->endDocument($this->format);