Merge pull request #8297 from MrPetovan/task/8285-api-events

[API] Add new api/friendica/events endpoint
This commit is contained in:
Philipp 2020-02-16 21:07:44 +01:00 committed by GitHub
commit 09961a07e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 202 additions and 0 deletions

View File

@ -361,6 +361,123 @@ Ex: Wed May 23 06:01:13 +0000 2007
</tbody>
</table>
## Event
<table class="table table-condensed table-striped table-bordered">
<thead>
<tr>
<th>Attribute</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>id</code></td>
<td>Integer</td>
<td></td>
</tr>
<tr>
<td><code>uid</code></td>
<td>Integer</td>
<td>Owner User Id</td>
</tr>
<tr>
<td><code>cid</code></td>
<td>Integer</td>
<td>Target Contact Id</td>
</tr>
<tr>
<td><code>uri</code></td>
<td>String</td>
<td>Item unique URI string</td>
</tr>
<tr>
<td><code>name</code></td>
<td>String (Plaintext)</td>
<td>Title</td>
</tr>
<tr>
<td><code>desc</code></td>
<td>String (HTML)</td>
<td>Description</td>
</tr>
<tr>
<td><code>startTime</code></td>
<td>String (UTC <code>YYYY-MM-DD HH:II:SS)</code>)</td>
<td></td>
</tr>
<tr>
<td><code>endTime</code></td>
<td>String (UTC <code>YYYY-MM-DD HH:II:SS)</code>)</td>
<td>Optional (null date is <code>0001-01-01 00:00:00</code></td>
</tr>
<tr>
<td><code>type</code></td>
<td>String (<code>event</code> or <code>birthday</code>)</td>
<td></td>
</tr>
<tr>
<td><code>nofinish</code></td>
<td>Boolean</td>
<td>Ongoing event</td>
</tr>
<tr>
<td><code>place</code></td>
<td>String</td>
<td>Optional. Location.</td>
</tr>
<tr>
<td><code>adjust</code></td>
<td>Boolean</td>
<td>???</td>
</tr>
<tr>
<td><code>ignore</code></td>
<td>Boolean</td>
<td>???</td>
</tr>
<tr>
<td><code>allow_cid</code></td>
<td>String (angle-brackets escaped integers)</td>
<td>Optional. List of allowed contact ids</td>
</tr>
<tr>
<td><code>allow_gid</code></td>
<td>String (angle-brackets escaped integers)</td>
<td>Optional. List of allowed group ids</td>
</tr>
<tr>
<td><code>deny_cid</code></td>
<td>String (angle-brackets escaped integers)</td>
<td>Optional. List of disallowed contact ids</td>
</tr>
<tr>
<td><code>deny_gid</code></td>
<td>String (angle-brackets escaped integers)</td>
<td>Optional. List of disallowed group ids</td>
</tr>
</tbody>
</table>
## Hashtag
Unused

View File

@ -15,6 +15,15 @@ These endpoints uses the [Friendica API entities](help/API-Entities).
## Endpoints
### GET api/friendica/events
Returns a list of [Event](help/API-Entities#Event) entities for the current logged in user.
#### Parameters
- `since_id`: (optional) minimum event id for pagination
- `count`: maximum number of items returned, default 20
### GET api/externalprofile/show
Returns a [Contact](help/API-Entities#Contact) entity for the provided profile URL.

View File

@ -0,0 +1,75 @@
<?php
/**
* @copyright Copyright (C) 2020, Friendica
*
* @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\Events;
use Friendica\Content\Text\BBCode;
use Friendica\Database\DBA;
use Friendica\Module\BaseApi;
use Friendica\Network\HTTPException;
/**
* api/friendica/events
*
* @package Friendica\Module\Api\Friendica\Events
*/
class Index extends BaseApi
{
public static function rawContent(array $parameters = [])
{
if (self::login() === false) {
throw new HTTPException\ForbiddenException();
}
$since_id = $_REQUEST['since_id'] ?? 0;
$count = $_REQUEST['count'] ?? 20;
$condition = ["`id` > ? AND `uid` = ?", $since_id, self::$current_user_id];
$params = ['limit' => $count];
$events = DBA::selectToArray('event', [], $condition, $params);
$items = [];
foreach ($events as $event) {
$items[] = [
'id' => intval($event['id']),
'uid' => intval($event['uid']),
'cid' => $event['cid'],
'uri' => $event['uri'],
'name' => $event['summary'],
'desc' => BBCode::convert($event['desc']),
'startTime' => $event['start'],
'endTime' => $event['finish'],
'type' => $event['type'],
'nofinish' => $event['nofinish'],
'place' => $event['location'],
'adjust' => $event['adjust'],
'ignore' => $event['ignore'],
'allow_cid' => $event['allow_cid'],
'allow_gid' => $event['allow_gid'],
'deny_cid' => $event['deny_cid'],
'deny_gid' => $event['deny_gid']
];
}
echo self::format('events', ['events' => $items]);
exit;
}
}

View File

@ -55,6 +55,7 @@ return [
],
'/friendica' => [
'/profile/show' => [Module\Api\Friendica\Profile\Show::class , [R::GET ]],
'/events' => [Module\Api\Friendica\Events\Index::class , [R::GET ]],
],
],