complete subscriber endpoint
This commit is contained in:
bovenliggende
c2e0717445
commit
c5085b1bb8
@ -2,18 +2,183 @@
|
||||
|
||||
namespace D3\KlicktippPhpClient\Entities;
|
||||
|
||||
use DateTime;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
|
||||
class Subscriber extends ArrayCollection
|
||||
{
|
||||
public const STATUS_SUBSCRIBED = 'subscribed';
|
||||
public const BOUNCE_NOTBOUNCED = 'Not Bounced';
|
||||
|
||||
public function getId(): string
|
||||
{
|
||||
return $this->get('id');
|
||||
return $this->get('id') ?? '';
|
||||
}
|
||||
|
||||
public function getListId(): string
|
||||
{
|
||||
return $this->get('listid') ?? '';
|
||||
}
|
||||
|
||||
public function getOptinTime(): string
|
||||
{
|
||||
return $this->get('optin') ?? '';
|
||||
}
|
||||
|
||||
public function getOptinIp(): string
|
||||
{
|
||||
return $this->get('optin_ip') ?? '';
|
||||
}
|
||||
|
||||
public function getEmailAddress(): string
|
||||
{
|
||||
return $this->get('email') ?? '';
|
||||
}
|
||||
|
||||
public function getStatus(): string
|
||||
{
|
||||
return $this->get('status') ?? '';
|
||||
}
|
||||
|
||||
public function getBounce(): string
|
||||
{
|
||||
return $this->get('bounce') ?? '';
|
||||
}
|
||||
|
||||
public function getDate(): string
|
||||
{
|
||||
return $this->get('date') ?? '';
|
||||
}
|
||||
|
||||
public function getIp(): string
|
||||
{
|
||||
return $this->get('ip') ?? '';
|
||||
}
|
||||
|
||||
public function getUnsubscription(): string
|
||||
{
|
||||
return $this->get('unsubscription') ?? '';
|
||||
}
|
||||
|
||||
public function getUnsubscriptionIp(): string
|
||||
{
|
||||
return $this->get('unsubscription_ip') ?? '';
|
||||
}
|
||||
|
||||
public function getReferrer(): string
|
||||
{
|
||||
return $this->get('referrer') ?? '';
|
||||
}
|
||||
|
||||
public function getSmsPhone(): string
|
||||
{
|
||||
return $this->get('sms_phone') ?? '';
|
||||
}
|
||||
|
||||
public function getSmsStatus(): string
|
||||
{
|
||||
return $this->get('sms_status') ?? '';
|
||||
}
|
||||
|
||||
public function getSmsBounce(): string
|
||||
{
|
||||
return $this->get('sms_bounce') ?? '';
|
||||
}
|
||||
|
||||
public function getSmsUnsubscription(): string
|
||||
{
|
||||
return $this->get('sms_unsubscription') ?? '';
|
||||
}
|
||||
|
||||
public function getSmsReferrer(): string
|
||||
{
|
||||
return $this->get('sms_referrer') ?? '';
|
||||
}
|
||||
|
||||
public function getField(string $fieldId): string
|
||||
{
|
||||
// ToDo: should we throw fieldNotSetException
|
||||
return $this->get('field'.trim($fieldId)) ?? '';
|
||||
}
|
||||
|
||||
public function getTags(): array
|
||||
{
|
||||
return $this->get('tags') ?? [];
|
||||
}
|
||||
|
||||
public function getManualTags(): array
|
||||
{
|
||||
return $this->get('manual_tags') ?? [];
|
||||
}
|
||||
|
||||
public function getManualTag(string $tagId): string
|
||||
{
|
||||
return $this->getManualTags()[$tagId] ?? '';
|
||||
}
|
||||
|
||||
public function getSmartTags(): array
|
||||
{
|
||||
return $this->get('smart_tags') ?? [];
|
||||
}
|
||||
|
||||
public function getSmartTag(string $tagId): string
|
||||
{
|
||||
return $this->getSmartTags()[$tagId] ?? '';
|
||||
}
|
||||
|
||||
public function getStartedCampaigns(): array
|
||||
{
|
||||
return $this->get('campaigns_started') ?? [];
|
||||
}
|
||||
|
||||
public function getStartedCampaign(string $campaignId): string
|
||||
{
|
||||
return $this->getStartedCampaigns()[$campaignId] ?? '';
|
||||
}
|
||||
|
||||
public function getFinishedCampaigns(): array
|
||||
{
|
||||
return $this->get('campaigns_finished') ?? [];
|
||||
}
|
||||
|
||||
public function getFinishedCampaign(string $campaignId): string
|
||||
{
|
||||
return $this->getFinishedCampaigns()[$campaignId] ?? '';
|
||||
}
|
||||
|
||||
public function getSentNotificationEmails(): array
|
||||
{
|
||||
return $this->get('notification_emails_sent') ?? [];
|
||||
}
|
||||
|
||||
public function getOutbound(): array
|
||||
{
|
||||
return $this->get('outbound') ?? [];
|
||||
}
|
||||
|
||||
public function getOpenedNotificationEmails(): array
|
||||
{
|
||||
return $this->get('notification_emails_opened') ?? [];
|
||||
}
|
||||
|
||||
public function isSubscribed(): bool
|
||||
{
|
||||
// ToDo: adjust request
|
||||
return $this->get('isSubscribed');
|
||||
return $this->getStatus() === self::STATUS_SUBSCRIBED;
|
||||
}
|
||||
|
||||
public function isOptedIn(): bool
|
||||
{
|
||||
return $this->getOptinTime() != '0000-00-00 00:00:00' &&
|
||||
new DateTime($this->getOptinTime()) < new DateTime();
|
||||
}
|
||||
|
||||
public function isBounced(): bool
|
||||
{
|
||||
return $this->getBounce() != self::BOUNCE_NOTBOUNCED;
|
||||
}
|
||||
|
||||
public function isTagSet(string $tagId): bool
|
||||
{
|
||||
return in_array($tagId, $this->getTags());
|
||||
}
|
||||
}
|
@ -137,4 +137,116 @@ class Subscriber extends Model
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws BaseException|GuzzleException
|
||||
*/
|
||||
public function tagged(string $tagId): string
|
||||
{
|
||||
return current(
|
||||
$this->connection->requestAndParse(
|
||||
'POST',
|
||||
'subscriber/tagged',
|
||||
[
|
||||
RequestOptions::FORM_PARAMS => [
|
||||
'tagid' => trim($tagId)
|
||||
]
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws BaseException|GuzzleException
|
||||
*/
|
||||
public function update(string $subscriberId, array $fields, string $newEmail, string $newSmsNumber): string
|
||||
{
|
||||
return current(
|
||||
$this->connection->requestAndParse(
|
||||
'PUT',
|
||||
'subscriber/'.urlencode(trim($subscriberId)),
|
||||
[
|
||||
RequestOptions::FORM_PARAMS => [
|
||||
//ToDo: apply trim to array
|
||||
'fields' => $fields,
|
||||
'newemail' => trim($newEmail),
|
||||
'newsmsnumber' => trim($newSmsNumber),
|
||||
]
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws BaseException|GuzzleException
|
||||
*/
|
||||
public function delete(string $subscriberId): string
|
||||
{
|
||||
return current(
|
||||
$this->connection->requestAndParse(
|
||||
'DELETE',
|
||||
'subscriber/'.urlencode(trim($subscriberId))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws BaseException|GuzzleException
|
||||
*/
|
||||
public function signin(string $apikey, string $emailAddress, array $fields, string $smsNumber): string
|
||||
{
|
||||
return current(
|
||||
$this->connection->requestAndParse(
|
||||
'POST',
|
||||
'subscriber/signin',
|
||||
[
|
||||
RequestOptions::FORM_PARAMS => [
|
||||
'apikey' => trim($apikey),
|
||||
'email' => trim($emailAddress),
|
||||
//ToDo: apply trim to array
|
||||
'fields' => $fields,
|
||||
'smsnumber' => trim($smsNumber),
|
||||
]
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws BaseException|GuzzleException
|
||||
*/
|
||||
public function signout(string $apikey, string $emailAddress): string
|
||||
{
|
||||
return current(
|
||||
$this->connection->requestAndParse(
|
||||
'POST',
|
||||
'subscriber/signout',
|
||||
[
|
||||
RequestOptions::FORM_PARAMS => [
|
||||
'apikey' => trim($apikey),
|
||||
'email' => trim($emailAddress),
|
||||
]
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws BaseException|GuzzleException
|
||||
*/
|
||||
public function signoff(string $apikey, string $emailAddress): string
|
||||
{
|
||||
return current(
|
||||
$this->connection->requestAndParse(
|
||||
'POST',
|
||||
'subscriber/signoff',
|
||||
[
|
||||
RequestOptions::FORM_PARAMS => [
|
||||
'apikey' => trim($apikey),
|
||||
'email' => trim($emailAddress),
|
||||
]
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Laden…
x
Verwijs in nieuw issue
Block a user