diff --git a/CHANGELOG.md b/CHANGELOG.md index 2116508..9147412 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ All notable changes to `laravel-xibo-api` will be documented in this file. -## 1.0.0 - 202X-XX-XX +## 0.1.0 - 2021-01-28 - initial release +- adds basics for the wrapper diff --git a/README.md b/README.md index f714805..6ec7e68 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,10 @@ # A Laravel package for using the Xibo api [![Latest Version on Packagist](https://img.shields.io/packagist/v/wimmie/laravel-xibo-api.svg?style=flat-square)](https://packagist.org/packages/wimmie/laravel-xibo-api) -[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/wimmie/laravel-xibo-api/run-tests?label=tests)](https://github.com/wimmie/laravel-xibo-api/actions?query=workflow%3ATests+branch%3Amaster) [![Total Downloads](https://img.shields.io/packagist/dt/wimmie/laravel-xibo-api.svg?style=flat-square)](https://packagist.org/packages/wimmie/laravel-xibo-api) -This is where your description should go. Limit it to a paragraph or two. Consider adding a small example. - -## Support us - -[](https://spatie.be/github-ad-click/package-laravel-xibo-api-laravel) - -We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us). - -We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards). +A wrapper for the Xibo api, see https://xibo.org.uk/manual/api/ as well. ## Installation @@ -23,13 +14,6 @@ You can install the package via composer: composer require wimmie/laravel-xibo-api ``` -You can publish and run the migrations with: - -```bash -php artisan vendor:publish --provider="Wimmie\XiboApi\XiboApiServiceProvider" --tag="migrations" -php artisan migrate -``` - You can publish the config file with: ```bash php artisan vendor:publish --provider="Wimmie\XiboApi\XiboApiServiceProvider" --tag="config" @@ -39,14 +23,17 @@ This is the contents of the published config file: ```php return [ + 'url' => env('XIBO_URL', ''), + 'client_id' => env('XIBO_CLIENT_ID', ''), + 'client_secret' => env('XIBO_CLIENT_SECRET', ''), ]; ``` ## Usage ```php -$laravel-xibo-api = new Wimmie\XiboApi(); -echo $laravel-xibo-api->echoPhrase('Hello, Wimmie!'); +$xiboApi = new Wimmie\XiboApi(); +echo $xiboApi->misc()->about(); ``` ## Testing @@ -70,7 +57,6 @@ Please review [our security policy](../../security/policy) on how to report secu ## Credits - [Willem](https://github.com/wimmie) -- [All Contributors](../../contributors) ## License diff --git a/composer.json b/composer.json index 9255d03..1838045 100644 --- a/composer.json +++ b/composer.json @@ -18,9 +18,10 @@ ], "require": { "php": "^7.4|^8.0", - "illuminate/contracts": "^8.0", "ext-curl": "*", - "ext-json": "*" + "ext-json": "*", + "illuminate/contracts": "^8.0", + "spatie/laravel-ray": "^1.9" }, "require-dev": { "orchestra/testbench": "^6.0", @@ -28,8 +29,7 @@ }, "autoload": { "psr-4": { - "Wimmie\\XiboApi\\": "src", - "Wimmie\\XiboApi\\Database\\Factories\\": "database/factories" + "Wimmie\\XiboApi\\": "src" } }, "autoload-dev": { diff --git a/src/Categories/CategoryWithCrud.php b/src/Categories/CategoryWithCrud.php index 4b23aea..de568bb 100644 --- a/src/Categories/CategoryWithCrud.php +++ b/src/Categories/CategoryWithCrud.php @@ -36,7 +36,8 @@ public function add(array $data) * @param array $data * @return mixed */ - public function edit(int $id, array $data) { + public function edit(int $id, array $data) + { $url = $this->xiboApi->generateUrl($this->name, null, $id); return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_PUT, $data); } @@ -46,7 +47,8 @@ public function edit(int $id, array $data) { * @param int $id * @return mixed */ - public function delete(int $id) { + public function delete(int $id) + { $url = $this->xiboApi->generateUrl($this->name, null, $id); return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_DELETE); } diff --git a/src/Categories/Command.php b/src/Categories/Command.php index d70ba23..afb1cbd 100644 --- a/src/Categories/Command.php +++ b/src/Categories/Command.php @@ -4,8 +4,6 @@ namespace Wimmie\XiboApi\Categories; -use Wimmie\XiboApi\XiboApi; - class Command extends CategoryWithCrud { /** diff --git a/src/Categories/Dataset.php b/src/Categories/Dataset.php index 6c665e2..7a041e8 100644 --- a/src/Categories/Dataset.php +++ b/src/Categories/Dataset.php @@ -12,4 +12,40 @@ class Dataset extends CategoryWithCrud * @inheritdoc */ protected string $name = 'dataset'; + + /** + * Copy DataSet + * @param int $id + * @param array $data + * @return mixed + */ + public function copy(int $id, array $data) + { + $url = $this->xiboApi->generateUrl($this->name, 'copy', $id); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_POST, $data); + } + + /** + * Import CSV + * @param int $id + * @param array $data + * @return mixed + */ + public function importCsv(int $id, array $data) + { + $url = $this->xiboApi->generateUrl($this->name, 'import', $id); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_POST, $data); + } + + /** + * Import JSON + * @param int $id + * @param string $json + * @return mixed + */ + public function importJson(int $id, string $json) + { + $url = $this->xiboApi->generateUrl($this->name, 'importjson', $id); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_POST, null, null, $json); + } } diff --git a/src/Categories/DatasetColumn.php b/src/Categories/DatasetColumn.php new file mode 100644 index 0000000..6ec7aa6 --- /dev/null +++ b/src/Categories/DatasetColumn.php @@ -0,0 +1,21 @@ +name = str_replace('{datasetId}', $datasetId, $this->name); + parent::__construct($xiboApi); + } +} diff --git a/src/Categories/DatasetData.php b/src/Categories/DatasetData.php new file mode 100644 index 0000000..209bfec --- /dev/null +++ b/src/Categories/DatasetData.php @@ -0,0 +1,65 @@ +name = str_replace('{datasetId}', $datasetId, $this->name); + parent::__construct($xiboApi); + } + + /** + * Search + * @return mixed + */ + public function get() + { + $url = $this->xiboApi->generateUrl($this->name); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_GET); + } + + /** + * Add + * @param array $data + * @return mixed + */ + public function add(array $data) + { + $url = $this->xiboApi->generateUrl($this->name); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_POST, $data); + } + + /** + * Edit + * @param int $id + * @param array $data + * @return mixed + */ + public function edit(int $id, array $data) + { + $url = $this->xiboApi->generateUrl($this->name, null, $id); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_PUT, $data); + } + + /** + * Delete + * @param int $id + * @return mixed + */ + public function delete(int $id) + { + $url = $this->xiboApi->generateUrl($this->name, null, $id); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_DELETE); + } +} diff --git a/src/Categories/DatasetRss.php b/src/Categories/DatasetRss.php new file mode 100644 index 0000000..13470ad --- /dev/null +++ b/src/Categories/DatasetRss.php @@ -0,0 +1,21 @@ +name = str_replace('{datasetId}', $datasetId, $this->name); + parent::__construct($xiboApi); + } +} diff --git a/src/Categories/DayPart.php b/src/Categories/DayPart.php index 4813146..bd6b39c 100644 --- a/src/Categories/DayPart.php +++ b/src/Categories/DayPart.php @@ -4,8 +4,6 @@ namespace Wimmie\XiboApi\Categories; -use Wimmie\XiboApi\XiboApi; - class DayPart extends CategoryWithCrud { /** diff --git a/src/Categories/Display.php b/src/Categories/Display.php index f033a61..508f603 100644 --- a/src/Categories/Display.php +++ b/src/Categories/Display.php @@ -12,4 +12,93 @@ class Display extends Category * @inheritdoc */ protected string $name = 'display'; + + /** + * Search + * @param array|null $parameters + * @return mixed + */ + public function search(array $parameters = null) + { + $url = $this->xiboApi->generateUrl($this->name, null, null, $parameters); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_GET); + } + + /** + * Edit + * @param int $id + * @param array $data + * @return mixed + */ + public function edit(int $id, array $data) + { + $url = $this->xiboApi->generateUrl($this->name, null, $id); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_PUT, $data); + } + + /** + * Delete + * @param int $id + * @return mixed + */ + public function delete(int $id) + { + $url = $this->xiboApi->generateUrl($this->name, null, $id); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_DELETE); + } + + /** + * Request Screen Shot + * @param int $id + * @return mixed + */ + public function requestScreenshot(int $id) + { + $url = $this->xiboApi->generateUrl($this->name, 'requestscreenshot', $id); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_PUT); + } + + /** + * Issue WOL + * @param int $id + * @return mixed + */ + public function wol(int $id) + { + $url = $this->xiboApi->generateUrl($this->name, 'wol', $id); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_POST); + } + + /** + * Toggle authorised + * @param int $id + * @return mixed + */ + public function toggleAuthorised(int $id) + { + $url = $this->xiboApi->generateUrl($this->name, 'authorise', $id); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_PUT); + } + + /** + * Set Default Layout + * @param int $id + * @return mixed + */ + public function defaultLayout(int $id, array $data) + { + $url = $this->xiboApi->generateUrl($this->name, 'defaultlayout', $id); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_PUT, $data); + } + + /** + * Licence Check + * @param int $id + * @return mixed + */ + public function licenceCheck(int $id) + { + $url = $this->xiboApi->generateUrl($this->name, 'licencecheck', $id); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_PUT); + } } diff --git a/src/Categories/DisplayGroup.php b/src/Categories/DisplayGroup.php index 6b19732..d633b4a 100644 --- a/src/Categories/DisplayGroup.php +++ b/src/Categories/DisplayGroup.php @@ -12,4 +12,16 @@ class DisplayGroup extends CategoryWithCrud * @inheritdoc */ protected string $name = 'displaygroup'; + + /** + * Copy Display Group + * @param $id + * @param array $data + * @return mixed + */ + public function copy(int $id, array $data) + { + $url = $this->xiboApi->generateUrl($this->name, null, $id) . '/copy'; + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_POST, $data); + } } diff --git a/src/Categories/DisplayGroupAction.php b/src/Categories/DisplayGroupAction.php new file mode 100644 index 0000000..fcf9f7d --- /dev/null +++ b/src/Categories/DisplayGroupAction.php @@ -0,0 +1,83 @@ +name = str_replace('{displayGroupId}', $displayGroupId, $this->name); + parent::__construct($xiboApi); + } + + /** + * Action: Collect Now + * @return mixed + */ + public function collectNow() + { + $url = $this->xiboApi->generateUrl($this->name, 'collectNow'); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_POST); + } + + /** + * Action: Clear Stats and Logs + * @return mixed + */ + public function clearStatsAndLogs() + { + $url = $this->xiboApi->generateUrl($this->name, 'clearStatsAndLogs'); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_POST); + } + + /** + * Action: Change Layout + * @return mixed + */ + public function changeLayout(array $data) + { + $url = $this->xiboApi->generateUrl($this->name, 'changelayout'); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_POST, $data); + } + + /** + * Action: Revert to Schedule + * @return mixed + */ + public function revertToSchedule() + { + $url = $this->xiboApi->generateUrl($this->name, 'revertToSchedule'); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_POST); + } + + /** + * Action: Overlay Layout + * @param array $data + * @return mixed + */ + public function overlayLayout(array $data) + { + $url = $this->xiboApi->generateUrl($this->name, 'overlaylayout'); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_POST, $data); + } + + /** + * Action: Overlay Layout + * @param array $data + * @return mixed + */ + public function command(array $data) + { + $url = $this->xiboApi->generateUrl($this->name, 'command'); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_POST, $data); + } +} diff --git a/src/Categories/DisplayGroupDisplay.php b/src/Categories/DisplayGroupDisplay.php new file mode 100644 index 0000000..3c1989b --- /dev/null +++ b/src/Categories/DisplayGroupDisplay.php @@ -0,0 +1,43 @@ +name = str_replace('{displayGroupId}', $displayGroupId, $this->name); + parent::__construct($xiboApi); + } + + /** + * Assign one or more Displays to a Display Group + * @param array $data + * @return mixed + */ + public function assign(array $data) + { + $url = $this->xiboApi->generateUrl($this->name, 'assign'); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_POST, $data); + } + + /** + * Unassigns one or more Displays to a Display Group + * @param array $data + * @return mixed + */ + public function unassign(array $data) + { + $url = $this->xiboApi->generateUrl($this->name, 'unassign'); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_POST, $data); + } +} diff --git a/src/Categories/DisplayGroupDisplayGroup.php b/src/Categories/DisplayGroupDisplayGroup.php new file mode 100644 index 0000000..897979e --- /dev/null +++ b/src/Categories/DisplayGroupDisplayGroup.php @@ -0,0 +1,43 @@ +name = str_replace('{displayGroupId}', $displayGroupId, $this->name); + parent::__construct($xiboApi); + } + + /** + * Assign one or more DisplaysGroups to a Display Group + * @param array $data + * @return mixed + */ + public function assign(array $data) + { + $url = $this->xiboApi->generateUrl($this->name, 'assign'); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_POST, $data); + } + + /** + * Unassigns one or more DisplaysGroups to a Display Group + * @param array $data + * @return mixed + */ + public function unassign(array $data) + { + $url = $this->xiboApi->generateUrl($this->name, 'unassign'); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_POST, $data); + } +} diff --git a/src/Categories/DisplayGroupLayout.php b/src/Categories/DisplayGroupLayout.php new file mode 100644 index 0000000..606f802 --- /dev/null +++ b/src/Categories/DisplayGroupLayout.php @@ -0,0 +1,43 @@ +name = str_replace('{displayGroupId}', $displayGroupId, $this->name); + parent::__construct($xiboApi); + } + + /** + * Assign one or more Layout items to a Display Group + * @param array $data + * @return mixed + */ + public function assign(array $data) + { + $url = $this->xiboApi->generateUrl($this->name, 'assign'); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_POST, $data); + } + + /** + * Unassigns one or more Layout items to a Display Group + * @param array $data + * @return mixed + */ + public function unassign(array $data) + { + $url = $this->xiboApi->generateUrl($this->name, 'unassign'); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_POST, $data); + } +} diff --git a/src/Categories/DisplayGroupMedia.php b/src/Categories/DisplayGroupMedia.php new file mode 100644 index 0000000..918ebe2 --- /dev/null +++ b/src/Categories/DisplayGroupMedia.php @@ -0,0 +1,43 @@ +name = str_replace('{displayGroupId}', $displayGroupId, $this->name); + parent::__construct($xiboApi); + } + + /** + * Assign one or more Media items to a Display Group + * @param array $data + * @return mixed + */ + public function assign(array $data) + { + $url = $this->xiboApi->generateUrl($this->name, 'assign'); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_POST, $data); + } + + /** + * Unassigns one or more Media items to a Display Group + * @param array $data + * @return mixed + */ + public function unassign(array $data) + { + $url = $this->xiboApi->generateUrl($this->name, 'unassign'); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_POST, $data); + } +} diff --git a/src/Categories/DisplayProfile.php b/src/Categories/DisplayProfile.php index cd8e84e..65cc887 100644 --- a/src/Categories/DisplayProfile.php +++ b/src/Categories/DisplayProfile.php @@ -14,16 +14,14 @@ class DisplayProfile extends CategoryWithCrud protected string $name = 'displayprofile'; /** - * Assign Layouts - * @param int $id + * Copy Display Profile + * @param $id * @param array $data * @return mixed */ - public function copy(int $id, string $name) + public function copy(int $id, array $data) { - $url = $this->xiboApi->generateUrl($this->name, 'layout/assign', $id, [ - 'name' => $name, - ]); - return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_POST); + $url = $this->xiboApi->generateUrl($this->name, null, $id) . '/copy'; + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_POST, $data); } } diff --git a/src/Categories/Layout.php b/src/Categories/Layout.php index d43a6e1..a62beef 100644 --- a/src/Categories/Layout.php +++ b/src/Categories/Layout.php @@ -12,4 +12,85 @@ class Layout extends CategoryWithCrud * @inheritdoc */ protected string $name = 'layout'; + + /** + * Copy layout + * @param $id + * @param array $data + * @return mixed + */ + public function copy(int $id, array $data) + { + $url = $this->xiboApi->generateUrl($this->name, 'copy', $id); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_POST, $data); + } + + /** + * Tag layout + * @param $id + * @param array $data + * @return mixed + */ + public function tag(int $id, array $data) + { + $url = $this->xiboApi->generateUrl($this->name, null, $id) . '/tag'; + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_POST, $data); + } + + /** + * Untag layout + * @param $id + * @param array $data + * @return mixed + */ + public function untag(int $id, array $data) + { + $url = $this->xiboApi->generateUrl($this->name, null, $id) . '/tag'; + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_POST, $data); + } + + /** + * Layout Status + * @param int $id + * @return mixed + */ + public function status(int $id) + { + $url = $this->xiboApi->generateUrl($this->name, 'status', $id); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_GET); + } + + /** + * Checkout Layout + * @param int $id + * @return mixed + */ + public function checkout(int $id) + { + $url = $this->xiboApi->generateUrl($this->name, 'checkout', $id); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_PUT); + } + + /** + * Publish Layout + * @param int $id + * @param array $data + * @return mixed + */ + public function publish(int $id, array $data) + { + $url = $this->xiboApi->generateUrl($this->name, 'publish', $id); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_PUT, $data); + } + + /** + * Discard Layout + * @param int $id + * @return mixed + */ + public function discard(int $id) + { + $url = $this->xiboApi->generateUrl($this->name, 'discard', $id); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_PUT); + } } diff --git a/src/Categories/Library.php b/src/Categories/Library.php index bbbe682..d495df8 100644 --- a/src/Categories/Library.php +++ b/src/Categories/Library.php @@ -12,4 +12,119 @@ class Library extends CategoryWithCrud * @inheritdoc */ protected string $name = 'library'; + + /** + * Enable Stats Collection + * @param int $id + * @param array $data + * @return mixed + */ + public function setEnableStats(int $id, array $data) + { + $url = $this->xiboApi->generateUrl($this->name, 'setenablestats', $id); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_PUT, $data); + } + + /** + * Tidy Library + * @param array|null $data + * @return mixed + */ + public function tidy(array $data = null) + { + $url = $this->xiboApi->generateUrl($this->name, 'tidy'); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_DELETE, $data); + } + + /** + * Download Media + * @param int $id + * @param string $type + * @return mixed + */ + public function download(int $id, string $type) + { + $url = $this->xiboApi->generateUrl($this->name, 'download', $id) . '/' . $type; + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_GET); + } + + /** + * Tag layout + * @param $id + * @param array $data + * @return mixed + */ + public function tag(int $id, array $data) + { + $url = $this->xiboApi->generateUrl($this->name, null, $id) . '/tag'; + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_POST, $data); + } + + /** + * Untag layout + * @param $id + * @param array $data + * @return mixed + */ + public function untag(int $id, array $data) + { + $url = $this->xiboApi->generateUrl($this->name, null, $id) . '/tag'; + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_POST, $data); + } + + /** + * Get Library Item Usage Report + * @param int $id + * @return mixed + */ + public function usage(int $id) + { + $url = $this->xiboApi->generateUrl($this->name, 'usage', $id); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_GET); + } + + /** + * Get Library Item Usage Report for Layouts + * @param int $id + * @return mixed + */ + public function usageLayouts(int $id) + { + $url = $this->xiboApi->generateUrl($this->name, 'usage/layouts', $id); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_GET); + } + + /** + * Copy Media + * @param $id + * @param array $data + * @return mixed + */ + public function copy(int $id, array $data) + { + $url = $this->xiboApi->generateUrl($this->name, 'copy', $id); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_POST, $data); + } + + /** + * Media usage check + * @param int $id + * @return mixed + */ + public function isUsed(int $id) + { + $url = $this->xiboApi->generateUrl($this->name, null, $id) . '/isused'; + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_GET); + } + + /** + * Upload Media from URL + * @param array $data + * @return mixed + */ + public function uploadUrl(array $data) + { + $url = $this->xiboApi->generateUrl($this->name, 'uploadUrl'); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_POST, $data); + } } diff --git a/src/Categories/Misc.php b/src/Categories/Misc.php index f735cb4..0efe156 100644 --- a/src/Categories/Misc.php +++ b/src/Categories/Misc.php @@ -14,7 +14,7 @@ class Misc extends Category public function clock() { $url = $this->xiboApi->generateUrl('clock'); - return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_GET); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_GET); } /** @@ -24,6 +24,6 @@ public function clock() public function about() { $url = $this->xiboApi->generateUrl('about'); - return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_GET); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_GET); } } diff --git a/src/Categories/PlayerSoftware.php b/src/Categories/PlayerSoftware.php index 4b404fd..df125bf 100644 --- a/src/Categories/PlayerSoftware.php +++ b/src/Categories/PlayerSoftware.php @@ -12,4 +12,27 @@ class PlayerSoftware extends Category * @inheritdoc */ protected string $name = 'playersoftware'; + + /** + * Edit Player Version + * @param int $versionId + * @param array|null $data + * @return mixed + */ + public function edit(int $versionId, array $data = null) + { + $url = $this->xiboApi->generateUrl($this->name, null, $versionId); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_PUT, $data); + } + + /** + * Delete Version + * @param int $versionId + * @return mixed + */ + public function delete(int $versionId) + { + $url = $this->xiboApi->generateUrl($this->name, null, $versionId); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_DELETE); + } } diff --git a/src/Categories/Playlist.php b/src/Categories/Playlist.php index 0c05450..fbeaeff 100644 --- a/src/Categories/Playlist.php +++ b/src/Categories/Playlist.php @@ -12,4 +12,119 @@ class Playlist extends Category * @inheritdoc */ protected string $name = 'playlist'; + + /** + * Search + * @param array|null $parameters + * @return mixed + */ + public function search(array $parameters = null) + { + $url = $this->xiboApi->generateUrl($this->name, null, null, $parameters); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_GET); + } + + /** + * Add + * @param array $data + * @return mixed + */ + public function add(array $data) + { + $url = $this->xiboApi->generateUrl($this->name); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_POST, $data); + } + + /** + * Edit + * @param int $id + * @param array $data + * @return mixed + */ + public function edit(int $id, array $data) + { + $url = $this->xiboApi->generateUrl($this->name, null, $id); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_PUT, $data); + } + + /** + * Copy Playlist + * @param $id + * @param array $data + * @return mixed + */ + public function copy(int $id, array $data) + { + $url = $this->xiboApi->generateUrl($this->name, 'copy', $id); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_POST, $data); + } + + /** + * Playlist Widget Search + * @param array|null $parameters + * @return mixed + */ + public function searchWidget(array $parameters = null) + { + $url = $this->xiboApi->generateUrl($this->name, 'widget', null, $parameters); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_GET); + } + + /** + * Assign Library Items + * @param $id + * @param array $data + * @return mixed + */ + public function assignLibrary(int $id, array $data) + { + $url = $this->xiboApi->generateUrl($this->name, 'library/assign', $id); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_POST, $data); + } + + /** + * Order Widgets + * @param $id + * @param array $data + * @return mixed + */ + public function order(int $id, array $data) + { + $url = $this->xiboApi->generateUrl($this->name, 'order', $id); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_POST, $data); + } + + /** + * Get Playlist Item Usage Report + * @param int $id + * @return mixed + */ + public function usageReport(int $id) + { + $url = $this->xiboApi->generateUrl($this->name, 'usage', $id); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_GET); + } + + /** + * Get Playlist Item Usage Report for Layouts + * @param int $id + * @return mixed + */ + public function usageLayoutReport(int $id) + { + $url = $this->xiboApi->generateUrl($this->name, 'usage/layouts', $id); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_GET); + } + + /** + * Enable Stats Collection + * @param int $id + * @param array $data + * @return mixed + */ + public function setEnableStat(int $id, array $data) + { + $url = $this->xiboApi->generateUrl($this->name, 'setenablestat', $id); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_PUT, $data); + } } diff --git a/src/Categories/Region.php b/src/Categories/Region.php new file mode 100644 index 0000000..c3144ed --- /dev/null +++ b/src/Categories/Region.php @@ -0,0 +1,61 @@ +xiboApi->generateUrl($this->name); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_POST, $data); + } + + /** + * Edit Region + * @param int $id + * @param array $data + * @return mixed + */ + public function edit(int $id, array $data) + { + $url = $this->xiboApi->generateUrl($this->name, null, $id); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_PUT, $data); + } + + /** + * Delete Region + * @param int $id + * @return mixed + */ + public function delete(int $id) + { + $url = $this->xiboApi->generateUrl($this->name, null, $id); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_DELETE); + } + + /** + * Position Regions + * @param int $layoutId + * @param array $data + * @return mixed + */ + public function position(int $layoutId, array $data) + { + $url = $this->xiboApi->generateUrl($this->name, 'position/all', $layoutId); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_PUT, $data); + } +} diff --git a/src/Categories/Resolution.php b/src/Categories/Resolution.php index 33e6d2b..79ec64d 100644 --- a/src/Categories/Resolution.php +++ b/src/Categories/Resolution.php @@ -4,8 +4,6 @@ namespace Wimmie\XiboApi\Categories; -use Wimmie\XiboApi\XiboApi; - class Resolution extends CategoryWithCrud { /** diff --git a/src/Categories/Schedule.php b/src/Categories/Schedule.php index dc0aa16..f6988a8 100644 --- a/src/Categories/Schedule.php +++ b/src/Categories/Schedule.php @@ -30,7 +30,8 @@ public function calendar(array $parameters = null) * @param array $parameters * @return mixed */ - public function list(int $displayGroupId, array $parameters) { + public function list(int $displayGroupId, array $parameters) + { $url = $this->xiboApi->generateUrl($this->name, 'events', $displayGroupId, $parameters); return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_GET); } @@ -40,7 +41,8 @@ public function list(int $displayGroupId, array $parameters) { * @param array $data * @return mixed */ - public function add(array $data) { + public function add(array $data) + { $url = $this->xiboApi->generateUrl($this->name); return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_POST, $data); } @@ -51,7 +53,8 @@ public function add(array $data) { * @param array $data * @return mixed */ - public function edit(int $eventId, array $data) { + public function edit(int $eventId, array $data) + { $url = $this->xiboApi->generateUrl($this->name, null, $eventId); return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_PUT, $data); } @@ -61,7 +64,8 @@ public function edit(int $eventId, array $data) { * @param int $eventId * @return mixed */ - public function delete(int $eventId) { + public function delete(int $eventId) + { $url = $this->xiboApi->generateUrl($this->name, null, $eventId); return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_DELETE); } @@ -71,7 +75,8 @@ public function delete(int $eventId) { * @param int $eventId * @return mixed */ - public function deleteRecurrence(int $eventId) { + public function deleteRecurrence(int $eventId) + { $url = $this->xiboApi->generateUrl($this->name . 'recurrence', null, $eventId); return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_DELETE); } diff --git a/src/Categories/Statistics.php b/src/Categories/Statistics.php index 02f8a27..39ed9a0 100644 --- a/src/Categories/Statistics.php +++ b/src/Categories/Statistics.php @@ -12,4 +12,24 @@ class Statistics extends Category * @inheritdoc */ protected string $name = 'stats'; + + /** + * @param array|null $parameters + * @return mixed + */ + public function stats(array $parameters = null) + { + $url = $this->xiboApi->generateUrl($this->name, null, null, $parameters); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_GET); + } + + /** + * @param array|null $parameters + * @return mixed + */ + public function timeDisconnected(array $parameters = null) + { + $url = $this->xiboApi->generateUrl($this->name, 'timeDisconnected', null, $parameters); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_GET); + } } diff --git a/src/Categories/Tags.php b/src/Categories/Tags.php index 5aca85b..258e26c 100644 --- a/src/Categories/Tags.php +++ b/src/Categories/Tags.php @@ -4,8 +4,6 @@ namespace Wimmie\XiboApi\Categories; -use Wimmie\XiboApi\XiboApi; - class Tags extends CategoryWithCrud { /** diff --git a/src/Categories/Template.php b/src/Categories/Template.php index 049f37a..b7b3c40 100644 --- a/src/Categories/Template.php +++ b/src/Categories/Template.php @@ -12,4 +12,27 @@ class Template extends Category * @inheritdoc */ protected string $name = 'template'; + + /** + * Template Search + * @param array|null $parameters + * @return mixed + */ + public function search(array $parameters = null) + { + $url = $this->xiboApi->generateUrl($this->name, null, null, $parameters); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_GET); + } + + /** + * Add a template from a Layout + * @param int $layoutId + * @param array|null $data + * @return mixed + */ + public function addFromLayout(int $layoutId, array $data = null) + { + $url = $this->xiboApi->generateUrl($this->name, null, $layoutId); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_GET, $data); + } } diff --git a/src/Categories/User.php b/src/Categories/User.php index abb482a..d807b45 100644 --- a/src/Categories/User.php +++ b/src/Categories/User.php @@ -12,4 +12,72 @@ class User extends CategoryWithCrud * @inheritdoc */ protected string $name = 'user'; + + /** + * Get Me + * @return mixed + */ + public function me() + { + $url = $this->xiboApi->generateUrl($this->name, 'me'); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_GET); + } + + /** + * Permission Data + * @param string $entity + * @param int $objectId + * @return mixed + */ + public function permissionData(string $entity, int $objectId) + { + $url = $this->xiboApi->generateUrl($this->name, 'permissions') . '/' . $entity . '/' . $objectId; + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_GET); + } + + /** + * Permission Set + * @param string $entity + * @param int $objectId + * @param array $data + * @return mixed + */ + public function permissionSet(string $entity, int $objectId, array $data) + { + $url = $this->xiboApi->generateUrl($this->name, 'permissions') . '/' . $entity . '/' . $objectId; + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_GET, $data); + } + + /** + * Retrieve User Preferences + * @param array|null $parameters + * @return mixed + */ + public function preferences(array $parameters = null) + { + $url = $this->xiboApi->generateUrl($this->name, 'pref', null, $parameters); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_GET); + } + + /** + * Save User Preferences + * @param array|null $data + * @return mixed + */ + public function savePreferences(array $data = null) + { + $url = $this->xiboApi->generateUrl($this->name, 'pref'); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_PUT, $data); + } + + /** + * Save User Preferences + * @param array|null $data + * @return mixed + */ + public function saveNonStatePreferences(array $data = null) + { + $url = $this->xiboApi->generateUrl($this->name, 'pref'); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_POST, $data); + } } diff --git a/src/Categories/UserGroup.php b/src/Categories/UserGroup.php index 0073690..26fe309 100644 --- a/src/Categories/UserGroup.php +++ b/src/Categories/UserGroup.php @@ -12,4 +12,40 @@ class UserGroup extends CategoryWithCrud * @inheritdoc */ protected string $name = 'group'; + + /** + * Assign User to User Group + * @param int $id + * @param array|null $data + * @return mixed + */ + public function assign(int $id, array $data) + { + $url = $this->xiboApi->generateUrl($this->name, 'members/assign', $id); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_POST, $data); + } + + /** + * Unassign User to User Group + * @param int $id + * @param array|null $data + * @return mixed + */ + public function unassign(int $id, array $data) + { + $url = $this->xiboApi->generateUrl($this->name, 'members/unassign', $id); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_POST, $data); + } + + /** + * Copy User Group + * @param $id + * @param array $data + * @return mixed + */ + public function copy(int $id, array $data) + { + $url = $this->xiboApi->generateUrl($this->name, null, $id) . '/copy'; + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_POST, $data); + } } diff --git a/src/Categories/Widget.php b/src/Categories/Widget.php index ffe4620..8b7fa12 100644 --- a/src/Categories/Widget.php +++ b/src/Categories/Widget.php @@ -12,4 +12,89 @@ class Widget extends Category * @inheritdoc */ protected string $name = 'playlist/widget'; + + /** + * Add a Widget to a Playlist + * @param string $type + * @param int $playlistId + * @param array|null $data + * @return mixed + */ + public function add(string $type, int $playlistId, array $data = null) + { + $url = $this->xiboApi->generateUrl($this->name) . '/' . $type . '/' . $playlistId; + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_POST, $data); + } + + /** + * Delete a Widget + * @param int $id + * @return mixed + */ + public function delete(int $id) + { + $url = $this->xiboApi->generateUrl($this->name, null, $id); + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_DELETE); + } + + /** + * Adds In/Out transition + * @param string $type + * @param int $playlistId + * @param array $data + * @return mixed + */ + public function addTransition(string $type, int $playlistId, array $data) + { + $url = $this->xiboApi->generateUrl($this->name, 'transition') . '/' . $type . '/' . $playlistId; + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_PUT, $data); + } + + /** + * Parameters for edting/adding audio file to a specific widget + * @param int $id + * @param array|null $data + * @return mixed + */ + public function audioParameters(int $id, array $data = null) + { + $url = $this->xiboApi->generateUrl($this->name, null, $id) . '/audio'; + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_PUT, $data); + } + + /** + * Delete assigned audio widget + * @param int $id + * @return mixed + */ + public function deleteAudio(int $id) + { + $url = $this->xiboApi->generateUrl($this->name, null, $id) . '/audio'; + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_DELETE); + } + + /** + * Set Widget From/To Dates + * @param int $id + * @param array|null $data + * @return mixed + */ + public function expiry(int $id, array $data = null) + { + $url = $this->xiboApi->generateUrl($this->name, null, $id) . '/expiry'; + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_PUT, $data); + } + + /** + * Edit Widget + * @param int $id + * @param string $type + * @param array|null $data + * @return mixed + */ + public function edit(int $id, string $type, array $data = null) + { + $url = $this->xiboApi->generateUrl($this->name, null, $id) . '?' . $type . '='; + return $this->xiboApi->sendRequest($url, XiboApi::REQUEST_PUT, $data); + } } diff --git a/src/XiboApi.php b/src/XiboApi.php index b2f5fb0..a33da8b 100644 --- a/src/XiboApi.php +++ b/src/XiboApi.php @@ -2,11 +2,35 @@ namespace Wimmie\XiboApi; -use CURLFile; -use Mockery\Matcher\Not; use Wimmie\XiboApi\Categories\Campaign; +use Wimmie\XiboApi\Categories\Dataset; +use Wimmie\XiboApi\Categories\DatasetColumn; +use Wimmie\XiboApi\Categories\DatasetData; +use Wimmie\XiboApi\Categories\DatasetRss; +use Wimmie\XiboApi\Categories\DayPart; +use Wimmie\XiboApi\Categories\Display; +use Wimmie\XiboApi\Categories\DisplayGroup; +use Wimmie\XiboApi\Categories\DisplayGroupAction; +use Wimmie\XiboApi\Categories\DisplayGroupDisplay; +use Wimmie\XiboApi\Categories\DisplayGroupDisplayGroup; +use Wimmie\XiboApi\Categories\DisplayGroupLayout; +use Wimmie\XiboApi\Categories\DisplayGroupMedia; +use Wimmie\XiboApi\Categories\DisplayProfile; +use Wimmie\XiboApi\Categories\Layout; +use Wimmie\XiboApi\Categories\Library; use Wimmie\XiboApi\Categories\Misc; use Wimmie\XiboApi\Categories\Notification; +use Wimmie\XiboApi\Categories\PlayerSoftware; +use Wimmie\XiboApi\Categories\Playlist; +use Wimmie\XiboApi\Categories\Region; +use Wimmie\XiboApi\Categories\Resolution; +use Wimmie\XiboApi\Categories\Schedule; +use Wimmie\XiboApi\Categories\Statistics; +use Wimmie\XiboApi\Categories\Tags; +use Wimmie\XiboApi\Categories\Template; +use Wimmie\XiboApi\Categories\User; +use Wimmie\XiboApi\Categories\UserGroup; +use Wimmie\XiboApi\Categories\Widget; class XiboApi { @@ -57,7 +81,7 @@ public function generateUrl(string $prefix = null, string $action = null, int $i $url .= '/' . $prefix; } if (isset($action)) { - $url .= '/'. $action; + $url .= '/' . $action; } if (isset($id)) { $url .= '/' . $id; @@ -195,4 +219,210 @@ public function widget(): Widget { return new Widget($this); } + + /** + * Get the dataset category of the Xibo api + * @return Dataset + */ + public function dataset(): Dataset + { + return new Dataset($this); + } + + /** + * Get the dataset column category of the Xibo api + * @param int $datasetId + * @return DatasetColumn + */ + public function datasetColumn(int $datasetId): DatasetColumn + { + return new DatasetColumn($this, $datasetId); + } + + /** + * Get the dataset data category of the Xibo api + * @param int $datasetId + * @return DatasetData + */ + public function datasetData(int $datasetId): DatasetData + { + return new DatasetData($this, $datasetId); + } + + /** + * Get the dataset rss category of the Xibo api + * @param int $datasetId + * @return DatasetRss + */ + public function datasetRss(int $datasetId): DatasetRss + { + return new DatasetRss($this, $datasetId); + } + + /** + * Get the day part category of the Xibo api + * @return DayPart + */ + public function dayPart(): DayPart + { + return new DayPart($this); + } + + /** + * Get the display category of the Xibo api + * @return Display + */ + public function display(): Display + { + return new Display($this); + } + + /** + * Get the display group category of the Xibo api + * @return DisplayGroup + */ + public function displayGroup(): DisplayGroup + { + return new DisplayGroup($this); + } + + /** + * Get the display group media category of the Xibo api + * @param int $displayGroupId + * @return DisplayGroupMedia + */ + public function displayGroupMedia(int $displayGroupId): DisplayGroupMedia + { + return new DisplayGroupMedia($this, $displayGroupId); + } + + /** + * Get the display group layout category of the Xibo api + * @param int $displayGroupId + * @return DisplayGroupLayout + */ + public function displayGroupLayout(int $displayGroupId): DisplayGroupLayout + { + return new DisplayGroupLayout($this, $displayGroupId); + } + + /** + * Get the display group display category of the Xibo api + * @param int $displayGroupId + * @return DisplayGroupDisplay + */ + public function displayGroupDisplay(int $displayGroupId): DisplayGroupDisplay + { + return new DisplayGroupDisplay($this, $displayGroupId); + } + + /** + * Get the display group display group category of the Xibo api + * @param int $displayGroupId + * @return DisplayGroupDisplayGroup + */ + public function displayGroupDisplayGroup(int $displayGroupId): DisplayGroupDisplayGroup + { + return new DisplayGroupDisplayGroup($this, $displayGroupId); + } + + /** + * Get the display group action category of the Xibo api + * @param int $displayGroupId + * @return DisplayGroupAction + */ + public function displayGroupAction(int $displayGroupId): DisplayGroupAction + { + return new DisplayGroupAction($this, $displayGroupId); + } + + /** + * Get the display profile category of the Xibo api + * @return DisplayProfile + */ + public function displayProfile(): DisplayProfile + { + return new DisplayProfile($this); + } + + /** + * Get the library category of the Xibo api + * @return Library + */ + public function library(): Library + { + return new Library($this); + } + + /** + * Get the player software category of the Xibo api + * @return PlayerSoftware + */ + public function playerSoftware(): PlayerSoftware + { + return new PlayerSoftware($this); + } + + /** + * Get the resolution category of the Xibo api + * @return Resolution + */ + public function resolution(): Resolution + { + return new Resolution($this); + } + + /** + * Get the statistics category of the Xibo api + * @return Statistics + */ + public function statistics(): Statistics + { + return new Statistics($this); + } + + /** + * Get the tags category of the Xibo api + * @return Tags + */ + public function tags(): Tags + { + return new Tags($this); + } + + /** + * Get the template category of the Xibo api + * @return Template + */ + public function template(): Template + { + return new Template($this); + } + + /** + * Get the user category of the Xibo api + * @return User + */ + public function user(): User + { + return new User($this); + } + + /** + * Get the user group category of the Xibo api + * @return UserGroup + */ + public function userGroup(): UserGroup + { + return new UserGroup($this); + } + + /** + * Get the region category of the Xibo api + * @return Region + */ + public function region(): Region + { + return new Region($this); + } } diff --git a/src/XiboApiServiceProvider.php b/src/XiboApiServiceProvider.php index 4b1bc30..23555cb 100644 --- a/src/XiboApiServiceProvider.php +++ b/src/XiboApiServiceProvider.php @@ -10,7 +10,7 @@ public function boot() { if ($this->app->runningInConsole()) { $this->publishes([ - __DIR__ . '/../config/laravel-xibo-api.php' => config_path('laravel-xibo-api.php'), + __DIR__ . '/../config/xibo-api.php' => config_path('xibo-api.php'), ], 'config'); } }