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