1 | <?php |
||
25 | abstract class BaseClientRemote extends AbstractClient |
||
26 | { |
||
27 | /** |
||
28 | * Directus base url |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | protected $baseUrl = 'http://localhost'; |
||
33 | |||
34 | /** |
||
35 | * Directus hosted base url format |
||
36 | * |
||
37 | * @var string |
||
38 | */ |
||
39 | protected $hostedBaseUrlFormat = 'https://%s.directus.io'; |
||
40 | |||
41 | /** |
||
42 | * Directus Server base endpoint |
||
43 | * |
||
44 | * @var string |
||
45 | */ |
||
46 | protected $baseEndpoint; |
||
47 | |||
48 | /** |
||
49 | * API Version |
||
50 | * |
||
51 | * @var string |
||
52 | */ |
||
53 | protected $apiVersion; |
||
54 | |||
55 | /** |
||
56 | * Directus Hosted endpoint format. |
||
57 | * |
||
58 | * @var string |
||
59 | */ |
||
60 | protected $hostedBaseEndpointFormat; |
||
61 | |||
62 | /** |
||
63 | * Directus Hosted Instance Key |
||
64 | * |
||
65 | * @var int|string |
||
66 | */ |
||
67 | protected $instanceKey; |
||
68 | |||
69 | /** |
||
70 | * Authentication Token |
||
71 | * |
||
72 | * @var string |
||
73 | */ |
||
74 | protected $accessToken; |
||
75 | |||
76 | /** |
||
77 | * HTTP Client |
||
78 | * |
||
79 | * @var \GuzzleHttp\Client |
||
80 | */ |
||
81 | protected $httpClient; |
||
82 | |||
83 | /** |
||
84 | * HTTP Client request timeout |
||
85 | * |
||
86 | * @var int |
||
87 | */ |
||
88 | protected $timeout = 60; |
||
89 | |||
90 | const ACTIVITY_GET_ENDPOINT = 'activity'; |
||
91 | |||
92 | const BOOKMARKS_CREATE_ENDPOINT = 'bookmarks'; |
||
93 | const BOOKMARKS_READ_ENDPOINT = 'bookmarks/%s'; |
||
94 | const BOOKMARKS_DELETE_ENDPOINT = 'bookmarks/%s'; |
||
95 | const BOOKMARKS_ALL_ENDPOINT = 'bookmarks'; |
||
96 | const BOOKMARKS_USER_ENDPOINT = 'bookmarks/user/%s'; |
||
97 | |||
98 | const TABLE_ENTRIES_ENDPOINT = 'tables/%s/rows'; |
||
99 | const TABLE_ENTRY_ENDPOINT = 'tables/%s/rows/%s'; |
||
100 | const TABLE_ENTRY_CREATE_ENDPOINT = 'tables/%s/rows'; |
||
101 | const TABLE_ENTRY_UPDATE_ENDPOINT = 'tables/%s/rows/%s'; |
||
102 | const TABLE_ENTRY_DELETE_ENDPOINT = 'tables/%s/rows/%s'; |
||
103 | const TABLE_LIST_ENDPOINT = 'tables'; |
||
104 | const TABLE_INFORMATION_ENDPOINT = 'tables/%s'; |
||
105 | const TABLE_PREFERENCES_ENDPOINT = 'tables/%s/preferences'; |
||
106 | const TABLE_CREATE_ENDPOINT = 'privileges/1'; // ID not being used but required @TODO: REMOVE IT |
||
107 | const TABLE_DELETE_ENDPOINT = 'tables/%s'; |
||
108 | |||
109 | const COLUMN_LIST_ENDPOINT = 'tables/%s/columns'; |
||
110 | const COLUMN_CREATE_ENDPOINT = 'tables/%s/columns'; |
||
111 | const COLUMN_DELETE_ENDPOINT = 'tables/%s/columns/%s'; |
||
112 | const COLUMN_INFORMATION_ENDPOINT = 'tables/%s/columns/%s'; |
||
113 | const COLUMN_OPTIONS_CREATE_ENDPOINT = 'tables/%s/columns/%s/%s'; |
||
114 | |||
115 | const GROUP_LIST_ENDPOINT = 'groups'; |
||
116 | const GROUP_CREATE_ENDPOINT = 'groups'; |
||
117 | const GROUP_INFORMATION_ENDPOINT = 'groups/%s'; |
||
118 | const GROUP_PRIVILEGES_ENDPOINT = 'privileges/%s'; |
||
119 | const GROUP_PRIVILEGES_CREATE_ENDPOINT = 'privileges/%s'; |
||
120 | |||
121 | const FILE_LIST_ENDPOINT = 'files'; |
||
122 | const FILE_CREATE_ENDPOINT = 'files'; |
||
123 | const FILE_UPDATE_ENDPOINT = 'files/%s'; |
||
124 | const FILE_INFORMATION_ENDPOINT = 'files/%s'; |
||
125 | |||
126 | const SETTING_LIST_ENDPOINT = 'settings'; |
||
127 | const SETTING_COLLECTION_GET_ENDPOINT = 'settings/%s'; |
||
128 | const SETTING_COLLECTION_UPDATE_ENDPOINT = 'settings/%s'; |
||
129 | |||
130 | const MESSAGES_CREATE_ENDPOINT = 'messages/rows'; |
||
131 | const MESSAGES_LIST_ENDPOINT = 'messages/rows'; |
||
132 | const MESSAGES_GET_ENDPOINT = 'messages/rows/%s'; |
||
133 | const MESSAGES_USER_LIST_ENDPOINT = 'messages/user/%s'; |
||
134 | |||
135 | 38 | public function __construct($accessToken, $options = []) |
|
156 | |||
157 | /** |
||
158 | * Get the base endpoint url |
||
159 | * |
||
160 | * @return string |
||
161 | */ |
||
162 | 4 | public function getBaseEndpoint() |
|
166 | |||
167 | /** |
||
168 | * Get the base url |
||
169 | * |
||
170 | * @return string |
||
171 | */ |
||
172 | 2 | public function getBaseUrl() |
|
176 | |||
177 | /** |
||
178 | * Get API Version |
||
179 | * |
||
180 | * @return int|string |
||
181 | */ |
||
182 | 38 | public function getAPIVersion() |
|
186 | |||
187 | /** |
||
188 | * Get the authentication access token |
||
189 | * |
||
190 | * @return string |
||
191 | */ |
||
192 | 2 | public function getAccessToken() |
|
196 | |||
197 | /** |
||
198 | * Set a new authentication access token |
||
199 | * |
||
200 | * @param $newAccessToken |
||
201 | */ |
||
202 | 2 | public function setAccessToken($newAccessToken) |
|
206 | |||
207 | /** |
||
208 | * Get the Directus hosted instance key |
||
209 | * |
||
210 | * @return null|string |
||
211 | */ |
||
212 | 4 | public function getInstanceKey() |
|
216 | |||
217 | /** |
||
218 | * Set the HTTP Client |
||
219 | * |
||
220 | * @param HTTPClient $httpClient |
||
221 | */ |
||
222 | 38 | public function setHTTPClient(HTTPClient $httpClient) |
|
226 | |||
227 | /** |
||
228 | * Get the HTTP Client |
||
229 | * |
||
230 | * @return HTTPClient|null |
||
231 | */ |
||
232 | 38 | public function getHTTPClient() |
|
236 | |||
237 | /** |
||
238 | * Get the default HTTP Client |
||
239 | * |
||
240 | * @return HTTPClient |
||
241 | */ |
||
242 | 38 | public function getDefaultHTTPClient() |
|
246 | |||
247 | /** |
||
248 | * Perform a HTTP Request |
||
249 | * |
||
250 | * @param $method |
||
251 | * @param $path |
||
252 | * @param array $params |
||
253 | * |
||
254 | * @return Entry|EntryCollection |
||
255 | * |
||
256 | * @throws UnauthorizedRequestException |
||
257 | */ |
||
258 | 28 | public function performRequest($method, $path, array $params = []) |
|
275 | |||
276 | /** |
||
277 | * Build a request object |
||
278 | * |
||
279 | * @param $method |
||
280 | * @param $path |
||
281 | * @param $params |
||
282 | * |
||
283 | * @return \GuzzleHttp\Message\Request |
||
284 | */ |
||
285 | 30 | public function buildRequest($method, $path, array $params = []) |
|
309 | |||
310 | /** |
||
311 | * Build a endpoint path based on a format |
||
312 | * |
||
313 | * @param string $pathFormat |
||
314 | * @param string|array $variables |
||
315 | * |
||
316 | * @return string |
||
317 | */ |
||
318 | 24 | public function buildPath($pathFormat, $variables = []) |
|
322 | } |
||
323 |