Skip to content

Commit

Permalink
Merge pull request #154 from renderforest/template-preset
Browse files Browse the repository at this point in the history
Template preset
  • Loading branch information
ArtyomHov authored May 4, 2021
2 parents 1be5f64 + 446ad65 commit e348cfc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 31 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "renderforest/sdk-php",
"description": "Renderforest SDK for PHP",
"version": "0.5.4",
"version": "0.5.5",
"homepage": "https://github.com/renderforest/renderforest-sdk-php",
"keywords": [
"animation maker",
Expand Down
7 changes: 4 additions & 3 deletions examples/projects/apply-template-preset-on-the-project.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
'your-client-id'
);

$projectId = $renderforestClient->applyTemplatePresetOnProject(
16297523,
294
$projectData = $renderforestClient->applyTemplatePresetOnProject(
15990207,
701,
3
);

echo 'Project ID - ' . $projectId . PHP_EOL;
50 changes: 23 additions & 27 deletions src/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ class ApiClient
const DELETE_PROJECT_VIDEOS_API_PATH_PREFIX = '/api/v1';
const DELETE_PROJECT_VIDEOS_API_PATH = self::DELETE_PROJECT_VIDEOS_API_PATH_PREFIX . '/projects/%d/videos/%d';

const APPLY_TEMPLATE_PRESET_PROJECT_API_PATH_PREFIX = '/api/v1';
const APPLY_TEMPLATE_PRESET_PROJECT_API_PATH = self::APPLY_TEMPLATE_PRESET_PROJECT_API_PATH_PREFIX . '/projects/%d/apply-template-preset';

const RENDER_PROJECT_API_PATH_PREFIX = '/api/v1';
const RENDER_PROJECT_API_PATH = self::RENDER_PROJECT_API_PATH_PREFIX . '/projects/%d/render';

Expand Down Expand Up @@ -353,49 +350,48 @@ public function deleteSpecificProjectVideos(int $projectId, int $quality = null)

/**
* @param int $projectId
* @param int $templatePresetId
* @param int $templateId
* @param int $presetId
* @return int
* @throws GuzzleException
*/
public function applyTemplatePresetOnProject(int $projectId, int $templatePresetId): int
public function applyTemplatePresetOnProject(int $projectId, int $templateId, int $presetId): int
{
$endpoint = self::APPLY_TEMPLATE_PRESET_PROJECT_API_PATH;

$applyTemplatePresetOnProjectApiPath = sprintf(
self::APPLY_TEMPLATE_PRESET_PROJECT_API_PATH,
$projectId
);
$uri = self::API_ENDPOINT . $applyTemplatePresetOnProjectApiPath;

$postData = [
'presetId' => $templatePresetId,
$endpoint = self::TRIAL_PROJECT_API_PATH;
$uri = self::API_ENDPOINT . self::TRIAL_PROJECT_API_PATH;

$queryParams = [
'templateId' => $templateId,
'presetId' => $presetId
];


$queryString = http_build_query($queryParams);
$uri .= '?' . $queryString;

$options = [
'method' => 'POST',
'method' => 'GET',
'headers' => [
'Accept' => 'application/json',
'User-Agent' => self::USER_AGENT,
],
'endpoint' => $endpoint,
'uri' => $uri,
'json' => $postData,
];

$options = $this->setAuthorization($options);

$response = $this->httpClient->request(
$httpClient = new Client();
$response = $httpClient->request(
$options['method'],
$options['uri'],
$options
);

$json = $response->getBody()->getContents();

$jsonResponse = $response->getBody()->getContents();
$arrayResponse = \GuzzleHttp\json_decode($jsonResponse, true);

$data = $arrayResponse['data'];
$projectId = intval($data['projectId']);
$projectData = new ProjectData();
$projectData->exchangeJson($json);

$projectId = $this->updateProjectData($projectId, $projectData);
return $projectId;
}

Expand Down

0 comments on commit e348cfc

Please sign in to comment.