Skip to content

Commit e348cfc

Browse files
authored
Merge pull request #154 from renderforest/template-preset
Template preset
2 parents 1be5f64 + 446ad65 commit e348cfc

File tree

3 files changed

+28
-31
lines changed

3 files changed

+28
-31
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "renderforest/sdk-php",
33
"description": "Renderforest SDK for PHP",
4-
"version": "0.5.4",
4+
"version": "0.5.5",
55
"homepage": "https://github.com/renderforest/renderforest-sdk-php",
66
"keywords": [
77
"animation maker",

examples/projects/apply-template-preset-on-the-project.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
'your-client-id'
88
);
99

10-
$projectId = $renderforestClient->applyTemplatePresetOnProject(
11-
16297523,
12-
294
10+
$projectData = $renderforestClient->applyTemplatePresetOnProject(
11+
15990207,
12+
701,
13+
3
1314
);
1415

1516
echo 'Project ID - ' . $projectId . PHP_EOL;

src/ApiClient.php

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ class ApiClient
4545
const DELETE_PROJECT_VIDEOS_API_PATH_PREFIX = '/api/v1';
4646
const DELETE_PROJECT_VIDEOS_API_PATH = self::DELETE_PROJECT_VIDEOS_API_PATH_PREFIX . '/projects/%d/videos/%d';
4747

48-
const APPLY_TEMPLATE_PRESET_PROJECT_API_PATH_PREFIX = '/api/v1';
49-
const APPLY_TEMPLATE_PRESET_PROJECT_API_PATH = self::APPLY_TEMPLATE_PRESET_PROJECT_API_PATH_PREFIX . '/projects/%d/apply-template-preset';
50-
5148
const RENDER_PROJECT_API_PATH_PREFIX = '/api/v1';
5249
const RENDER_PROJECT_API_PATH = self::RENDER_PROJECT_API_PATH_PREFIX . '/projects/%d/render';
5350

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

354351
/**
355352
* @param int $projectId
356-
* @param int $templatePresetId
353+
* @param int $templateId
354+
* @param int $presetId
357355
* @return int
358356
* @throws GuzzleException
359357
*/
360-
public function applyTemplatePresetOnProject(int $projectId, int $templatePresetId): int
358+
public function applyTemplatePresetOnProject(int $projectId, int $templateId, int $presetId): int
361359
{
362-
$endpoint = self::APPLY_TEMPLATE_PRESET_PROJECT_API_PATH;
363-
364-
$applyTemplatePresetOnProjectApiPath = sprintf(
365-
self::APPLY_TEMPLATE_PRESET_PROJECT_API_PATH,
366-
$projectId
367-
);
368-
$uri = self::API_ENDPOINT . $applyTemplatePresetOnProjectApiPath;
369-
370-
$postData = [
371-
'presetId' => $templatePresetId,
360+
$endpoint = self::TRIAL_PROJECT_API_PATH;
361+
$uri = self::API_ENDPOINT . self::TRIAL_PROJECT_API_PATH;
362+
363+
$queryParams = [
364+
'templateId' => $templateId,
365+
'presetId' => $presetId
372366
];
373-
367+
368+
$queryString = http_build_query($queryParams);
369+
$uri .= '?' . $queryString;
370+
374371
$options = [
375-
'method' => 'POST',
372+
'method' => 'GET',
376373
'headers' => [
377374
'Accept' => 'application/json',
378375
'User-Agent' => self::USER_AGENT,
379376
],
380377
'endpoint' => $endpoint,
381378
'uri' => $uri,
382-
'json' => $postData,
383379
];
384-
385-
$options = $this->setAuthorization($options);
386-
387-
$response = $this->httpClient->request(
380+
381+
$httpClient = new Client();
382+
383+
$response = $httpClient->request(
388384
$options['method'],
389385
$options['uri'],
390386
$options
391387
);
388+
389+
$json = $response->getBody()->getContents();
392390

393-
$jsonResponse = $response->getBody()->getContents();
394-
$arrayResponse = \GuzzleHttp\json_decode($jsonResponse, true);
395-
396-
$data = $arrayResponse['data'];
397-
$projectId = intval($data['projectId']);
391+
$projectData = new ProjectData();
392+
$projectData->exchangeJson($json);
398393

394+
$projectId = $this->updateProjectData($projectId, $projectData);
399395
return $projectId;
400396
}
401397

0 commit comments

Comments
 (0)