diff --git a/README.md b/README.md index beaf912..ea35c50 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,7 @@ Welcome to the Renderforest API! You can use our API to: - [Get Pluggable-Screens of the Template](#get-pluggable-screens-of-the-template) - [Get Recommended-Custom-Colors of the Template](#get-recommended-custom-colors-of-the-template) - [Get Template-Presets of the Template](#get-template-presets-of-the-template) + - [Get SVG Content of the Template](#get-svg-content-of-the-template) - [Get Theme of the Template](#get-theme-of-the-template) - [Get Transitions of the Template](#get-transitions-of-the-template) * [Users API](#users-api) @@ -1105,6 +1106,29 @@ Template-presets are ready-made stories created from this template to fasten you [See example](https://github.com/renderforest/renderforest-sdk-php/blob/master/examples/templates/get-template-presets.php) +### Get SVG Content of the Template +Retrieves SVG content of the template. + +```php + 701 +]; +try { + $templateSVGContent = \Renderforest\Client::getTemplateSVGContent($payload); +} catch (\GuzzleHttp\Exception\GuzzleException $e) { + var_dump($e); // handle the error +} + +var_dump($templateRecommendedCustomColors); // handle the success +``` + +[See example](https://github.com/renderforest/renderforest-sdk-php/blob/master/examples/templates/get-template-svg-content.php) + + ### Get Theme of the Template Retrieves theme of the template. @@ -1187,4 +1211,4 @@ var_dump($currentUser); // handle the success Example for creating project from scratch. Includes creating project, updating project data, video rendering status checking and video downloading. -[See example](https://github.com/renderforest/renderforest-sdk-php/blob/master/examples/scratch-project/create-project-from-scratch.php) \ No newline at end of file +[See example](https://github.com/renderforest/renderforest-sdk-php/blob/master/examples/scratch-project/create-project-from-scratch.php) diff --git a/composer.json b/composer.json index 6fa9463..f09bf24 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "renderforest/sdk-php", "description": "Renderforest SDK for PHP", - "version": "0.3.7", + "version": "0.3.8", "homepage": "https://github.com/renderforest/renderforest-sdk-php", "authors": [ { @@ -24,8 +24,9 @@ "video maker" ], "require": { - "php": ">=5.5", - "guzzlehttp/guzzle": "6.3.3" + "php": ">=7.1", + "guzzlehttp/guzzle": "6.3.3", + "ext-json": "" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index 1f29d55..190f780 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "8f09b969c40e440c385c6540b88ca75f", + "content-hash": "ebb1702a783a79758d2b024852576587", "packages": [ { "name": "guzzlehttp/guzzle", @@ -124,32 +124,33 @@ }, { "name": "guzzlehttp/psr7", - "version": "1.4.2", + "version": "1.5.2", "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", - "reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c" + "reference": "9f83dded91781a01c63574e387eaa769be769115" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/f5b8a8512e2b58b0071a7280e39f14f72e05d87c", - "reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/9f83dded91781a01c63574e387eaa769be769115", + "reference": "9f83dded91781a01c63574e387eaa769be769115", "shasum": "" }, "require": { "php": ">=5.4.0", - "psr/http-message": "~1.0" + "psr/http-message": "~1.0", + "ralouphie/getallheaders": "^2.0.5" }, "provide": { "psr/http-message-implementation": "1.0" }, "require-dev": { - "phpunit/phpunit": "~4.0" + "phpunit/phpunit": "~4.8.36 || ^5.7.27 || ^6.5.8" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.4-dev" + "dev-master": "1.5-dev" } }, "autoload": { @@ -179,13 +180,14 @@ "keywords": [ "http", "message", + "psr-7", "request", "response", "stream", "uri", "url" ], - "time": "2017-03-20T17:10:46+00:00" + "time": "2018-12-04T20:46:45+00:00" }, { "name": "psr/http-message", @@ -236,6 +238,46 @@ "response" ], "time": "2016-08-06T14:39:51+00:00" + }, + { + "name": "ralouphie/getallheaders", + "version": "2.0.5", + "source": { + "type": "git", + "url": "https://github.com/ralouphie/getallheaders.git", + "reference": "5601c8a83fbba7ef674a7369456d12f1e0d0eafa" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/5601c8a83fbba7ef674a7369456d12f1e0d0eafa", + "reference": "5601c8a83fbba7ef674a7369456d12f1e0d0eafa", + "shasum": "" + }, + "require": { + "php": ">=5.3" + }, + "require-dev": { + "phpunit/phpunit": "~3.7.0", + "satooshi/php-coveralls": ">=1.0" + }, + "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.", + "time": "2016-02-11T07:05:27+00:00" } ], "packages-dev": [], @@ -244,6 +286,9 @@ "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, - "platform": [], + "platform": { + "php": ">=7.1", + "ext-json": "*" + }, "platform-dev": [] } diff --git a/examples/templates/get-template-svg-content.php b/examples/templates/get-template-svg-content.php new file mode 100644 index 0000000..ccd49c6 --- /dev/null +++ b/examples/templates/get-template-svg-content.php @@ -0,0 +1,21 @@ + 701 +]; +try { + $templateSVGContent = \Renderforest\Client::getTemplateSVGContent($payload); +} catch (\GuzzleHttp\Exception\GuzzleException $e) { + var_dump($e); // handle the error +} + +var_dump($templateRecommendedCustomColors); // handle the success diff --git a/examples/users/get-current-user.php b/examples/users/get-current-user.php index fa042c4..d43d7a5 100644 --- a/examples/users/get-current-user.php +++ b/examples/users/get-current-user.php @@ -9,9 +9,7 @@ require 'vendor/autoload.php'; -$options = ['signKey' => '', 'clientId' => -1]; - -$renderforest = new \Renderforest\Client($options);; +$renderforest = new \Renderforest\Client(['signKey' => '', 'clientId' => -1]); try { $currentUser = $renderforest->getCurrentUser(); diff --git a/src/Client.php b/src/Client.php index e3410a3..56f1e50 100644 --- a/src/Client.php +++ b/src/Client.php @@ -9,19 +9,38 @@ namespace Renderforest; -use Renderforest\Request\Http; -use Renderforest\Resource; +use Renderforest; + +use Renderforest\Request\Api; + +use Renderforest\Resource\ProjectData; +use Renderforest\Resource\Projects; +use Renderforest\Resource\Sounds; +use Renderforest\Resource\Supports; +use Renderforest\Resource\Templates; +use Renderforest\Resource\Users; + +class Client +{ + private $ApiRequest; -class Client { - private $Request; private $Project_data; private $Projects; private $Sounds; private $Supports; private $Users; + /** + * @var Resource\Projects + */ private static $staticProjects; + /** + * @var Resource\Sounds + */ private static $staticSounds; + /** + * @var Resource\Templates + */ private static $staticTemplates; /** @@ -30,33 +49,37 @@ class Client { */ public function __construct($options) { - $this->Request = Http::getInstance(); - $this->Project_data = new Resource\ProjectData(); - $this->Projects = new Resource\Projects(); - $this->Sounds = new Resource\Sounds(); - $this->Supports = new Resource\Supports(); - $this->Users = new Resource\Users(); - - $this->Request->setConfig($options['signKey'], $options['clientId']); + $this->ApiRequest = Api::getInstance(); + $this->ApiRequest->setConfig($options['signKey'], $options['clientId']); + + $this->Project_data = new ProjectData(); + $this->Projects = new Projects(); + $this->Sounds = new Sounds(); + $this->Supports = new Supports(); + $this->Users = new Users(); } /** * Initialize static members of Renderforest class. + * @t */ - public static function init () { - self::$staticProjects = new Resource\Projects(); - self::$staticSounds = new Resource\Sounds(); - self::$staticTemplates = new Resource\Templates(); + public static function init() + { + + self::$staticProjects = new Projects(); + self::$staticSounds = new Sounds(); + self::$staticTemplates = new Templates(); } /** * Gets Project-data. * @param array $payload - * @return ProjectData + * @return Renderforest\ProjectData\ProjectData * @throws \GuzzleHttp\Exception\GuzzleException */ - public function getProjectData ($payload) { - return $this->Project_data->getProjectData($payload); + public function getProjectData($payload) + { + return $this->Project_data->getProjectData($payload); } /** @@ -65,8 +88,9 @@ public function getProjectData ($payload) { * @return array|null * @throws \GuzzleHttp\Exception\GuzzleException */ - public function updateProjectDataPartial ($payload) { - return $this->Project_data->updateProjectDataPartial($payload); + public function updateProjectDataPartial($payload) + { + return $this->Project_data->updateProjectDataPartial($payload); } /** @@ -75,8 +99,9 @@ public function updateProjectDataPartial ($payload) { * @return array|null * @throws \GuzzleHttp\Exception\GuzzleException */ - public function getProjects ($payload) { - return $this->Projects->getProjects($payload); + public function getProjects($payload) + { + return $this->Projects->getProjects($payload); } /** @@ -85,8 +110,9 @@ public function getProjects ($payload) { * @return array|null * @throws \GuzzleHttp\Exception\GuzzleException */ - public function addProject ($payload) { - return $this->Projects->addProject($payload); + public function addProject($payload) + { + return $this->Projects->addProject($payload); } /** @@ -95,8 +121,9 @@ public function addProject ($payload) { * @return array|null * @throws \GuzzleHttp\Exception\GuzzleException */ - public function getProject ($payload) { - return $this->Projects->getProject($payload); + public function getProject($payload) + { + return $this->Projects->getProject($payload); } /** @@ -105,8 +132,9 @@ public function getProject ($payload) { * @return array|null * @throws \GuzzleHttp\Exception\GuzzleException */ - public function updateProjectPartial ($payload) { - return $this->Projects->updateProjectPartial($payload); + public function updateProjectPartial($payload) + { + return $this->Projects->updateProjectPartial($payload); } /** @@ -115,7 +143,8 @@ public function updateProjectPartial ($payload) { * @return array|null * @throws \GuzzleHttp\Exception\GuzzleException */ - public function deleteProject ($payload) { + public function deleteProject($payload) + { return $this->Projects->deleteProject($payload); } @@ -125,8 +154,9 @@ public function deleteProject ($payload) { * @return array|null * @throws \GuzzleHttp\Exception\GuzzleException */ - public function applyTemplatePresetOnProject ($payload) { - return $this->Projects->applyTemplatePresetOnProject($payload); + public function applyTemplatePresetOnProject($payload) + { + return $this->Projects->applyTemplatePresetOnProject($payload); } /** @@ -135,8 +165,9 @@ public function applyTemplatePresetOnProject ($payload) { * @return array|null * @throws \GuzzleHttp\Exception\GuzzleException */ - public function duplicateProject ($payload) { - return $this->Projects->duplicateProject($payload); + public function duplicateProject($payload) + { + return $this->Projects->duplicateProject($payload); } /** @@ -145,8 +176,9 @@ public function duplicateProject ($payload) { * @return array|null * @throws \GuzzleHttp\Exception\GuzzleException */ - public function renderProject ($payload) { - return $this->Projects->renderProject($payload); + public function renderProject($payload) + { + return $this->Projects->renderProject($payload); } /** @@ -155,8 +187,9 @@ public function renderProject ($payload) { * @return array|null * @throws \GuzzleHttp\Exception\GuzzleException */ - public function getSounds ($payload) { - return $this->Sounds->getSounds($payload); + public function getSounds($payload) + { + return $this->Sounds->getSounds($payload); } /** @@ -165,8 +198,9 @@ public function getSounds ($payload) { * @return array|null * @throws \GuzzleHttp\Exception\GuzzleException */ - public function getRecommendedSounds ($payload) { - return $this->Sounds->getRecommendedSounds($payload); + public function getRecommendedSounds($payload) + { + return $this->Sounds->getRecommendedSounds($payload); } /** @@ -175,8 +209,9 @@ public function getRecommendedSounds ($payload) { * @return array|null * @throws \GuzzleHttp\Exception\GuzzleException */ - public function addSupportsTicket ($payload) { - return $this->Supports->addSupportsTicket($payload); + public function addSupportsTicket($payload) + { + return $this->Supports->addSupportsTicket($payload); } /** @@ -184,8 +219,9 @@ public function addSupportsTicket ($payload) { * @return array|null * @throws \GuzzleHttp\Exception\GuzzleException */ - public function getCurrentUser () { - return $this->Users->getCurrentUser(); + public function getCurrentUser() + { + return $this->Users->getCurrentUser(); } /** @@ -194,7 +230,8 @@ public function getCurrentUser () { * @return array|null * @throws \GuzzleHttp\Exception\GuzzleException */ - public static function getTrialProject ($payload) { + public static function getTrialProject($payload) + { return self::$staticProjects->getTrialProject($payload); } @@ -204,8 +241,9 @@ public static function getTrialProject ($payload) { * @return array|null * @throws \GuzzleHttp\Exception\GuzzleException */ - public static function getCompanySoundsLimited ($payload) { - return self::$staticSounds->getRecommendedSoundsLimited($payload); + public static function getCompanySoundsLimited($payload) + { + return self::$staticSounds->getRecommendedSoundsLimited($payload); } /** @@ -214,8 +252,9 @@ public static function getCompanySoundsLimited ($payload) { * @return array|null * @throws \GuzzleHttp\Exception\GuzzleException */ - public static function getRecommendedSoundsLimited ($payload) { - return self::$staticSounds->getRecommendedSoundsLimited($payload); + public static function getRecommendedSoundsLimited($payload) + { + return self::$staticSounds->getRecommendedSoundsLimited($payload); } /** @@ -224,8 +263,9 @@ public static function getRecommendedSoundsLimited ($payload) { * @return array|null * @throws \GuzzleHttp\Exception\GuzzleException */ - public static function getTemplates ($payload) { - return self::$staticTemplates->getTemplates($payload); + public static function getTemplates($payload) + { + return self::$staticTemplates->getTemplates($payload); } /** @@ -234,8 +274,9 @@ public static function getTemplates ($payload) { * @return array|null * @throws \GuzzleHttp\Exception\GuzzleException */ - public static function getTemplatesCategories ($payload) { - return self::$staticTemplates->getTemplatesCategories($payload); + public static function getTemplatesCategories($payload) + { + return self::$staticTemplates->getTemplatesCategories($payload); } /** @@ -244,8 +285,9 @@ public static function getTemplatesCategories ($payload) { * @return array|null * @throws \GuzzleHttp\Exception\GuzzleException */ - public static function getTemplate ($payload) { - return self::$staticTemplates->getTemplate($payload); + public static function getTemplate($payload) + { + return self::$staticTemplates->getTemplate($payload); } /** @@ -254,8 +296,9 @@ public static function getTemplate ($payload) { * @return array|null * @throws \GuzzleHttp\Exception\GuzzleException */ - public static function getTemplateColorPresets ($payload) { - return self::$staticTemplates->getTemplateColorPresets($payload); + public static function getTemplateColorPresets($payload) + { + return self::$staticTemplates->getTemplateColorPresets($payload); } /** @@ -264,8 +307,9 @@ public static function getTemplateColorPresets ($payload) { * @return array|null * @throws \GuzzleHttp\Exception\GuzzleException */ - public static function getTemplatePluggableScreens ($payload) { - return self::$staticTemplates->getTemplatePluggableScreens($payload); + public static function getTemplatePluggableScreens($payload) + { + return self::$staticTemplates->getTemplatePluggableScreens($payload); } /** @@ -274,8 +318,9 @@ public static function getTemplatePluggableScreens ($payload) { * @return array|null * @throws \GuzzleHttp\Exception\GuzzleException */ - public static function getTemplateRecommendedCustomColors ($payload) { - return self::$staticTemplates->getTemplateRecommendedCustomColors($payload); + public static function getTemplateRecommendedCustomColors($payload) + { + return self::$staticTemplates->getTemplateRecommendedCustomColors($payload); } /** @@ -284,8 +329,20 @@ public static function getTemplateRecommendedCustomColors ($payload) { * @return array|null * @throws \GuzzleHttp\Exception\GuzzleException */ - public static function getTemplatePresets ($payload) { - return self::$staticTemplates->getTemplatePresets($payload); + public static function getTemplatePresets($payload) + { + return self::$staticTemplates->getTemplatePresets($payload); + } + + /** + * Gets Template-SVG-Content of the template. + * @param array $payload + * @return array|null + * @throws \GuzzleHttp\Exception\GuzzleException + */ + public static function getTemplateSVGContent($payload) + { + return self::$staticTemplates->getTemplateSVGContent($payload); } /** @@ -294,8 +351,9 @@ public static function getTemplatePresets ($payload) { * @return array|null * @throws \GuzzleHttp\Exception\GuzzleException */ - public static function getTemplateTheme ($payload) { - return self::$staticTemplates->getTemplateTheme($payload); + public static function getTemplateTheme($payload) + { + return self::$staticTemplates->getTemplateTheme($payload); } /** @@ -304,8 +362,10 @@ public static function getTemplateTheme ($payload) { * @return array|null * @throws \GuzzleHttp\Exception\GuzzleException */ - public static function getTemplateTransitions ($payload) { - return self::$staticTemplates->getTempalateTransitions($payload); + public static function getTemplateTransitions($payload) + { + return self::$staticTemplates->getTemplateTransitions($payload); } } + Client::init(); diff --git a/src/Config/Config.php b/src/Config/Config.php new file mode 100644 index 0000000..784b61c --- /dev/null +++ b/src/Config/Config.php @@ -0,0 +1,27 @@ + 'https://api.renderforest.com', + 'API_PREFIX' => '/api/v1', + 'HTTP_DEFAULT_OPTIONS' => [ + 'method' => 'GET', + 'headers' => [ + 'Accept' => 'application/json', + 'User-Agent' => "renderforest/sdk-php/{$composerJson['version']}" + ] + ], + 'PROJECT_DATA_API_PREFIX' => '/api/v5', + 'WEB_HOST' => 'https://www.renderforest.com', + 'WEB_PREFIX' => '/api/v1' +]; diff --git a/src/Params.php b/src/Params.php index 36edc03..d1f77c3 100644 --- a/src/Params.php +++ b/src/Params.php @@ -13,8 +13,8 @@ class Params { /** - * @param $payload {Array} - * @param $props {Array} + * @param array $payload + * @param array $props * @return array * @description Destruct given properties from the payload. */ @@ -35,7 +35,7 @@ public function destructParams($payload, $props) /** * @param array $payload - * @param $param + * @param string $param * @return mixed * @throws RenderforestError * @description Destruct URL param from the payload. diff --git a/src/ProjectData/ProjectData.php b/src/ProjectData/ProjectData.php index f04c765..9e07326 100644 --- a/src/ProjectData/ProjectData.php +++ b/src/ProjectData/ProjectData.php @@ -13,6 +13,8 @@ class ProjectData { + private $CONFIG; + private $generator; private $patchProperties; private $projectDataJson; @@ -24,11 +26,8 @@ class ProjectData */ public function __construct($projectDataJson) { - $composer = file_get_contents(dirname(__FILE__) . '/../../composer.json'); - $composerJson = json_decode($composer, true); - $sdkVersion = $composerJson['version']; - - $this->generator = "renderforest/sdk-php/$sdkVersion"; + $this->CONFIG = include "../Config/Config.php"; + $this->generator = $this->CONFIG['HTTP_DEFAULT_OPTIONS']['headers']['User-Agent']; $this->patchProperties = []; $this->projectDataJson = $this->objectToArray($projectDataJson); $this->projectDataUtil = new ProjectDataUtil(); diff --git a/src/Request/Http.php b/src/Request/Api.php similarity index 79% rename from src/Request/Http.php rename to src/Request/Api.php index dcc9027..a9d2c7a 100644 --- a/src/Request/Http.php +++ b/src/Request/Api.php @@ -9,44 +9,41 @@ namespace Renderforest\Request; +use GuzzleHttp\Client; + use Renderforest\Auth\Auth; use Renderforest\Singleton; -class Http +class Api { use Singleton; + private $CONFIG; + private $signKey; private $clientId; - private $HOST; - private $DEFAULT_OPTIONS; - + /** + * @var Auth + */ private $Auth; + /** + * @var Client + */ private $requestClient; /** - * Http constructor. + * Api constructor. */ private function __construct() { + $this->CONFIG = include dirname(__FILE__) . '/../Config/Config.php'; + $this->signKey = NULL; $this->clientId = NULL; - $this->HOST = 'https://api.renderforest.com'; - - // Get SDK version from composer.json file and set it in `User-Agent`. - $ComposerJson = json_decode(file_get_contents(dirname(__FILE__) . '/../../composer.json'), true); - $sdkVersion = $ComposerJson['version']; - $this->DEFAULT_OPTIONS = [ - 'method' => 'GET', - 'headers' => [ - 'Accept' => 'application/json', - 'User-Agent' => "renderforest/sdk-php/$sdkVersion" - ] - ]; $this->Auth = Auth::getInstance(); - $this->requestClient = new \GuzzleHttp\Client(); + $this->requestClient = new Client(); } /** @@ -84,7 +81,7 @@ public function setConfig($signKey, $clientId) * @param array $options * @return array */ - public function appendQueryParams($options) + private function appendQueryParams($options) { if ( isset($options['method']) && @@ -104,10 +101,10 @@ public function appendQueryParams($options) * @param array options * @return array */ - public function appendURI($options) + private function appendURI($options) { $endpoint = $options['endpoint']; - $options['uri'] = $this->HOST . $endpoint; + $options['uri'] = $this->CONFIG['API_HOST'] . $endpoint; return $options; } @@ -119,7 +116,7 @@ public function appendURI($options) * @param array options * @return array */ - public function prepareRequest($options) + private function prepareRequest($options) { $appendedQueryParamsOptions = $this->appendQueryParams($options); $_options = $this->appendURI($appendedQueryParamsOptions); @@ -133,7 +130,7 @@ public function prepareRequest($options) * @return mixed * @throws \GuzzleHttp\Exception\GuzzleException */ - public function request($options) + private function request($options) { $requestMethod = isset($options['method']) ? $options['method'] : 'GET'; $requestURI = isset($options['uri']) ? $options['uri'] : ''; @@ -154,7 +151,7 @@ public function request($options) */ public function unauthorizedRequest($options) { - $_options = array_replace_recursive($this->DEFAULT_OPTIONS, $options); + $_options = array_replace_recursive($this->CONFIG['HTTP_DEFAULT_OPTIONS'], $options); $preparedOptions = $this->prepareRequest($_options); return $this->request($preparedOptions); @@ -171,7 +168,7 @@ public function unauthorizedRequest($options) */ public function authorizedRequest($options) { - $options = array_replace_recursive($this->DEFAULT_OPTIONS, $options); + $options = array_replace_recursive($this->CONFIG['HTTP_DEFAULT_OPTIONS'], $options); $preparedOptions = $this->prepareRequest($options); $cleanGetAreasOptions = $this->recursiveUnset($preparedOptions, 'getAreas'); diff --git a/src/Request/Web.php b/src/Request/Web.php new file mode 100644 index 0000000..4347cca --- /dev/null +++ b/src/Request/Web.php @@ -0,0 +1,67 @@ +CONFIG = include dirname(__FILE__) . '/../Config/Config.php'; + $this->requestClient = new Client(); + } + + /** + * Appends URI in given `$options` array. + * @param array options + * @return array + */ + private function appendURI($options) + { + $endpoint = $options['endpoint']; + $options['uri'] = $this->CONFIG['WEB_HOST'] . $endpoint; + + return $options; + } + + /** + * Makes request with given `$options`. + * @param array $options + * @return mixed + * @throws \GuzzleHttp\Exception\GuzzleException + */ + public function request($options) + { + $_options = array_replace_recursive($this->CONFIG['HTTP_DEFAULT_OPTIONS'], $options); + $optionsWithUri = $this->appendURI($_options); + + $requestMethod = isset($optionsWithUri['method']) ? $optionsWithUri['method'] : 'GET'; + $requestURI = isset($optionsWithUri['uri']) ? $optionsWithUri['uri'] : ''; + $response = $this->requestClient->request($requestMethod, $requestURI, $optionsWithUri); + $responseContent = $response->getBody()->getContents(); + + return isset($responseContent) ? $responseContent : NULL; + } +} diff --git a/src/Resource/ProjectData.php b/src/Resource/ProjectData.php index ef4a90c..3b81428 100644 --- a/src/Resource/ProjectData.php +++ b/src/Resource/ProjectData.php @@ -11,37 +11,45 @@ use Renderforest; +use Renderforest\Params; + +use Renderforest\Request\Api; + class ProjectData { - private $API_PREFIX = '/api/v5'; + private $CONFIG; private $Params; - private $Request; + + private $ApiRequest; /** * Projects constructor. - * Initialize Http, Params libraries. + * Initialize Api, Params libraries. */ public function __construct() { - $this->Params = new Renderforest\Params(); - $this->Request = Renderforest\Request\Http::getInstance(); + $this->CONFIG = include dirname(__FILE__) . '/../Config/Config.php'; + + $this->Params = new Params(); + + $this->ApiRequest = Api::getInstance(); } /** * Gets the project data. * @param $payload - * @return Renderforest\ProjectData + * @return Renderforest\ProjectData\ProjectData * @throws \GuzzleHttp\Exception\GuzzleException Get Project-data. */ public function getProjectData($payload) { $projectId = $this->Params->destructURLParam($payload, 'projectId'); $options = [ - 'endpoint' => "$this->API_PREFIX/project-data/$projectId" + 'endpoint' => "{$this->CONFIG['API_PREFIX']}/project-data/$projectId" ]; - $projectDataJson = $this->Request->authorizedRequest($options); + $projectDataJson = $this->ApiRequest->authorizedRequest($options); return new Renderforest\ProjectData\ProjectData($projectDataJson); } @@ -58,10 +66,10 @@ public function updateProjectDataPartial($payload) $projectId = $this->Params->destructURLParam($payload, 'projectId'); $options = [ 'method' => 'PATCH', - 'endpoint' => "$this->API_PREFIX/project-data/$projectId", + 'endpoint' => "{$this->CONFIG['API_PREFIX']}/project-data/$projectId", 'json' => $body ]; - return $this->Request->authorizedRequest($options); + return $this->ApiRequest->authorizedRequest($options); } } diff --git a/src/Resource/Projects.php b/src/Resource/Projects.php index 0240842..9b6bcea 100644 --- a/src/Resource/Projects.php +++ b/src/Resource/Projects.php @@ -9,23 +9,29 @@ namespace Renderforest\Resource; -use Renderforest; +use Renderforest\Params; + +use Renderforest\Request\Api; class Projects { - private $API_PREFIX = '/api/v1'; + private $CONFIG; private $Params; - private $Request; + + private $ApiRequest; /** * Projects constructor. - * Initialize Http, Params libraries. + * Initialize Api, Params libraries. */ public function __construct() { - $this->Params = new Renderforest\Params(); - $this->Request = Renderforest\Request\Http::getInstance(); + $this->CONFIG = include dirname(__FILE__) . '/../Config/Config.php'; + + $this->Params = new Params(); + + $this->ApiRequest = Api::getInstance(); } /** @@ -39,11 +45,11 @@ public function getProjects($payload) $qs = $this->Params->destructParams($payload, ['limit', 'offset']); $options = [ - 'endpoint' => "$this->API_PREFIX/projects", + 'endpoint' => "{$this->CONFIG['API_PREFIX']}/projects", 'qs' => $qs ]; - return $this->Request->authorizedRequest($options); + return $this->ApiRequest->authorizedRequest($options); } /** @@ -58,11 +64,11 @@ public function addProject($payload) $options = [ 'method' => 'POST', - 'endpoint' => "$this->API_PREFIX/projects", + 'endpoint' => "{$this->CONFIG['API_PREFIX']}/projects", 'json' => $body ]; - return $this->Request->authorizedRequest($options); + return $this->ApiRequest->authorizedRequest($options); } /** @@ -76,11 +82,11 @@ public function getTrialProject($payload) $qs = $this->Params->destructParams($payload, ['templateId']); $options = [ - 'endpoint' => "$this->API_PREFIX/projects/trial", + 'endpoint' => "{$this->CONFIG['API_PREFIX']}/projects/trial", 'qs' => $qs ]; - return $this->Request->unauthorizedRequest($options); + return $this->ApiRequest->unauthorizedRequest($options); } /** @@ -94,10 +100,10 @@ public function getProject($payload) $projectId = $this->Params->destructURLParam($payload, 'projectId'); $options = [ - 'endpoint' => "$this->API_PREFIX/projects/$projectId" + 'endpoint' => "{$this->CONFIG['API_PREFIX']}/projects/$projectId" ]; - return $this->Request->authorizedRequest($options); + return $this->ApiRequest->authorizedRequest($options); } /** @@ -113,11 +119,11 @@ public function updateProjectPartial($payload) $options = [ 'method' => 'PATCH', - 'endpoint' => "$this->API_PREFIX/projects/$projectId", + 'endpoint' => "{$this->CONFIG['API_PREFIX']}/projects/$projectId", 'json' => $body ]; - return $this->Request->authorizedRequest($options); + return $this->ApiRequest->authorizedRequest($options); } /** @@ -132,10 +138,10 @@ public function deleteProject($payload) $options = [ 'method' => 'DELETE', - 'endpoint' => "$this->API_PREFIX/projects/$projectId" + 'endpoint' => "{$this->CONFIG['API_PREFIX']}/projects/$projectId" ]; - return $this->Request->authorizedRequest($options); + return $this->ApiRequest->authorizedRequest($options); } /** @@ -151,11 +157,11 @@ public function applyTemplatePresetOnProject($payload) $options = [ 'method' => 'POST', - 'endpoint' => "$this->API_PREFIX/projects/$projectId/apply-template-preset", + 'endpoint' => "{$this->CONFIG['API_PREFIX']}/projects/$projectId/apply-template-preset", 'json' => $body ]; - return $this->Request->authorizedRequest($options); + return $this->ApiRequest->authorizedRequest($options); } /** @@ -170,10 +176,10 @@ public function duplicateProject($payload) $options = [ 'method' => 'POST', - 'endpoint' => "$this->API_PREFIX/projects/$projectId/duplicate" + 'endpoint' => "{$this->CONFIG['API_PREFIX']}/projects/$projectId/duplicate" ]; - return $this->Request->authorizedRequest($options); + return $this->ApiRequest->authorizedRequest($options); } /** @@ -189,10 +195,10 @@ public function renderProject($payload) $options = [ 'method' => 'POST', - 'endpoint' => "$this->API_PREFIX/projects/$projectId/render", + 'endpoint' => "{$this->CONFIG['API_PREFIX']}/projects/$projectId/render", 'json' => $body ]; - return $this->Request->authorizedRequest($options); + return $this->ApiRequest->authorizedRequest($options); } } diff --git a/src/Resource/Sounds.php b/src/Resource/Sounds.php index 39c38a4..9a8da14 100644 --- a/src/Resource/Sounds.php +++ b/src/Resource/Sounds.php @@ -9,18 +9,25 @@ namespace Renderforest\Resource; -use Renderforest; +use Renderforest\Params; + +use Renderforest\Request\Api; class Sounds { - private $API_PREFIX = '/api/v1'; + private $CONFIG; + private $Params; - private $Request; + + private $ApiRequest; public function __construct() { - $this->Params = new Renderforest\Params(); - $this->Request = Renderforest\Request\Http::getInstance(); + $this->CONFIG = include dirname(__FILE__) . '/../Config/Config.php'; + + $this->Params = new Params(); + + $this->ApiRequest = Api::getInstance(); } /** @@ -33,11 +40,11 @@ public function getCompanySoundsLimited($payload) { $qs = $this->Params->destructParams($payload, ['duration']); $options = [ - 'endpoint' => "$this->API_PREFIX/sounds", + 'endpoint' => "{$this->CONFIG['API_PREFIX']}/sounds", 'qs' => $qs ]; - return $this->Request->unauthorizedRequest($options); + return $this->ApiRequest->unauthorizedRequest($options); } /** @@ -49,11 +56,11 @@ public function getCompanySoundsLimited($payload) public function getSounds($payload) { $qs = $this->Params->destructParams($payload, ['duration']); - $options = ['endpoint' => "$this->API_PREFIX/sounds", + $options = ['endpoint' => "{$this->CONFIG['API_PREFIX']}/sounds", 'qs' => $qs ]; - return $this->Request->authorizedRequest($options); + return $this->ApiRequest->authorizedRequest($options); } /** @@ -66,11 +73,11 @@ public function getRecommendedSoundsLimited($payload) { $qs = $this->Params->destructParams($payload, ['duration', 'templateId']); $options = [ - 'endpoint' => "$this->API_PREFIX/sounds/recommended", + 'endpoint' => "{$this->CONFIG['API_PREFIX']}/sounds/recommended", 'qs' => $qs ]; - return $this->Request->unauthorizedRequest($options); + return $this->ApiRequest->unauthorizedRequest($options); } /** @@ -83,10 +90,10 @@ public function getRecommendedSounds($payload) { $qs = $this->Params->destructParams($payload, ['duration', 'templateId']); $options = [ - 'endpoint' => "$this->API_PREFIX/sounds/recommended", + 'endpoint' => "{$this->CONFIG['API_PREFIX']}/sounds/recommended", 'qs' => $qs ]; - return $this->Request->authorizedRequest($options); + return $this->ApiRequest->authorizedRequest($options); } } diff --git a/src/Resource/Supports.php b/src/Resource/Supports.php index 8cc1e12..6d731e9 100644 --- a/src/Resource/Supports.php +++ b/src/Resource/Supports.php @@ -9,18 +9,25 @@ namespace Renderforest\Resource; -use Renderforest; +use Renderforest\Params; + +use Renderforest\Request\Api; class Supports { - private $API_PREFIX = '/api/v1'; + private $CONFIG; + private $Params; - private $Request; + + private $ApiRequest; public function __construct() { - $this->Params = new Renderforest\Params(); - $this->Request = Renderforest\Request\Http::getInstance(); + $this->CONFIG = include dirname(__FILE__) . '/../Config/Config.php'; + + $this->Params = new Params(); + + $this->ApiRequest = Api::getInstance(); } /** @@ -33,10 +40,10 @@ public function addSupportsTicket ($payload) { $body = $this->Params->destructParams($payload, ['message', 'mailType', 'subject']); $options = [ 'method' => 'POST', - 'endpoint' => "$this->API_PREFIX/supports/ticket", + 'endpoint' => "{$this->CONFIG['API_PREFIX']}/supports/ticket", 'json' => $body ]; - return $this->Request->authorizedRequest($options); + return $this->ApiRequest->authorizedRequest($options); } } diff --git a/src/Resource/Templates.php b/src/Resource/Templates.php index 624925a..47120a7 100644 --- a/src/Resource/Templates.php +++ b/src/Resource/Templates.php @@ -9,18 +9,28 @@ namespace Renderforest\Resource; -use Renderforest; +use Renderforest\Params; + +use Renderforest\Request\Api; +use Renderforest\Request\Web; class Templates { - private $API_PREFIX = '/api/v1'; + private $CONFIG; + private $Params; - private $Request; + + private $ApiRequest; + private $WebRequest; public function __construct() { - $this->Params = new Renderforest\Params(); - $this->Request = Renderforest\Request\Http::getInstance(); + $this->CONFIG = include dirname(__FILE__) . '/../Config/Config.php'; + + $this->Params = new Params(); + + $this->ApiRequest = Api::getInstance(); + $this->WebRequest = Web::getInstance(); } /** @@ -33,11 +43,11 @@ public function getTemplates($payload) { $qs = $this->Params->destructParams($payload, ['categoryId', 'equalizer', 'limit', 'offset']); $options = [ - 'endpoint' => "$this->API_PREFIX/templates", + 'endpoint' => "{$this->CONFIG['API_PREFIX']}/templates", 'qs' => $qs ]; - return $this->Request->unauthorizedRequest($options); + return $this->ApiRequest->unauthorizedRequest($options); } /** @@ -50,11 +60,11 @@ public function getTemplatesCategories($payload) { $qs = $this->Params->destructParams($payload, ['language']); $options = [ - 'endpoint' => "$this->API_PREFIX/templates/categories", + 'endpoint' => "{$this->CONFIG['API_PREFIX']}/templates/categories", 'qs' => $qs ]; - return $this->Request->unauthorizedRequest($options); + return $this->ApiRequest->unauthorizedRequest($options); } /** @@ -68,11 +78,11 @@ public function getTemplate($payload) $qs = $this->Params->destructParams($payload, ['language']); $templateId = $this->Params->destructURLParam($payload, 'templateId'); $options = [ - 'endpoint' => "$this->API_PREFIX/templates/$templateId", + 'endpoint' => "{$this->CONFIG['API_PREFIX']}/templates/$templateId", 'qs' => $qs ]; - return $this->Request->unauthorizedRequest($options); + return $this->ApiRequest->unauthorizedRequest($options); } /** @@ -85,10 +95,10 @@ public function getTemplateColorPresets($payload) { $templateId = $this->Params->destructURLParam($payload, 'templateId'); $options = [ - 'endpoint' => "$this->API_PREFIX/templates/$templateId/color-presets" + 'endpoint' => "{$this->CONFIG['API_PREFIX']}/templates/$templateId/color-presets" ]; - return $this->Request->unauthorizedRequest($options); + return $this->ApiRequest->unauthorizedRequest($options); } /** @@ -101,10 +111,10 @@ public function getTemplatePluggableScreens($payload) { $templateId = $this->Params->destructURLParam($payload, 'templateId'); $options = [ - 'endpoint' => "$this->API_PREFIX/templates/$templateId/pluggable-screens" + 'endpoint' => "{$this->CONFIG['API_PREFIX']}/templates/$templateId/pluggable-screens" ]; - return $this->Request->unauthorizedRequest($options); + return $this->ApiRequest->unauthorizedRequest($options); } /** @@ -117,10 +127,10 @@ public function getTemplateRecommendedCustomColors($payload) { $templateId = $this->Params->destructURLParam($payload, 'templateId'); $options = [ - 'endpoint' => "$this->API_PREFIX/templates/$templateId/recommended-custom-colors" + 'endpoint' => "{$this->CONFIG['API_PREFIX']}/templates/$templateId/recommended-custom-colors" ]; - return $this->Request->unauthorizedRequest($options); + return $this->ApiRequest->unauthorizedRequest($options); } /** @@ -133,10 +143,25 @@ public function getTemplatePresets($payload) { $templateId = $this->Params->destructURLParam($payload, 'templateId'); $options = [ - 'endpoint' => "$this->API_PREFIX/templates/$templateId/template-presets" + 'endpoint' => "{$this->CONFIG['API_PREFIX']}/templates/$templateId/template-presets" + ]; + + return $this->ApiRequest->unauthorizedRequest($options); + } + + /** + * Gets Template-SVG-Content of the Template. + * @param $payload + * @return array|null + * @throws \GuzzleHttp\Exception\GuzzleException + */ + public function getTemplateSVGContent($payload) { + $templateId = $this->Params->destructURLParam($payload, 'templateId'); + $options = [ + 'endpoint' => "{$this->CONFIG['WEB_PREFIX']}/templates/termplatesvg/$templateId" ]; - return $this->Request->unauthorizedRequest($options); + return $this->WebRequest->request($options); } /** @@ -149,10 +174,10 @@ public function getTemplateTheme($payload) { $templateId = $this->Params->destructURLParam($payload, 'templateId'); $options = [ - 'endpoint' => "$this->API_PREFIX/templates/$templateId/theme" + 'endpoint' => "{$this->CONFIG['API_PREFIX']}/templates/$templateId/theme" ]; - return $this->Request->unauthorizedRequest($options); + return $this->ApiRequest->unauthorizedRequest($options); } /** @@ -165,9 +190,9 @@ public function getTemplateTransitions($payload) { $templateId = $this->Params->destructURLParam($payload, 'templateId'); $options = [ - 'endpoint' => "$this->API_PREFIX/templates/$templateId/transitions" + 'endpoint' => "{$this->CONFIG['API_PREFIX']}/templates/$templateId/transitions" ]; - return $this->Request->unauthorizedRequest($options); + return $this->ApiRequest->unauthorizedRequest($options); } } diff --git a/src/Resource/Users.php b/src/Resource/Users.php index 73c9edb..9344acb 100644 --- a/src/Resource/Users.php +++ b/src/Resource/Users.php @@ -9,19 +9,21 @@ namespace Renderforest\Resource; -use Renderforest; +use Renderforest\Request\Api; class Users { - private $API_PREFIX = '/api/v1'; - private $Request; + private $CONFIG; + + private $ApiRequest; /** * Users constructor. */ public function __construct() { - $this->Request = Renderforest\Request\Http::getInstance(); + $this->CONFIG = include dirname(__FILE__) . '/../Config/Config.php'; + $this->ApiRequest = Api::getInstance(); } /** @@ -32,9 +34,9 @@ public function __construct() public function getCurrentUser() { $options = [ - 'endpoint' => "$this->API_PREFIX/users/current" + 'endpoint' => "{$this->CONFIG['API_PREFIX']}/users/current" ]; - return $this->Request->authorizedRequest($options); + return $this->ApiRequest->authorizedRequest($options); } } diff --git a/src/Singleton.php b/src/Singleton.php index 48445a3..3727db4 100644 --- a/src/Singleton.php +++ b/src/Singleton.php @@ -22,27 +22,10 @@ private function __construct() } /** - * Prevent user to clone class. - * @return Singleton + * Get instance method + * @return static */ - private function __clone() - { - return self::$instance; - } - - /** - * Prevent user to copy class via unserialize. - * @return Singleton - */ - private function __wakeup() - { - return self::$instance; - } - - /** - * @return Singleton - */ - static public function getInstance() + public static function getInstance() { if (!isset(self::$instance)) { self::$instance = new self();