$typeTemplates) { foreach($typeTemplates as $id => $templateData) { $allTemplates[$id] = $templateData; } } return $allTemplates; } protected static function _getTemplates(string $apiKey, string $type = null) { if (isset(self::$_templates[$apiKey])) { return self::_getTemplatesOfType(self::$_templates[$apiKey], $type); } return []; } /** * Get all the templates for an API key * @param string $apiKey * @param string $type template type * @param bool $forceRefresh allow to bypass the cache * @return array */ public static function loadTemplates(string $apiKey, string $type = null, bool $forceRefresh = false) { if (self::_hasLoadedTemplates($apiKey) && !$forceRefresh) { return self::_getTemplates($apiKey, $type); } $path = 'get-templates/' . $apiKey; $apiCall = self::call($path); if ($apiCall === null) return []; $templates = []; if ($apiCall['success']) { foreach($apiCall['data'] as $templateData) { if (!isset($templates[$templateData['type']])) { $templates[$templateData['type']] = []; } $templates[$templateData['type']][$templateData['id']] = $templateData; } } self::$_templates[$apiKey] = $templates; return self::_getTemplatesOfType(self::$_templates[$apiKey], $type); } public static function getTemplate(string $apiKey, $templateId) { $templates = self::loadTemplates($apiKey); if (isset($templates[$templateId])) { return $templates[$templateId]; } return null; } /** * Check an API key * @param string $apiKey * @return array */ public static function checkApiKey(string $apiKey) { $path = 'test-key/' . $apiKey; return self::call($path); } /** * Check the stats of an API key * @param string $apiKey * @return array */ public static function getAffiliateStats(string $apiKey) { $path = 'affiliate-stats/' . $apiKey; return self::call($path); } }