Disclaimer : This library still in development. It had been setup in order to develop some PHP CMS specific modules, while keeping in common any possible part of code. At this state, the library implements only a small subset of the web api calls. Feel free to PR unimplemented ones to make this lib grow up. Some useful contributors' documentation can be found in this repository's docs/contributors directory.
useNuclia\ApiClient;
$token = '<your-nucliadb-token>';
$kbid = '<your-nucliadb-knoledgebox-id>';
$zone = '<your-nucliadb-zone>'; //Such as 'europe-1'$apiClient = newApiClient($zone, $token, $kbid);The search API aims to reflect NucliaDB search web API
$searchApi = $apiClient->createSearchApi();useNuclia\Query\SearchQuery;
$response = $searchApi->search((newSearchQuery())->setQuery('you+shall+not+pass'));$response returns an instance of Symfony HTTP Client response
The resources API aims to reflect NucliaDB resources web API
$resourcesApi = $apiClient->createResourcesApi();useNuclia\Query\GetResourceQuery;
$rid = '<resource-id>'$response = $resourcesApi->getResource($rid,(newGetResourceQuery()
->setShow(EnumArray::show([ShowEnum::VALUES, ShowEnum::BASIC]))
);$response = $resourcesApi->createResource([
'title' => 'The Fellowship of the Ring',
'links' => [
'link-1' => [
'uri' => 'https://en.wikipedia.org/wiki/The_Lord_of_the_Rings:_The_Fellowship_of_the_Ring'
]
]
]);$rid = '<resource-id>'$response = $resourcesApi->modifyResource(
$rid,
[
'title' => 'The Fellowship of the Ring (Updated)',
'links' => [
'link-1' => [
'uri' => 'https://www.rottentomatoes.com/m/the_lord_of_the_rings_the_fellowship_of_the_ring'
]
]
]);$rid = '<resource-id>'$resourcesApi->deleteResource($rid);The resource fields API aims to reflect NucliaDB resource fields web API
$resourceFieldsApi = $apiClient->createResourceFieldsApi();$body = file_get_contents('The-Fellowship-Of-The-Ring.jpg', 'r');
$md5 = md5($body);
$rid = '<resource-id>'$fieldId = '<field-id>'// A free string used to identify your file field in resource.$response = $resourceFieldsApi->uploadBinaryFile($rid, $fieldId, $body, (newUploadBinaryFileHeaders())->setMd5($md5));