| | |
| | | namespace JVBase\integrations; |
| | | |
| | | use JVBase\managers\Cache; |
| | | use JVBase\managers\Errors; |
| | | use JVBase\managers\IconsManager; |
| | | |
| | | if (!defined('ABSPATH')) { |
| | |
| | | protected string $apiVersion; |
| | | protected Cache $cache; |
| | | protected ?string $cacheName = null; |
| | | //Use Trait "Requests" to set this |
| | | protected bool $hasRequests = false; |
| | | protected ?RateLimits $requestLimiter = null; |
| | | //Use Trait "OAuth" to set this |
| | | protected ?RateLimits $oauthLimiter = null; |
| | | protected bool $hasOAuth = false; |
| | | //Use trait "Webhooks" to set this true |
| | | protected bool $hasWebhooks = false; |
| | | |
| | | |
| | | /** |
| | | * @var array Each item in the array becomes a li element in the ordered list of instructions |
| | |
| | | * @var bool Flag to indicate there are extra options that warrant a dedicated options page for this service |
| | | * Usually used for default field values for syncable services |
| | | */ |
| | | public bool $hasExtraOptions = false; |
| | | public static bool $hasExtraOptions = false; |
| | | public bool $hasBatchCreate = false; |
| | | public bool $hasBatchUpdate = false; |
| | | public bool $hasBatchDelete = false; |
| | |
| | | */ |
| | | protected array $contentTypes = []; |
| | | |
| | | protected array $credentials; |
| | | |
| | | |
| | | /** |
| | | * Check if integration is properly configured |
| | |
| | | |
| | | public function loadCredentials():array |
| | | { |
| | | return Auth::getInstance()->getCredentials($this->service_name, $this->userID); |
| | | if (!isset($this->credentials)) { |
| | | $this->credentials = Auth::getInstance()->getCredentials($this->service_name, $this->userID); |
| | | } |
| | | return $this->credentials; |
| | | } |
| | | |
| | | protected function logError(string $method, string $message, array $context = []):void |
| | | { |
| | | $context['service'] = $this->service_name; |
| | | JVB()->error()->log('['.self::class.']'.$method, $message, $context); |
| | | Errors::getInstance()->log('['.self::class.']'.$method, $message, $context); |
| | | } |
| | | |
| | | protected function getReturnURL():string |
| | |
| | | |
| | | protected function initializeRateLimiters():void |
| | | { |
| | | $key = $this->service_name; |
| | | if (!is_null($this->userID)) { |
| | | $key .= '_'.$this->userID; |
| | | if (method_exists($this, 'initializeRequestLimiter')) { |
| | | $this->initializeRequestLimiter(); |
| | | } |
| | | |
| | | if ($this->hasRequests && !isset($this->requestLimiter) && !is_null($this->oauthLimiter)) { |
| | | $this->requestLimiter = new RateLimits($key); |
| | | } |
| | | if ($this->hasOAuth && !isset($this->oauthLimiter) && !is_null($this->oauthLimiter)) { |
| | | $key .= '_oauth'; |
| | | $this->oauthLimiter = new RateLimits($key, ['s' => 1,'m' => 10, 'h' => 100]); |
| | | if (method_exists($this, 'initializeOAuthRateLimiter')) { |
| | | $this->initializeOAuthRateLimiter(); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | return $response; |
| | | } |
| | | |
| | | public function getAllowedContent():array |
| | | { |
| | | return array_keys($this->contentTypes); |
| | | } |
| | | |
| | | public function getServiceName():string |
| | | { |
| | | return $this->service_name; |
| | | } |
| | | } |