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 | |||
98 | const COLUMN_LIST_ENDPOINT = 'tables/%s/columns'; |
||
99 | const COLUMN_INFORMATION_ENDPOINT = 'tables/%s/columns/%s'; |
||
100 | |||
101 | const GROUP_LIST_ENDPOINT = 'groups'; |
||
102 | const GROUP_INFORMATION_ENDPOINT = 'groups/%s'; |
||
103 | const GROUP_PRIVILEGES_ENDPOINT = 'privileges/%s'; |
||
104 | |||
105 | const FILE_LIST_ENDPOINT = 'files'; |
||
106 | const FILE_CREATE_ENDPOINT = 'files'; |
||
107 | const FILE_INFORMATION_ENDPOINT = 'files/%s'; |
||
108 | |||
109 | const SETTING_LIST_ENDPOINT = 'settings'; |
||
110 | const SETTING_COLLECTION_ENDPOINT = 'settings/%s'; |
||
111 | |||
112 | const MESSAGES_USER_ENDPOINT = 'messages/rows/%s'; |
||
113 | |||
114 | 38 | public function __construct($accessToken, $options = []) |
|
135 | |||
136 | /** |
||
137 | * Get the base endpoint url |
||
138 | * |
||
139 | * @return string |
||
140 | */ |
||
141 | 4 | public function getBaseEndpoint() |
|
145 | |||
146 | /** |
||
147 | * Get the base url |
||
148 | * |
||
149 | * @return string |
||
150 | */ |
||
151 | 2 | public function getBaseUrl() |
|
155 | |||
156 | /** |
||
157 | * Get API Version |
||
158 | * |
||
159 | * @return int|string |
||
160 | */ |
||
161 | 38 | public function getAPIVersion() |
|
165 | |||
166 | /** |
||
167 | * Get the authentication access token |
||
168 | * |
||
169 | * @return string |
||
170 | */ |
||
171 | 2 | public function getAccessToken() |
|
175 | |||
176 | /** |
||
177 | * Set a new authentication access token |
||
178 | * |
||
179 | * @param $newAccessToken |
||
180 | */ |
||
181 | 2 | public function setAccessToken($newAccessToken) |
|
185 | |||
186 | /** |
||
187 | * Get the Directus hosted instance key |
||
188 | * |
||
189 | * @return null|string |
||
190 | */ |
||
191 | 4 | public function getInstanceKey() |
|
195 | |||
196 | /** |
||
197 | * Set the HTTP Client |
||
198 | * |
||
199 | * @param HTTPClient $httpClient |
||
200 | */ |
||
201 | 38 | public function setHTTPClient(HTTPClient $httpClient) |
|
205 | |||
206 | /** |
||
207 | * Get the HTTP Client |
||
208 | * |
||
209 | * @return HTTPClient|null |
||
210 | */ |
||
211 | 38 | public function getHTTPClient() |
|
215 | |||
216 | /** |
||
217 | * Get the default HTTP Client |
||
218 | * |
||
219 | * @return HTTPClient |
||
220 | */ |
||
221 | 38 | public function getDefaultHTTPClient() |
|
225 | |||
226 | 28 | public function performRequest($method, $path, array $params = []) |
|
243 | |||
244 | /** |
||
245 | * Build a request object |
||
246 | * |
||
247 | * @param $method |
||
248 | * @param $path |
||
249 | * @param $params |
||
250 | * |
||
251 | * @return \GuzzleHttp\Message\Request |
||
252 | */ |
||
253 | 30 | public function buildRequest($method, $path, array $params = []) |
|
277 | |||
278 | /** |
||
279 | * Build a endpoint path based on a format |
||
280 | * |
||
281 | * @param string $pathFormat |
||
282 | * @param array $variables |
||
283 | * |
||
284 | * @return string |
||
285 | */ |
||
286 | 24 | public function buildPath($pathFormat, $variables = []) |
|
290 | } |
||
291 |