Laravel AT Protocol Client (alpha & unstable)
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add BackedEnum support to HTTP client methods

+11 -6
+3 -1
src/Client/Public/PublicClient.php
··· 2 2 3 3 namespace SocialDept\AtpClient\Client\Public; 4 4 5 + use BackedEnum; 5 6 use Illuminate\Support\Facades\Http; 6 7 use SocialDept\AtpClient\Exceptions\AtpResponseException; 7 8 use SocialDept\AtpClient\Http\Response; ··· 12 13 protected string $serviceUrl 13 14 ) {} 14 15 15 - public function get(string $endpoint, array $params = []): Response 16 + public function get(string|BackedEnum $endpoint, array $params = []): Response 16 17 { 18 + $endpoint = $endpoint instanceof BackedEnum ? $endpoint->value : $endpoint; 17 19 $url = rtrim($this->serviceUrl, '/') . '/xrpc/' . $endpoint; 18 20 $params = array_filter($params, fn ($v) => !is_null($v)); 19 21
+8 -5
src/Http/HasHttp.php
··· 2 2 3 3 namespace SocialDept\AtpClient\Http; 4 4 5 + use BackedEnum; 5 6 use Illuminate\Http\Client\Response as LaravelResponse; 6 7 use Illuminate\Support\Facades\Http; 7 8 use InvalidArgumentException; ··· 27 28 * Make XRPC call 28 29 */ 29 30 protected function call( 30 - string $endpoint, 31 + string|BackedEnum $endpoint, 31 32 string $method, 32 33 ?array $params = null, 33 34 ?array $body = null 34 35 ): Response { 36 + $endpoint = $endpoint instanceof BackedEnum ? $endpoint->value : $endpoint; 35 37 $session = $this->sessions->ensureValid($this->did); 36 38 $url = rtrim($session->pdsEndpoint(), '/').'/xrpc/'.$endpoint; 37 39 ··· 102 104 /** 103 105 * Make GET request 104 106 */ 105 - public function get(string $endpoint, array $params = []): Response 107 + public function get(string|BackedEnum $endpoint, array $params = []): Response 106 108 { 107 109 return $this->call($endpoint, 'GET', $params); 108 110 } ··· 110 112 /** 111 113 * Make POST request 112 114 */ 113 - public function post(string $endpoint, array $body = []): Response 115 + public function post(string|BackedEnum $endpoint, array $body = []): Response 114 116 { 115 117 return $this->call($endpoint, 'POST', null, $body); 116 118 } ··· 118 120 /** 119 121 * Make DELETE request 120 122 */ 121 - public function delete(string $endpoint, array $params = []): Response 123 + public function delete(string|BackedEnum $endpoint, array $params = []): Response 122 124 { 123 125 return $this->call($endpoint, 'DELETE', $params); 124 126 } ··· 126 128 /** 127 129 * Make POST request with raw binary body (for blob uploads) 128 130 */ 129 - public function postBlob(string $endpoint, string $data, string $mimeType): Response 131 + public function postBlob(string|BackedEnum $endpoint, string $data, string $mimeType): Response 130 132 { 133 + $endpoint = $endpoint instanceof BackedEnum ? $endpoint->value : $endpoint; 131 134 $session = $this->sessions->ensureValid($this->did); 132 135 $url = rtrim($session->pdsEndpoint(), '/').'/xrpc/'.$endpoint; 133 136