]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/apiaccountratelimitstatus.php
8490e2965c87bad502750611157a916c68426184
[quix0rs-gnu-social.git] / actions / apiaccountratelimitstatus.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Dummy action that emulates Twitter's rate limit status API resource
6  *
7  * PHP version 5
8  *
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.
13  *
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.
18  *
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/>.
21  *
22  * @category  API
23  * @package   StatusNet
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/
32  */
33
34 if (!defined('STATUSNET')) {
35     exit(1);
36 }
37
38 require_once INSTALLDIR . '/lib/apibareauth.php';
39
40 /**
41  * We don't have a rate limit, but some clients check this method.
42  * It always returns the same thing: 150 hits left.
43  *
44  * @category API
45  * @package  StatusNet
46  * @author   Evan Prodromou <evan@status.net>
47  * @author   Robin Millette <robin@millette.info>
48  * @author   Zach Copley <zach@status.net>
49  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
50  * @link     http://status.net/
51  */
52 class ApiAccountRateLimitStatusAction extends ApiBareAuthAction
53 {
54     /**
55      * Handle the request
56      *
57      * Return some Twitter-ish data about API limits
58      *
59      * @param array $args $_REQUEST data (unused)
60      *
61      * @return void
62      */
63     function handle($args)
64     {
65         parent::handle($args);
66
67         if (!in_array($this->format, array('xml', 'json'))) {
68             $this->clientError(
69                 // TRANS: Client error displayed when coming across a non-supported API method.
70                 _('API method not found.'),
71                 404,
72                 $this->format
73             );
74             return;
75         }
76
77         $reset   = new DateTime();
78         $reset->modify('+1 hour');
79
80         $this->initDocument($this->format);
81
82          if ($this->format == 'xml') {
83              $this->elementStart('hash');
84              $this->element('remaining-hits', array('type' => 'integer'), 150);
85              $this->element('hourly-limit', array('type' => 'integer'), 150);
86              $this->element(
87                  'reset-time', array('type' => 'datetime'),
88                  common_date_iso8601($reset->format('r'))
89              );
90              $this->element(
91                  'reset_time_in_seconds',
92                  array('type' => 'integer'),
93                  strtotime('+1 hour')
94              );
95              $this->elementEnd('hash');
96          } elseif ($this->format == 'json') {
97              $out = array(
98                  'reset_time_in_seconds' => strtotime('+1 hour'),
99                  'remaining_hits' => 150,
100                  'hourly_limit' => 150,
101                  'reset_time' => common_date_rfc2822(
102                      $reset->format('r')
103                   )
104              );
105              print json_encode($out);
106          }
107
108         $this->endDocument($this->format);
109     }
110
111     /**
112      * Return true if read only.
113      *
114      * MAY override
115      *
116      * @param array $args other arguments
117      *
118      * @return boolean is read only action?
119      */
120     function isReadOnly($args)
121     {
122         return true;
123     }
124 }