Total Complexity | 69 |
Total Lines | 1171 |
Duplicated Lines | 0 % |
Changes | 15 | ||
Bugs | 0 | Features | 0 |
Complex classes like Client often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Client, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
37 | class Client implements ClientInterface |
||
38 | { |
||
39 | /** @var ConnectorInterface The API connector. */ |
||
40 | protected $connector; |
||
41 | |||
42 | /** @var array Query strings to be applied to the request. */ |
||
43 | protected $query = []; |
||
44 | |||
45 | /** |
||
46 | * Client constructor. |
||
47 | * |
||
48 | * @param ConnectorInterface $connector |
||
49 | */ |
||
50 | public function __construct(ConnectorInterface $connector) |
||
51 | { |
||
52 | $this->connector = $connector; |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * Client factory method for instantiating . |
||
57 | * |
||
58 | * @param ConnectorInterface $connector |
||
59 | * |
||
60 | * @return static |
||
61 | */ |
||
62 | public static function factory(ConnectorInterface $connector) |
||
63 | { |
||
64 | $client = new static( |
||
65 | $connector |
||
66 | ); |
||
67 | |||
68 | return $client; |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * Get query from Client. |
||
73 | * |
||
74 | * @return array |
||
75 | */ |
||
76 | public function getQuery() |
||
77 | { |
||
78 | return $this->query; |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * Clear query. |
||
83 | */ |
||
84 | public function clearQuery() |
||
85 | { |
||
86 | $this->query = []; |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * Add a query parameter to filter results. |
||
91 | * |
||
92 | * @param string $name |
||
93 | * @param string $value |
||
94 | */ |
||
95 | public function addQuery($name, $value) |
||
96 | { |
||
97 | $this->query = array_merge_recursive($this->query, [$name => $value]); |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * Returns details about your account. |
||
102 | * |
||
103 | * @return AccountResponse |
||
104 | */ |
||
105 | public function account() |
||
106 | { |
||
107 | return new AccountResponse($this->connector->request('get', '/account', $this->query)); |
||
|
|||
108 | } |
||
109 | |||
110 | /** |
||
111 | * Returns details about a notification. |
||
112 | * |
||
113 | * @return NotificationResponse |
||
114 | */ |
||
115 | public function notification($notificationUuid) |
||
116 | { |
||
117 | return new NotificationResponse( |
||
118 | $this->connector->request( |
||
119 | 'get', |
||
120 | "/notifications/${notificationUuid}", |
||
121 | $this->query |
||
122 | ) |
||
123 | ); |
||
124 | } |
||
125 | |||
126 | /** |
||
127 | * Returns a list of notifications. |
||
128 | * |
||
129 | * @param string $applicationUuid |
||
130 | * |
||
131 | * @return NotificationsResponse |
||
132 | */ |
||
133 | public function notifications($applicationUuid) |
||
134 | { |
||
135 | return new NotificationsResponse( |
||
136 | $this->connector->request( |
||
137 | 'get', |
||
138 | "/applications/${applicationUuid}/notifications", |
||
139 | $this->query |
||
140 | ) |
||
141 | ); |
||
142 | } |
||
143 | |||
144 | /** |
||
145 | * Shows all applications. |
||
146 | * |
||
147 | * @return ApplicationsResponse |
||
148 | */ |
||
149 | public function applications() |
||
150 | { |
||
151 | return new ApplicationsResponse($this->connector->request('get', '/applications', $this->query)); |
||
152 | } |
||
153 | |||
154 | /** |
||
155 | * Shows information about an application. |
||
156 | * |
||
157 | * @param string $applicationUuid |
||
158 | * @return ApplicationResponse |
||
159 | */ |
||
160 | public function application($applicationUuid) |
||
161 | { |
||
162 | return new ApplicationResponse( |
||
163 | $this->connector->request( |
||
164 | 'get', |
||
165 | "/applications/${applicationUuid}", |
||
166 | $this->query |
||
167 | ) |
||
168 | ); |
||
169 | } |
||
170 | |||
171 | /** |
||
172 | * Renames an application. |
||
173 | * |
||
174 | * @param string $applicationUuid |
||
175 | * @param string $name |
||
176 | * @return OperationResponse |
||
177 | */ |
||
178 | public function renameApplication($applicationUuid, $name) |
||
179 | { |
||
180 | |||
181 | $options = [ |
||
182 | 'form_params' => [ |
||
183 | 'name' => $name, |
||
184 | ], |
||
185 | ]; |
||
186 | |||
187 | return new OperationResponse( |
||
188 | $this->connector->request( |
||
189 | 'put', |
||
190 | "/applications/${applicationUuid}", |
||
191 | $options, |
||
192 | $this->query |
||
193 | ) |
||
194 | ); |
||
195 | } |
||
196 | |||
197 | /** |
||
198 | * Shows all code branches and tags in an application. |
||
199 | * |
||
200 | * @param string $applicationUuid |
||
201 | * @return BranchesResponse |
||
202 | */ |
||
203 | public function code($applicationUuid) |
||
204 | { |
||
205 | return new BranchesResponse( |
||
206 | $this->connector->request( |
||
207 | 'get', |
||
208 | "/applications/${applicationUuid}/code", |
||
209 | $this->query |
||
210 | ) |
||
211 | ); |
||
212 | } |
||
213 | |||
214 | /** |
||
215 | * Shows all databases in an application. |
||
216 | * |
||
217 | * @param string $applicationUuid |
||
218 | * @return DatabasesResponse |
||
219 | */ |
||
220 | public function databases($applicationUuid) |
||
221 | { |
||
222 | return new DatabasesResponse( |
||
223 | $this->connector->request( |
||
224 | 'get', |
||
225 | "/applications/${applicationUuid}/databases", |
||
226 | $this->query |
||
227 | ) |
||
228 | ); |
||
229 | } |
||
230 | |||
231 | /** |
||
232 | * Shows all databases in an environment. |
||
233 | * |
||
234 | * @param string $environmentUuid |
||
235 | * @return DatabasesResponse |
||
236 | */ |
||
237 | public function environmentDatabases($environmentUuid) |
||
238 | { |
||
239 | return new DatabasesResponse( |
||
240 | $this->connector->request( |
||
241 | 'get', |
||
242 | "/environments/${environmentUuid}/databases", |
||
243 | $this->query |
||
244 | ) |
||
245 | ); |
||
246 | } |
||
247 | |||
248 | /** |
||
249 | * Copies a database from an environment to an environment. |
||
250 | * |
||
251 | * @param string $environmentFromUuid |
||
252 | * @param string $dbName |
||
253 | * @param string $environmentToUuid |
||
254 | * @return OperationResponse |
||
255 | */ |
||
256 | public function databaseCopy($environmentFromUuid, $dbName, $environmentToUuid) |
||
257 | { |
||
258 | $options = [ |
||
259 | 'form_params' => [ |
||
260 | 'name' => $dbName, |
||
261 | 'source' => $environmentFromUuid, |
||
262 | ], |
||
263 | ]; |
||
264 | |||
265 | return new OperationResponse( |
||
266 | $this->connector->request('post', "/environments/${environmentToUuid}/databases", $this->query, $options) |
||
267 | ); |
||
268 | } |
||
269 | |||
270 | /** |
||
271 | * Create a new database. |
||
272 | * |
||
273 | * @param string $applicationUuid |
||
274 | * @param string $name |
||
275 | * @return OperationResponse |
||
276 | */ |
||
277 | public function databaseCreate($applicationUuid, $name) |
||
278 | { |
||
279 | $options = [ |
||
280 | 'form_params' => [ |
||
281 | 'name' => $name, |
||
282 | ], |
||
283 | ]; |
||
284 | |||
285 | return new OperationResponse( |
||
286 | $this->connector->request('post', "/applications/${applicationUuid}/databases", $this->query, $options) |
||
287 | ); |
||
288 | } |
||
289 | |||
290 | /** |
||
291 | * Delete a database. |
||
292 | * |
||
293 | * @param string $applicationUuid |
||
294 | * @param string $name |
||
295 | * @return OperationResponse |
||
296 | */ |
||
297 | public function databaseDelete($applicationUuid, $name) |
||
298 | { |
||
299 | return new OperationResponse( |
||
300 | $this->connector->request('delete', "/applications/${applicationUuid}/databases/${name}", $this->query) |
||
301 | ); |
||
302 | } |
||
303 | |||
304 | /** |
||
305 | * Backup a database. |
||
306 | * |
||
307 | * @param string $environmentUuid |
||
308 | * @param string $dbName |
||
309 | * @return OperationResponse |
||
310 | */ |
||
311 | public function createDatabaseBackup($environmentUuid, $dbName) |
||
312 | { |
||
313 | return new OperationResponse( |
||
314 | $this->connector->request( |
||
315 | 'post', |
||
316 | "/environments/${environmentUuid}/databases/${dbName}/backups", |
||
317 | $this->query |
||
318 | ) |
||
319 | ); |
||
320 | } |
||
321 | |||
322 | /** |
||
323 | * Shows all database backups in an environment. |
||
324 | * |
||
325 | * @param string $environmentUuid |
||
326 | * @param string $dbName |
||
327 | * @return BackupsResponse |
||
328 | */ |
||
329 | public function databaseBackups($environmentUuid, $dbName) |
||
330 | { |
||
331 | return new BackupsResponse( |
||
332 | $this->connector->request( |
||
333 | 'get', |
||
334 | "/environments/${environmentUuid}/databases/${dbName}/backups", |
||
335 | $this->query |
||
336 | ) |
||
337 | ); |
||
338 | } |
||
339 | |||
340 | /** |
||
341 | * Gets information about a database backup. |
||
342 | * |
||
343 | * @param string $environmentUuid |
||
344 | * @param string $dbName |
||
345 | * @param int $backupId |
||
346 | * @return BackupResponse |
||
347 | */ |
||
348 | public function databaseBackup($environmentUuid, $dbName, $backupId) |
||
349 | { |
||
350 | return new BackupResponse( |
||
351 | $this->connector->request( |
||
352 | 'get', |
||
353 | "/environments/${environmentUuid}/databases/${dbName}/backups/${backupId}", |
||
354 | $this->query |
||
355 | ) |
||
356 | ); |
||
357 | } |
||
358 | |||
359 | /** |
||
360 | * Restores a database backup to a database in an environment. |
||
361 | * |
||
362 | * @param string $environmentUuid |
||
363 | * @param string $dbName |
||
364 | * @param int $backupId |
||
365 | * @return OperationResponse |
||
366 | */ |
||
367 | public function restoreDatabaseBackup($environmentUuid, $dbName, $backupId) |
||
368 | { |
||
369 | return new OperationResponse( |
||
370 | $this->connector->request( |
||
371 | 'post', |
||
372 | "/environments/${environmentUuid}/databases/${dbName}/backups/${backupId}/actions/restore", |
||
373 | $this->query |
||
374 | ) |
||
375 | ); |
||
376 | } |
||
377 | |||
378 | /** |
||
379 | * Copies files from an environment to another environment. |
||
380 | * |
||
381 | * @param string $environmentUuidFrom |
||
382 | * @param string $environmentUuidTo |
||
383 | * @return OperationResponse |
||
384 | */ |
||
385 | public function copyFiles($environmentUuidFrom, $environmentUuidTo) |
||
386 | { |
||
387 | $options = [ |
||
388 | 'form_params' => [ |
||
389 | 'source' => $environmentUuidFrom, |
||
390 | ], |
||
391 | ]; |
||
392 | |||
393 | return new OperationResponse( |
||
394 | $this->connector->request('post', "/environments/${environmentUuidTo}/files", $this->query, $options) |
||
395 | ); |
||
396 | } |
||
397 | |||
398 | /** |
||
399 | * Deploys a code branch/tag to an environment. |
||
400 | * |
||
401 | * @param string $environmentUuid |
||
402 | * @param string $branch |
||
403 | * @return OperationResponse |
||
404 | */ |
||
405 | public function switchCode($environmentUuid, $branch) |
||
406 | { |
||
407 | |||
408 | $options = [ |
||
409 | 'form_params' => [ |
||
410 | 'branch' => $branch, |
||
411 | ], |
||
412 | ]; |
||
413 | |||
414 | return new OperationResponse( |
||
415 | $this->connector->request( |
||
416 | 'post', |
||
417 | "/environments/${environmentUuid}/code/actions/switch", |
||
418 | $this->query, |
||
419 | $options |
||
420 | ) |
||
421 | ); |
||
422 | } |
||
423 | |||
424 | /** |
||
425 | * Deploys code from one environment to another environment. |
||
426 | * |
||
427 | * @param string $environmentFromUuid |
||
428 | * @param string $environmentToUuid |
||
429 | * @param string $commitMessage |
||
430 | */ |
||
431 | public function deployCode($environmentFromUuid, $environmentToUuid, $commitMessage = null) |
||
432 | { |
||
433 | |||
434 | $options = [ |
||
435 | 'form_params' => [ |
||
436 | 'source' => $environmentFromUuid, |
||
437 | 'message' => $commitMessage, |
||
438 | ], |
||
439 | ]; |
||
440 | |||
441 | return new OperationResponse( |
||
442 | $this->connector->request( |
||
443 | 'post', |
||
444 | "/environments/${environmentToUuid}/code", |
||
445 | $this->query, |
||
446 | $options |
||
447 | ) |
||
448 | ); |
||
449 | } |
||
450 | |||
451 | /** |
||
452 | * Shows all domains on an environment. |
||
453 | * |
||
454 | * @param string $environmentUuid |
||
455 | * @return DomainsResponse |
||
456 | */ |
||
457 | public function domains($environmentUuid) |
||
464 | ) |
||
465 | ); |
||
466 | } |
||
467 | |||
468 | /** |
||
469 | * Return details about a domain. |
||
470 | * |
||
471 | * @param string $environmentUuid |
||
472 | * @param string $domain |
||
473 | * @return DomainResponse |
||
474 | */ |
||
475 | public function domain($environmentUuid, $domain) |
||
476 | { |
||
477 | return new DomainResponse( |
||
478 | $this->connector->request( |
||
479 | 'get', |
||
480 | "/environments/${environmentUuid}/domains/${domain}", |
||
481 | $this->query |
||
482 | ) |
||
483 | ); |
||
484 | } |
||
485 | |||
486 | /** |
||
487 | * Adds a domain to an environment. |
||
488 | * |
||
489 | * @param string $environmentUuid |
||
490 | * @param string $hostname |
||
491 | * @return OperationResponse |
||
492 | */ |
||
493 | public function createDomain($environmentUuid, $hostname) |
||
494 | { |
||
495 | |||
496 | $options = [ |
||
497 | 'form_params' => [ |
||
498 | 'hostname' => $hostname, |
||
499 | ], |
||
500 | ]; |
||
501 | |||
502 | return new OperationResponse( |
||
503 | $this->connector->request('post', "/environments/${environmentUuid}/domains", $this->query, $options) |
||
504 | ); |
||
505 | } |
||
506 | |||
507 | /** |
||
508 | * Deletes a domain from an environment. |
||
509 | * |
||
510 | * @param string $environmentUuid |
||
511 | * @param string $domain |
||
512 | * @return OperationResponse |
||
513 | */ |
||
514 | public function deleteDomain($environmentUuid, $domain) |
||
515 | { |
||
516 | return new OperationResponse( |
||
517 | $this->connector->request('delete', "/environments/${environmentUuid}/domains/${domain}", $this->query) |
||
518 | ); |
||
519 | } |
||
520 | |||
521 | /** |
||
522 | * Purges varnish for selected domains in an environment. |
||
523 | * |
||
524 | * @param string $environmentUuid |
||
525 | * @param array $domains |
||
526 | * @return OperationResponse |
||
527 | */ |
||
528 | public function purgeVarnishCache($environmentUuid, array $domains) |
||
529 | { |
||
530 | |||
531 | $options = [ |
||
532 | 'form_params' => [ |
||
533 | 'domains' => $domains, |
||
534 | ], |
||
535 | ]; |
||
536 | |||
537 | return new OperationResponse( |
||
538 | $this->connector->request( |
||
539 | 'post', |
||
540 | "/environments/${environmentUuid}/domains/actions/clear-varnish", |
||
541 | $this->query, |
||
542 | $options |
||
543 | ) |
||
544 | ); |
||
545 | } |
||
546 | |||
547 | /** |
||
548 | * Shows all tasks in an application. |
||
549 | * |
||
550 | * @param string $applicationUuid |
||
551 | * @return TasksResponse |
||
552 | */ |
||
553 | public function tasks($applicationUuid) |
||
554 | { |
||
555 | return new TasksResponse( |
||
556 | $this->connector->request( |
||
557 | 'get', |
||
558 | "/applications/${applicationUuid}/tasks", |
||
559 | $this->query |
||
560 | ) |
||
561 | ); |
||
562 | } |
||
563 | |||
564 | /** |
||
565 | * Shows all environments in an application. |
||
566 | * |
||
567 | * @param string $applicationUuid |
||
568 | * @return EnvironmentsResponse |
||
569 | */ |
||
570 | public function environments($applicationUuid) |
||
571 | { |
||
572 | return new EnvironmentsResponse( |
||
573 | $this->connector->request( |
||
574 | 'get', |
||
575 | "/applications/${applicationUuid}/environments", |
||
576 | $this->query |
||
577 | ) |
||
578 | ); |
||
579 | } |
||
580 | |||
581 | /** |
||
582 | * Gets information about an environment. |
||
583 | * |
||
584 | * @param string $environmentUuid |
||
585 | * @return EnvironmentResponse |
||
586 | */ |
||
587 | public function environment($environmentUuid) |
||
588 | { |
||
589 | return new EnvironmentResponse( |
||
590 | $this->connector->request( |
||
591 | 'get', |
||
592 | "/environments/${environmentUuid}", |
||
593 | $this->query |
||
594 | ) |
||
595 | ); |
||
596 | } |
||
597 | |||
598 | /** |
||
599 | * Modifies configuration settings for an environment. |
||
600 | * |
||
601 | * @param string $environmentUuid |
||
602 | * @param array $config |
||
603 | * @return OperationResponse |
||
604 | */ |
||
605 | public function modifyEnvironment($environmentUuid, array $config) |
||
606 | { |
||
607 | |||
608 | $options = [ |
||
609 | 'form_params' => $config, |
||
610 | ]; |
||
611 | |||
612 | return new OperationResponse( |
||
613 | $this->connector->request( |
||
614 | 'put', |
||
615 | "/environments/${environmentUuid}", |
||
616 | $this->query, |
||
617 | $options |
||
618 | ) |
||
619 | ); |
||
620 | } |
||
621 | |||
622 | /** |
||
623 | * Renames an environment. |
||
624 | * |
||
625 | * @param string $environmentUuid |
||
626 | * @param string $label |
||
627 | * @return OperationResponse |
||
628 | */ |
||
629 | public function renameEnvironment($environmentUuid, $label) |
||
630 | { |
||
631 | |||
632 | $options = [ |
||
633 | 'form_params' => [ |
||
634 | 'label' => $label, |
||
635 | ], |
||
636 | ]; |
||
637 | |||
638 | return new OperationResponse( |
||
639 | $this->connector->request( |
||
640 | 'post', |
||
641 | "/environments/${environmentUuid}/actions/change-label", |
||
642 | $this->query, |
||
643 | $options |
||
644 | ) |
||
645 | ); |
||
646 | } |
||
647 | |||
648 | /** |
||
649 | * Deletes an environment. |
||
650 | * |
||
651 | * @param string $environmentUuid |
||
652 | * @return OperationResponse |
||
653 | */ |
||
654 | public function deleteEnvironment($environmentUuid) |
||
655 | { |
||
656 | |||
657 | return new OperationResponse( |
||
658 | $this->connector->request( |
||
659 | 'delete', |
||
660 | "/environments/${environmentUuid}", |
||
661 | $this->query |
||
662 | ) |
||
663 | ); |
||
664 | } |
||
665 | |||
666 | /** |
||
667 | * Show all servers associated with an environment. |
||
668 | * |
||
669 | * @param string $environmentUuid |
||
670 | * @return ServersResponse |
||
671 | */ |
||
672 | public function servers($environmentUuid) |
||
673 | { |
||
674 | return new ServersResponse( |
||
675 | $this->connector->request( |
||
676 | 'get', |
||
677 | "/environments/${environmentUuid}/servers", |
||
678 | $this->query |
||
679 | ) |
||
680 | ); |
||
681 | } |
||
682 | |||
683 | /** |
||
684 | * Enable livedev mode for an environment. |
||
685 | * |
||
686 | * @param string $environmentUuid |
||
687 | * @return OperationResponse |
||
688 | */ |
||
689 | public function enableLiveDev($environmentUuid) |
||
690 | { |
||
691 | return new OperationResponse( |
||
692 | $this->connector->request('post', "/environments/${environmentUuid}/livedev/actions/enable", $this->query) |
||
693 | ); |
||
694 | } |
||
695 | |||
696 | /** |
||
697 | * Disable livedev mode for an environment. |
||
698 | * |
||
699 | * @param string $environmentUuid |
||
700 | * @return OperationResponse |
||
701 | */ |
||
702 | public function disableLiveDev($environmentUuid) |
||
703 | { |
||
704 | |||
705 | $options = [ |
||
706 | 'form_params' => [ |
||
707 | 'discard' => 1, |
||
708 | ], |
||
709 | ]; |
||
710 | |||
711 | return new OperationResponse( |
||
712 | $this->connector->request( |
||
713 | 'post', |
||
714 | "/environments/${environmentUuid}/livedev/actions/disable", |
||
715 | $this->query, |
||
716 | $options |
||
717 | ) |
||
718 | ); |
||
719 | } |
||
720 | |||
721 | /** |
||
722 | * Enable production mode for an environment. |
||
723 | * |
||
724 | * @param string $environmentUuid |
||
725 | * @return OperationResponse |
||
726 | */ |
||
727 | public function enableProductionMode($environmentUuid) |
||
728 | { |
||
729 | return new OperationResponse( |
||
730 | $this->connector->request( |
||
731 | 'post', |
||
732 | "/environments/${environmentUuid}/production-mode/actions/enable", |
||
733 | $this->query |
||
734 | ) |
||
735 | ); |
||
736 | } |
||
737 | |||
738 | /** |
||
739 | * Disable production mode for an environment. |
||
740 | * |
||
741 | * @param string $environmentUuid |
||
742 | * @return OperationResponse |
||
743 | */ |
||
744 | public function disableProductionMode($environmentUuid) |
||
745 | { |
||
746 | return new OperationResponse( |
||
747 | $this->connector->request( |
||
748 | 'post', |
||
749 | "/environments/${environmentUuid}/production-mode/actions/disable", |
||
750 | $this->query |
||
751 | ) |
||
752 | ); |
||
753 | } |
||
754 | |||
755 | /** |
||
756 | * Show all cron tasks for an environment. |
||
757 | * |
||
758 | * @param string $environmentUuid The environment ID |
||
759 | * @return CronsResponse |
||
760 | */ |
||
761 | public function crons($environmentUuid) |
||
762 | { |
||
763 | return new CronsResponse( |
||
764 | $this->connector->request( |
||
765 | 'get', |
||
766 | "/environments/${environmentUuid}/crons", |
||
767 | $this->query |
||
768 | ) |
||
769 | ); |
||
770 | } |
||
771 | |||
772 | /** |
||
773 | * Get information about a cron task. |
||
774 | * |
||
775 | * @param string $environmentUuid The environment ID |
||
776 | * @param int $cronId |
||
777 | * @return CronResponse |
||
778 | */ |
||
779 | public function cron($environmentUuid, $cronId) |
||
780 | { |
||
781 | return new CronResponse( |
||
782 | $this->connector->request( |
||
783 | 'get', |
||
784 | "/environments/${environmentUuid}/crons/${cronId}", |
||
785 | $this->query |
||
786 | ) |
||
787 | ); |
||
788 | } |
||
789 | |||
790 | /** |
||
791 | * Add a cron task. |
||
792 | * |
||
793 | * @param string $environmentUuid |
||
794 | * @param string $command |
||
795 | * @param string $frequency |
||
796 | * @param string $label |
||
797 | * @return OperationResponse |
||
798 | */ |
||
799 | public function createCron($environmentUuid, $command, $frequency, $label) |
||
800 | { |
||
801 | |||
802 | $options = [ |
||
803 | 'form_params' => [ |
||
804 | 'command' => $command, |
||
805 | 'frequency' => $frequency, |
||
806 | 'label' => $label, |
||
807 | ], |
||
808 | ]; |
||
809 | |||
810 | return new OperationResponse( |
||
811 | $this->connector->request('post', "/environments/${environmentUuid}/crons", $this->query, $options) |
||
812 | ); |
||
813 | } |
||
814 | |||
815 | /** |
||
816 | * Delete a cron task. |
||
817 | * |
||
818 | * @param string $environmentUuid |
||
819 | * @param int $cronId |
||
820 | * @return OperationResponse |
||
821 | */ |
||
822 | public function deleteCron($environmentUuid, $cronId) |
||
823 | { |
||
824 | return new OperationResponse( |
||
825 | $this->connector->request('delete', "/environments/${environmentUuid}/crons/${cronId}", $this->query) |
||
826 | ); |
||
827 | } |
||
828 | |||
829 | /** |
||
830 | * Disable a cron task. |
||
831 | * |
||
832 | * @param string $environmentUuid |
||
833 | * @param int $cronId |
||
834 | * @return OperationResponse |
||
835 | */ |
||
836 | public function disableCron($environmentUuid, $cronId) |
||
837 | { |
||
838 | return new OperationResponse( |
||
839 | $this->connector->request( |
||
840 | 'post', |
||
841 | "/environments/${environmentUuid}/crons/${cronId}/actions/disable", |
||
842 | $this->query |
||
843 | ) |
||
844 | ); |
||
845 | } |
||
846 | |||
847 | /** |
||
848 | * Enable a cron task. |
||
849 | * |
||
850 | * @param string $environmentUuid |
||
851 | * @param int $cronId |
||
852 | * @return OperationResponse |
||
853 | */ |
||
854 | public function enableCron($environmentUuid, $cronId) |
||
855 | { |
||
856 | return new OperationResponse( |
||
857 | $this->connector->request( |
||
858 | 'post', |
||
859 | "/environments/${environmentUuid}/crons/${cronId}/actions/enable", |
||
860 | $this->query |
||
861 | ) |
||
862 | ); |
||
863 | } |
||
864 | |||
865 | /** |
||
866 | * Provides an archived set of files for Acquia Drush aliases. |
||
867 | * |
||
868 | * @return StreamInterface |
||
869 | */ |
||
870 | public function drushAliases() |
||
871 | { |
||
872 | return $this->connector->request('get', '/account/drush-aliases/download', $this->query); |
||
873 | } |
||
874 | |||
875 | /** |
||
876 | * Show insights data from an application. |
||
877 | * |
||
878 | * @param string $applicationUuid |
||
879 | * @return InsightsResponse |
||
880 | */ |
||
881 | public function applicationInsights($applicationUuid) |
||
882 | { |
||
883 | return new InsightsResponse( |
||
884 | $this->connector->request('get', "/applications/${applicationUuid}/insight", $this->query) |
||
885 | ); |
||
886 | } |
||
887 | |||
888 | /** |
||
889 | * Show insights data from a specific environment. |
||
890 | * |
||
891 | * @param string $environmentUuid |
||
892 | * @return InsightsResponse |
||
893 | */ |
||
894 | public function environmentInsights($environmentUuid) |
||
895 | { |
||
896 | return new InsightsResponse( |
||
897 | $this->connector->request('get', "/environments/${environmentUuid}/insight", $this->query) |
||
898 | ); |
||
899 | } |
||
900 | |||
901 | /** |
||
902 | * Show all organizations. |
||
903 | * |
||
904 | * @return OrganizationsResponse |
||
905 | */ |
||
906 | public function organizations() |
||
907 | { |
||
908 | return new OrganizationsResponse($this->connector->request('get', '/organizations', $this->query)); |
||
909 | } |
||
910 | |||
911 | /** |
||
912 | * Show all applications in an organisation. |
||
913 | * |
||
914 | * @param string $organizationUuid |
||
915 | * |
||
916 | * @return ApplicationsResponse |
||
917 | */ |
||
918 | public function organizationApplications($organizationUuid) |
||
919 | { |
||
920 | return new ApplicationsResponse( |
||
921 | $this->connector->request('get', "/organizations/${organizationUuid}/applications", $this->query) |
||
922 | ); |
||
923 | } |
||
924 | |||
925 | /** |
||
926 | * Show all roles in an organization. |
||
927 | * |
||
928 | * @param string $organizationUuid |
||
929 | * @return RolesResponse |
||
930 | */ |
||
931 | public function organizationRoles($organizationUuid) |
||
932 | { |
||
933 | return new RolesResponse( |
||
934 | $this->connector->request('get', "/organizations/${organizationUuid}/roles", $this->query) |
||
935 | ); |
||
936 | } |
||
937 | |||
938 | /** |
||
939 | * Update the permissions associated with a role. |
||
940 | * |
||
941 | * @param string $roleUuid |
||
942 | * @param array $permissions |
||
943 | * @return OperationResponse |
||
944 | */ |
||
945 | public function updateRole($roleUuid, array $permissions) |
||
946 | { |
||
947 | $options = [ |
||
948 | 'form_params' => [ |
||
949 | 'permissions' => $permissions, |
||
950 | ], |
||
951 | ]; |
||
952 | |||
953 | return new OperationResponse( |
||
954 | $this->connector->request('put', "/roles/${roleUuid}", $this->query, $options) |
||
955 | ); |
||
956 | } |
||
957 | |||
958 | /** |
||
959 | * Create a new role. |
||
960 | * |
||
961 | * @param string $organizationUuid |
||
962 | * @param string $name |
||
963 | * @param array $permissions |
||
964 | * @param null|string $description |
||
965 | * @return OperationResponse |
||
966 | */ |
||
967 | public function createRole($organizationUuid, $name, array $permissions, $description = null) |
||
968 | { |
||
969 | $options = [ |
||
970 | 'form_params' => [ |
||
971 | 'name' => $name, |
||
972 | 'permissions' => $permissions, |
||
973 | 'description' => $description, |
||
974 | ], |
||
975 | ]; |
||
976 | |||
977 | return new OperationResponse( |
||
978 | $this->connector->request('post', "/organizations/${organizationUuid}/roles", $this->query, $options) |
||
979 | ); |
||
980 | } |
||
981 | |||
982 | /** |
||
983 | * Delete a role. |
||
984 | * |
||
985 | * @param string $roleUuid |
||
986 | * @return OperationResponse |
||
987 | */ |
||
988 | public function deleteRole($roleUuid) |
||
989 | { |
||
990 | return new OperationResponse($this->connector->request('delete', "/roles/${roleUuid}", $this->query)); |
||
991 | } |
||
992 | |||
993 | /** |
||
994 | * Show all teams in an organization. |
||
995 | * |
||
996 | * @param string $organizationUuid |
||
997 | * @return TeamsResponse |
||
998 | */ |
||
999 | public function organizationTeams($organizationUuid) |
||
1000 | { |
||
1001 | return new TeamsResponse( |
||
1002 | $this->connector->request('get', "/organizations/${organizationUuid}/teams", $this->query) |
||
1003 | ); |
||
1004 | } |
||
1005 | |||
1006 | /** |
||
1007 | * Show all teams. |
||
1008 | * |
||
1009 | * @return TeamsResponse |
||
1010 | */ |
||
1011 | public function teams() |
||
1012 | { |
||
1013 | return new TeamsResponse( |
||
1014 | $this->connector->request('get', '/teams', $this->query) |
||
1015 | ); |
||
1016 | } |
||
1017 | |||
1018 | /** |
||
1019 | * Rename an existing team. |
||
1020 | * |
||
1021 | * @param string $teamUuid |
||
1022 | * @param string $name |
||
1023 | * @return OperationResponse |
||
1024 | */ |
||
1025 | public function renameTeam($teamUuid, $name) |
||
1026 | { |
||
1027 | $options = [ |
||
1028 | 'form_params' => [ |
||
1029 | 'name' => $name, |
||
1030 | ], |
||
1031 | ]; |
||
1032 | |||
1033 | return new OperationResponse( |
||
1034 | $this->connector->request('put', "/teams/${teamUuid}", $options) |
||
1035 | ); |
||
1036 | } |
||
1037 | |||
1038 | /** |
||
1039 | * Create a new team. |
||
1040 | * |
||
1041 | * @param string $organizationUuid |
||
1042 | * @param string $name |
||
1043 | * @return OperationResponse |
||
1044 | */ |
||
1045 | public function createTeam($organizationUuid, $name) |
||
1046 | { |
||
1047 | $options = [ |
||
1048 | 'form_params' => [ |
||
1049 | 'name' => $name, |
||
1050 | ], |
||
1051 | ]; |
||
1052 | |||
1053 | return new OperationResponse( |
||
1054 | $this->connector->request('post', "/organizations/${organizationUuid}/teams", $this->query, $options) |
||
1055 | ); |
||
1056 | } |
||
1057 | |||
1058 | /** |
||
1059 | * Delete a team. |
||
1060 | * |
||
1061 | * @param string $teamUuid |
||
1062 | * @return OperationResponse |
||
1063 | */ |
||
1064 | public function deleteTeam($teamUuid) |
||
1065 | { |
||
1066 | return new OperationResponse( |
||
1067 | $this->connector->request('delete', "/teams/${teamUuid}", $this->query) |
||
1068 | ); |
||
1069 | } |
||
1070 | |||
1071 | /** |
||
1072 | * Add an application to a team. |
||
1073 | * |
||
1074 | * @param string $teamUuid |
||
1075 | * @param string $applicationUuid |
||
1076 | * @return OperationResponse |
||
1077 | */ |
||
1078 | public function addApplicationToTeam($teamUuid, $applicationUuid) |
||
1088 | ); |
||
1089 | } |
||
1090 | |||
1091 | /** |
||
1092 | * Invites a user to join a team. |
||
1093 | * |
||
1094 | * @param string $teamUuid |
||
1095 | * @param string $email |
||
1096 | * @param array $roles |
||
1097 | * @return OperationResponse |
||
1098 | */ |
||
1099 | public function createTeamInvite($teamUuid, $email, $roles) |
||
1100 | { |
||
1101 | $options = [ |
||
1102 | 'form_params' => [ |
||
1103 | 'email' => $email, |
||
1104 | 'roles' => $roles |
||
1105 | ], |
||
1106 | ]; |
||
1107 | |||
1108 | return new OperationResponse( |
||
1109 | $this->connector->request('post', "/teams/${teamUuid}/invites", $options) |
||
1110 | ); |
||
1111 | } |
||
1112 | |||
1113 | /** |
||
1114 | * Invites a user to become admin of an organization. |
||
1115 | * |
||
1116 | * @param string $organizationUuid |
||
1117 | * @param string $email |
||
1118 | * @return OperationResponse |
||
1119 | */ |
||
1120 | public function createOrganizationAdminInvite($organizationUuid, $email) |
||
1121 | { |
||
1122 | $options = [ |
||
1123 | 'form_params' => [ |
||
1124 | 'email' => $email, |
||
1125 | ], |
||
1126 | ]; |
||
1127 | |||
1128 | return new OperationResponse( |
||
1129 | $this->connector->request('post', "/teams/${organizationUuid}/invites", $this->query, $options) |
||
1130 | ); |
||
1131 | } |
||
1132 | |||
1133 | /** |
||
1134 | * Show all applications associated with a team. |
||
1135 | * |
||
1136 | * @param string $teamUuid |
||
1137 | * @return ApplicationsResponse |
||
1138 | */ |
||
1139 | public function teamApplications($teamUuid) |
||
1140 | { |
||
1141 | return new ApplicationsResponse( |
||
1142 | $this->connector->request('get', "/teams/${teamUuid}/applications", $this->query) |
||
1143 | ); |
||
1144 | } |
||
1145 | |||
1146 | /** |
||
1147 | * Show all members of an organisation. |
||
1148 | * |
||
1149 | * @param string $organizationUuid |
||
1150 | * @return MembersResponse |
||
1151 | */ |
||
1152 | public function members($organizationUuid) |
||
1153 | { |
||
1154 | return new MembersResponse( |
||
1155 | $this->connector->request('get', "/organizations/${organizationUuid}/members", $this->query) |
||
1156 | ); |
||
1157 | } |
||
1158 | |||
1159 | /** |
||
1160 | * Show all members invited to an organisation. |
||
1161 | * |
||
1162 | * @param string $organizationUuid |
||
1163 | * @return InvitationsResponse |
||
1164 | */ |
||
1165 | public function invitees($organizationUuid) |
||
1169 | ); |
||
1170 | } |
||
1171 | |||
1172 | /** |
||
1173 | * Delete a member from an organisation. |
||
1174 | * |
||
1175 | * @param string $organizationUuid |
||
1176 | * @param string $memberUuid |
||
1177 | * @return OperationResponse |
||
1178 | */ |
||
1179 | public function deleteMember($organizationUuid, $memberUuid) |
||
1180 | { |
||
1181 | return new OperationResponse( |
||
1182 | $this->connector->request( |
||
1183 | 'delete', |
||
1184 | "/organizations/${organizationUuid}/members/${memberUuid}", |
||
1185 | $this->query |
||
1186 | ) |
||
1187 | ); |
||
1188 | } |
||
1189 | |||
1190 | /** |
||
1191 | * Show all available permissions. |
||
1192 | * |
||
1193 | * @return PermissionsResponse |
||
1194 | */ |
||
1195 | public function permissions() |
||
1198 | } |
||
1199 | |||
1200 | /** |
||
1201 | * Returns logstream WSS streams. |
||
1202 | * |
||
1203 | * @return LogstreamResponse |
||
1204 | */ |
||
1205 | public function logstream($environmentUuid) |
||
1206 | { |
||
1207 | return new LogstreamResponse($this->connector->request('get', "/environments/${environmentUuid}/logstream")); |
||
1208 | } |
||
1209 | } |
||
1210 |