gathercontent / client
GatherContent client
Requires
- php: >=7.4
- guzzlehttp/guzzle: ^6.3 | ^7
Requires (Dev)
- phpunit/phpunit: ^9
- squizlabs/php_codesniffer: ^3.7
- webmozart/path-util: ^2.3
This package is not auto-updated.
Last update: 2024-12-16 15:59:48 UTC
README
Supported endpoints
Legacy
Compatible with application/vnd.gathercontent.v0.5+json
These endpoints are essential, so we kept the support for them in this new version. In the future these endpoints will be in the v2 API and we will replace them accordingly.
- GET: /me
$gc->meGet()
- GET: /accounts
$gc->accountsGet()
- GET: /accounts/:account_id
$gc->accountGet()
- GET: /projects
$gc->projectsGet()
- GET: /projects/:project_id
$gc->projectGet()
- POST: /projects
$gc->projectsPost()
- GET: /projects/:project_id/statuses
$gc->projectStatusesGet()
- GET: /projects/:project_id/statuses/:status_id
$gc->projectStatusGet()
- POST: /items/:item_id/choose_status
$gc->itemChooseStatusPost()
Current
Compatible with application/vnd.gathercontent.v2+json
Items
- GET: /projects/:project_id/items
$gc->itemsGet()
- GET: /items/:item_id
$gc->itemGet()
- POST: /projects/:project_id/items
$gc->itemPost()
- POST: /items/:item_id/content
$gc->itemUpdatePost()
- POST: /items/:item_id/rename
$gc->itemRenamePost()
- POST: /items/:item_id/move
$gc->itemMovePost()
- POST: /items/:item_id/apply_template
$gc->itemApplyTemplatePost()
- POST: /items/:item_id/disconnect_template
$gc->itemDisconnectTemplatePost()
- POST: /items/:item_id/duplicate
$gc->itemDuplicatePost()
Templates
- GET: /projects/:project_id/templates
$gc->templatesGet()
- GET: /templates/:template_id
$gc->templateGet()
- POST: /projects/:project_id/templates
$gc->templatePost()
- DELETE: /templates/:template_id/delete
$gc->templateDelete()
- POST: /templates/:template_id/rename
$gc->templateRenamePost()
- POST: /templates/:template_id/duplicate
$gc->templateDuplicatePost()
Structures
- GET: /structures/:structure_uuid
$gc->structureGet()
- PUT: /structures/:structure_uuid
$gc->structureAlterPut()
- POST: /structures/:structure_uuid/save_as_template
$gc->structureSaveAsTemplatePost()
Folders
- GET: /folders
$gc->foldersGet()
- POST: /folders
$gc->folderPost()
- POST: /folders
$gc->folderRenamePost()
- POST: /folders
$gc->folderMovePost()
- DELETE: /folders
$gc->folderDelete()
- POST: /folders
$gc->folderRestorePost()
Basic usage
To create the GatherContentClient simply pass in a Guzzle client in the constructor.
You will need:
- your e-mail address to log into GatherContent
- your API key from GatherContent
<?php $email = 'YOUR_GATHERCONTENT_EMAIL'; $apiKey = 'YOUR_GATHERCONTENT_API_KEY'; $client = new \GuzzleHttp\Client(); $gc = new \Cheppers\GatherContent\GatherContentClient($client); $gc ->setEmail($email) ->setApiKey($apiKey); try { $me = $gc->meGet(); } catch (\Exception $e) { echo 'ERROR: ' . $e->getMessage() . PHP_EOL; exit(1); } echo "Email = {$me->email}" . PHP_EOL; echo "First name = {$me->firstName}" . PHP_EOL; echo "Last name = {$me->lastName}" . PHP_EOL;
The listing endpoints are returning pagination data in this new version, you can access it like this:
<?php $email = 'YOUR_GATHERCONTENT_EMAIL'; $apiKey = 'YOUR_GATHERCONTENT_API_KEY'; $client = new \GuzzleHttp\Client(); $gc = new \Cheppers\GatherContent\GatherContentClient($client); $gc ->setEmail($email) ->setApiKey($apiKey); try { $projectId = 12345; $items = $gc->itemsGet($projectId); } catch (\Exception $e) { echo 'ERROR: ' . $e->getMessage() . PHP_EOL; exit(1); } $firstItem = reset($items['data']); echo "First content's name = {$firstItem->name}" . PHP_EOL; echo "Pagination total = {$items['pagination']->total}" . PHP_EOL; echo "Pagination current page = {$items['pagination']->currentPage}" . PHP_EOL;
For additional parameters please visit the documentation: /projects/:project_id/items.
The get template endpoint is returning structure object data in this new version, you can access it like this:
<?php $email = 'YOUR_GATHERCONTENT_EMAIL'; $apiKey = 'YOUR_GATHERCONTENT_API_KEY'; $client = new \GuzzleHttp\Client(); $gc = new \Cheppers\GatherContent\GatherContentClient($client); $gc ->setEmail($email) ->setApiKey($apiKey); try { $templateId = 12345; $template = $gc->templateGet($templateId); } catch (\Exception $e) { echo 'ERROR: ' . $e->getMessage() . PHP_EOL; exit(1); } echo "Template's name = {$template['data']->name}".PHP_EOL; echo "Structure UUID = {$template['related']->structure->id}".PHP_EOL; $group = reset($template['related']->structure->groups); echo "Structure's first Group's name = {$group->name}".PHP_EOL;
To create an item with assets, you can do the following:
<?php $email = 'YOUR_GATHERCONTENT_EMAIL'; $apiKey = 'YOUR_GATHERCONTENT_API_KEY'; $client = new \GuzzleHttp\Client(); $gc = new \Cheppers\GatherContent\GatherContentClient($client); $gc ->setEmail($email) ->setApiKey($apiKey); try { $projectId = 12345; $templateId = 12345; $item = $gc->itemPost($projectId, new Item([ 'name' => 'Item name', 'template_id' => $templateId, 'content' => [ 'field-uuid' => 'Body content', ], 'assets' => [ 'file-field-uuid' => [ '/path-to-your-file/test.jpg', '/path-to-your-file/test.txt', ], ], ])); } catch (\Exception $e) { echo 'ERROR: ' . $e->getMessage() . PHP_EOL; exit(1); } echo "Content's name = {$item['data']->name}".PHP_EOL; echo "Item ID = {$item['data']->id}".PHP_EOL; echo "Created assets array = {$item['meta']->assets}".PHP_EOL;
To update an item with assets, you can do the following:
<?php $email = 'YOUR_GATHERCONTENT_EMAIL'; $apiKey = 'YOUR_GATHERCONTENT_API_KEY'; $client = new \GuzzleHttp\Client(); $gc = new \Cheppers\GatherContent\GatherContentClient($client); $gc ->setEmail($email) ->setApiKey($apiKey); try { $itemId = 12345; $item = $gc->itemUpdatePost($itemId, [ 'field-uuid' => 'Body change', ], [ 'file-field-uuid' => [ '/path-to-your-file/test.jpg', '/path-to-your-file/test.txt', ], ]); } catch (\Exception $e) { echo 'ERROR: ' . $e->getMessage() . PHP_EOL; exit(1); } echo "Created assets array = {$item->assets}".PHP_EOL;
Credits
This library has been forked from https://github.com/Cheppers/gathercontent-client and re-released under a new name and ownership of Gathercontent.