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