Release 0.9a: Move ng to main, modernize PHP 8.1+ client, update documentation and add Gitea workflow
This commit is contained in:
1 parent
76e09c0b96
commit
67bc8aa462
9 files changed
+1560
-1455
No files matched your search
+531
-239
@@ -1,327 +1,619 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* ninjaMail API kliens alaposztály
|
||||
*
|
||||
* Kezeli a HTTP kommunikációt a ninjaMail API végponttal.
|
||||
*/
|
||||
class ninjaMail
|
||||
{
|
||||
private string $host = '';
|
||||
private string $key = '';
|
||||
public ?object $data = null;
|
||||
|
||||
private $host;
|
||||
private $key;
|
||||
public $data;
|
||||
/** @var int cURL időtúllépés másodpercben */
|
||||
private int $timeout = 15;
|
||||
|
||||
public function __construct($host, $key = false)
|
||||
{
|
||||
$this->host = $host;
|
||||
if ($key) $this->key = $key;
|
||||
}
|
||||
/**
|
||||
* @param string $host Az API gazdagép alap URL-je (pl. https://example.org)
|
||||
* @param string|bool $key API hitelesítési kulcs
|
||||
*/
|
||||
public function __construct(string $host, string|bool $key = false)
|
||||
{
|
||||
$this->host = rtrim($host, '/');
|
||||
if ($key !== false && $key !== '') {
|
||||
$this->key = (string)$key;
|
||||
}
|
||||
}
|
||||
|
||||
public function check()
|
||||
{
|
||||
if (!$this->host || !$this->key)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Ellenőrzi, hogy az API gazdagép és kulcs be van-e állítva.
|
||||
*/
|
||||
public function check(): bool
|
||||
{
|
||||
return !empty($this->host) && !empty($this->key);
|
||||
}
|
||||
|
||||
public function process($f, $data, $post_method = true)
|
||||
{
|
||||
$ch = curl_init($this->host.'/a/'.$f.'/?key='.$this->key);
|
||||
curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
||||
$data = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
/**
|
||||
* POST kérést küld az API adott végpontjára.
|
||||
*
|
||||
* @param string $endpoint A végpont neve (pl. 'subscribe')
|
||||
* @param array $data POST mezők tömbje
|
||||
* @return object A dekódolt JSON válasz objektumként
|
||||
* @throws RuntimeException Ha hiányoznak a hitelesítési adatok, cURL hiba
|
||||
* esetén, vagy ha a válasz nem érvényes JSON
|
||||
*/
|
||||
public function process(string $endpoint, array $data): object
|
||||
{
|
||||
if (!$this->check()) {
|
||||
throw new RuntimeException('ninjaMail: hiányzó gazdagép vagy API kulcs.');
|
||||
}
|
||||
|
||||
$data = @(object)json_decode($data);
|
||||
$this->data = $data;
|
||||
return $data;
|
||||
}
|
||||
$url = $this->host . '/a/' . rawurlencode($endpoint) . '/?key=' . urlencode($this->key);
|
||||
|
||||
public function login()
|
||||
{
|
||||
return $this->process('login', ['rkey' => md5(time().rand(0,65500).rand(0,10))]);
|
||||
}
|
||||
$ch = curl_init($url);
|
||||
if ($ch === false) {
|
||||
throw new RuntimeException('ninjaMail: nem sikerült inicializálni a cURL munkamenetet.');
|
||||
}
|
||||
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_ENCODING => 'UTF-8',
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_POST => true,
|
||||
CURLOPT_POSTFIELDS => is_array($data) ? http_build_query($data) : $data,
|
||||
CURLOPT_TIMEOUT => $this->timeout,
|
||||
CURLOPT_CONNECTTIMEOUT => 10,
|
||||
CURLOPT_SSL_VERIFYPEER => true,
|
||||
CURLOPT_SSL_VERIFYHOST => 2,
|
||||
CURLOPT_FOLLOWLOCATION => false,
|
||||
CURLOPT_MAXREDIRS => 0,
|
||||
CURLOPT_HTTPHEADER => ['Accept: application/json'],
|
||||
]);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
$errno = curl_errno($ch);
|
||||
$error = curl_error($ch);
|
||||
|
||||
if ($response === false) {
|
||||
throw new RuntimeException(
|
||||
sprintf('ninjaMail: cURL hiba (%d): %s', $errno, $error)
|
||||
);
|
||||
}
|
||||
|
||||
$responseStr = trim((string)$response);
|
||||
if ($responseStr === '') {
|
||||
$result = (object)[];
|
||||
$this->data = $result;
|
||||
return $result;
|
||||
}
|
||||
|
||||
$decoded = json_decode($responseStr);
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
throw new RuntimeException(
|
||||
'ninjaMail: érvénytelen JSON válasz: ' . json_last_error_msg()
|
||||
);
|
||||
}
|
||||
|
||||
$result = (object)$decoded;
|
||||
$this->data = $result;
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Véletlenszerű kulccsal indít távoli belépési munkamenetet.
|
||||
*
|
||||
* @return object API válasz (tartalmaz 'token' mezőt siker esetén)
|
||||
* @throws RuntimeException Lásd: process()
|
||||
*/
|
||||
public function login(): object
|
||||
{
|
||||
return $this->process('login', [
|
||||
'rkey' => bin2hex(random_bytes(16)),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Send Email
|
||||
// ---------------------------------------------------------------------------
|
||||
// Levélküldés
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Egyszeri e-mail küldése megadott címzettnek.
|
||||
*/
|
||||
class ninjaMailSend extends ninjaMail
|
||||
{
|
||||
private string $to = '';
|
||||
private string $subject = '';
|
||||
private string $message = '';
|
||||
private string $message_text = '';
|
||||
|
||||
private $to;
|
||||
private $subject;
|
||||
private $message;
|
||||
private $message_text;
|
||||
|
||||
public function to($to)
|
||||
/**
|
||||
* @param string $to Feliratkozó azonosítója vagy e-mail cím
|
||||
*/
|
||||
public function to(string $to): true
|
||||
{
|
||||
$this->to = $to;
|
||||
return true;
|
||||
$this->to = trim($to);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function subject($s)
|
||||
/**
|
||||
* @param string $s Az e-mail tárgya
|
||||
*/
|
||||
public function subject(string $s): true
|
||||
{
|
||||
$this->subject = $s;
|
||||
return true;
|
||||
$this->subject = $s;
|
||||
return true;
|
||||
}
|
||||
|
||||
public function message($m, $t = false)
|
||||
/**
|
||||
* @param string $m HTML tartalom
|
||||
* @param string|bool $t Opcionális egyszerű szöveges változat;
|
||||
* ha nincs megadva, a HTML-ből kerül levezetésre
|
||||
*/
|
||||
public function message(string $m, string|bool $t = false): true
|
||||
{
|
||||
$this->message = $m;
|
||||
if (!$t) $this->message_text = trim(strip_tags($m));
|
||||
else $this->message_text = $t;
|
||||
return true;
|
||||
$this->message = $m;
|
||||
$this->message_text = ($t !== false && $t !== '')
|
||||
? (string)$t
|
||||
: trim(strip_tags($m));
|
||||
return true;
|
||||
}
|
||||
|
||||
public function send()
|
||||
/**
|
||||
* Elküldi az e-mailt.
|
||||
*
|
||||
* @return bool true ha a levél sikeresen sorba állt
|
||||
* @throws InvalidArgumentException Ha kötelező mező hiányzik
|
||||
* @throws RuntimeException Lásd: process()
|
||||
*/
|
||||
public function send(): bool
|
||||
{
|
||||
$post = [
|
||||
'to' => $this->to,
|
||||
'subject' => $this->subject,
|
||||
'message' => $this->message,
|
||||
'message_text' => $this->message_text
|
||||
];
|
||||
return $this->process('send', $post, true)->status == 'message_queued' ? true : false;
|
||||
if (empty($this->to) || empty($this->subject) || empty($this->message)) {
|
||||
throw new InvalidArgumentException(
|
||||
'ninjaMailSend: a to, subject és message mezők kötelezők.'
|
||||
);
|
||||
}
|
||||
|
||||
$post = [
|
||||
'to' => $this->to,
|
||||
'subject' => $this->subject,
|
||||
'message' => $this->message,
|
||||
'message_text' => $this->message_text,
|
||||
];
|
||||
|
||||
return ($this->process('send', $post)->status ?? '') === 'message_queued';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Subscribe
|
||||
// ---------------------------------------------------------------------------
|
||||
// Feliratkozások
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Feliratkozók hozzáadása és eltávolítása levelezőlistákból.
|
||||
*/
|
||||
class ninjaMailSubscription extends ninjaMail
|
||||
{
|
||||
private int $list = 0;
|
||||
private int $activated = 0;
|
||||
private int $forcenamechange = 0;
|
||||
|
||||
private $list;
|
||||
private $activated = 0;
|
||||
private $forcenamechange = 0;
|
||||
|
||||
public function list($id)
|
||||
/**
|
||||
* @param int $id Lista azonosítója
|
||||
* @return bool false ha az azonosító nem pozitív egész szám
|
||||
*/
|
||||
public function list(int $id): bool
|
||||
{
|
||||
if (is_numeric($id))
|
||||
{
|
||||
$this->list = $id;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
if ($id <= 0) {
|
||||
return false;
|
||||
}
|
||||
$this->list = $id;
|
||||
return true;
|
||||
}
|
||||
|
||||
public function activated($s)
|
||||
/**
|
||||
* @param bool $s true = azonnal megerősített; false = megerősítő e-mail küldése
|
||||
*/
|
||||
public function activated(bool $s): true
|
||||
{
|
||||
if ($s) $this->activated = 1;
|
||||
else $this->activated = 0;
|
||||
return true;
|
||||
$this->activated = $s ? 1 : 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
public function namechange($s)
|
||||
{
|
||||
if ($s) $this->forcenamechange = 1;
|
||||
else $this->forcenamechange = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
public function subscribe($email, $name = '')
|
||||
/**
|
||||
* @param bool $s true = névfrissítés engedélyezése meglévő feliratkozóknál
|
||||
*/
|
||||
public function namechange(bool $s): true
|
||||
{
|
||||
if (!$this->list || !is_numeric($this->activated))
|
||||
return false;
|
||||
|
||||
$post = [
|
||||
'list' => $this->list,
|
||||
'name' => $name,
|
||||
'email' => $email,
|
||||
'activated' => $this->activated,
|
||||
'forcenamechange' => $this->forcenamechange
|
||||
];
|
||||
return $this->process('subscribe', $post, true)->status == 'success' ? true : false;
|
||||
$this->forcenamechange = $s ? 1 : 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
public function unsubscribe($email)
|
||||
/**
|
||||
* Feliratkozó hozzáadása a listához.
|
||||
*
|
||||
* @param string $email A feliratkozó e-mail címe
|
||||
* @param string $name A feliratkozó neve (opcionális)
|
||||
* @return bool true sikeres feliratkozás esetén
|
||||
* @throws InvalidArgumentException Ha a lista nincs beállítva
|
||||
* @throws RuntimeException Lásd: process()
|
||||
*/
|
||||
public function subscribe(string $email, string $name = ''): bool
|
||||
{
|
||||
if (!$this->list)
|
||||
return false;
|
||||
if ($this->list <= 0) {
|
||||
throw new InvalidArgumentException(
|
||||
'ninjaMailSubscription: lista azonosítója nincs beállítva.'
|
||||
);
|
||||
}
|
||||
|
||||
$post = [
|
||||
'list' => $this->list,
|
||||
'email' => $email
|
||||
];
|
||||
return $this->process('unsubscribe', $post, true)->status == 'success' ? true : false;
|
||||
$post = [
|
||||
'list' => $this->list,
|
||||
'name' => $name,
|
||||
'email' => $email,
|
||||
'activated' => $this->activated,
|
||||
'forcenamechange' => $this->forcenamechange,
|
||||
];
|
||||
|
||||
return ($this->process('subscribe', $post)->status ?? '') === 'success';
|
||||
}
|
||||
|
||||
/**
|
||||
* Feliratkozó eltávolítása a listából.
|
||||
*
|
||||
* @param string $email A leiratkozó e-mail címe
|
||||
* @return bool true sikeres leiratkozás esetén
|
||||
* @throws InvalidArgumentException Ha a lista nincs beállítva
|
||||
* @throws RuntimeException Lásd: process()
|
||||
*/
|
||||
public function unsubscribe(string $email): bool
|
||||
{
|
||||
if ($this->list <= 0) {
|
||||
throw new InvalidArgumentException(
|
||||
'ninjaMailSubscription: lista azonosítója nincs beállítva.'
|
||||
);
|
||||
}
|
||||
|
||||
$post = [
|
||||
'list' => $this->list,
|
||||
'email' => $email,
|
||||
];
|
||||
|
||||
return ($this->process('unsubscribe', $post)->status ?? '') === 'success';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Newsletter
|
||||
// ---------------------------------------------------------------------------
|
||||
// Hírlevél
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Hírlevelek létrehozása, frissítése és küldése.
|
||||
*/
|
||||
class ninjaMailNewsletter extends ninjaMail
|
||||
{
|
||||
private int $newsletter = 0;
|
||||
private string $subject = '';
|
||||
private string $message = '';
|
||||
private string $message_text = '';
|
||||
|
||||
private $newsletter;
|
||||
private $subject;
|
||||
private $message;
|
||||
private $message_text;
|
||||
|
||||
|
||||
public function newsletter($id = false)
|
||||
{
|
||||
if (is_numeric($id))
|
||||
{
|
||||
$this->newsletter = $id;
|
||||
return true;
|
||||
}
|
||||
return $this->newsletter;
|
||||
}
|
||||
|
||||
public function subject($s)
|
||||
/**
|
||||
* Lekérdezi vagy beállítja az aktuális hírlevél azonosítóját.
|
||||
*
|
||||
* @param int|false $id Hírlevél azonosítója a beállításhoz; false = lekérdezés
|
||||
* @return int|bool Lekérdezési módban az aktuális azonosítót adja vissza;
|
||||
* beállítási módban true/false
|
||||
*/
|
||||
public function newsletter(int|false $id = false): int|bool
|
||||
{
|
||||
$this->subject = $s;
|
||||
return true;
|
||||
if ($id !== false) {
|
||||
if ($id > 0) {
|
||||
$this->newsletter = $id;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return $this->newsletter;
|
||||
}
|
||||
|
||||
public function message($m, $t = false)
|
||||
/**
|
||||
* @param string $s A hírlevél tárgya
|
||||
*/
|
||||
public function subject(string $s): true
|
||||
{
|
||||
$this->message = $m;
|
||||
if (!$t) $this->message_text = trim(strip_tags($m));
|
||||
else $this->message_text = $t;
|
||||
return true;
|
||||
$this->subject = $s;
|
||||
return true;
|
||||
}
|
||||
|
||||
public function query($update = false)
|
||||
{
|
||||
if (!$this->message)
|
||||
return false;
|
||||
/**
|
||||
* @param string $m HTML tartalom
|
||||
* @param string|bool $t Opcionális egyszerű szöveges változat
|
||||
*/
|
||||
public function message(string $m, string|bool $t = false): true
|
||||
{
|
||||
$this->message = $m;
|
||||
$this->message_text = ($t !== false && $t !== '')
|
||||
? (string)$t
|
||||
: trim(strip_tags($m));
|
||||
return true;
|
||||
}
|
||||
|
||||
$post = [
|
||||
'new' => true,
|
||||
'id' => $update ? $this->newsletter : false,
|
||||
'subject' => $this->subject,
|
||||
'message' => $this->message,
|
||||
'message_text' => $this->message_text
|
||||
];
|
||||
$data = $this->process('newsletter', $post, true);
|
||||
if ($data->status == 'success')
|
||||
{
|
||||
$this->newsletter = $data->id;
|
||||
return $data->id;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* @param bool $update true = meglévő frissítése; false = új létrehozása
|
||||
* @return int|false Az új/frissített hírlevél azonosítója, vagy false hiba esetén
|
||||
* @throws InvalidArgumentException Ha nincs üzenet beállítva
|
||||
* @throws RuntimeException Lásd: process()
|
||||
*/
|
||||
private function query(bool $update = false): int|false
|
||||
{
|
||||
if (empty($this->message)) {
|
||||
throw new InvalidArgumentException(
|
||||
'ninjaMailNewsletter: az üzenet tartalma kötelező.'
|
||||
);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return $this->query(false);
|
||||
}
|
||||
$post = [
|
||||
'new' => true,
|
||||
'id' => $update ? $this->newsletter : false,
|
||||
'subject' => $this->subject,
|
||||
'message' => $this->message,
|
||||
'message_text' => $this->message_text,
|
||||
];
|
||||
|
||||
public function update()
|
||||
{
|
||||
if (!$this->newsletter)
|
||||
return false;
|
||||
$data = $this->process('newsletter', $post);
|
||||
if (($data->status ?? '') === 'success' && isset($data->id) && is_numeric($data->id)) {
|
||||
$this->newsletter = (int)$data->id;
|
||||
return $this->newsletter;
|
||||
}
|
||||
|
||||
return $this->query(true);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function send($time = false)
|
||||
{
|
||||
if (!$this->newsletter)
|
||||
return false;
|
||||
/**
|
||||
* Új hírlevelet hoz létre.
|
||||
*
|
||||
* @return int|false Az új hírlevél azonosítója, vagy false hiba esetén
|
||||
*/
|
||||
public function create(): int|false
|
||||
{
|
||||
return $this->query(false);
|
||||
}
|
||||
|
||||
$post = [
|
||||
'send' => true,
|
||||
'id' => $this->newsletter,
|
||||
'start' => $time ? $time : 0
|
||||
];
|
||||
$data = $this->process('newsletter', $post, true);
|
||||
if ($data->status == 'success' || $this->status == 'already_queued')
|
||||
return true;
|
||||
/**
|
||||
* Meglévő hírlevelet frissít.
|
||||
*
|
||||
* @return int|false A hírlevél azonosítója, vagy false hiba esetén
|
||||
* @throws InvalidArgumentException Ha nincs hírlevél kiválasztva
|
||||
*/
|
||||
public function update(): int|false
|
||||
{
|
||||
if ($this->newsletter <= 0) {
|
||||
throw new InvalidArgumentException(
|
||||
'ninjaMailNewsletter: hírlevél azonosítója nincs beállítva a frissítéshez.'
|
||||
);
|
||||
}
|
||||
return $this->query(true);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Hírlevelet küld azonnali vagy ütemezett időpontban.
|
||||
*
|
||||
* @param int|false $time Unix időbélyeg a küldés időpontjához; false vagy 0 = azonnali
|
||||
* @return bool true sikeres sorbaállítás esetén
|
||||
* @throws InvalidArgumentException Ha nincs hírlevél kiválasztva
|
||||
* @throws RuntimeException Lásd: process()
|
||||
*/
|
||||
public function send(int|false $time = false): bool
|
||||
{
|
||||
if ($this->newsletter <= 0) {
|
||||
throw new InvalidArgumentException(
|
||||
'ninjaMailNewsletter: hírlevél azonosítója nincs beállítva a küldéshez.'
|
||||
);
|
||||
}
|
||||
|
||||
public function get()
|
||||
{
|
||||
return $this->process('newsletter', ['get' => true], true);
|
||||
}
|
||||
$post = [
|
||||
'send' => true,
|
||||
'id' => $this->newsletter,
|
||||
'start' => ($time && $time > 0) ? $time : 0,
|
||||
];
|
||||
|
||||
$data = $this->process('newsletter', $post);
|
||||
return in_array($data->status ?? '', ['success', 'already_queued'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Listázza az elérhető híreveleket.
|
||||
*
|
||||
* @return object API válasz tömbbel
|
||||
* @throws RuntimeException Lásd: process()
|
||||
*/
|
||||
public function get(): object
|
||||
{
|
||||
return $this->process('newsletter', ['get' => true]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Campaign
|
||||
// ---------------------------------------------------------------------------
|
||||
// Kampány
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Kampányok létrehozása, törlése és konfigurálása.
|
||||
*/
|
||||
class ninjaMailCampaign extends ninjaMail
|
||||
{
|
||||
private $campaign;
|
||||
private int $campaign = 0;
|
||||
|
||||
public function campaign($id = false)
|
||||
{
|
||||
if (!$id)
|
||||
return $this->campaign;
|
||||
/**
|
||||
* Lekérdezi vagy beállítja az aktuális kampány azonosítóját.
|
||||
*
|
||||
* @param int|false $id Kampány azonosítója beállításhoz; false = lekérdezés
|
||||
* @return int|bool Lekérdezési módban az aktuális azonosítót adja vissza;
|
||||
* beállítási módban true/false
|
||||
*/
|
||||
public function campaign(int|false $id = false): int|bool
|
||||
{
|
||||
if ($id === false) {
|
||||
return $this->campaign;
|
||||
}
|
||||
if ($id > 0) {
|
||||
$this->campaign = $id;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_numeric($id))
|
||||
{
|
||||
$this->campaign = $id;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Új kampányt hoz létre.
|
||||
*
|
||||
* @param string $name A kampány neve
|
||||
* @return int|false Az új kampány azonosítója, vagy false hiba esetén
|
||||
* @throws InvalidArgumentException Ha a név üres
|
||||
* @throws RuntimeException Lásd: process()
|
||||
*/
|
||||
public function create(string $name): int|false
|
||||
{
|
||||
if (trim($name) === '') {
|
||||
throw new InvalidArgumentException(
|
||||
'ninjaMailCampaign: a kampány neve nem lehet üres.'
|
||||
);
|
||||
}
|
||||
|
||||
public function create($name)
|
||||
{
|
||||
$post = [
|
||||
'new' => true,
|
||||
'name' => $name
|
||||
];
|
||||
$data = $this->process('campaign', $post, true);
|
||||
if ($data->status == 'success')
|
||||
{
|
||||
$this->campaign = $data->id;
|
||||
return $data->id;
|
||||
}
|
||||
$post = [
|
||||
'new' => true,
|
||||
'name' => $name,
|
||||
];
|
||||
|
||||
return false;
|
||||
}
|
||||
$data = $this->process('campaign', $post);
|
||||
if (($data->status ?? '') === 'success' && isset($data->id) && is_numeric($data->id)) {
|
||||
$this->campaign = (int)$data->id;
|
||||
return $this->campaign;
|
||||
}
|
||||
|
||||
public function remove()
|
||||
{
|
||||
$post = [
|
||||
'remove' => true,
|
||||
'id' => $this->campaign
|
||||
];
|
||||
return $this->process('campaign', $post, true)->status == 'success' ? true : false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function update($lists)
|
||||
{
|
||||
if (!is_array($lists))
|
||||
return false;
|
||||
/**
|
||||
* Törli az aktuális kampányt.
|
||||
*
|
||||
* @return bool true sikeres törlés esetén
|
||||
* @throws InvalidArgumentException Ha nincs kampány kiválasztva
|
||||
* @throws RuntimeException Lásd: process()
|
||||
*/
|
||||
public function remove(): bool
|
||||
{
|
||||
if ($this->campaign <= 0) {
|
||||
throw new InvalidArgumentException(
|
||||
'ninjaMailCampaign: kampány azonosítója nincs beállítva a törléshez.'
|
||||
);
|
||||
}
|
||||
|
||||
$post = [
|
||||
'update' => true,
|
||||
'id' => $this->campaign,
|
||||
'lists' => $lists
|
||||
];
|
||||
return $this->process('campaign', $post, true)->status == 'success' ? true : false;
|
||||
}
|
||||
$post = [
|
||||
'remove' => true,
|
||||
'id' => $this->campaign,
|
||||
];
|
||||
|
||||
public function attach($newsletter)
|
||||
{
|
||||
if (!is_numeric($newsletter))
|
||||
return false;
|
||||
return ($this->process('campaign', $post)->status ?? '') === 'success';
|
||||
}
|
||||
|
||||
$post = [
|
||||
'relations' => true,
|
||||
'id' => $this->campaign,
|
||||
'newsletter' => $newsletter
|
||||
];
|
||||
return $this->process('campaign', $post, true)->status == 'success' ? true : false;
|
||||
}
|
||||
/**
|
||||
* Listákat rendel a kampányhoz.
|
||||
*
|
||||
* @param int[] $lists Lista azonosítók tömbje
|
||||
* @return bool true sikeres frissítés esetén
|
||||
* @throws InvalidArgumentException Ha a $lists üres vagy nincs kampány beállítva
|
||||
* @throws RuntimeException Lásd: process()
|
||||
*/
|
||||
public function update(array $lists): bool
|
||||
{
|
||||
if (empty($lists)) {
|
||||
throw new InvalidArgumentException(
|
||||
'ninjaMailCampaign: legalább egy lista azonosítója szükséges.'
|
||||
);
|
||||
}
|
||||
if ($this->campaign <= 0) {
|
||||
throw new InvalidArgumentException(
|
||||
'ninjaMailCampaign: kampány azonosítója nincs beállítva a frissítéshez.'
|
||||
);
|
||||
}
|
||||
|
||||
$post = [
|
||||
'update' => true,
|
||||
'id' => $this->campaign,
|
||||
'lists' => $lists,
|
||||
];
|
||||
|
||||
return ($this->process('campaign', $post)->status ?? '') === 'success';
|
||||
}
|
||||
|
||||
/**
|
||||
* Hírlevelet csatol a kampányhoz.
|
||||
*
|
||||
* @param int $newsletter A csatolni kívánt hírlevél azonosítója
|
||||
* @return bool true sikeres csatolás esetén
|
||||
* @throws InvalidArgumentException Ha az azonosító érvénytelen vagy nincs kampány beállítva
|
||||
* @throws RuntimeException Lásd: process()
|
||||
*/
|
||||
public function attach(int $newsletter): bool
|
||||
{
|
||||
if ($newsletter <= 0) {
|
||||
throw new InvalidArgumentException(
|
||||
'ninjaMailCampaign: érvénytelen hírlevél azonosító.'
|
||||
);
|
||||
}
|
||||
if ($this->campaign <= 0) {
|
||||
throw new InvalidArgumentException(
|
||||
'ninjaMailCampaign: kampány azonosítója nincs beállítva a csatoláshoz.'
|
||||
);
|
||||
}
|
||||
|
||||
$post = [
|
||||
'relations' => true,
|
||||
'campaign' => $this->campaign,
|
||||
'id' => $this->campaign,
|
||||
'newsletter' => $newsletter,
|
||||
];
|
||||
|
||||
return ($this->process('campaign', $post)->status ?? '') === 'success';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Statistics
|
||||
// ---------------------------------------------------------------------------
|
||||
// Statisztika
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Hírlevél-statisztikák lekérdezése.
|
||||
*/
|
||||
class ninjaMailStatistics extends ninjaMail
|
||||
{
|
||||
/**
|
||||
* Statisztikát kér le egy adott hírlevélről.
|
||||
*
|
||||
* @param int $id A hírlevél azonosítója
|
||||
* @return object Az API statisztikai válasza
|
||||
* @throws InvalidArgumentException Ha az azonosító érvénytelen
|
||||
* @throws RuntimeException Lásd: process()
|
||||
*/
|
||||
public function get(int $id): object
|
||||
{
|
||||
if ($id <= 0) {
|
||||
throw new InvalidArgumentException(
|
||||
'ninjaMailStatistics: érvénytelen hírlevél azonosító.'
|
||||
);
|
||||
}
|
||||
|
||||
public function get($id)
|
||||
{
|
||||
if (!is_numeric($id))
|
||||
return false;
|
||||
|
||||
$post = [
|
||||
'newsletter' => $id,
|
||||
'type' => 1
|
||||
];
|
||||
return $this->process('statistics', $post, true);
|
||||
}
|
||||
$post = [
|
||||
'newsletter' => $id,
|
||||
'type' => 1,
|
||||
];
|
||||
|
||||
return $this->process('statistics', $post);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user