Skip to content

Commit 64ccfcf

Browse files
authored
Merge pull request #143 from tigranmaestro/upgrade-get-all-templates
Upgrade "Get All Templates"
2 parents 2f82968 + cbcc826 commit 64ccfcf

File tree

2 files changed

+68
-34
lines changed

2 files changed

+68
-34
lines changed

examples/templates/get-all-templates.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
require '../../vendor/autoload.php';
44

5-
$templates = \Renderforest\ApiClient::getAllTemplates();
5+
$templates = \Renderforest\ApiClient::getAllTemplates(
6+
3,
7+
false,
8+
4,
9+
10
10+
);
611

712
echo 'Count - ' . count($templates) . PHP_EOL;
813
echo PHP_EOL;

src/ApiClient.php

Lines changed: 62 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Renderforest;
44

55
use GuzzleHttp\Client;
6+
use GuzzleHttp\Exception\GuzzleException;
67
use Renderforest\Font\Collection\FontCollection;
78
use Renderforest\Project\Collection\ProjectCollection;
89
use Renderforest\Project\Project;
@@ -161,7 +162,7 @@ public function updateProjectData(
161162
/**
162163
* @param int $templateId
163164
* @return int
164-
* @throws \GuzzleHttp\Exception\GuzzleException
165+
* @throws GuzzleException
165166
*/
166167
public function addProject(int $templateId): int
167168
{
@@ -202,7 +203,7 @@ public function addProject(int $templateId): int
202203
* @param int $projectId
203204
* @param string|null $customTitle
204205
* @return int
205-
* @throws \GuzzleHttp\Exception\GuzzleException
206+
* @throws GuzzleException
206207
*/
207208
public function updateProject(
208209
int $projectId,
@@ -248,7 +249,7 @@ public function updateProject(
248249
/**
249250
* @param int $projectId
250251
* @return int
251-
* @throws \GuzzleHttp\Exception\GuzzleException
252+
* @throws GuzzleException
252253
*/
253254
public function deleteSpecificProject(int $projectId): int
254255
{
@@ -286,7 +287,7 @@ public function deleteSpecificProject(int $projectId): int
286287
* @param int $projectId
287288
* @param int|null $quality
288289
* @return int
289-
* @throws \GuzzleHttp\Exception\GuzzleException
290+
* @throws GuzzleException
290291
*/
291292
public function deleteSpecificProjectVideos(int $projectId, int $quality = null): int
292293
{
@@ -334,7 +335,7 @@ public function deleteSpecificProjectVideos(int $projectId, int $quality = null)
334335
* @param int $projectId
335336
* @param int $templatePresetId
336337
* @return int
337-
* @throws \GuzzleHttp\Exception\GuzzleException
338+
* @throws GuzzleException
338339
*/
339340
public function applyTemplatePresetOnProject(int $projectId, int $templatePresetId): int
340341
{
@@ -381,7 +382,7 @@ public function applyTemplatePresetOnProject(int $projectId, int $templatePreset
381382
/**
382383
* @param int $projectId
383384
* @return int
384-
* @throws \GuzzleHttp\Exception\GuzzleException
385+
* @throws GuzzleException
385386
*/
386387
public function duplicateProject(int $projectId): int
387388
{
@@ -425,7 +426,7 @@ public function duplicateProject(int $projectId): int
425426
* @param int $quality
426427
* @param string|null $watermarkImageUrl
427428
* @return int
428-
* @throws \GuzzleHttp\Exception\GuzzleException
429+
* @throws GuzzleException
429430
*/
430431
public function renderProject(
431432
int $projectId,
@@ -481,7 +482,7 @@ public function renderProject(
481482
*
482483
* @param string|null $languageIsoCode
483484
* @return CategoryCollection
484-
* @throws \GuzzleHttp\Exception\GuzzleException
485+
* @throws GuzzleException
485486
*/
486487
public static function getTemplatesCategories(string $languageIsoCode = null): CategoryCollection
487488
{
@@ -526,7 +527,7 @@ public static function getTemplatesCategories(string $languageIsoCode = null): C
526527
/**
527528
* @param int $templateId
528529
* @return CustomColorCollection
529-
* @throws \GuzzleHttp\Exception\GuzzleException
530+
* @throws GuzzleException
530531
*/
531532
public static function getTemplateRecommendedCustomColors(int $templateId): CustomColorCollection
532533
{
@@ -567,7 +568,7 @@ public static function getTemplateRecommendedCustomColors(int $templateId): Cust
567568
/**
568569
* @param int $templateId
569570
* @return TemplatePresetCollection
570-
* @throws \GuzzleHttp\Exception\GuzzleException
571+
* @throws GuzzleException
571572
*/
572573
public static function getTemplatePresets(int $templateId): TemplatePresetCollection
573574
{
@@ -608,7 +609,7 @@ public static function getTemplatePresets(int $templateId): TemplatePresetCollec
608609
/**
609610
* @param int $templateId
610611
* @return TemplateTheme
611-
* @throws \GuzzleHttp\Exception\GuzzleException
612+
* @throws GuzzleException
612613
*/
613614
public static function getTemplateTheme(int $templateId): TemplateTheme
614615
{
@@ -649,7 +650,7 @@ public static function getTemplateTheme(int $templateId): TemplateTheme
649650
/**
650651
* @param int $templateId
651652
* @return PluggableScreensGroupCollection
652-
* @throws \GuzzleHttp\Exception\GuzzleException
653+
* @throws GuzzleException
653654
*/
654655
public static function getTemplatePluggableScreens(int $templateId): PluggableScreensGroupCollection
655656
{
@@ -690,7 +691,7 @@ public static function getTemplatePluggableScreens(int $templateId): PluggableSc
690691
/**
691692
* @param int $templateId
692693
* @return TemplateTransitions
693-
* @throws \GuzzleHttp\Exception\GuzzleException
694+
* @throws GuzzleException
694695
*/
695696
public static function getTemplateTransitions(int $templateId): TemplateTransitions
696697
{
@@ -731,7 +732,7 @@ public static function getTemplateTransitions(int $templateId): TemplateTransiti
731732
/**
732733
* @param int $templateId
733734
* @return ColorPresetCollection
734-
* @throws \GuzzleHttp\Exception\GuzzleException
735+
* @throws GuzzleException
735736
*/
736737
public static function getTemplateColorPresets(int $templateId): ColorPresetCollection
737738
{
@@ -770,17 +771,45 @@ public static function getTemplateColorPresets(int $templateId): ColorPresetColl
770771
}
771772

772773
/**
774+
* @param int|null $categoryId
775+
* @param bool|null $isEqualizer
776+
* @param int|null $limit
777+
* @param int|null $offset
773778
* @return TemplateCollection
774-
* @throws \GuzzleHttp\Exception\GuzzleException
779+
* @throws GuzzleException
775780
*/
776-
public static function getAllTemplates(): TemplateCollection
777-
{
778-
// @todo query params
779-
// ?categoryId=3&equalizer=false&limit=4&offset=10
781+
public static function getAllTemplates(
782+
?int $categoryId = null,
783+
?bool $isEqualizer = null,
784+
?int $limit = null,
785+
?int $offset = null
786+
): TemplateCollection {
787+
$queryParams = [];
788+
if (false === is_null($categoryId)) {
789+
$queryParams['categoryId'] = $categoryId;
790+
}
791+
792+
if (false === is_null($isEqualizer)) {
793+
$queryParams['equalizer'] = $isEqualizer ? 'true' : 'false';
794+
}
795+
796+
if (false === is_null($limit)) {
797+
$queryParams['limit'] = $limit;
798+
}
799+
800+
if (false === is_null($offset)) {
801+
$queryParams['offset'] = $offset;
802+
}
780803

781804
$endpoint = self::TEMPLATES_API_PATH_PREFIX;
782805
$uri = self::API_ENDPOINT . self::TEMPLATES_API_PATH;
783806

807+
if (count($queryParams)) {
808+
$queryString = http_build_query($queryParams);
809+
810+
$uri = $uri . '?' . $queryString;
811+
}
812+
784813
$options = [
785814
'method' => 'GET',
786815
'headers' => [
@@ -811,7 +840,7 @@ public static function getAllTemplates(): TemplateCollection
811840
* @param int $templateId
812841
* @param string|null $languageIsoCode
813842
* @return TemplateExtended
814-
* @throws \GuzzleHttp\Exception\GuzzleException
843+
* @throws GuzzleException
815844
*/
816845
public static function getTemplate(
817846
int $templateId,
@@ -858,7 +887,7 @@ public static function getTemplate(
858887

859888
/**
860889
* @return User
861-
* @throws \GuzzleHttp\Exception\GuzzleException
890+
* @throws GuzzleException
862891
*/
863892
public function getCurrentUser(): User
864893
{
@@ -894,7 +923,7 @@ public function getCurrentUser(): User
894923
/**
895924
* @param int $templateId
896925
* @return FontCollection
897-
* @throws \GuzzleHttp\Exception\GuzzleException
926+
* @throws GuzzleException
898927
*/
899928
public function getTemplateAvailableFonts(int $templateId): FontCollection
900929
{
@@ -937,7 +966,7 @@ public function getTemplateAvailableFonts(int $templateId): FontCollection
937966
/**
938967
* @param int $duration
939968
* @return SoundCollection
940-
* @throws \GuzzleHttp\Exception\GuzzleException
969+
* @throws GuzzleException
941970
*/
942971
public function getAllSounds(int $duration = null): SoundCollection
943972
{
@@ -982,7 +1011,7 @@ public function getAllSounds(int $duration = null): SoundCollection
9821011
/**
9831012
* @param int $duration
9841013
* @return SoundCollection
985-
* @throws \GuzzleHttp\Exception\GuzzleException
1014+
* @throws GuzzleException
9861015
*/
9871016
public static function getCompanySoundsLimited(int $duration = null): SoundCollection
9881017
{
@@ -1027,7 +1056,7 @@ public static function getCompanySoundsLimited(int $duration = null): SoundColle
10271056
/**
10281057
* @param int $duration
10291058
* @return SoundCollection
1030-
* @throws \GuzzleHttp\Exception\GuzzleException
1059+
* @throws GuzzleException
10311060
*/
10321061
public function getCompanySounds(int $duration = null): SoundCollection
10331062
{
@@ -1072,7 +1101,7 @@ public function getCompanySounds(int $duration = null): SoundCollection
10721101
/**
10731102
* @param int $duration
10741103
* @return SoundCollection
1075-
* @throws \GuzzleHttp\Exception\GuzzleException
1104+
* @throws GuzzleException
10761105
*/
10771106
public static function getRecommendedSoundsLimited(int $templateId, int $duration): SoundCollection
10781107
{
@@ -1116,7 +1145,7 @@ public static function getRecommendedSoundsLimited(int $templateId, int $duratio
11161145
/**
11171146
* @param int $duration
11181147
* @return SoundCollection
1119-
* @throws \GuzzleHttp\Exception\GuzzleException
1148+
* @throws GuzzleException
11201149
*/
11211150
public function getRecommendedSounds(int $templateId, int $duration): SoundCollection
11221151
{
@@ -1160,7 +1189,7 @@ public function getRecommendedSounds(int $templateId, int $duration): SoundColle
11601189
/**
11611190
* @param SupportTicket $supportTicket
11621191
* @return SupportTicketResponse
1163-
* @throws \GuzzleHttp\Exception\GuzzleException
1192+
* @throws GuzzleException
11641193
*/
11651194
public function createSupportTicket(SupportTicket $supportTicket): SupportTicketResponse
11661195
{
@@ -1197,7 +1226,7 @@ public function createSupportTicket(SupportTicket $supportTicket): SupportTicket
11971226
/**
11981227
* @param int $projectId
11991228
* @return ProjectData
1200-
* @throws \GuzzleHttp\Exception\GuzzleException
1229+
* @throws GuzzleException
12011230
*/
12021231
public function getProjectData(int $projectId): ProjectData
12031232
{
@@ -1233,7 +1262,7 @@ public function getProjectData(int $projectId): ProjectData
12331262
/**
12341263
* @param ProjectData $projectData
12351264
* @return str
1236-
* @throws \GuzzleHttp\Exception\GuzzleException
1265+
* @throws GuzzleException
12371266
*/
12381267
public function getScreenSnapshot(ProjectData $projectData): string {
12391268
$endpoint = self::PREVIEW_API_PATH;
@@ -1271,7 +1300,7 @@ public function getScreenSnapshot(ProjectData $projectData): string {
12711300
/**
12721301
* @param int $templateId
12731302
* @return ProjectData
1274-
* @throws \GuzzleHttp\Exception\GuzzleException
1303+
* @throws GuzzleException
12751304
*/
12761305
public static function getTrialProject(int $templateId): ProjectData
12771306
{
@@ -1319,7 +1348,7 @@ public static function getTrialProject(int $templateId): ProjectData
13191348
* @param string $orderBy
13201349
* @param string|null $search
13211350
* @return ProjectCollection
1322-
* @throws \GuzzleHttp\Exception\GuzzleException
1351+
* @throws GuzzleException
13231352
*/
13241353
public function getAllProjects(
13251354
int $limit = null,
@@ -1385,7 +1414,7 @@ public function getAllProjects(
13851414
/**
13861415
* @param int $projectId
13871416
* @return Project
1388-
* @throws \GuzzleHttp\Exception\GuzzleException
1417+
* @throws GuzzleException
13891418
*/
13901419
public function getProject(int $projectId): Project
13911420
{

0 commit comments

Comments
 (0)