Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[People] People API Improvements for Developers #23

Merged
merged 4 commits into from
Nov 28, 2024
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
1 change: 1 addition & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
c98bbfd28bd7b34f22ade287046434127a6e200c
de929a45798d68147fec3ab9527979a5e5f0fce1
c90d7383de6e86260b6cc997b3d0af8e64826a11
baa146cd798ade580c6a6f4f2cbf98d5b72cc19f
4 changes: 2 additions & 2 deletions src/Objects/People/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function get(): ClientResponse
public function forPerson(): ClientResponse
{
$http = $this->client()
->get($this->hostname() . Person::PEOPLE_ENDPOINT . "/" . $this->attributes->personId . "/emails");
->get($this->hostname() . Person::PEOPLE_ENDPOINT . "/{$this->attributes->personId}/emails");

$clientResponse = new ClientResponse($http);

Expand All @@ -58,7 +58,7 @@ public function forPerson(): ClientResponse
public function update(): ClientResponse
{
$http = $this->client()
->patch($this->hostname() . self::EMAIL_ENDPOINT . "/" . $this->attributes->emailAddressId, $this->mapToPco());
->patch($this->hostname() . self::EMAIL_ENDPOINT . "/{$this->attributes->emailAddressId}", $this->mapToPco());

return $this->processResponse($http);
}
Expand Down
13 changes: 10 additions & 3 deletions src/Objects/People/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ public static function make(?string $clientId = null, ?string $clientSecret = nu
return $person;
}

public function forPersonId(string $personId): static
{
$this->attributes->personId = $personId;

return $this;
}

public function all(?array $query = null): ClientResponse
{
$http = $this->client()
Expand All @@ -51,7 +58,7 @@ public function all(?array $query = null): ClientResponse
public function get(?array $query = null): ClientResponse
{
$http = $this->client()
->get($this->hostname() . self::PEOPLE_ENDPOINT . "/" . $this->attributes->personId, $query);
->get($this->hostname() . self::PEOPLE_ENDPOINT . "/{$this->attributes->personId}", $query);

return $this->processResponse($http);
}
Expand All @@ -67,15 +74,15 @@ public function create(): ClientResponse
public function update(): ClientResponse
{
$http = $this->client()
->patch($this->hostname() . self::PEOPLE_ENDPOINT . "/" . $this->attributes->personId, $this->mapToPco());
->patch($this->hostname() . self::PEOPLE_ENDPOINT . "/{$this->attributes->personId}", $this->mapToPco());

return $this->processResponse($http);
}

public function delete(): ClientResponse
{
$http = $this->client()
->delete($this->hostname() . self::PEOPLE_ENDPOINT . "/" . $this->attributes->personId);
->delete($this->hostname() . self::PEOPLE_ENDPOINT . "/{$this->attributes->personId}");

return $this->processResponse($http);
}
Expand Down
9 changes: 8 additions & 1 deletion src/Objects/People/PersonMerger/PersonMerger.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,17 @@ public static function make(string $clientId, string $clientSecret): PersonMerge
return $personMerger;
}

public function forPersonId(string $personId): static
{
$this->attributes->personMergerId = $personId;

return $this;
}

public function get(?array $query = []): ClientResponse
{
$http = $this->client()
->get($this->hostname() . self::PERSON_MERGER_ENDPOINT . "/" . $this->attributes->personMergerId, $query);
->get($this->hostname() . self::PERSON_MERGER_ENDPOINT . "/{$this->attributes->personMergerId}", $query);

return $this->processResponse($http);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/HasPlanningCenterClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __construct(?string $clientId = null, ?string $clientSecret = nu
$this->clientId = $clientId ?? "";
$this->clientSecret = $clientSecret ?? "";

$builder = new HttpClientBuilder;
new HttpClientBuilder;
}

public function client(): PendingRequest
Expand Down
3 changes: 1 addition & 2 deletions tests/Unit/People/PersonTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@

test('People: Can Get Person By ID', function () {
$person = Person::make(TestConstants::CLIENT_ID, TestConstants::CLIENT_SECRET);
$person->attributes->personId = "1";

$response = $person->get();
$response = $person->forPersonId("1")->get();
/** @var Person $personProfile */
$personProfile = $response->data->first();

Expand Down