-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathClient.php
More file actions
78 lines (65 loc) · 1.75 KB
/
Client.php
File metadata and controls
78 lines (65 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
namespace OpenApi;
use OpenApi\Interfaces\HttpTransportInterface;
use OpenApi\Transports\CurlTransport;
use Psr\Http\Client\ClientInterface as PsrClientInterface;;
/**
* Generic HTTP client for OpenAPI services
* Handles REST operations with Bearer token authentication
*/
class Client
{
private string $token;
private HttpTransportInterface|PsrClientInterface $transport;
/**
* Initialize client with Bearer token
*/
public function __construct(string $token, HttpTransportInterface|PsrClientInterface|null $transport = null)
{
$this->token = $token;
$this->transport = $transport ?? new CurlTransport($token);
}
public function request(
string $method,
string $url,
mixed $payload = null,
?array $params = null
): string {
return $this->transport->request($method, $url, $payload, $params);
}
/**
* Perform GET request
*/
public function get(string $url, ?array $params = null): string
{
return $this->request('GET', $url, null, $params);
}
/**
* Perform POST request
*/
public function post(string $url, mixed $payload = null): string
{
return $this->request('POST', $url, $payload);
}
/**
* Perform PUT request
*/
public function put(string $url, mixed $payload = null): string
{
return $this->request('PUT', $url, $payload);
}
/**
* Perform DELETE request
*/
public function delete(string $url): string
{
return $this->request('DELETE', $url);
}
/**
* Perform PATCH request
*/
public function patch(string $url, mixed $payload = null): string
{
return $this->request('PATCH', $url, $payload);
}
}