etherpad prefix v drupal modul, dokumentacija APIja, WIP izboljsave

pull/26/head
Jurij Podgoršek 2023-12-15 17:08:37 +01:00
parent cc4c427b89
commit 1ae74fdcd4
5 changed files with 30 additions and 52 deletions

15
doc/api.org 100644
View File

@ -0,0 +1,15 @@
# -*- restclient -*-
##########################
# YUFU API dokumentacija #
##########################
# Poganjamo z restclient major mode-om v emacsu
# Ustvari nov pad
POST https://yufu-manifest.ddev.site/etherpad-api/createPad?padID=d2d479bf-b3cb-455a-b7db-5d53c31d1fa2
Content-Type: application/x-www-form-urlencoded
text=While post-communist, post-socialist and post-Yugoslav discourses merely reinforce the appearance of an unchanging and unstable present with a more or less accurate expression of the situation, Yugofuturism follows the example of other ethnofuturist movements such as Afrofuturism, Sinofuturism, Baltic Ethnofuturism and Hungarofuturism, which tactically empower peripheral identities and subversively affirm individual cultural curiosities.
# Brisi vsebino pada
GET https://yufu-manifest.ddev.site/etherpad-api/deletePad?padID=d2d479bf-b3cb-455a-b7db-5d53c31d1fa2

View File

@ -3,4 +3,3 @@ JSONAPI_PATH="/jsonapi"
FILE_PATH="/sites/default/files"
ETHERPAD_URL="https://pisi.kompot.si"
ETHERPAD_API_URL="https://yufu-manifest.ddev.site/etherpad-api"
ETHERPAD_PREFIX="yufu-"

View File

@ -52,15 +52,14 @@ class Client {
/**
* Method description.
*/
public function request($method, $url) {
$uri = "{$this->baseUrl}/" . self::API_VERSION . '/' . $url;
if (str_contains($uri, '?')) {
$uri .= "&apikey={$this->apiKey}";
} else {
$uri .= "?apikey={$this->apiKey}";
public function request($method, $url, $opts = []) {
$uri = "{$this->baseUrl}/" . self::API_VERSION . '/' . explode('?', $url)[0];
if (!isset($opts['form_params'])) {
$opts['form_params'] = [];
}
$opts['form_params']['apikey'] = $this->apiKey;
$opts['verify'] = false;
return $this->httpClient->request($method, $uri);
return $this->httpClient->post($uri, $opts);
}
}

View File

@ -1,42 +0,0 @@
<?php
namespace Drupal\etherpad_api\Controller;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use GuzzleHttp\Exception\ClientException;
use Drupal\etherpad_api\Client;
/**
* Returns responses for Etherpad API routes.
*/
class EtherpadApiController extends ControllerBase {
protected $client;
public function __construct(Client $client) {
$this->client = $client;
}
public static function create(ContainerInterface $container) {
return new static($container->get('etherpad_api.client'));
}
/**
* Builds the response.
*/
public function build($components, Request $request) {
$uri = str_replace(':', '/', $components);
if ($params = $request->getQueryString()) {
$uri .= "?$params";
}
try {
return $this->client->request($request->getMethod(), $uri);
} catch (ClientException $exception) {
return new Response($exception->getMessage(), $exception->getCode());
}
}
}

View File

@ -33,8 +33,15 @@ class EtherpadApiController extends ControllerBase {
$uri .= "?$params";
}
$data = array_merge($request->query->all(), $request->request->all());
if ($data['padID']) {
// @TODO prefix v config!
$data['padID'] = 'yufu-' . $data['padID'];
}
$opts = ['form_params' => $data];
try {
return $this->client->request($request->getMethod(), $uri);
return $this->client->request($request->getMethod(), $uri, $opts);
} catch (ClientException $exception) {
return new Response($exception->getMessage(), $exception->getCode());
}