Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template preset #154

Merged
merged 3 commits into from
May 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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