1 | <?php |
||
23 | abstract class BaseClientRemote extends AbstractClient |
||
24 | { |
||
25 | /** |
||
26 | * Directus base url |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $baseUrl = 'http://localhost'; |
||
31 | |||
32 | /** |
||
33 | * Directus hosted base url format |
||
34 | * |
||
35 | * @var string |
||
36 | */ |
||
37 | protected $hostedBaseUrlFormat = 'https://%s.directus.io'; |
||
38 | |||
39 | /** |
||
40 | * Directus Server base endpoint |
||
41 | * |
||
42 | * @var string |
||
43 | */ |
||
44 | protected $baseEndpoint; |
||
45 | |||
46 | /** |
||
47 | * API Version |
||
48 | * |
||
49 | * @var string |
||
50 | */ |
||
51 | protected $apiVersion; |
||
52 | |||
53 | /** |
||
54 | * Directus Hosted endpoint format. |
||
55 | * |
||
56 | * @var string |
||
57 | */ |
||
58 | protected $hostedBaseEndpointFormat; |
||
59 | |||
60 | /** |
||
61 | * Directus Hosted Instance Key |
||
62 | * |
||
63 | * @var int|string |
||
64 | */ |
||
65 | protected $instanceKey; |
||
66 | |||
67 | /** |
||
68 | * Authentication Token |
||
69 | * |
||
70 | * @var string |
||
71 | */ |
||
72 | protected $accessToken; |
||
73 | |||
74 | /** |
||
75 | * HTTP Client |
||
76 | * |
||
77 | * @var \GuzzleHttp\Client |
||
78 | */ |
||
79 | protected $httpClient; |
||
80 | |||
81 | /** |
||
82 | * HTTP Client request timeout |
||
83 | * |
||
84 | * @var int |
||
85 | */ |
||
86 | protected $timeout = 60; |
||
87 | |||
88 | const TABLE_ENTRIES_ENDPOINT = 'tables/%s/rows'; |
||
89 | const TABLE_ENTRY_ENDPOINT = 'tables/%s/rows/%s'; |
||
90 | const TABLE_ENTRY_CREATE_ENDPOINT = 'tables/%s/rows'; |
||
91 | const TABLE_ENTRY_UPDATE_ENDPOINT = 'tables/%s/rows/%s'; |
||
92 | const TABLE_ENTRY_DELETE_ENDPOINT = 'tables/%s/rows/%s'; |
||
93 | const TABLE_LIST_ENDPOINT = 'tables'; |
||
94 | const TABLE_INFORMATION_ENDPOINT = 'tables/%s'; |
||
95 | const TABLE_PREFERENCES_ENDPOINT = 'tables/%s/preferences'; |
||
96 | const TABLE_BOOKMARKS_CREATE_ENDPOINT = 'bookmarks'; |
||
97 | const TABLE_CREATE_ENDPOINT = 'privileges/1'; // ID not being used but required @TODO: REMOVE IT |
||
98 | const TABLE_DELETE_ENDPOINT = 'tables/%s'; |
||
99 | |||
100 | const COLUMN_LIST_ENDPOINT = 'tables/%s/columns'; |
||
101 | const COLUMN_CREATE_ENDPOINT = 'tables/%s/columns'; |
||
102 | const COLUMN_DELETE_ENDPOINT = 'tables/%s/columns/%s'; |
||
103 | const COLUMN_INFORMATION_ENDPOINT = 'tables/%s/columns/%s'; |
||
104 | const COLUMN_OPTIONS_CREATE_ENDPOINT = 'tables/%s/columns/%s/%s'; |
||
105 | |||
106 | const GROUP_LIST_ENDPOINT = 'groups'; |
||
107 | const GROUP_CREATE_ENDPOINT = 'groups'; |
||
108 | const GROUP_INFORMATION_ENDPOINT = 'groups/%s'; |
||
109 | const GROUP_PRIVILEGES_ENDPOINT = 'privileges/%s'; |
||
110 | const GROUP_PRIVILEGES_CREATE_ENDPOINT = 'privileges/%s'; |
||
111 | |||
112 | const FILE_LIST_ENDPOINT = 'files'; |
||
113 | const FILE_CREATE_ENDPOINT = 'files'; |
||
114 | const FILE_UPDATE_ENDPOINT = 'files/%s'; |
||
115 | const FILE_INFORMATION_ENDPOINT = 'files/%s'; |
||
116 | |||
117 | const SETTING_LIST_ENDPOINT = 'settings'; |
||
118 | const SETTING_COLLECTION_ENDPOINT = 'settings/%s'; |
||
119 | |||
120 | const MESSAGES_CREATE_ENDPOINT = 'messages/rows'; |
||
121 | const MESSAGES_USER_ENDPOINT = 'messages/rows/%s'; |
||
122 | |||
123 | 38 | public function __construct($accessToken, $options = []) |
|
144 | |||
145 | /** |
||
146 | * Get the base endpoint url |
||
147 | * |
||
148 | * @return string |
||
149 | */ |
||
150 | 4 | public function getBaseEndpoint() |
|
154 | |||
155 | /** |
||
156 | * Get the base url |
||
157 | * |
||
158 | * @return string |
||
159 | */ |
||
160 | 2 | public function getBaseUrl() |
|
164 | |||
165 | /** |
||
166 | * Get API Version |
||
167 | * |
||
168 | * @return int|string |
||
169 | */ |
||
170 | 38 | public function getAPIVersion() |
|
174 | |||
175 | /** |
||
176 | * Get the authentication access token |
||
177 | * |
||
178 | * @return string |
||
179 | */ |
||
180 | 2 | public function getAccessToken() |
|
184 | |||
185 | /** |
||
186 | * Set a new authentication access token |
||
187 | * |
||
188 | * @param $newAccessToken |
||
189 | */ |
||
190 | 2 | public function setAccessToken($newAccessToken) |
|
194 | |||
195 | /** |
||
196 | * Get the Directus hosted instance key |
||
197 | * |
||
198 | * @return null|string |
||
199 | */ |
||
200 | 4 | public function getInstanceKey() |
|
204 | |||
205 | /** |
||
206 | * Set the HTTP Client |
||
207 | * |
||
208 | * @param HTTPClient $httpClient |
||
209 | */ |
||
210 | 38 | public function setHTTPClient(HTTPClient $httpClient) |
|
214 | |||
215 | /** |
||
216 | * Get the HTTP Client |
||
217 | * |
||
218 | * @return HTTPClient|null |
||
219 | */ |
||
220 | 38 | public function getHTTPClient() |
|
224 | |||
225 | /** |
||
226 | * Get the default HTTP Client |
||
227 | * |
||
228 | * @return HTTPClient |
||
229 | */ |
||
230 | 38 | public function getDefaultHTTPClient() |
|
234 | |||
235 | 28 | public function performRequest($method, $path, array $params = []) |
|
252 | |||
253 | /** |
||
254 | * Build a request object |
||
255 | * |
||
256 | * @param $method |
||
257 | * @param $path |
||
258 | * @param $params |
||
259 | * |
||
260 | * @return \GuzzleHttp\Message\Request |
||
261 | */ |
||
262 | 30 | public function buildRequest($method, $path, array $params = []) |
|
286 | |||
287 | /** |
||
288 | * Build a endpoint path based on a format |
||
289 | * |
||
290 | * @param string $pathFormat |
||
291 | * @param array $variables |
||
292 | * |
||
293 | * @return string |
||
294 | */ |
||
295 | 24 | public function buildPath($pathFormat, $variables = []) |
|
299 | } |
||
300 |