Skip to content

Commit 26c81df

Browse files
Merge pull request #123 from renderforest/delete-videos-and-watermark-feature
delete-videos-and-watermark-feature
2 parents d7e4fe8 + cdacced commit 26c81df

File tree

7 files changed

+120
-20
lines changed

7 files changed

+120
-20
lines changed

README.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Welcome to the Renderforest API! You can use our API to:
3737
- [Get a Specific Project](#get-a-specific-project)
3838
- [Update the Project - partial update](#update-the-project---partial-update)
3939
- [Delete a Specific Project](#delete-a-specific-project)
40+
- [Delete Specific Project Videos](#delete-specific-project-videos)
4041
- [Apply Template Preset on the Project](#apply-template-preset-on-the-project)
4142
- [Duplicate the Project](#duplicate-the-project)
4243
- [Render the Project](#render-the-project)
@@ -272,6 +273,35 @@ var_dump($deleteProject); // handle the success
272273
[See example](https://github.com/renderforest/renderforest-sdk-php/blob/master/examples/projects/delete-project.php)
273274

274275

276+
### Delete Specific Project Videos
277+
278+
Deletes specific project videos. The quality parameter is optional.
279+
280+
**IMPORTANT**: If you want to delete only a single quality video, you have to specify quality parameter,
281+
otherwise all quality videos of the project will be deleted.
282+
283+
```php
284+
<?php
285+
286+
require 'vendor/autoload.php';
287+
288+
$renderforest = new \Renderforest\Client(['signKey' => '<signKey>', 'clientId' => -1]);
289+
290+
$payload = [
291+
'projectId' => 5000658,
292+
'quality' => 360 // optional argument
293+
];
294+
try {
295+
$deleteProject = $renderforest->deleteProjectVideos($payload);
296+
} catch (\GuzzleHttp\Exception\GuzzleException $e) {
297+
var_dump($e); // handle the error
298+
}
299+
300+
var_dump($deleteProject); // handle the success
301+
```
302+
303+
[See example](https://github.com/renderforest/renderforest-sdk-php/blob/master/examples/projects/delete-project-videos.php)
304+
275305
### Apply Template Preset on the Project
276306

277307
Applies template preset on the project.
@@ -327,7 +357,9 @@ var_dump($duplicateProject); // handle the success
327357

328358
### Render the Project
329359

330-
Renders the project.
360+
Renders the project with given quality. The possible values for the quality are: 0, 360, 720, and 1080.
361+
The watermark parameter is optional, must be in '.png' file format and have canvas size of 1920 x 1080 pixels,
362+
url length must not exceed 250 characters and is not applicable to HD quality videos.
331363

332364
```php
333365
<?php
@@ -338,7 +370,8 @@ $renderforest = new \Renderforest\Client(['signKey' => '<signKey>', 'clientId' =
338370

339371
$payload = [
340372
'projectId' => 5000658,
341-
'quality' => 1080
373+
'quality' => 360,
374+
'watermark' => 'https://example.com/watermark.png' // optional parameter
342375
];
343376
try {
344377
$renderProject = $renderforest->renderProject($payload);

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.3.9",
4+
"version": "0.3.10",
55
"homepage": "https://github.com/renderforest/renderforest-sdk-php",
66
"authors": [
77
{
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
* Copyright (c) 2018-present, Renderforest, LLC.
4+
* All rights reserved.
5+
*
6+
* This source code is licensed under the license found in the
7+
* LICENSE file in the root directory.
8+
*/
9+
10+
require 'vendor/autoload.php';
11+
12+
$renderforest = new \Renderforest\Client(['signKey' => '<signKey>', 'clientId' => -1]);
13+
14+
$payload = [
15+
'projectId' => 5000658,
16+
'quality' => 360 // optional argument
17+
];
18+
try {
19+
$deleteProject = $renderforest->deleteProjectVideos($payload);
20+
} catch (\GuzzleHttp\Exception\GuzzleException $e) {
21+
var_dump($e); // handle the error
22+
}
23+
24+
var_dump($deleteProject); // handle the success

examples/projects/render-project.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313

1414
$payload = [
1515
'projectId' => 5000658,
16-
'quality' => 1080
16+
'quality' => 360,
17+
'watermark' => 'https://example.com/watermark.png' // optional argument
1718
];
1819
try {
1920
$renderProject = $renderforest->renderProject($payload);

src/Client.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,17 @@ public function deleteProject($payload)
148148
return $this->Projects->deleteProject($payload);
149149
}
150150

151+
/**
152+
* Deletes the rendered project videos based given on quality.
153+
* @param array $payload
154+
* @return array|null
155+
* @throws \GuzzleHttp\Exception\GuzzleException
156+
*/
157+
public function deleteProjectVideos($payload)
158+
{
159+
return $this->Projects->deleteProjectVideos($payload);
160+
}
161+
151162
/**
152163
* Applies template preset on the project.
153164
* @param array $payload

src/Params.php

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@
66
* This source code is licensed under the license found in the
77
* LICENSE file in the root directory.
88
*/
9+
910
namespace Renderforest;
1011

1112
use Renderforest\Error\RenderforestError;
1213

1314
class Params
1415
{
1516
/**
16-
* @param array $payload
17-
* @param array $props
17+
* Destructs given properties from the payload.
18+
* @param array $payload - The array to destruct.
19+
* @param array $props - The prop to destruct from array.
1820
* @return array
19-
* @description Destruct given properties from the payload.
2021
*/
2122
public function destructParams($payload, $props)
2223
{
@@ -34,11 +35,11 @@ public function destructParams($payload, $props)
3435
}
3536

3637
/**
37-
* @param array $payload
38-
* @param string $param
39-
* @return mixed
38+
* Destructs URL param from the payload.
39+
* @param array $payload - The array to destruct.
40+
* @param string $param - The param to destruct from array.
41+
* @return string
4042
* @throws RenderforestError
41-
* @description Destruct URL param from the payload.
4243
*/
4344
public function destructURLParam($payload, $param)
4445
{
@@ -48,4 +49,24 @@ public function destructURLParam($payload, $param)
4849

4950
return $payload[$param];
5051
}
52+
53+
/**
54+
* Destructs optional URL param from the given payload.
55+
* @param $payload - Thr array to destruct.
56+
* @param $param - The param to destruct from array.
57+
* @return string
58+
* @throws RenderforestError
59+
*/
60+
public function destructOptionalURLParam($payload, $param)
61+
{
62+
if (!isset($payload) || sizeof($payload)) {
63+
throw new RenderforestError("Missing optional parameter: ${param}.");
64+
}
65+
66+
if (!isset($payload[$param])) {
67+
return '';
68+
}
69+
70+
return $payload[$param];
71+
}
5172
}

src/Resource/Projects.php

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ public function getProjects($payload)
4848
'endpoint' => "{$this->CONFIG['API_PREFIX']}/projects",
4949
'qs' => $qs
5050
];
51-
5251
return $this->ApiRequest->authorizedRequest($options);
5352
}
5453

@@ -67,7 +66,6 @@ public function addProject($payload)
6766
'endpoint' => "{$this->CONFIG['API_PREFIX']}/projects",
6867
'json' => $body
6968
];
70-
7169
return $this->ApiRequest->authorizedRequest($options);
7270
}
7371

@@ -85,7 +83,6 @@ public function getTrialProject($payload)
8583
'endpoint' => "{$this->CONFIG['API_PREFIX']}/projects/trial",
8684
'qs' => $qs
8785
];
88-
8986
return $this->ApiRequest->unauthorizedRequest($options);
9087
}
9188

@@ -102,7 +99,6 @@ public function getProject($payload)
10299
$options = [
103100
'endpoint' => "{$this->CONFIG['API_PREFIX']}/projects/$projectId"
104101
];
105-
106102
return $this->ApiRequest->authorizedRequest($options);
107103
}
108104

@@ -122,7 +118,6 @@ public function updateProjectPartial($payload)
122118
'endpoint' => "{$this->CONFIG['API_PREFIX']}/projects/$projectId",
123119
'json' => $body
124120
];
125-
126121
return $this->ApiRequest->authorizedRequest($options);
127122
}
128123

@@ -140,7 +135,25 @@ public function deleteProject($payload)
140135
'method' => 'DELETE',
141136
'endpoint' => "{$this->CONFIG['API_PREFIX']}/projects/$projectId"
142137
];
138+
return $this->ApiRequest->authorizedRequest($options);
139+
}
143140

141+
/**
142+
* Deletes specific project videos. The quality parameter is optional.
143+
* IMPORTANT: In case if quality is not specified, it will remove all rendered videos.
144+
* @param $payload
145+
* @return array|null
146+
* @throws \GuzzleHttp\Exception\GuzzleException
147+
*/
148+
public function deleteProjectVideos($payload)
149+
{
150+
$projectId = $this->Params->destructURLParam($payload, 'projectId');
151+
$quality = $this->Params->destructOptionalURLParam($payload, 'quality');
152+
153+
$options = [
154+
'method' => 'DELETE',
155+
'endpoints' => "{$this->CONFIG['API_PREFIX']}/projects/$projectId/videos/$quality"
156+
];
144157
return $this->ApiRequest->authorizedRequest($options);
145158
}
146159

@@ -160,7 +173,6 @@ public function applyTemplatePresetOnProject($payload)
160173
'endpoint' => "{$this->CONFIG['API_PREFIX']}/projects/$projectId/apply-template-preset",
161174
'json' => $body
162175
];
163-
164176
return $this->ApiRequest->authorizedRequest($options);
165177
}
166178

@@ -178,7 +190,6 @@ public function duplicateProject($payload)
178190
'method' => 'POST',
179191
'endpoint' => "{$this->CONFIG['API_PREFIX']}/projects/$projectId/duplicate"
180192
];
181-
182193
return $this->ApiRequest->authorizedRequest($options);
183194
}
184195

@@ -190,15 +201,14 @@ public function duplicateProject($payload)
190201
*/
191202
public function renderProject($payload)
192203
{
193-
$body = $this->Params->destructParams($payload, ['quality']);
204+
$body = $this->Params->destructParams($payload, ['quality', 'watermark']);
194205
$projectId = $this->Params->destructURLParam($payload, 'projectId');
195206

196207
$options = [
197208
'method' => 'POST',
198209
'endpoint' => "{$this->CONFIG['API_PREFIX']}/projects/$projectId/render",
199210
'json' => $body
200211
];
201-
202212
return $this->ApiRequest->authorizedRequest($options);
203213
}
204214
}

0 commit comments

Comments
 (0)