[PLUGIN][Pinboard] Refactor and cleanup code

This commit is contained in:
Hugo Sales 2022-04-01 00:17:57 +01:00
parent 74ffd261b8
commit 539104ec33
No known key found for this signature in database
GPG Key ID: 7D0C7EAFC9D835A0
2 changed files with 32 additions and 49 deletions

View File

@ -17,7 +17,9 @@ use App\Util\Exception\ClientException;
use App\Util\Exception\ServerException;
use App\Util\Formatting;
use Component\Conversation\Conversation;
use Component\Link\Link;
use Component\Tag\Entity\NoteTag;
use Component\Tag\Tag;
use Datetime;
use DateTimeImmutable;
use DateTimeInterface;
@ -29,8 +31,6 @@ use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Serializer\Encoder\XmlEncoder;
use Component\Tag\Tag;
use Component\Link\Link;
class APIv1 extends Controller
{
@ -82,7 +82,7 @@ class APIv1 extends Controller
return null;
}
[$id, $token] = explode(':', $input);
if (filter_var($id, FILTER_VALIDATE_INT) !== false) {
if (filter_var($id, \FILTER_VALIDATE_INT) !== false) {
return Token::get((int) $id, $token)?->getUser();
} else {
return null;
@ -108,7 +108,7 @@ class APIv1 extends Controller
}
/**
* @param Pin[] $pins
* @param Pin[] $pins
* @param string[] $tags
*/
private function filterByTags(array $pins, array $tags): array
@ -270,7 +270,7 @@ class APIv1 extends Controller
$user = $check;
}
$url = $this->string('url');
$url = $this->string('url');
if (\is_null($url)) {
throw new ClientException('URL must be provided');
}
@ -409,4 +409,15 @@ class APIv1 extends Controller
return self::respond($tags_freq);
}
public function unimplmented(Request $request)
{
$check = self::preCheck();
if (!$check instanceof LocalUser) {
return $check;
} else {
$user = $check;
}
return self::respond(['result_code' => 'something went wrong', 'reason' => 'Unimplemented']);
}
}

View File

@ -44,54 +44,26 @@ class Pinboard extends Plugin
public function onAddRoute(Router $r): bool
{
$r->connect(
self::controller_route,
'/pinboard/settings',
C\Settings::class,
options: ['method' => 'post'],
);
$r->connect(self::controller_route, '/pinboard/settings', C\Settings::class, options: ['method' => 'post']);
$r->connect(
'pinboard_posts_update',
'/pinboard/v1/posts/update',
[C\APIv1::class, 'posts_update'],
);
$r->connect('pinboard_posts_update', '/pinboard/v1/posts/update', [C\APIv1::class, 'posts_update']);
$r->connect('pinboard_posts_add', '/pinboard/v1/posts/add', [C\APIv1::class, 'posts_add']);
$r->connect('pinboard_posts_delete', '/pinboard/v1/posts/delete', [C\APIv1::class, 'posts_delete']);
$r->connect('pinboard_posts_get', '/pinboard/v1/posts/get', [C\APIv1::class, 'posts_get']);
$r->connect('pinboard_posts_recent', '/pinboard/v1/posts/recent', [C\APIv1::class, 'posts_recent']);
$r->connect('pinboard_posts_all', '/pinboard/v1/posts/all', [C\APIv1::class, 'posts_all']);
$r->connect(
'pinboard_posts_add',
'/pinboard/v1/posts/add',
[C\APIv1::class, 'posts_add'],
);
$r->connect('pinboard_posts_dates', '/pinboard/v1/posts/dates', [C\APIv1::class, 'unimplemented']);
$r->connect('pinboard_posts_suggest', '/pinboard/v1/posts/suggest', [C\APIv1::class, 'unimplemented']);
$r->connect(
'pinboard_posts_delete',
'/pinboard/v1/posts/delete',
[C\APIv1::class, 'posts_delete'],
);
$r->connect('pinboard_tags_get', '/pinboard/v1/tags/get', [C\APIv1::class, 'tags_get']);
$r->connect(
'pinboard_posts_get',
'/pinboard/v1/posts/get',
[C\APIv1::class, 'posts_get'],
);
$r->connect(
'pinboard_posts_recent',
'/pinboard/v1/posts/recent',
[C\APIv1::class, 'posts_recent'],
);
$r->connect(
'pinboard_posts_all',
'/pinboard/v1/posts/all',
[C\APIv1::class, 'posts_all'],
);
$r->connect(
'pinboard_tags_get',
'/pinboard/v1/tags/get',
[C\APIv1::class, 'tags_get'],
);
$r->connect('pinboard_tags_delete', '/pinboard/v1/tags/delete', [C\APIv1::class, 'unimplemented']);
$r->connect('pinboard_tags_rename', '/pinboard/v1/tags/rename', [C\APIv1::class, 'unimplemented']);
$r->connect('pinboard_user_secret', '/pinboard/v1/user/secret', [C\APIv1::class, 'unimplemented']);
$r->connect('pinboard_user_api_token', '/pinboard/v1/user/api_token', [C\APIv1::class, 'unimplemented']);
$r->connect('pinboard_notes_list', '/pinboard/v1/notes/list', [C\APIv1::class, 'unimplemented']);
$r->connect('pinboard_notes_id', '/pinboard/v1/notes/{id}', [C\APIv1::class, 'unimplemented']);
return Event::next;
}