makina-corpus/nucliadb-php-client
最新稳定版本:0.2.0
Composer 安装命令:
composer require makina-corpus/nucliadb-php-client
包简介
PHP client for NucliaDB API
README 文档
README
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.
Usage
Initialize client API
use Nuclia\ApiClient; $token = '<your-nucliadb-token>'; $kbid = '<your-nucliadb-knoledgebox-id>'; $zone = '<your-nucliadb-zone>'; //Such as 'europe-1' $apiClient = new ApiClient($zone, $token, $kbid);
Using search API
The search API aims to reflect NucliaDB search web API
Create a search API instance
$searchApi = $apiClient->createSearchApi();
Run a simple full text search
use Nuclia\Query\SearchQuery; $response = $searchApi->search((new SearchQuery())->setQuery('you+shall+not+pass'));
$response returns an instance of Symfony HTTP Client response
Using resources API
The resources API aims to reflect NucliaDB resources web API
Create a resource API instance
$resourcesApi = $apiClient->createResourcesApi();
Get resource.
use Nuclia\Query\GetResourceQuery; $rid = '<resource-id>' $response = $resourcesApi->getResource($rid,(new GetResourceQuery() ->setShow(EnumArray::show([ShowEnum::VALUES, ShowEnum::BASIC])) );
Create resource.
$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' ] ] ]);
Update resource.
$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' ] ] ]);
Delete resource.
$rid = '<resource-id>' $resourcesApi->deleteResource($rid);
Using resource fields API
The resource fields API aims to reflect NucliaDB resource fields web API
Create a resource fields API instance
$resourceFieldsApi = $apiClient->createResourceFieldsApi();
Upload a binary File as a resource field
$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, (new UploadBinaryFileHeaders())->setMd5($md5));
统计信息
- 总下载量: 727
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-09-21