Skip to content

Commit

Permalink
Added Email::get() and Email::update
Browse files Browse the repository at this point in the history
  • Loading branch information
onairmarc committed Nov 9, 2023
1 parent 75f02e1 commit 8b4ee22
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 16 deletions.
54 changes: 47 additions & 7 deletions src/People/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,54 @@
use DateTime;
use GuzzleHttp\Psr7\Request;
use JMS\Serializer\SerializerBuilder;
use stdClass;

class Email
{
public string $id;
public string $address;
public string $location;
public bool $primary;
public DateTime $created_at;
public DateTime $updated_at;
public bool $blocked;
public $id;
public $address;
public $location;
public $primary;
public $created_at;
public $updated_at;
public $blocked;

public static function get($PCOClient, Person $person): string
{
$config = $GLOBALS['pcoClientConfig'];
$headers = [
'Authorization' => $config['authorization'],
'X-PCO-API-Version' => $config['people']['apiVersion'],
];

$request = new Request('GET', 'people/v2/people/' . $person->id . '/emails', $headers, json_encode($person));

return $PCOClient->send($request);
}

public static function update($PCOClient, self $email): string
{
$config = $GLOBALS['pcoClientConfig'];
$headers = [
'Authorization' => $config['authorization'],
'X-PCO-API-Version' => $config['people']['apiVersion'],
];

$Email = self::prepareDataObject($email);

$request = new Request('PATCH', 'people/v2/emails/' . $email->id, $headers, json_encode($Email));

return $PCOClient->send($request);
}

private static function prepareDataObject($email)
{
$Email = new stdClass();
$Email->data = new stdClass();
$Email->data->attributes = new stdClass();
$Email->data->attributes->address = $email->address;
$Email->data->attributes->primary = $email->primary;

return $Email;
}
}
11 changes: 2 additions & 9 deletions src/People/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,9 @@ public static function delete($PCOClient, self $person): string
return $PCOClient->send($request);
}

public static function emails($PCOClient, self $person): string
public static function email($PCOClient, self $person): string
{
$config = $GLOBALS['pcoClientConfig'];
$headers = [
'Authorization' => $config['authorization'],
'X-PCO-API-Version' => $config['people']['apiVersion'],
];
$request = new Request('DELETE', 'people/v2/emails/' . $person->id . '/person', $headers, json_encode($person));

return $PCOClient->send($request);
return Email::get($PCOClient, $person);
}

private static function prepareDataObject($person)
Expand Down

0 comments on commit 8b4ee22

Please sign in to comment.