2024-12-20 23:46:48 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace D3\KlicktippPhpClient\Resources;
|
|
|
|
|
|
|
|
use D3\KlicktippPhpClient\Entities\Subscriber as SubscriberEntity;
|
2024-12-22 23:36:29 +01:00
|
|
|
use D3\KlicktippPhpClient\Entities\SubscriberList;
|
2024-12-20 23:46:48 +01:00
|
|
|
use D3\KlicktippPhpClient\Exceptions\BaseException;
|
|
|
|
use GuzzleHttp\Exception\GuzzleException;
|
2024-12-21 19:25:33 +01:00
|
|
|
use GuzzleHttp\RequestOptions;
|
2024-12-20 23:46:48 +01:00
|
|
|
|
|
|
|
class Subscriber extends Model
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @throws BaseException|GuzzleException
|
|
|
|
*/
|
2024-12-22 23:36:29 +01:00
|
|
|
public function index(): SubscriberList
|
2024-12-20 23:46:48 +01:00
|
|
|
{
|
2024-12-22 23:36:29 +01:00
|
|
|
$data = $this->connection->requestAndParse(
|
2024-12-20 23:46:48 +01:00
|
|
|
'GET',
|
2024-12-21 19:25:33 +01:00
|
|
|
'subscriber'
|
2024-12-20 23:46:48 +01:00
|
|
|
);
|
2024-12-22 23:36:29 +01:00
|
|
|
|
|
|
|
return new SubscriberList($data);
|
2024-12-20 23:46:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws BaseException|GuzzleException
|
|
|
|
*/
|
|
|
|
public function get(string $subscriberId): SubscriberEntity
|
|
|
|
{
|
|
|
|
$data = $this->connection->requestAndParse(
|
|
|
|
'GET',
|
2024-12-21 19:25:33 +01:00
|
|
|
'subscriber/'.urlencode(trim($subscriberId))
|
2024-12-20 23:46:48 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
return new SubscriberEntity($data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws BaseException|GuzzleException
|
|
|
|
*/
|
|
|
|
public function search(string $mailAddress): string
|
|
|
|
{
|
|
|
|
return current(
|
|
|
|
$this->connection->requestAndParse(
|
|
|
|
'POST',
|
|
|
|
'subscriber/search',
|
|
|
|
[
|
2024-12-21 19:25:33 +01:00
|
|
|
RequestOptions::FORM_PARAMS => [
|
2024-12-20 23:46:48 +01:00
|
|
|
'email' => trim($mailAddress)
|
|
|
|
]
|
|
|
|
]
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2024-12-22 13:54:42 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws BaseException|GuzzleException
|
|
|
|
*/
|
|
|
|
public function subscribe(
|
|
|
|
string $mailAddress,
|
|
|
|
string $listId,
|
|
|
|
string $tagId,
|
|
|
|
array $fields,
|
|
|
|
string $smsNumber
|
|
|
|
): string
|
|
|
|
{
|
|
|
|
return current(
|
|
|
|
$this->connection->requestAndParse(
|
|
|
|
'POST',
|
|
|
|
'subscriber',
|
|
|
|
[
|
|
|
|
RequestOptions::FORM_PARAMS => [
|
|
|
|
'email' => trim($mailAddress),
|
|
|
|
'listid' => trim($listId),
|
|
|
|
'tagid' => trim($tagId),
|
|
|
|
'fields' => array_filter($fields),
|
|
|
|
'smsnumber' => trim($smsNumber),
|
|
|
|
]
|
|
|
|
]
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws BaseException|GuzzleException
|
|
|
|
*/
|
|
|
|
public function unsubscribe(string $mailAddress): string
|
|
|
|
{
|
|
|
|
return current(
|
|
|
|
$this->connection->requestAndParse(
|
|
|
|
'POST',
|
|
|
|
'subscriber/unsubscribe',
|
|
|
|
[
|
|
|
|
RequestOptions::FORM_PARAMS => [
|
|
|
|
'email' => trim($mailAddress)
|
|
|
|
]
|
|
|
|
]
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws BaseException|GuzzleException
|
|
|
|
*/
|
|
|
|
public function tag(string $mailAddress, string $tagId): string
|
|
|
|
{
|
|
|
|
return current(
|
|
|
|
$this->connection->requestAndParse(
|
|
|
|
'POST',
|
|
|
|
'subscriber/tag',
|
|
|
|
[
|
|
|
|
RequestOptions::FORM_PARAMS => [
|
|
|
|
'email' => trim($mailAddress),
|
|
|
|
'tagid' => trim($tagId)
|
|
|
|
]
|
|
|
|
]
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws BaseException|GuzzleException
|
|
|
|
*/
|
|
|
|
public function untag(string $mailAddress, string $tagId): string
|
|
|
|
{
|
|
|
|
return current(
|
|
|
|
$this->connection->requestAndParse(
|
|
|
|
'POST',
|
|
|
|
'subscriber/search',
|
|
|
|
[
|
|
|
|
RequestOptions::FORM_PARAMS => [
|
|
|
|
'email' => trim($mailAddress),
|
|
|
|
'tagid' => trim($tagId)
|
|
|
|
]
|
|
|
|
]
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2024-12-20 23:46:48 +01:00
|
|
|
}
|