1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of GitterApi package. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
*/ |
8
|
|
|
declare(strict_types=1); |
9
|
|
|
|
10
|
|
|
namespace Gitter\Resources; |
11
|
|
|
|
12
|
|
|
use Gitter\Route; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Group schema |
16
|
|
|
* - id: Group ID. |
17
|
|
|
* - name: Group name. |
18
|
|
|
* - uri: Group URI on Gitter. |
19
|
|
|
* - backedBy: Security descriptor. Describes the backing object we get permissions from. |
20
|
|
|
* - type: [null|'ONE_TO_ONE'|'GH_REPO'|'GH_ORG'|'GH_USER'] |
21
|
|
|
* - linkPath: Represents how we find the backing object given the type |
22
|
|
|
* - avatarUrl: Base avatar URL (add s parameter to size) |
23
|
|
|
* |
24
|
|
|
* @package Gitter\Resources |
25
|
|
|
*/ |
26
|
|
|
class Groups extends AbstractResource implements \IteratorAggregate |
27
|
|
|
{ |
28
|
|
|
const TYPE_ONE_TO_ONE = 'ONE_TO_ONE'; |
29
|
|
|
const TYPE_GITHUB_REPO = 'GH_REPO'; |
30
|
|
|
const TYPE_GITHUB_ORG = 'GH_ORG'; |
31
|
|
|
const TYPE_GITHUB_USER = 'GH_USER'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* List groups the current user is in. |
35
|
|
|
* Parameters: none |
36
|
|
|
* |
37
|
|
|
* @return array |
38
|
|
|
* @throws \Throwable |
39
|
|
|
* @throws \Exception |
40
|
|
|
* @throws \InvalidArgumentException |
41
|
|
|
*/ |
42
|
|
|
public function all(): array |
43
|
|
|
{ |
44
|
|
|
return $this->fetch(Route::get('groups')); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* List of rooms nested under the specified group. |
49
|
|
|
* |
50
|
|
|
* @param string $groupId |
51
|
|
|
* @return array |
52
|
|
|
* @throws \Throwable |
53
|
|
|
* @throws \Exception |
54
|
|
|
* @throws \InvalidArgumentException |
55
|
|
|
*/ |
56
|
|
|
public function rooms(string $groupId): array |
57
|
|
|
{ |
58
|
|
|
return $this->fetch(Route::get('groups/{groupId}/rooms')->with('groupId', $groupId)); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @return \Generator |
63
|
|
|
* @throws \Throwable |
64
|
|
|
* @throws \Exception |
65
|
|
|
* @throws \InvalidArgumentException |
66
|
|
|
*/ |
67
|
|
|
public function getIterator(): \Generator |
68
|
|
|
{ |
69
|
|
|
$groups = $this->all(); |
70
|
|
|
|
71
|
|
|
foreach ($groups as $i => $group) { |
72
|
|
|
yield $i => $group; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|