instance = $this->normalizeInstance($instance); $this->token = $token; } /** * Normalize instance URL to just the domain name */ private function normalizeInstance(string $instance): string { // Remove protocol if present $instance = preg_replace('/^https?:\/\//', '', $instance); // Remove trailing slash if present $instance = rtrim($instance, '/'); return $instance; } /** * @param array $params */ public function get(string $endpoint, array $params = []): Response { $url = "https://{$this->instance}/api/v3/{$endpoint}"; $request = Http::timeout(30); if ($this->token) { $request = $request->withToken($this->token); } return $request->get($url, $params); } /** * @param array $data */ public function post(string $endpoint, array $data = []): Response { $url = "https://{$this->instance}/api/v3/{$endpoint}"; $request = Http::timeout(30); if ($this->token) { $request = $request->withToken($this->token); } return $request->post($url, $data); } public function withToken(string $token): self { $this->token = $token; return $this; } }