etherpad prefix v drupal modul, dokumentacija APIja, WIP izboljsave
parent
cc4c427b89
commit
1ae74fdcd4
|
@ -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
|
|
@ -3,4 +3,3 @@ JSONAPI_PATH="/jsonapi"
|
||||||
FILE_PATH="/sites/default/files"
|
FILE_PATH="/sites/default/files"
|
||||||
ETHERPAD_URL="https://pisi.kompot.si"
|
ETHERPAD_URL="https://pisi.kompot.si"
|
||||||
ETHERPAD_API_URL="https://yufu-manifest.ddev.site/etherpad-api"
|
ETHERPAD_API_URL="https://yufu-manifest.ddev.site/etherpad-api"
|
||||||
ETHERPAD_PREFIX="yufu-"
|
|
||||||
|
|
|
@ -52,15 +52,14 @@ class Client {
|
||||||
/**
|
/**
|
||||||
* Method description.
|
* Method description.
|
||||||
*/
|
*/
|
||||||
public function request($method, $url) {
|
public function request($method, $url, $opts = []) {
|
||||||
$uri = "{$this->baseUrl}/" . self::API_VERSION . '/' . $url;
|
$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;
|
||||||
|
|
||||||
if (str_contains($uri, '?')) {
|
return $this->httpClient->post($uri, $opts);
|
||||||
$uri .= "&apikey={$this->apiKey}";
|
|
||||||
} else {
|
|
||||||
$uri .= "?apikey={$this->apiKey}";
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->httpClient->request($method, $uri);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -33,8 +33,15 @@ class EtherpadApiController extends ControllerBase {
|
||||||
$uri .= "?$params";
|
$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 {
|
try {
|
||||||
return $this->client->request($request->getMethod(), $uri);
|
return $this->client->request($request->getMethod(), $uri, $opts);
|
||||||
} catch (ClientException $exception) {
|
} catch (ClientException $exception) {
|
||||||
return new Response($exception->getMessage(), $exception->getCode());
|
return new Response($exception->getMessage(), $exception->getCode());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue