force json response format, fix subscriber endpoint

Cette révision appartient à :
Daniel Seifert 2024-12-29 00:46:28 +01:00
Parent 59f927af32
révision ccdac0c4a0
Signé par: DanielS
ID de la clé GPG: 6A513E13AEE66170
4 fichiers modifiés avec 147 ajouts et 94 suppressions

Voir le fichier

@ -1,5 +1,18 @@
<?php
/**
* Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
* @link https://www.oxidmodule.com
*/
namespace D3\KlicktippPhpClient\Resources;
use D3\KlicktippPhpClient\Exceptions\BaseException;
@ -9,34 +22,32 @@ use GuzzleHttp\RequestOptions;
class Account extends Model
{
/**
* @throws BaseException|GuzzleException
* @throws BaseException
*/
public function login(): array
{
$response = $this->connection->request(
return $this->connection->requestAndParse(
'POST',
'account/login',
'account/login.json',
[
RequestOptions::FORM_PARAMS => [
'username' => $this->connection->getClientKey(),
'password' => $this->connection->getSecretKey()
]
'password' => $this->connection->getSecretKey(),
],
]
);
return $this->connection->parseResponse($response);
}
/**
* @throws BaseException|GuzzleException
* @throws BaseException
*/
public function logout(): bool
{
$response = $this->connection->requestAndParse(
'POST',
'account/logout'
'account/logout.json'
);
return (bool) current($response);
return (bool)current($response);
}
}

Voir le fichier

@ -1,21 +1,33 @@
<?php
/**
* Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
* @link https://www.oxidmodule.com
*/
namespace D3\KlicktippPhpClient\Resources;
use D3\KlicktippPhpClient\Entities\FieldList;
use D3\KlicktippPhpClient\Exceptions\BaseException;
use GuzzleHttp\Exception\GuzzleException;
class Field extends Model
{
/**
* @throws BaseException|GuzzleException
* @throws BaseException
*/
public function index(): FieldList
{
$data = $this->connection->requestAndParse(
'GET',
'field'
'field.json'
);
return new FieldList($data);

Voir le fichier

@ -1,5 +1,18 @@
<?php
/**
* Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
* @link https://www.oxidmodule.com
*/
namespace D3\KlicktippPhpClient\Resources;
use D3\KlicktippPhpClient\Connection;

Voir le fichier

@ -1,5 +1,18 @@
<?php
/**
* Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
* @link https://www.oxidmodule.com
*/
namespace D3\KlicktippPhpClient\Resources;
use D3\KlicktippPhpClient\Entities\Subscriber as SubscriberEntity;
@ -11,195 +24,199 @@ use GuzzleHttp\RequestOptions;
class Subscriber extends Model
{
/**
* @throws BaseException|GuzzleException
* @throws BaseException
*/
public function index(): SubscriberList
{
$data = $this->connection->requestAndParse(
'GET',
'subscriber'
'subscriber.json'
);
return new SubscriberList($data);
}
/**
* @throws BaseException|GuzzleException
* @throws BaseException
*/
public function get(string $subscriberId): SubscriberEntity
{
$data = $this->connection->requestAndParse(
'GET',
'subscriber/'.urlencode(trim($subscriberId))
'subscriber/'.urlencode(trim($subscriberId)).'.json'
);
return new SubscriberEntity($data);
}
/**
* @throws BaseException|GuzzleException
* @throws BaseException
*/
public function search(string $mailAddress): string
{
return current(
$this->connection->requestAndParse(
'POST',
'subscriber/search',
[
RequestOptions::FORM_PARAMS => [
'email' => trim($mailAddress)
]
]
)
);
}
/**
* @throws BaseException|GuzzleException
*/
public function subscribe(
string $mailAddress,
string $listId,
string $tagId,
array $fields,
string $smsNumber
): string
{
return current(
$this->connection->requestAndParse(
'POST',
'subscriber',
'subscriber/search.json',
[
RequestOptions::FORM_PARAMS => [
'email' => trim($mailAddress),
'listid' => trim($listId),
'tagid' => trim($tagId),
'fields' => array_filter($fields),
'smsnumber' => trim($smsNumber),
]
],
]
)
);
}
/**
* @throws BaseException|GuzzleException
* @throws BaseException
*/
public function unsubscribe(string $mailAddress): string
{
public function subscribe(
string $mailAddress,
?string $listId = null,
?string $tagId = null,
?array $fields = null,
?string $smsNumber = null,
): string {
return current(
$this->connection->requestAndParse(
'POST',
'subscriber/unsubscribe',
'subscriber.json',
[
RequestOptions::FORM_PARAMS => [
'email' => trim($mailAddress)
]
RequestOptions::FORM_PARAMS => array_filter(
[
'email' => trim($mailAddress),
'listid' => trim($listId ?? ''),
'tagid' => trim($tagId ?? ''),
'fields' => array_filter($fields ?? []),
'smsnumber' => trim($smsNumber ?? ''),
]
),
]
)
);
}
/**
* @throws BaseException|GuzzleException
* @throws BaseException
*/
public function unsubscribe(string $mailAddress): bool
{
return (bool) current(
$this->connection->requestAndParse(
'POST',
'subscriber/unsubscribe.json',
[
RequestOptions::FORM_PARAMS => [
'email' => trim($mailAddress),
],
]
)
);
}
/**
* @throws BaseException
*/
public function tag(string $mailAddress, array $tagIds): string
{
return current(
$this->connection->requestAndParse(
'POST',
'subscriber/tag',
'subscriber/tag.json',
[
RequestOptions::FORM_PARAMS => [
'email' => trim($mailAddress),
//ToDo: apply trim to array
'tagids' => $tagIds
]
'tagids' => implode(',', array_filter(
array_map('trim', $tagIds)
)),
],
]
)
);
}
/**
* @throws BaseException|GuzzleException
* @throws BaseException
*/
public function untag(string $mailAddress, string $tagId): string
{
return current(
$this->connection->requestAndParse(
'POST',
'subscriber/search',
'subscriber/untag.json',
[
RequestOptions::FORM_PARAMS => [
'email' => trim($mailAddress),
'tagid' => trim($tagId)
]
'tagid' => trim($tagId),
],
]
)
);
}
/**
* @throws BaseException|GuzzleException
* @throws BaseException
*/
public function tagged(string $tagId): string
public function tagged(string $tagId): array
{
return current(
$this->connection->requestAndParse(
'POST',
'subscriber/tagged',
[
RequestOptions::FORM_PARAMS => [
'tagid' => trim($tagId)
]
]
)
);
return $this->connection->requestAndParse(
'POST',
'subscriber/tagged.json',
[
RequestOptions::FORM_PARAMS => [
'tagid' => trim($tagId),
],
]
) ?? [];
}
/**
* @throws BaseException|GuzzleException
* @throws BaseException
*/
public function update(string $subscriberId, array $fields, string $newEmail = '', string $newSmsNumber = ''): string
{
public function update(
string $subscriberId,
array $fields,
string $newEmail = '',
string $newSmsNumber = ''
): string {
return current(
$this->connection->requestAndParse(
'PUT',
'subscriber/'.urlencode(trim($subscriberId)),
'subscriber/'.urlencode(trim($subscriberId)).'.json',
[
RequestOptions::FORM_PARAMS => [
//ToDo: apply trim to array
'fields' => $fields,
'fields' => array_filter(array_map('trim', $fields)),
'newemail' => trim($newEmail),
'newsmsnumber' => trim($newSmsNumber),
]
],
]
)
);
}
/**
* @throws BaseException|GuzzleException
* @throws BaseException
*/
public function delete(string $subscriberId): string
{
return current(
$this->connection->requestAndParse(
'DELETE',
'subscriber/'.urlencode(trim($subscriberId))
'subscriber/'.urlencode(trim($subscriberId)).'.json'
)
);
}
/**
* @throws BaseException|GuzzleException
* @throws BaseException
*/
public function signin(string $apikey, string $emailAddress, array $fields, string $smsNumber): string
{
return current(
$this->connection->requestAndParse(
'POST',
'subscriber/signin',
'subscriber/signin.json',
[
RequestOptions::FORM_PARAMS => [
'apikey' => trim($apikey),
@ -207,45 +224,45 @@ class Subscriber extends Model
//ToDo: apply trim to array
'fields' => $fields,
'smsnumber' => trim($smsNumber),
]
],
]
)
);
}
/**
* @throws BaseException|GuzzleException
* @throws BaseException
*/
public function signout(string $apikey, string $emailAddress): string
{
return current(
$this->connection->requestAndParse(
'POST',
'subscriber/signout',
'subscriber/signout.json',
[
RequestOptions::FORM_PARAMS => [
'apikey' => trim($apikey),
'email' => trim($emailAddress),
]
],
]
)
);
}
/**
* @throws BaseException|GuzzleException
* @throws BaseException
*/
public function signoff(string $apikey, string $emailAddress): string
{
return current(
$this->connection->requestAndParse(
'POST',
'subscriber/signoff',
'subscriber/signoff.json',
[
RequestOptions::FORM_PARAMS => [
'apikey' => trim($apikey),
'email' => trim($emailAddress),
]
],
]
)
);