diff --git a/composer.json b/composer.json index 5c33616..8a53210 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "renderforest/sdk-php", "description": "Renderforest SDK for PHP", - "version": "0.6.0", + "version": "0.7.0", "homepage": "https://github.com/renderforest/renderforest-sdk-php", "keywords": [ "animation maker", diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..3af7e4d --- /dev/null +++ b/composer.lock @@ -0,0 +1,677 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "877f6dea9e5189cecac2148db112eb19", + "packages": [ + { + "name": "guzzlehttp/guzzle", + "version": "7.9.2", + "source": { + "type": "git", + "url": "https://github.com/guzzle/guzzle.git", + "reference": "d281ed313b989f213357e3be1a179f02196ac99b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/d281ed313b989f213357e3be1a179f02196ac99b", + "reference": "d281ed313b989f213357e3be1a179f02196ac99b", + "shasum": "" + }, + "require": { + "ext-json": "*", + "guzzlehttp/promises": "^1.5.3 || ^2.0.3", + "guzzlehttp/psr7": "^2.7.0", + "php": "^7.2.5 || ^8.0", + "psr/http-client": "^1.0", + "symfony/deprecation-contracts": "^2.2 || ^3.0" + }, + "provide": { + "psr/http-client-implementation": "1.0" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.8.2", + "ext-curl": "*", + "guzzle/client-integration-tests": "3.0.2", + "php-http/message-factory": "^1.1", + "phpunit/phpunit": "^8.5.39 || ^9.6.20", + "psr/log": "^1.1 || ^2.0 || ^3.0" + }, + "suggest": { + "ext-curl": "Required for CURL handler support", + "ext-intl": "Required for Internationalized Domain Name (IDN) support", + "psr/log": "Required for using the Log middleware" + }, + "type": "library", + "extra": { + "bamarni-bin": { + "bin-links": true, + "forward-command": false + } + }, + "autoload": { + "files": [ + "src/functions_include.php" + ], + "psr-4": { + "GuzzleHttp\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Jeremy Lindblom", + "email": "jeremeamia@gmail.com", + "homepage": "https://github.com/jeremeamia" + }, + { + "name": "George Mponos", + "email": "gmponos@gmail.com", + "homepage": "https://github.com/gmponos" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://github.com/sagikazarmark" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" + } + ], + "description": "Guzzle is a PHP HTTP client library", + "keywords": [ + "client", + "curl", + "framework", + "http", + "http client", + "psr-18", + "psr-7", + "rest", + "web service" + ], + "support": { + "issues": "https://github.com/guzzle/guzzle/issues", + "source": "https://github.com/guzzle/guzzle/tree/7.9.2" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://github.com/Nyholm", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/guzzle", + "type": "tidelift" + } + ], + "time": "2024-07-24T11:22:20+00:00" + }, + { + "name": "guzzlehttp/promises", + "version": "2.0.3", + "source": { + "type": "git", + "url": "https://github.com/guzzle/promises.git", + "reference": "6ea8dd08867a2a42619d65c3deb2c0fcbf81c8f8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/promises/zipball/6ea8dd08867a2a42619d65c3deb2c0fcbf81c8f8", + "reference": "6ea8dd08867a2a42619d65c3deb2c0fcbf81c8f8", + "shasum": "" + }, + "require": { + "php": "^7.2.5 || ^8.0" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.8.2", + "phpunit/phpunit": "^8.5.39 || ^9.6.20" + }, + "type": "library", + "extra": { + "bamarni-bin": { + "bin-links": true, + "forward-command": false + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Promise\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" + } + ], + "description": "Guzzle promises library", + "keywords": [ + "promise" + ], + "support": { + "issues": "https://github.com/guzzle/promises/issues", + "source": "https://github.com/guzzle/promises/tree/2.0.3" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://github.com/Nyholm", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/promises", + "type": "tidelift" + } + ], + "time": "2024-07-18T10:29:17+00:00" + }, + { + "name": "guzzlehttp/psr7", + "version": "2.7.0", + "source": { + "type": "git", + "url": "https://github.com/guzzle/psr7.git", + "reference": "a70f5c95fb43bc83f07c9c948baa0dc1829bf201" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/a70f5c95fb43bc83f07c9c948baa0dc1829bf201", + "reference": "a70f5c95fb43bc83f07c9c948baa0dc1829bf201", + "shasum": "" + }, + "require": { + "php": "^7.2.5 || ^8.0", + "psr/http-factory": "^1.0", + "psr/http-message": "^1.1 || ^2.0", + "ralouphie/getallheaders": "^3.0" + }, + "provide": { + "psr/http-factory-implementation": "1.0", + "psr/http-message-implementation": "1.0" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.8.2", + "http-interop/http-factory-tests": "0.9.0", + "phpunit/phpunit": "^8.5.39 || ^9.6.20" + }, + "suggest": { + "laminas/laminas-httphandlerrunner": "Emit PSR-7 responses" + }, + "type": "library", + "extra": { + "bamarni-bin": { + "bin-links": true, + "forward-command": false + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Psr7\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "George Mponos", + "email": "gmponos@gmail.com", + "homepage": "https://github.com/gmponos" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://github.com/sagikazarmark" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://sagikazarmark.hu" + } + ], + "description": "PSR-7 message implementation that also provides common utility methods", + "keywords": [ + "http", + "message", + "psr-7", + "request", + "response", + "stream", + "uri", + "url" + ], + "support": { + "issues": "https://github.com/guzzle/psr7/issues", + "source": "https://github.com/guzzle/psr7/tree/2.7.0" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://github.com/Nyholm", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/psr7", + "type": "tidelift" + } + ], + "time": "2024-07-18T11:15:46+00:00" + }, + { + "name": "laminas/laminas-stdlib", + "version": "3.17.0", + "source": { + "type": "git", + "url": "https://github.com/laminas/laminas-stdlib.git", + "reference": "dd35c868075bad80b6718959740913e178eb4274" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laminas/laminas-stdlib/zipball/dd35c868075bad80b6718959740913e178eb4274", + "reference": "dd35c868075bad80b6718959740913e178eb4274", + "shasum": "" + }, + "require": { + "php": "~8.1.0 || ~8.2.0" + }, + "conflict": { + "zendframework/zend-stdlib": "*" + }, + "require-dev": { + "laminas/laminas-coding-standard": "^2.5", + "phpbench/phpbench": "^1.2.9", + "phpunit/phpunit": "^10.0.16", + "psalm/plugin-phpunit": "^0.18.4", + "vimeo/psalm": "^5.8" + }, + "type": "library", + "autoload": { + "psr-4": { + "Laminas\\Stdlib\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "description": "SPL extensions, array utilities, error handlers, and more", + "homepage": "https://laminas.dev", + "keywords": [ + "laminas", + "stdlib" + ], + "support": { + "chat": "https://laminas.dev/chat", + "docs": "https://docs.laminas.dev/laminas-stdlib/", + "forum": "https://discourse.laminas.dev", + "issues": "https://github.com/laminas/laminas-stdlib/issues", + "rss": "https://github.com/laminas/laminas-stdlib/releases.atom", + "source": "https://github.com/laminas/laminas-stdlib" + }, + "funding": [ + { + "url": "https://funding.communitybridge.org/projects/laminas-project", + "type": "community_bridge" + } + ], + "time": "2023-03-20T13:51:37+00:00" + }, + { + "name": "psr/http-client", + "version": "1.0.3", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-client.git", + "reference": "bb5906edc1c324c9a05aa0873d40117941e5fa90" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-client/zipball/bb5906edc1c324c9a05aa0873d40117941e5fa90", + "reference": "bb5906edc1c324c9a05aa0873d40117941e5fa90", + "shasum": "" + }, + "require": { + "php": "^7.0 || ^8.0", + "psr/http-message": "^1.0 || ^2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Client\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP clients", + "homepage": "https://github.com/php-fig/http-client", + "keywords": [ + "http", + "http-client", + "psr", + "psr-18" + ], + "support": { + "source": "https://github.com/php-fig/http-client" + }, + "time": "2023-09-23T14:17:50+00:00" + }, + { + "name": "psr/http-factory", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-factory.git", + "reference": "2b4765fddfe3b508ac62f829e852b1501d3f6e8a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-factory/zipball/2b4765fddfe3b508ac62f829e852b1501d3f6e8a", + "reference": "2b4765fddfe3b508ac62f829e852b1501d3f6e8a", + "shasum": "" + }, + "require": { + "php": ">=7.1", + "psr/http-message": "^1.0 || ^2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "PSR-17: Common interfaces for PSR-7 HTTP message factories", + "keywords": [ + "factory", + "http", + "message", + "psr", + "psr-17", + "psr-7", + "request", + "response" + ], + "support": { + "source": "https://github.com/php-fig/http-factory" + }, + "time": "2024-04-15T12:06:14+00:00" + }, + { + "name": "psr/http-message", + "version": "2.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message.git", + "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/402d35bcb92c70c026d1a6a9883f06b2ead23d71", + "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP messages", + "homepage": "https://github.com/php-fig/http-message", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "support": { + "source": "https://github.com/php-fig/http-message/tree/2.0" + }, + "time": "2023-04-04T09:54:51+00:00" + }, + { + "name": "ralouphie/getallheaders", + "version": "3.0.3", + "source": { + "type": "git", + "url": "https://github.com/ralouphie/getallheaders.git", + "reference": "120b605dfeb996808c31b6477290a714d356e822" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", + "reference": "120b605dfeb996808c31b6477290a714d356e822", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "require-dev": { + "php-coveralls/php-coveralls": "^2.1", + "phpunit/phpunit": "^5 || ^6.5" + }, + "type": "library", + "autoload": { + "files": [ + "src/getallheaders.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ralph Khattar", + "email": "ralph.khattar@gmail.com" + } + ], + "description": "A polyfill for getallheaders.", + "support": { + "issues": "https://github.com/ralouphie/getallheaders/issues", + "source": "https://github.com/ralouphie/getallheaders/tree/develop" + }, + "time": "2019-03-08T08:55:37+00:00" + }, + { + "name": "symfony/deprecation-contracts", + "version": "v3.5.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/deprecation-contracts.git", + "reference": "0e0d29ce1f20deffb4ab1b016a7257c4f1e789a1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/0e0d29ce1f20deffb4ab1b016a7257c4f1e789a1", + "reference": "0e0d29ce1f20deffb4ab1b016a7257c4f1e789a1", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.5-dev" + }, + "thanks": { + "name": "symfony/contracts", + "url": "https://github.com/symfony/contracts" + } + }, + "autoload": { + "files": [ + "function.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "A generic function and convention to trigger deprecation notices", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/deprecation-contracts/tree/v3.5.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-04-18T09:32:20+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": ">=8.1.11", + "ext-json": "*" + }, + "platform-dev": [], + "plugin-api-version": "2.6.0" +} diff --git a/doc/PROJECTS_API.md b/doc/PROJECTS_API.md index bbcc032..1638d40 100644 --- a/doc/PROJECTS_API.md +++ b/doc/PROJECTS_API.md @@ -13,6 +13,9 @@ - [Duplicate the Project](#duplicate-the-project) - [Render the Project](#render-the-project) - [Get rendering status](#get-rendering-status) + - [Generate Lego Screens Previews](#generate-lego-screens-previews) + - [Cancel Lego Preview](#cancel-lego-preview) + - [Get Project Preview URLs](#get-project-preview-urls) ### Get All Projects @@ -251,4 +254,87 @@ $queueId = $renderforestClient->renderProject( (Coming soon) +### Generate Lego Screens Previews + +Generates previews for lego screens of a project. + +```php + 0, // 0, 360, 720, 1080 + 'screenIds' => [1, 2, 3], // Replace with actual screen IDs +]; + +$previewUrl = $renderforestClient->generateLegoScreensPreviews($projectId, $params); +``` + +- The `quality` parameter is an integer: + - 0 for video with watermark + - 720 for video without watermark +- The `screenIds` parameter is an array of screen IDs for which you want to generate previews. + +[See generate lego screens previews example](/examples/projects/generate-lego-screens-previews.php) + +### Cancel Lego Preview + +Cancels the lego preview for specified queue IDs of a project. + +```php +cancelLegoPreview($projectId, $queueIds); + echo "Cancel Lego Preview Result: " . print_r($result, true) . PHP_EOL; +} catch (\GuzzleHttp\Exception\GuzzleException $e) { + echo "Error: " . $e->getMessage() . PHP_EOL; +} +``` + +### Get Project Preview URLs + +Retrieves preview URLs for a specific project. + +```php + 720, +]; + +try { + $previewUrls = $renderforestClient->getProjectPreviewUrls($projectId, $params); + echo "Project Preview URLs: " . PHP_EOL; + print_r($previewUrls); +} catch (\GuzzleHttp\Exception\GuzzleException $e) { + echo "Error: " . $e->getMessage() . PHP_EOL; +} +``` + **[⬆ back to the top](#projects-api)** \ No newline at end of file diff --git a/examples/projects/cancel-lego-preview.php b/examples/projects/cancel-lego-preview.php new file mode 100644 index 0000000..0aba1ed --- /dev/null +++ b/examples/projects/cancel-lego-preview.php @@ -0,0 +1,18 @@ +cancelLegoPreview($projectId, $queueIds); + echo "Cancel Lego Preview Result: " . print_r($result, true) . PHP_EOL; +} catch (\GuzzleHttp\Exception\GuzzleException $e) { + echo "Error: " . $e->getMessage() . PHP_EOL; +} \ No newline at end of file diff --git a/examples/projects/generate-lego-screens-previews.php b/examples/projects/generate-lego-screens-previews.php new file mode 100644 index 0000000..4321919 --- /dev/null +++ b/examples/projects/generate-lego-screens-previews.php @@ -0,0 +1,21 @@ + 0, + 'screenIds' => [99938256, 99938257], +]; + +try { + $result = $renderforestClient->generateLegoScreensPreviews($projectId, $params); + echo "Result: " . print_r($result, true) . PHP_EOL; +} catch (\Exception $e) { + echo "Error: " . $e->getMessage() . PHP_EOL; +} \ No newline at end of file diff --git a/examples/projects/get-project-preview-urls.php b/examples/projects/get-project-preview-urls.php new file mode 100644 index 0000000..29986db --- /dev/null +++ b/examples/projects/get-project-preview-urls.php @@ -0,0 +1,21 @@ + 720, +]; + +try { + $previewUrls = $renderforestClient->getProjectPreviewUrls($projectId, $params); + echo "Project Preview URLs: " . PHP_EOL; + print_r($previewUrls); +} catch (\GuzzleHttp\Exception\GuzzleException $e) { + echo "Error: " . $e->getMessage() . PHP_EOL; +} \ No newline at end of file diff --git a/src/ApiClient.php b/src/ApiClient.php index 273b08e..3e22f30 100644 --- a/src/ApiClient.php +++ b/src/ApiClient.php @@ -99,6 +99,14 @@ class ApiClient const PREVIEW_API_PATH_PREFIX = '/api/v1'; const PREVIEW_API_PATH = self::PREVIEW_API_PATH_PREFIX . '/preview/generate'; + const GENERATE_LEGO_SCREENS_PREVIEWS_API_PATH_PREFIX = '/api/v1'; + const GENERATE_LEGO_SCREENS_PREVIEWS_API_PATH = self::GENERATE_LEGO_SCREENS_PREVIEWS_API_PATH_PREFIX . '/projects/%d/preview-lego-render'; + + const CANCEL_LEGO_PREVIEW_API_PATH_PREFIX = '/api/v1'; + const CANCEL_LEGO_PREVIEW_API_PATH = self::CANCEL_LEGO_PREVIEW_API_PATH_PREFIX . '/projects/%d/cancel-preview'; + + const PROJECT_PREVIEW_URLS_API_PATH_PREFIX = '/api/v1'; + const PROJECT_PREVIEW_URLS_API_PATH = self::PROJECT_PREVIEW_URLS_API_PATH_PREFIX . '/projects/%d/preview-urls'; /** @var string */ protected $apiKey; @@ -1464,6 +1472,128 @@ public function getProject(int $projectId): Project return $project; } + /** + * @param int $projectId + * @param array $params + * @return array + * @throws GuzzleException + */ + public function generateLegoScreensPreviews(int $projectId, array $params): array + { + $endpoint = sprintf(self::GENERATE_LEGO_SCREENS_PREVIEWS_API_PATH, $projectId); + $uri = self::API_ENDPOINT . $endpoint; + + $options = [ + 'method' => 'POST', + 'headers' => [ + 'Accept' => 'application/json', + 'User-Agent' => self::USER_AGENT, + ], + 'endpoint' => $endpoint, + 'uri' => $uri, + 'json' => [ + 'quality' => $params['quality'], + 'screenIds' => $params['screenIds'], + ], + ]; + + $options = $this->setAuthorization($options); + + $response = $this->httpClient->request( + $options['method'], + $options['uri'], + $options + ); + + $jsonResponse = $response->getBody()->getContents(); + $arrayResponse = \GuzzleHttp\json_decode($jsonResponse, true); + + if (isset($arrayResponse['data']) && is_array($arrayResponse['data'])) { + return $arrayResponse['data']; + } + + throw new \RuntimeException('Unexpected response format from the API'); + } + + /** + * @param int $projectId + * @param array $queueIds + * @return array + * @throws GuzzleException + */ + public function cancelLegoPreview(int $projectId, array $queueIds): array + { + $endpoint = sprintf(self::CANCEL_LEGO_PREVIEW_API_PATH, $projectId); + $uri = self::API_ENDPOINT . $endpoint; + + $options = [ + 'method' => 'POST', + 'headers' => [ + 'Accept' => 'application/json', + 'User-Agent' => self::USER_AGENT, + ], + 'endpoint' => $endpoint, + 'uri' => $uri, + 'json' => [ + 'queueIds' => $queueIds, + ], + ]; + + $options = $this->setAuthorization($options); + + $response = $this->httpClient->request( + $options['method'], + $options['uri'], + $options + ); + + $jsonResponse = $response->getBody()->getContents(); + $arrayResponse = \GuzzleHttp\json_decode($jsonResponse, true); + + return $arrayResponse['data']; + } + + /** + * @param int $projectId + * @param array $params + * @return array + * @throws GuzzleException + */ + public function getProjectPreviewUrls(int $projectId, array $params): array + { + $endpoint = sprintf(self::PROJECT_PREVIEW_URLS_API_PATH, $projectId); + $uri = self::API_ENDPOINT . $endpoint; + + // Add query parameters to the URI + if (!empty($params)) { + $queryString = http_build_query($params); + $uri .= '?' . $queryString; + } + + $options = [ + 'method' => 'GET', + 'headers' => [ + 'Accept' => 'application/json', + 'User-Agent' => self::USER_AGENT, + ], + 'endpoint' => $endpoint, + 'uri' => $uri, + ]; + + $options = $this->setAuthorization($options); + + $response = $this->httpClient->request( + $options['method'], + $options['uri'], + $options + ); + + $jsonResponse = $response->getBody()->getContents(); + $arrayResponse = \GuzzleHttp\json_decode($jsonResponse, true); + + return $arrayResponse['data']; + } + /** * @param $options * @return array @@ -1479,13 +1609,14 @@ private function setAuthorization($options): array $headers['clientid'] = $clientId; $headers['timestamp'] = $this->dateNow(); $parsedUrl = parse_url(isset($opts['uri']) ? $opts['uri'] : ''); + $path = isset($parsedUrl['path']) ? $parsedUrl['path'] : ''; $query = isset($parsedUrl['query']) ? $parsedUrl['query'] : ''; - $path = $query ? $parsedUrl['path'] . '?' . $query : $parsedUrl['path']; + $fullPath = $query ? $path . '?' . $query : $path; $headers['authorization'] = $this->generateHash([ 'clientId' => $clientId, - 'path' => $path ? $path : '', - 'qs' => $query ? $query : '', + 'path' => $fullPath, + 'qs' => $query, 'body' => isset($opts['json']) ? json_encode($opts['json'], JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE) : '{}', 'nonce' => $headers['nonce'], 'timestamp' => $headers['timestamp']