Skip to content

Commit

Permalink
Merge pull request #143 from tigranmaestro/upgrade-get-all-templates
Browse files Browse the repository at this point in the history
Upgrade "Get All Templates"
  • Loading branch information
emarukyan authored Jul 11, 2020
2 parents 2f82968 + cbcc826 commit 64ccfcf
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 34 deletions.
7 changes: 6 additions & 1 deletion examples/templates/get-all-templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

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

$templates = \Renderforest\ApiClient::getAllTemplates();
$templates = \Renderforest\ApiClient::getAllTemplates(
3,
false,
4,
10
);

echo 'Count - ' . count($templates) . PHP_EOL;
echo PHP_EOL;
Expand Down
95 changes: 62 additions & 33 deletions src/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Renderforest;

use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use Renderforest\Font\Collection\FontCollection;
use Renderforest\Project\Collection\ProjectCollection;
use Renderforest\Project\Project;
Expand Down Expand Up @@ -161,7 +162,7 @@ public function updateProjectData(
/**
* @param int $templateId
* @return int
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
*/
public function addProject(int $templateId): int
{
Expand Down Expand Up @@ -202,7 +203,7 @@ public function addProject(int $templateId): int
* @param int $projectId
* @param string|null $customTitle
* @return int
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
*/
public function updateProject(
int $projectId,
Expand Down Expand Up @@ -248,7 +249,7 @@ public function updateProject(
/**
* @param int $projectId
* @return int
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
*/
public function deleteSpecificProject(int $projectId): int
{
Expand Down Expand Up @@ -286,7 +287,7 @@ public function deleteSpecificProject(int $projectId): int
* @param int $projectId
* @param int|null $quality
* @return int
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
*/
public function deleteSpecificProjectVideos(int $projectId, int $quality = null): int
{
Expand Down Expand Up @@ -334,7 +335,7 @@ public function deleteSpecificProjectVideos(int $projectId, int $quality = null)
* @param int $projectId
* @param int $templatePresetId
* @return int
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
*/
public function applyTemplatePresetOnProject(int $projectId, int $templatePresetId): int
{
Expand Down Expand Up @@ -381,7 +382,7 @@ public function applyTemplatePresetOnProject(int $projectId, int $templatePreset
/**
* @param int $projectId
* @return int
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
*/
public function duplicateProject(int $projectId): int
{
Expand Down Expand Up @@ -425,7 +426,7 @@ public function duplicateProject(int $projectId): int
* @param int $quality
* @param string|null $watermarkImageUrl
* @return int
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
*/
public function renderProject(
int $projectId,
Expand Down Expand Up @@ -481,7 +482,7 @@ public function renderProject(
*
* @param string|null $languageIsoCode
* @return CategoryCollection
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
*/
public static function getTemplatesCategories(string $languageIsoCode = null): CategoryCollection
{
Expand Down Expand Up @@ -526,7 +527,7 @@ public static function getTemplatesCategories(string $languageIsoCode = null): C
/**
* @param int $templateId
* @return CustomColorCollection
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
*/
public static function getTemplateRecommendedCustomColors(int $templateId): CustomColorCollection
{
Expand Down Expand Up @@ -567,7 +568,7 @@ public static function getTemplateRecommendedCustomColors(int $templateId): Cust
/**
* @param int $templateId
* @return TemplatePresetCollection
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
*/
public static function getTemplatePresets(int $templateId): TemplatePresetCollection
{
Expand Down Expand Up @@ -608,7 +609,7 @@ public static function getTemplatePresets(int $templateId): TemplatePresetCollec
/**
* @param int $templateId
* @return TemplateTheme
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
*/
public static function getTemplateTheme(int $templateId): TemplateTheme
{
Expand Down Expand Up @@ -649,7 +650,7 @@ public static function getTemplateTheme(int $templateId): TemplateTheme
/**
* @param int $templateId
* @return PluggableScreensGroupCollection
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
*/
public static function getTemplatePluggableScreens(int $templateId): PluggableScreensGroupCollection
{
Expand Down Expand Up @@ -690,7 +691,7 @@ public static function getTemplatePluggableScreens(int $templateId): PluggableSc
/**
* @param int $templateId
* @return TemplateTransitions
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
*/
public static function getTemplateTransitions(int $templateId): TemplateTransitions
{
Expand Down Expand Up @@ -731,7 +732,7 @@ public static function getTemplateTransitions(int $templateId): TemplateTransiti
/**
* @param int $templateId
* @return ColorPresetCollection
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
*/
public static function getTemplateColorPresets(int $templateId): ColorPresetCollection
{
Expand Down Expand Up @@ -770,17 +771,45 @@ public static function getTemplateColorPresets(int $templateId): ColorPresetColl
}

/**
* @param int|null $categoryId
* @param bool|null $isEqualizer
* @param int|null $limit
* @param int|null $offset
* @return TemplateCollection
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
*/
public static function getAllTemplates(): TemplateCollection
{
// @todo query params
// ?categoryId=3&equalizer=false&limit=4&offset=10
public static function getAllTemplates(
?int $categoryId = null,
?bool $isEqualizer = null,
?int $limit = null,
?int $offset = null
): TemplateCollection {
$queryParams = [];
if (false === is_null($categoryId)) {
$queryParams['categoryId'] = $categoryId;
}

if (false === is_null($isEqualizer)) {
$queryParams['equalizer'] = $isEqualizer ? 'true' : 'false';
}

if (false === is_null($limit)) {
$queryParams['limit'] = $limit;
}

if (false === is_null($offset)) {
$queryParams['offset'] = $offset;
}

$endpoint = self::TEMPLATES_API_PATH_PREFIX;
$uri = self::API_ENDPOINT . self::TEMPLATES_API_PATH;

if (count($queryParams)) {
$queryString = http_build_query($queryParams);

$uri = $uri . '?' . $queryString;
}

$options = [
'method' => 'GET',
'headers' => [
Expand Down Expand Up @@ -811,7 +840,7 @@ public static function getAllTemplates(): TemplateCollection
* @param int $templateId
* @param string|null $languageIsoCode
* @return TemplateExtended
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
*/
public static function getTemplate(
int $templateId,
Expand Down Expand Up @@ -858,7 +887,7 @@ public static function getTemplate(

/**
* @return User
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
*/
public function getCurrentUser(): User
{
Expand Down Expand Up @@ -894,7 +923,7 @@ public function getCurrentUser(): User
/**
* @param int $templateId
* @return FontCollection
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
*/
public function getTemplateAvailableFonts(int $templateId): FontCollection
{
Expand Down Expand Up @@ -937,7 +966,7 @@ public function getTemplateAvailableFonts(int $templateId): FontCollection
/**
* @param int $duration
* @return SoundCollection
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
*/
public function getAllSounds(int $duration = null): SoundCollection
{
Expand Down Expand Up @@ -982,7 +1011,7 @@ public function getAllSounds(int $duration = null): SoundCollection
/**
* @param int $duration
* @return SoundCollection
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
*/
public static function getCompanySoundsLimited(int $duration = null): SoundCollection
{
Expand Down Expand Up @@ -1027,7 +1056,7 @@ public static function getCompanySoundsLimited(int $duration = null): SoundColle
/**
* @param int $duration
* @return SoundCollection
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
*/
public function getCompanySounds(int $duration = null): SoundCollection
{
Expand Down Expand Up @@ -1072,7 +1101,7 @@ public function getCompanySounds(int $duration = null): SoundCollection
/**
* @param int $duration
* @return SoundCollection
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
*/
public static function getRecommendedSoundsLimited(int $templateId, int $duration): SoundCollection
{
Expand Down Expand Up @@ -1116,7 +1145,7 @@ public static function getRecommendedSoundsLimited(int $templateId, int $duratio
/**
* @param int $duration
* @return SoundCollection
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
*/
public function getRecommendedSounds(int $templateId, int $duration): SoundCollection
{
Expand Down Expand Up @@ -1160,7 +1189,7 @@ public function getRecommendedSounds(int $templateId, int $duration): SoundColle
/**
* @param SupportTicket $supportTicket
* @return SupportTicketResponse
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
*/
public function createSupportTicket(SupportTicket $supportTicket): SupportTicketResponse
{
Expand Down Expand Up @@ -1197,7 +1226,7 @@ public function createSupportTicket(SupportTicket $supportTicket): SupportTicket
/**
* @param int $projectId
* @return ProjectData
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
*/
public function getProjectData(int $projectId): ProjectData
{
Expand Down Expand Up @@ -1233,7 +1262,7 @@ public function getProjectData(int $projectId): ProjectData
/**
* @param ProjectData $projectData
* @return str
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
*/
public function getScreenSnapshot(ProjectData $projectData): string {
$endpoint = self::PREVIEW_API_PATH;
Expand Down Expand Up @@ -1271,7 +1300,7 @@ public function getScreenSnapshot(ProjectData $projectData): string {
/**
* @param int $templateId
* @return ProjectData
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
*/
public static function getTrialProject(int $templateId): ProjectData
{
Expand Down Expand Up @@ -1319,7 +1348,7 @@ public static function getTrialProject(int $templateId): ProjectData
* @param string $orderBy
* @param string|null $search
* @return ProjectCollection
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
*/
public function getAllProjects(
int $limit = null,
Expand Down Expand Up @@ -1385,7 +1414,7 @@ public function getAllProjects(
/**
* @param int $projectId
* @return Project
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
*/
public function getProject(int $projectId): Project
{
Expand Down

0 comments on commit 64ccfcf

Please sign in to comment.