Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.phpunit.cache
vendor
composer.lock
.idea/
.vscode/
.DS_Store
7 changes: 5 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
parameters:
checkMissingIterableValueType: false

level: 6
paths:
- src
- src

ignoreErrors:
-
identifier: missingType.iterableValue
5 changes: 2 additions & 3 deletions src/AbstractClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,13 @@ public function factorResponse(ResponseInterface $response, ?bool $throwNotFound
protected function checkIfRequestWasSuccessful(?array $response = null, ?bool $throwNotFoundException = null): void
{
if (isset($response['status']) && $response['status'] === Status::UNAUTHORIZED) {
$message = isset($response['message']) ? $response['message'] : "The request was not authorized.";
$message = $response['message'] ?? "The request was not authorized.";

throw new RequestUnauthorizedException($message);
}

if (isset($response['success']) && boolval($response['success']) === false) {
$message = isset($response['message']) ?
$response['message'] :
$message = $response['message'] ??
"The request did not return a successful response.";

throw new UnsuccessfulResponseException($message);
Expand Down
13 changes: 9 additions & 4 deletions src/Endpoint/Cource/Coruces.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@

use AdroSoftware\CircleSoSdk\Endpoint\AbstractEndpoint;
use AdroSoftware\CircleSoSdk\Endpoint\EndpointInterface;
use AdroSoftware\CircleSoSdk\Exception\{
CommunityIdNotPresentException,
UnsuccessfulResponseException,
};
use AdroSoftware\CircleSoSdk\Exception\{CommunityIdNotPresentException,
RequestUnauthorizedException,
ResourceNotFoundException,
UnsuccessfulResponseException};
use Http\Client\Exception;

class Courses extends AbstractEndpoint implements EndpointInterface
{
Expand Down Expand Up @@ -110,6 +111,7 @@ public function showLesson(int $id, ?int $communityId = null): mixed
/**
* Create a course lesson.
*
* @param array<string, mixed> $data
* @throws CommunityIdNotPresentException
* @throws UnsuccessfulResponseException
*/
Expand All @@ -131,6 +133,9 @@ public function createLesson(
* Delete a course lesson.
*
* @throws CommunityIdNotPresentException
* @throws Exception
* @throws RequestUnauthorizedException
* @throws ResourceNotFoundException
* @throws UnsuccessfulResponseException
*/
public function deleteLesson(
Expand Down
24 changes: 24 additions & 0 deletions src/Endpoint/Member/Members.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,28 @@ public function remove(string $email, ?int $communityId = null): mixed
)
);
}

/**
* Invite Member to Community
*/
public function invite(string $email, ?int $communityId = null): mixed
{
$endpoint = "/community_members/";

$data = [
'email' => $email,
];

if (!empty($communityId)) {
$this->ensureCommunityIdIsPresent($communityId);
$data['community_id'] = $communityId;
}

return $this->factorResponse(
$this->circleSo->getHttpClient()->post(
uri: $endpoint,
body: json_encode($data),
)
);
}
}
34 changes: 34 additions & 0 deletions tests/Endpoint/Member/MembersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,38 @@ public function test_member_removed_failed(): void
->remove('i_dont_exist@example.com');

}

public function test_member_invite_ok(): void
{
$circleSo = $this->getSdkWithMockedClient([
new Response(200, [], json_response('invite_member')),
]);

$response = $circleSo
->members()
->communityId(1)
->invite('adro@example.com');

$this->assertSame(true, $response['success']);
$this->assertSame('This user has been invited to the community.', $response['message']);
}

public function test_member_invite_failed(): void
{
$this->expectException(UnsuccessfulResponseException::class);
$this->expectExceptionMessage(
'This user could not be invited. Please ensure that the user and community specified exists, and that the user is not already a member of the community.'
);

$this->expectExceptionCode(500);

$circleSo = $this->getSdkWithMockedClient([
new Response(200, [], json_response('invite_member_failed')),
]);

$circleSo
->members()
->communityId(1)
->invite('error@example.com');
}
}
34 changes: 34 additions & 0 deletions tests/stubs/responses/invite_member.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"success": true,
"message": "This user has been invited to the community.",
"user": {
"id": 1,
"email": "adri@example.com",
"first_name": "Adro",
"last_name": "Morelos",
"bio": null,
"time_zone": null,
"accepted_terms_at": "2023-05-19T08:31:00.000Z",
"accepted_privacy_at": "2023-05-19T08:31:00.000Z",
"admin": null,
"prefs": null,
"created_at": "2023-05-19T08:31:00.000Z",
"updated_at": "2023-05-19T08:31:00.000Z",
"headline": "API Test Purposes",
"posts_count": 0,
"comments_count": 0,
"profile_info": {},
"public_uid": "195c6c33",
"affiliate_code": null,
"affiliate_ref": null,
"password_confirmed_at": null,
"password_confirmation_sent_at": null,
"password_set_at": null,
"checkout_sessions": null,
"is_flagged": false,
"utm_source": null,
"terms_of_service": null,
"attachable_sgid": "BAh7CEkiCGdpZAY6BkVUSSIwZ2lkOi8vanVtcHN0YXJ0LWFwcC9Vc2VyLzkxNTE0Nzc_ZXhwaXJlc19pbgY7AFRJIgxwdXJwb3NlBjsAVEkiD2F0dGFjaGFibGUGOwBUSSIPZXhwaXJlc19hdAY7AFQw--de1c1ec6a2629b31ff66c06058c0ab25a40ee126",
"community_member_id": 10117090
}
}
4 changes: 4 additions & 0 deletions tests/stubs/responses/invite_member_failed.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"success": false,
"message": "This user could not be invited. Please ensure that the user and community specified exists, and that the user is not already a member of the community."
}