force json response format, fix subscriber endpoint
This commit is contained in:
bovenliggende
59f927af32
commit
ccdac0c4a0
@ -1,5 +1,18 @@
|
|||||||
<?php
|
<?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;
|
namespace D3\KlicktippPhpClient\Resources;
|
||||||
|
|
||||||
use D3\KlicktippPhpClient\Exceptions\BaseException;
|
use D3\KlicktippPhpClient\Exceptions\BaseException;
|
||||||
@ -9,32 +22,30 @@ use GuzzleHttp\RequestOptions;
|
|||||||
class Account extends Model
|
class Account extends Model
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @throws BaseException|GuzzleException
|
* @throws BaseException
|
||||||
*/
|
*/
|
||||||
public function login(): array
|
public function login(): array
|
||||||
{
|
{
|
||||||
$response = $this->connection->request(
|
return $this->connection->requestAndParse(
|
||||||
'POST',
|
'POST',
|
||||||
'account/login',
|
'account/login.json',
|
||||||
[
|
[
|
||||||
RequestOptions::FORM_PARAMS => [
|
RequestOptions::FORM_PARAMS => [
|
||||||
'username' => $this->connection->getClientKey(),
|
'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
|
public function logout(): bool
|
||||||
{
|
{
|
||||||
$response = $this->connection->requestAndParse(
|
$response = $this->connection->requestAndParse(
|
||||||
'POST',
|
'POST',
|
||||||
'account/logout'
|
'account/logout.json'
|
||||||
);
|
);
|
||||||
|
|
||||||
return (bool)current($response);
|
return (bool)current($response);
|
||||||
|
@ -1,21 +1,33 @@
|
|||||||
<?php
|
<?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;
|
namespace D3\KlicktippPhpClient\Resources;
|
||||||
|
|
||||||
use D3\KlicktippPhpClient\Entities\FieldList;
|
use D3\KlicktippPhpClient\Entities\FieldList;
|
||||||
use D3\KlicktippPhpClient\Exceptions\BaseException;
|
use D3\KlicktippPhpClient\Exceptions\BaseException;
|
||||||
use GuzzleHttp\Exception\GuzzleException;
|
|
||||||
|
|
||||||
class Field extends Model
|
class Field extends Model
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @throws BaseException|GuzzleException
|
* @throws BaseException
|
||||||
*/
|
*/
|
||||||
public function index(): FieldList
|
public function index(): FieldList
|
||||||
{
|
{
|
||||||
$data = $this->connection->requestAndParse(
|
$data = $this->connection->requestAndParse(
|
||||||
'GET',
|
'GET',
|
||||||
'field'
|
'field.json'
|
||||||
);
|
);
|
||||||
|
|
||||||
return new FieldList($data);
|
return new FieldList($data);
|
||||||
|
@ -1,5 +1,18 @@
|
|||||||
<?php
|
<?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;
|
namespace D3\KlicktippPhpClient\Resources;
|
||||||
|
|
||||||
use D3\KlicktippPhpClient\Connection;
|
use D3\KlicktippPhpClient\Connection;
|
||||||
|
@ -1,5 +1,18 @@
|
|||||||
<?php
|
<?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;
|
namespace D3\KlicktippPhpClient\Resources;
|
||||||
|
|
||||||
use D3\KlicktippPhpClient\Entities\Subscriber as SubscriberEntity;
|
use D3\KlicktippPhpClient\Entities\Subscriber as SubscriberEntity;
|
||||||
@ -11,195 +24,199 @@ use GuzzleHttp\RequestOptions;
|
|||||||
class Subscriber extends Model
|
class Subscriber extends Model
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @throws BaseException|GuzzleException
|
* @throws BaseException
|
||||||
*/
|
*/
|
||||||
public function index(): SubscriberList
|
public function index(): SubscriberList
|
||||||
{
|
{
|
||||||
$data = $this->connection->requestAndParse(
|
$data = $this->connection->requestAndParse(
|
||||||
'GET',
|
'GET',
|
||||||
'subscriber'
|
'subscriber.json'
|
||||||
);
|
);
|
||||||
|
|
||||||
return new SubscriberList($data);
|
return new SubscriberList($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws BaseException|GuzzleException
|
* @throws BaseException
|
||||||
*/
|
*/
|
||||||
public function get(string $subscriberId): SubscriberEntity
|
public function get(string $subscriberId): SubscriberEntity
|
||||||
{
|
{
|
||||||
$data = $this->connection->requestAndParse(
|
$data = $this->connection->requestAndParse(
|
||||||
'GET',
|
'GET',
|
||||||
'subscriber/'.urlencode(trim($subscriberId))
|
'subscriber/'.urlencode(trim($subscriberId)).'.json'
|
||||||
);
|
);
|
||||||
|
|
||||||
return new SubscriberEntity($data);
|
return new SubscriberEntity($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws BaseException|GuzzleException
|
* @throws BaseException
|
||||||
*/
|
*/
|
||||||
public function search(string $mailAddress): string
|
public function search(string $mailAddress): string
|
||||||
{
|
{
|
||||||
return current(
|
return current(
|
||||||
$this->connection->requestAndParse(
|
$this->connection->requestAndParse(
|
||||||
'POST',
|
'POST',
|
||||||
'subscriber/search',
|
'subscriber/search.json',
|
||||||
[
|
|
||||||
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',
|
|
||||||
[
|
[
|
||||||
RequestOptions::FORM_PARAMS => [
|
RequestOptions::FORM_PARAMS => [
|
||||||
'email' => trim($mailAddress),
|
'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(
|
return current(
|
||||||
$this->connection->requestAndParse(
|
$this->connection->requestAndParse(
|
||||||
'POST',
|
'POST',
|
||||||
'subscriber/unsubscribe',
|
'subscriber.json',
|
||||||
[
|
[
|
||||||
RequestOptions::FORM_PARAMS => [
|
RequestOptions::FORM_PARAMS => array_filter(
|
||||||
'email' => trim($mailAddress)
|
[
|
||||||
|
'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
|
public function tag(string $mailAddress, array $tagIds): string
|
||||||
{
|
{
|
||||||
return current(
|
return current(
|
||||||
$this->connection->requestAndParse(
|
$this->connection->requestAndParse(
|
||||||
'POST',
|
'POST',
|
||||||
'subscriber/tag',
|
'subscriber/tag.json',
|
||||||
[
|
[
|
||||||
RequestOptions::FORM_PARAMS => [
|
RequestOptions::FORM_PARAMS => [
|
||||||
'email' => trim($mailAddress),
|
'email' => trim($mailAddress),
|
||||||
//ToDo: apply trim to array
|
'tagids' => implode(',', array_filter(
|
||||||
'tagids' => $tagIds
|
array_map('trim', $tagIds)
|
||||||
]
|
)),
|
||||||
|
],
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws BaseException|GuzzleException
|
* @throws BaseException
|
||||||
*/
|
*/
|
||||||
public function untag(string $mailAddress, string $tagId): string
|
public function untag(string $mailAddress, string $tagId): string
|
||||||
{
|
{
|
||||||
return current(
|
return current(
|
||||||
$this->connection->requestAndParse(
|
$this->connection->requestAndParse(
|
||||||
'POST',
|
'POST',
|
||||||
'subscriber/search',
|
'subscriber/untag.json',
|
||||||
[
|
[
|
||||||
RequestOptions::FORM_PARAMS => [
|
RequestOptions::FORM_PARAMS => [
|
||||||
'email' => trim($mailAddress),
|
'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(
|
return $this->connection->requestAndParse(
|
||||||
$this->connection->requestAndParse(
|
|
||||||
'POST',
|
'POST',
|
||||||
'subscriber/tagged',
|
'subscriber/tagged.json',
|
||||||
[
|
[
|
||||||
RequestOptions::FORM_PARAMS => [
|
RequestOptions::FORM_PARAMS => [
|
||||||
'tagid' => trim($tagId)
|
'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(
|
return current(
|
||||||
$this->connection->requestAndParse(
|
$this->connection->requestAndParse(
|
||||||
'PUT',
|
'PUT',
|
||||||
'subscriber/'.urlencode(trim($subscriberId)),
|
'subscriber/'.urlencode(trim($subscriberId)).'.json',
|
||||||
[
|
[
|
||||||
RequestOptions::FORM_PARAMS => [
|
RequestOptions::FORM_PARAMS => [
|
||||||
//ToDo: apply trim to array
|
//ToDo: apply trim to array
|
||||||
'fields' => $fields,
|
'fields' => array_filter(array_map('trim', $fields)),
|
||||||
'newemail' => trim($newEmail),
|
'newemail' => trim($newEmail),
|
||||||
'newsmsnumber' => trim($newSmsNumber),
|
'newsmsnumber' => trim($newSmsNumber),
|
||||||
]
|
],
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws BaseException|GuzzleException
|
* @throws BaseException
|
||||||
*/
|
*/
|
||||||
public function delete(string $subscriberId): string
|
public function delete(string $subscriberId): string
|
||||||
{
|
{
|
||||||
return current(
|
return current(
|
||||||
$this->connection->requestAndParse(
|
$this->connection->requestAndParse(
|
||||||
'DELETE',
|
'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
|
public function signin(string $apikey, string $emailAddress, array $fields, string $smsNumber): string
|
||||||
{
|
{
|
||||||
return current(
|
return current(
|
||||||
$this->connection->requestAndParse(
|
$this->connection->requestAndParse(
|
||||||
'POST',
|
'POST',
|
||||||
'subscriber/signin',
|
'subscriber/signin.json',
|
||||||
[
|
[
|
||||||
RequestOptions::FORM_PARAMS => [
|
RequestOptions::FORM_PARAMS => [
|
||||||
'apikey' => trim($apikey),
|
'apikey' => trim($apikey),
|
||||||
@ -207,45 +224,45 @@ class Subscriber extends Model
|
|||||||
//ToDo: apply trim to array
|
//ToDo: apply trim to array
|
||||||
'fields' => $fields,
|
'fields' => $fields,
|
||||||
'smsnumber' => trim($smsNumber),
|
'smsnumber' => trim($smsNumber),
|
||||||
]
|
],
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws BaseException|GuzzleException
|
* @throws BaseException
|
||||||
*/
|
*/
|
||||||
public function signout(string $apikey, string $emailAddress): string
|
public function signout(string $apikey, string $emailAddress): string
|
||||||
{
|
{
|
||||||
return current(
|
return current(
|
||||||
$this->connection->requestAndParse(
|
$this->connection->requestAndParse(
|
||||||
'POST',
|
'POST',
|
||||||
'subscriber/signout',
|
'subscriber/signout.json',
|
||||||
[
|
[
|
||||||
RequestOptions::FORM_PARAMS => [
|
RequestOptions::FORM_PARAMS => [
|
||||||
'apikey' => trim($apikey),
|
'apikey' => trim($apikey),
|
||||||
'email' => trim($emailAddress),
|
'email' => trim($emailAddress),
|
||||||
]
|
],
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws BaseException|GuzzleException
|
* @throws BaseException
|
||||||
*/
|
*/
|
||||||
public function signoff(string $apikey, string $emailAddress): string
|
public function signoff(string $apikey, string $emailAddress): string
|
||||||
{
|
{
|
||||||
return current(
|
return current(
|
||||||
$this->connection->requestAndParse(
|
$this->connection->requestAndParse(
|
||||||
'POST',
|
'POST',
|
||||||
'subscriber/signoff',
|
'subscriber/signoff.json',
|
||||||
[
|
[
|
||||||
RequestOptions::FORM_PARAMS => [
|
RequestOptions::FORM_PARAMS => [
|
||||||
'apikey' => trim($apikey),
|
'apikey' => trim($apikey),
|
||||||
'email' => trim($emailAddress),
|
'email' => trim($emailAddress),
|
||||||
]
|
],
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
Laden…
x
Verwijs in nieuw issue
Block a user