| | |
| | | |
| | | trait Requests |
| | | { |
| | | protected bool $hasRequests = true; |
| | | /** |
| | | * Child classes must set this (e.g. 'https://api.example.com/v1/') |
| | | */ |
| | | protected ?string $baseUrl = null; |
| | | protected int $ttl = 300; //5 minutes default |
| | | protected ?RateLimits $requestLimiter = null; |
| | | |
| | | /** |
| | | * Child classes define their auth headers (Bearer token, API key, etc.) |
| | |
| | | */ |
| | | abstract protected function handleResponse(array|\WP_Error $response, string $method, string $endpoint): array; |
| | | |
| | | protected function initializeRequestLimiter():void |
| | | { |
| | | $key = $this->service_name; |
| | | if (!is_null($this->userID)) { |
| | | $key .= '_'.$this->userID; |
| | | } |
| | | $this->requestLimiter = new RateLimits($key); |
| | | } |
| | | |
| | | public function getRequest(string $endpoint, array $data = [], bool $force = false, ?int $ttl = null): array |
| | | { |
| | | $key = [$this->service_name, $this->userID, $endpoint, $data]; |