Skip to content

Commit 6645ad5

Browse files
feat(cource/space): add cource and space endpoints.
Thansk to Adam Haining for contributing to this repo indirectly. If you whish you can contribute in the feature by crating a PR, we try to be vigilant to new PRs. Co-authored-by: Adam Haining <[email protected]>
1 parent 8c53d2c commit 6645ad5

File tree

3 files changed

+272
-3
lines changed

3 files changed

+272
-3
lines changed

src/CircleSo.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
use AdroSoftware\CircleSoSdk\Contracts\InteractsWithEndpoints;
88
use AdroSoftware\CircleSoSdk\Endpoint\{
99
Community\Communities,
10+
Course\Courses,
1011
Me\Me,
1112
Member\Members,
1213
MemberTag\MemberTag,
13-
TaggedMembers\TaggedMembers,
14+
Space\Spaces,
1415
SpaceGroup\SpaceGroups,
16+
TaggedMembers\TaggedMembers,
1517
};
1618

1719
final class CircleSo extends AbstractClient implements InteractsWithEndpoints
@@ -33,6 +35,11 @@ public function communities(): Communities
3335
return new Communities($this);
3436
}
3537

38+
public function courses(): Courses
39+
{
40+
return new Courses($this);
41+
}
42+
3643
public function members(): Members
3744
{
3845
return new Members($this);
@@ -43,13 +50,18 @@ public function memberTags(): MemberTag
4350
return new MemberTag($this);
4451
}
4552

46-
public function taggedMembers(): TaggedMembers
53+
public function spaces(): Spaces
4754
{
48-
return new TaggedMembers($this);
55+
return new Spaces($this);
4956
}
5057

5158
public function spaceGroups(): SpaceGroups
5259
{
5360
return new SpaceGroups($this);
5461
}
62+
63+
public function taggedMembers(): TaggedMembers
64+
{
65+
return new TaggedMembers($this);
66+
}
5567
}

src/Endpoint/Cource/Coruces.php

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace AdroSoftware\CircleSoSdk\Endpoint\Course;
6+
7+
use AdroSoftware\CircleSoSdk\Endpoint\AbstractEndpoint;
8+
use AdroSoftware\CircleSoSdk\Endpoint\EndpointInterface;
9+
use AdroSoftware\CircleSoSdk\Exception\{
10+
CommunityIdNotPresentException,
11+
UnsuccessfulResponseException,
12+
};
13+
14+
class Courses extends AbstractEndpoint implements EndpointInterface
15+
{
16+
/**
17+
* @throws CommunityIdNotPresentException
18+
*/
19+
public function sections(
20+
int $spaceId,
21+
?int $communityId = null,
22+
?int $page = null,
23+
?int $perPage = null,
24+
): mixed {
25+
$this->ensureCommunityIdIsPresent($communityId);
26+
27+
$query = [
28+
'community_id' => $this->communityId,
29+
'space_id' => $spaceId,
30+
];
31+
32+
if ($page) {
33+
$query['page'] = $page;
34+
}
35+
36+
if ($perPage) {
37+
$query['per_page'] = $perPage;
38+
}
39+
40+
return $this->factorResponse(
41+
$this->circleSo->getHttpClient()->get(
42+
'/course_sections?' . http_build_query($query)
43+
)
44+
);
45+
}
46+
47+
/**
48+
* @throws CommunityIdNotPresentException
49+
* @throws UnsuccessfulResponseException
50+
*/
51+
public function showSection(int $id, ?int $communityId = null): mixed
52+
{
53+
$this->ensureCommunityIdIsPresent($communityId);
54+
55+
return $this->factorResponse(
56+
$this->circleSo->getHttpClient()->get(
57+
"/course_sections/{$id}?community_id={$this->communityId}"
58+
)
59+
);
60+
}
61+
62+
/**
63+
* @throws CommunityIdNotPresentException
64+
*/
65+
public function lessons(
66+
int $spaceId,
67+
int $sectionId,
68+
?int $communityId = null,
69+
?int $page = null,
70+
?int $perPage = null,
71+
): mixed {
72+
$this->ensureCommunityIdIsPresent($communityId);
73+
74+
$query = [
75+
'community_id' => $this->communityId,
76+
'space_id' => $spaceId,
77+
'section_id' => $sectionId,
78+
];
79+
80+
if ($page) {
81+
$query['page'] = $page;
82+
}
83+
84+
if ($perPage) {
85+
$query['per_page'] = $perPage;
86+
}
87+
88+
return $this->factorResponse(
89+
$this->circleSo->getHttpClient()->get(
90+
'/course_lessons?' . http_build_query($query)
91+
)
92+
);
93+
}
94+
95+
/**
96+
* @throws CommunityIdNotPresentException
97+
* @throws UnsuccessfulResponseException
98+
*/
99+
public function showLesson(int $id, ?int $communityId = null): mixed
100+
{
101+
$this->ensureCommunityIdIsPresent($communityId);
102+
103+
return $this->factorResponse(
104+
$this->circleSo->getHttpClient()->get(
105+
"/course_lessons/{$id}?community_id={$this->communityId}"
106+
)
107+
);
108+
}
109+
110+
/**
111+
* Create a course lesson.
112+
*
113+
* @throws CommunityIdNotPresentException
114+
* @throws UnsuccessfulResponseException
115+
*/
116+
public function createLesson(
117+
array $data,
118+
?int $communityId = null,
119+
): mixed {
120+
$this->ensureCommunityIdIsPresent($communityId);
121+
122+
return $this->factorResponse(
123+
$this->circleSo->getHttpClient()->post(
124+
uri: "/course_lessons?community_id={$this->communityId}",
125+
body: json_encode($data),
126+
)
127+
);
128+
}
129+
130+
/**
131+
* Delete a course lesson.
132+
*
133+
* @throws CommunityIdNotPresentException
134+
* @throws UnsuccessfulResponseException
135+
*/
136+
public function deleteLesson(
137+
int $id,
138+
?int $communityId = null,
139+
): mixed {
140+
$this->ensureCommunityIdIsPresent($communityId);
141+
142+
return $this->factorResponse(
143+
$this->circleSo->getHttpClient()->delete(
144+
"/course_lessons/{$id}?community_id={$this->communityId}",
145+
)
146+
);
147+
}
148+
}

src/Endpoint/Space/Spaces.php

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace AdroSoftware\CircleSoSdk\Endpoint\Space;
6+
7+
use AdroSoftware\CircleSoSdk\Endpoint\AbstractEndpoint;
8+
use AdroSoftware\CircleSoSdk\Endpoint\EndpointInterface;
9+
use AdroSoftware\CircleSoSdk\Exception\{
10+
CommunityIdNotPresentException,
11+
UnsuccessfulResponseException,
12+
};
13+
14+
class Spaces extends AbstractEndpoint implements EndpointInterface
15+
{
16+
/**
17+
* @throws CommunityIdNotPresentException
18+
*/
19+
public function spaces(?int $communityId = null): mixed
20+
{
21+
$this->ensureCommunityIdIsPresent($communityId);
22+
23+
return $this->factorResponse(
24+
$this->circleSo->getHttpClient()->get(
25+
"/spaces?community_id={$this->communityId}"
26+
)
27+
);
28+
}
29+
30+
/**
31+
* @throws CommunityIdNotPresentException
32+
* @throws UnsuccessfulResponseException
33+
*/
34+
public function show(int $id, ?int $communityId = null): mixed
35+
{
36+
$this->ensureCommunityIdIsPresent($communityId);
37+
38+
return $this->factorResponse(
39+
$this->circleSo->getHttpClient()->get(
40+
"/spaces/{$id}?community_id={$this->communityId}"
41+
)
42+
);
43+
}
44+
45+
/**
46+
* Create a space.
47+
*
48+
* The following json example should demonstrate
49+
* what the `$data` array should look like:
50+
* ```json
51+
* {
52+
* "name": "Awesome Space",
53+
* "is_private": true,
54+
* "is_hidden_from_non_members": false,
55+
* "is_hidden": true,
56+
* "slug": "awesome-space",
57+
* "space_group_id": 1,
58+
* "topics": [],
59+
* }
60+
* ```
61+
* @throws CommunityIdNotPresentException
62+
* @throws UnsuccessfulResponseException
63+
*/
64+
public function create(
65+
array $data,
66+
?int $communityId = null,
67+
): mixed {
68+
$this->ensureCommunityIdIsPresent($communityId);
69+
70+
return $this->factorResponse(
71+
$this->circleSo->getHttpClient()->post(
72+
uri: "/spaces?community_id={$this->communityId}",
73+
body: json_encode($data),
74+
)
75+
);
76+
}
77+
78+
/**
79+
* Delete a space.
80+
*
81+
* @throws CommunityIdNotPresentException
82+
* @throws UnsuccessfulResponseException
83+
*/
84+
public function delete(
85+
int $id,
86+
?int $communityId = null,
87+
): mixed {
88+
$this->ensureCommunityIdIsPresent($communityId);
89+
90+
return $this->factorResponse(
91+
$this->circleSo->getHttpClient()->delete(
92+
"/spaces/{$id}?community_id={$this->communityId}",
93+
)
94+
);
95+
}
96+
97+
public function members(
98+
int $id,
99+
?int $communityId = null
100+
): mixed {
101+
$this->ensureCommunityIdIsPresent($communityId);
102+
103+
return $this->factorResponse(
104+
$this->circleSo->getHttpClient()->delete(
105+
"/space_members/{$id}?space_id={$id}&community_id={$this->communityId}",
106+
)
107+
);
108+
}
109+
}

0 commit comments

Comments
 (0)