1 | <?php |
||
7 | abstract class BaseClient |
||
8 | { |
||
9 | /** |
||
10 | * Directus Server base endpoint |
||
11 | * @var string |
||
12 | */ |
||
13 | protected $baseEndpoint; |
||
14 | |||
15 | /** |
||
16 | * API Version |
||
17 | * @var string |
||
18 | */ |
||
19 | protected $apiVersion; |
||
20 | |||
21 | /** |
||
22 | * Directus Hosted endpoint format. |
||
23 | * @var string |
||
24 | */ |
||
25 | protected $hostedBaseEndpointFormat; |
||
26 | |||
27 | /** |
||
28 | * Directus Hosted Instance Key |
||
29 | * @var int|string |
||
30 | */ |
||
31 | protected $instanceKey; |
||
32 | |||
33 | /** |
||
34 | * Authentication Token |
||
35 | * @var string |
||
36 | */ |
||
37 | protected $accessToken; |
||
38 | |||
39 | /** |
||
40 | * HTTP Client |
||
41 | * @var \GuzzleHttp\Client |
||
42 | */ |
||
43 | protected $httpClient; |
||
44 | |||
45 | /** |
||
46 | * HTTP Client request timeout |
||
47 | * @var int |
||
48 | */ |
||
49 | protected $timeout = 60; |
||
50 | |||
51 | const TABLE_ENTRIES_ENDPOINT = 'tables/%s/rows'; |
||
52 | const TABLE_ENTRY_ENDPOINT = 'tables/%s/rows/%s'; |
||
53 | const TABLE_LIST_ENDPOINT = 'tables'; |
||
54 | const TABLE_INFORMATION_ENDPOINT = 'tables/%s'; |
||
55 | const TABLE_PREFERENCES_ENDPOINT = 'tables/%s/preferences'; |
||
56 | |||
57 | const COLUMN_LIST_ENDPOINT = 'tables/%s/columns'; |
||
58 | const COLUMN_INFORMATION_ENDPOINT = 'tables/%s/columns/%s'; |
||
59 | |||
60 | const GROUP_LIST_ENDPOINT = 'groups'; |
||
61 | const GROUP_INFORMATION_ENDPOINT = 'groups/%s'; |
||
62 | const GROUP_PRIVILEGES_ENDPOINT = 'privileges/%s'; |
||
63 | |||
64 | const FILE_LIST_ENDPOINT = 'files'; |
||
65 | const FILE_INFORMATION_ENDPOINT = 'files/%s'; |
||
66 | |||
67 | const SETTING_LIST_ENDPOINT = 'settings'; |
||
68 | const SETTING_COLLECTION_ENDPOINT = 'settings/%s'; |
||
69 | |||
70 | 38 | public function __construct($accessToken, $options = []) |
|
89 | |||
90 | /** |
||
91 | * Get the base endpoint url |
||
92 | * @return string |
||
93 | */ |
||
94 | 4 | public function getBaseEndpoint() |
|
98 | |||
99 | /** |
||
100 | * Get API Version |
||
101 | * @return int|string |
||
102 | */ |
||
103 | 4 | public function getAPIVersion() |
|
104 | { |
||
105 | 4 | return $this->apiVersion; |
|
106 | } |
||
107 | |||
108 | /** |
||
109 | * Get the authentication access token |
||
110 | * @return string |
||
111 | */ |
||
112 | 2 | public function getAccessToken() |
|
116 | |||
117 | /** |
||
118 | * Set a new authentication access token |
||
119 | * @param $newAccessToken |
||
120 | */ |
||
121 | 2 | public function setAccessToken($newAccessToken) |
|
125 | |||
126 | /** |
||
127 | * Get the Directus hosted instance key |
||
128 | * @return null|string |
||
129 | */ |
||
130 | 4 | public function getInstanceKey() |
|
131 | { |
||
132 | 4 | return $this->instanceKey; |
|
133 | } |
||
134 | |||
135 | /** |
||
136 | * Set the HTTP Client |
||
137 | * @param HTTPClient $httpClient |
||
138 | */ |
||
139 | 38 | public function setHTTPClient(HTTPClient $httpClient) |
|
143 | |||
144 | /** |
||
145 | * Get the HTTP Client |
||
146 | * @return HTTPClient|null |
||
147 | */ |
||
148 | 38 | public function getHTTPClient() |
|
152 | |||
153 | /** |
||
154 | * Get the default HTTP Client |
||
155 | * @return HTTPClient |
||
156 | */ |
||
157 | 38 | public function getDefaultHTTPClient() |
|
161 | |||
162 | 28 | public function performRequest($method, $pathFormat, $variables = []) |
|
169 | |||
170 | /** |
||
171 | * Build a request object |
||
172 | * @param $method |
||
173 | * @param $pathFormat |
||
174 | * @param $variables |
||
175 | * @return \GuzzleHttp\Message\Request |
||
176 | */ |
||
177 | 30 | public function buildRequest($method, $pathFormat, $variables = []) |
|
185 | |||
186 | /** |
||
187 | * Build a endpoint path based on a format |
||
188 | * @param string $pathFormat |
||
189 | * @param array $variables |
||
190 | * @return string |
||
191 | */ |
||
192 | 32 | public function buildPath($pathFormat, $variables = []) |
|
196 | } |
||
197 |