123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <?php
- if (!defined('STATUSNET')) {
- exit(1);
- }
- class ApiAccountRateLimitStatusAction extends ApiBareAuthAction
- {
-
- function handle($args)
- {
- parent::handle($args);
- if (!in_array($this->format, array('xml', 'json'))) {
- $this->clientError(
-
- _('API method not found.'),
- 404,
- $this->format
- );
- return;
- }
- $reset = new DateTime();
- $reset->modify('+1 hour');
- $this->initDocument($this->format);
- if ($this->format == 'xml') {
- $this->elementStart('hash');
- $this->element('remaining-hits', array('type' => 'integer'), 150);
- $this->element('hourly-limit', array('type' => 'integer'), 150);
- $this->element(
- 'reset-time', array('type' => 'datetime'),
- common_date_iso8601($reset->format('r'))
- );
- $this->element(
- 'reset_time_in_seconds',
- array('type' => 'integer'),
- strtotime('+1 hour')
- );
- $this->elementEnd('hash');
- } elseif ($this->format == 'json') {
- $out = array(
- 'reset_time_in_seconds' => strtotime('+1 hour'),
- 'remaining_hits' => 150,
- 'hourly_limit' => 150,
- 'reset_time' => common_date_rfc2822(
- $reset->format('r')
- )
- );
- print json_encode($out);
- }
- $this->endDocument($this->format);
- }
-
- function isReadOnly($args)
- {
- return true;
- }
- }
|