diff --git a/CHANGELOG b/CHANGELOG
index c7166eb..ddcd217 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,7 @@
+Date 2025-11-17
+Version 1.12.1
+- Fix encoding issue in path for unsubscribeContactByExternalId
+
Date 2025-09-18
Version 1.12.0
- Added support for param trash in mailing endpoints
diff --git a/README.md b/README.md
index 0856330..cb7a02f 100644
--- a/README.md
+++ b/README.md
@@ -18,7 +18,7 @@ Maileon's REST API documentation can be found [here](https://maileon.com/support
The API client requires `PHP >= 7.0` with `libxml` and `libcurl`.
-Additionally all requests use an SSL encrypted API endpoint.
+Additionally, all requests use an SSL encrypted API endpoint.
To enable SSL support in CURL, please follow these steps:
1. Download the official SSL cert bundle by CURL from https://curl.haxx.se/ca/cacert.pem
2. Save the bundle to a directory that can be accessed by your PHP installation
@@ -38,7 +38,7 @@ composer require xqueue/maileon-api-client
## Usage
-The API client divides the features of Maileon's REST API into specific consumable services. Each service provides all functions of it's specific category.
+The API client divides the features of Maileon's REST API into specific consumable services. Each service provides all functions of its specific category.
The following services are available:
@@ -48,8 +48,8 @@ Read, subscribe, edit, unsubscribe or delete contacts. Functions for individual
* **Blacklists**
Manage your blacklists.
-* **Contactfilters**
-Segmentate your address pool by filter rules.
+* **Contact filters**
+Segment your address pool by filter rules.
* **Targetgroups**
Manage distribution lists to specify who gets which mailing.
@@ -106,7 +106,7 @@ $contact = $contactsService->getContactByEmail('foo@bar.com')->getResult();
*/
```
-* Request a contact identified by it's email address including their first name and a predefined custom field and also check for a valid response:
+* Request a contact identified by its email address including their first name and a predefined custom field and also check for a valid response:
```php
getResult() as $unsubscriber) {
- printf('%s unsusbcribed in mailing %u at %s'.PHP_EOL,
+ printf('%s unsubscribed in mailing %u at %s'.PHP_EOL,
$unsubscriber->contact->email,
$unsubscriber->mailingId,
$unsubscriber->timestamp
);
}
-} while($getUnsubscribers->getResponseHeaders()['X-Pages'] >= $index);
+} while($getUnsubscribers->getResponseHeader('x-pages') >= $index);
```
* Get [KPI](https://kpi.org/KPI-Basics) data for a specific mailing:
diff --git a/composer.json b/composer.json
index eefa8ef..b129fe5 100644
--- a/composer.json
+++ b/composer.json
@@ -22,9 +22,12 @@
"require" : {
"php" : "^7.0|^8.0",
"ext-curl" : "*",
- "ext-mbstring" : "*",
- "ext-libxml" : "*"
- },
+ "ext-dom": "*",
+ "ext-json": "*",
+ "ext-libxml" : "*",
+ "ext-mbstring" : "*",
+ "ext-simplexml": "*"
+ },
"require-dev" : {
"phpunit/phpunit" : "^4",
"phpstan/phpstan": "^1.8"
diff --git a/src/AbstractMaileonService.php b/src/AbstractMaileonService.php
index 4bbe0e9..fff9863 100644
--- a/src/AbstractMaileonService.php
+++ b/src/AbstractMaileonService.php
@@ -2,17 +2,36 @@
namespace de\xqueue\maileon\api\client;
-use CurlHandle;
use de\xqueue\maileon\api\client\contacts\PreferenceCategory;
+use Exception;
use RuntimeException;
+use function array_key_exists;
+use function base64_encode;
+use function curl_close;
+use function curl_errno;
+use function curl_error;
+use function curl_exec;
+use function curl_init;
+use function curl_setopt;
+use function curl_setopt_array;
+use function defined;
+use function fopen;
+use function htmlentities;
+use function is_array;
+use function preg_replace;
+use function rewind;
+use function rtrim;
+use function stream_get_contents;
+use function urlencode;
+
/**
* Abstract base class for all the service accessing individual resources. This class handles
* the basic authentication and provides convenience methods to access the four HTTP methods
* used in RESTful web services.
*
* @author Felix Heinrichs
- * @author Marcus Beckerle
+ * @author Marcus Beckerle | XQueue GmbH | marcus.beckerle@xqueue.com
*/
abstract class AbstractMaileonService
{
@@ -20,80 +39,83 @@ abstract class AbstractMaileonService
/**
* Mime type for the maileon xml data format.
*
- * @var string $MAILEON_XML_MIME_TYPE
+ * @var string
*/
public static $MAILEON_XML_MIME_TYPE = 'application/vnd.maileon.api+xml';
/**
* Configuration object storing BASE_URI and API_KEY to access the maileon REST API.
*
- * @var array $configuration
+ * @var array
*/
protected $configuration;
/**
* Base64 encoded version of the API key.
*
- * @var string $encodedApiKey
+ * @var string
*/
protected $encodedApiKey;
/**
* If true, print debug output (e.g. sent header will be printed)
*
- * @var boolean $debug
+ * @var boolean
*/
protected $debug = false;
/**
- * If true, throw an exception if a transmission or server error occures
+ * If true, throw an exception if a transmission or server error occurs
*
- * @var boolean $throwException
+ * @var boolean
*/
protected $throwException = true;
/**
* If a proxy is used, provide the proxy IP here
*
- * @var string $proxy_host
+ * @var string
*/
protected $proxy_host;
/**
* If a proxy is used, use this port. Default is 80.
*
- * @var int $proxy_port
+ * @var int
*/
protected $proxy_port = 80;
/**
* If set, this sets the timeout for a CURL request
*
- * @var int $timeout
+ * @var int
*/
protected $timeout = 5;
- private $verboseOut = null;
+ private $verboseOut;
/**
* Creates a new instance of the service.
*
- * @param string[] $config
- * the API call configuration array
+ * @param string[] $config The API call configuration array
+ *
* @throws RuntimeException if API key is not set
*/
public function __construct(array $config)
{
// check for valid configuration object
- if (!array_key_exists('API_KEY', $config)) {
+ if (! array_key_exists('API_KEY', $config)) {
throw new RuntimeException('API_KEY not set');
}
- if (!array_key_exists('BASE_URI', $config)) {
- $config['BASE_URI'] = "https://api.maileon.com/1.0";
+
+ if (! array_key_exists('BASE_URI', $config)) {
+ $config['BASE_URI'] = 'https://api.maileon.com/1.0';
}
+
if (array_key_exists('THROW_EXCEPTION', $config)) {
$this->throwException = $config['THROW_EXCEPTION'];
}
+
if (array_key_exists('DEBUG', $config)) {
$this->debug = $config['DEBUG'];
}
@@ -102,6 +124,7 @@ public function __construct(array $config)
if (array_key_exists('PROXY_HOST', $config)) {
$this->proxy_host = $config['PROXY_HOST'];
}
+
if (array_key_exists('PROXY_PORT', $config)) {
$this->proxy_port = $config['PROXY_PORT'];
}
@@ -110,6 +133,7 @@ public function __construct(array $config)
if (array_key_exists('TIMEOUT', $config)) {
$this->timeout = $config['TIMEOUT'];
}
+
$this->configuration = $config;
$this->encodedApiKey = base64_encode($config['API_KEY']);
}
@@ -118,8 +142,7 @@ public function __construct(array $config)
* (De)activates printing debug output.
* CAUTION: enabling this in production may compromise sensitive information.
*
- * @param bool $isDebug
- * true to enable debugging, false to disable it
+ * @param bool $isDebug true to enable debugging, false to disable it
*/
public function setDebug($isDebug)
{
@@ -127,8 +150,7 @@ public function setDebug($isDebug)
}
/**
- * @return boolean
- * true if debug output is enabled, false otherwise
+ * @return boolean true if debug output is enabled, false otherwise
*/
public function isDebug()
{
@@ -138,53 +160,45 @@ public function isDebug()
/**
* Performs a GET operation on a resource
*
- * @param string $resourcePath
- * the path of the resource to GET
- * @param string[] $queryParameters
- * any additional query parameters
- * @param string $mimeType
- * the acceptable response MIME type
- * @param mixed $deserializationType
- * The name of the class this result should be deserialized as. Use
- * array( 'array', 'typename' ) to deserialize arrays of a type.
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @param string $resourcePath the path of the resource to GET
+ * @param string[] $queryParameters any additional query parameters
+ * @param string $mimeType the acceptable response MIME type
+ * @param mixed $deserializationType The name of the class this result should be deserialized as. Use array( 'array', 'typename' )
+ * to deserialize arrays of a type.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function get(
$resourcePath,
- $queryParameters = array(),
+ $queryParameters = [],
$mimeType = 'application/vnd.maileon.api+xml',
$deserializationType = null
) {
$curlSession = $this->prepareSession($resourcePath, $queryParameters, $mimeType);
+
return $this->performRequest($curlSession, $deserializationType);
}
/**
* Performs a PUT operation (i.e. an update) on a resource.
*
- * @param string $resourcePath
- * the path of the resource to PUT
- * @param string $payload
- * the payload data to PUT, i.e. the data to update the current state of the resource with
- * @param array $queryParameters
- * any additional query parameters
- * @param string $mimeType
- * the acceptable response MIME type
- * @param mixed $deserializationType
- * The name of the class this result should be deserialized as. Use
- * array( 'array', 'typename' ) to deserialize arrays of a type.
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @param string $resourcePath the path of the resource to PUT
+ * @param string $payload the payload data to PUT, i.e. the data to update the current state of the resource with
+ * @param array $queryParameters any additional query parameters
+ * @param string $mimeType the acceptable response MIME type
+ * @param mixed $deserializationType The name of the class this result should be deserialized as. Use array( 'array', 'typename' )
+ * to deserialize arrays of a type.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function put(
$resourcePath,
- $payload = "",
- $queryParameters = array(),
+ $payload = '',
+ $queryParameters = [],
$mimeType = 'application/vnd.maileon.api+xml',
$deserializationType = null
) {
@@ -195,35 +209,31 @@ public function put(
* http://developers.sugarcrm.com/wordpress/2011/11/22/howto-do-put-requests-with-php-curl-without-writing-to-a-file/
* Because of this, we use a custom request here.
*/
- curl_setopt($curlSession, CURLOPT_CUSTOMREQUEST, "PUT");
+ curl_setopt($curlSession, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($curlSession, CURLOPT_POSTFIELDS, $payload);
+
return $this->performRequest($curlSession, $deserializationType);
}
/**
* Performs a POST operation (i.e. creates a new instance) on a resource.
*
- * @param string $resourcePath
- * the path of the resource to POST. This is typically the parent (or owner) resource
- * of the resource instance to create.
- * @param string $payload
- * the data to POST, i.e. the contents of the new resource instance
- * @param array $queryParameters
- * any additional query parameters
- * @param string $mimeType
- * the acceptable response MIME type
- * @param mixed $deserializationType
- * The name of the class this result should be deserialized as. Use
- * array( 'array', 'typename' ) to deserialize arrays of a type.
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @param string $resourcePath the path of the resource to POST. This is typically the parent (or owner) resource of the resource
+ * instance to create.
+ * @param string $payload the data to POST, i.e. the contents of the new resource instance
+ * @param array $queryParameters any additional query parameters
+ * @param string $mimeType the acceptable response MIME type
+ * @param mixed $deserializationType The name of the class this result should be deserialized as. Use array( 'array', 'typename' ) to
+ * deserialize arrays of a type.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function post(
$resourcePath,
- $payload = "",
- $queryParameters = array(),
+ $payload = '',
+ $queryParameters = [],
$mimeType = 'application/vnd.maileon.api+xml',
$deserializationType = null,
$contentType = null,
@@ -232,39 +242,43 @@ public function post(
$curlSession = $this->prepareSession($resourcePath, $queryParameters, $mimeType, $contentType, $contentLength);
curl_setopt($curlSession, CURLOPT_POST, true);
curl_setopt($curlSession, CURLOPT_POSTFIELDS, $payload);
+
return $this->performRequest($curlSession, $deserializationType);
}
/**
* Performs a DELETE operation on a resource.
*
- * @param string $resourcePath
- * the resource to DELETE
- * @param array $queryParameters
- * any additional query parameters
- * @param string $mimeType
- * the acceptable response MIME type
- * @param mixed $deserializationType
- * The name of the class this result should be deserialized as. Use
- * array( 'array', 'typename' ) to deserialize arrays of a type.
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @param string $resourcePath the resource to DELETE
+ * @param array $queryParameters any additional query parameters
+ * @param string $mimeType the acceptable response MIME type
+ * @param mixed $deserializationType The name of the class this result should be deserialized as. Use array( 'array', 'typename' ) to
+ * deserialize arrays of a type.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function delete(
$resourcePath,
- $queryParameters = array(),
+ $queryParameters = [],
$mimeType = 'application/vnd.maileon.api+xml',
$deserializationType = null
) {
$curlSession = $this->prepareSession($resourcePath, $queryParameters, $mimeType);
- curl_setopt($curlSession, CURLOPT_CUSTOMREQUEST, "DELETE");
+ curl_setopt($curlSession, CURLOPT_CUSTOMREQUEST, 'DELETE');
+
return $this->performRequest($curlSession, $deserializationType);
}
/**
- * @return false|CurlHandle
+ * @param $resourcePath
+ * @param $queryParameters
+ * @param $mimeType
+ * @param $contentType
+ * @param $contentLength
+ *
+ * @return false|resource false|CurlHandle|resource
*/
private function prepareSession(
$resourcePath,
@@ -273,46 +287,49 @@ private function prepareSession(
$contentType = null,
$contentLength = null
) {
- $requestUrl = $this->constructRequestUrl($resourcePath, $queryParameters);
- $headers = $this->constructHeaders($mimeType, $contentType, $contentLength);
+ $requestUrl = $this->constructRequestUrl($resourcePath, $queryParameters);
+ $headers = $this->constructHeaders($mimeType, $contentType, $contentLength);
$curlSession = curl_init($requestUrl);
- $options = array(
- CURLOPT_HEADER => true,
+ $options = [
+ CURLOPT_HEADER => true,
CURLOPT_RETURNTRANSFER => true,
- CURLOPT_HTTPHEADER => $headers,
- CURLOPT_FAILONERROR => false,
- CURLOPT_VERBOSE => $this->debug
- );
+ CURLOPT_HTTPHEADER => $headers,
+ CURLOPT_FAILONERROR => false,
+ CURLOPT_VERBOSE => $this->debug,
+ ];
if ($this->debug) {
- $this->verboseOut = fopen("php://temp", "rw+");
+ $this->verboseOut = fopen("php://temp", "rw+");
$options[CURLOPT_STDERR] = $this->verboseOut;
}
if ($this->timeout) {
$options[CURLOPT_CONNECTTIMEOUT] = $this->timeout;
- $options[CURLOPT_TIMEOUT] = $this->timeout;
+ $options[CURLOPT_TIMEOUT] = $this->timeout;
}
if ($this->proxy_host) {
- $options[CURLOPT_PROXY] = $this->proxy_host;
+ $options[CURLOPT_PROXY] = $this->proxy_host;
$options[CURLOPT_PROXYPORT] = $this->proxy_port;
}
curl_setopt_array($curlSession, $options);
+
return $curlSession;
}
- private function constructRequestUrl($resourcePath, $queryParameters)
- {
- $requestUrl = $this->configuration['BASE_URI'] . "/" . $resourcePath;
+ private function constructRequestUrl(
+ $resourcePath,
+ $queryParameters
+ ): string {
+ $requestUrl = $this->configuration['BASE_URI'] . '/' . $resourcePath;
- if (isset($queryParameters) && !empty($queryParameters)) {
- $requestUrl = $requestUrl . '?';
+ if (! empty($queryParameters)) {
+ $requestUrl .= '?';
foreach ($queryParameters as $key => $value) {
- // If the query parameter is an array, then walk through the array, create a multi-
- // valued query string and replace boolean fields with it's string counterpart.
+ // If the query parameter is an array, then walk through the array, create a multivalued
+ // query string and replace boolean fields with its string counterpart.
// Such query parameters usually won't ever occur since Maileon doesn't support them.
// Example query: ?emails[]=foo@bar.baz&emails[]=alice@bob.eve&emails[]=a@b.xy
@@ -332,17 +349,13 @@ private function constructRequestUrl($resourcePath, $queryParameters)
$requestUrl .= $key . '=' . $innerValue . '&';
}
}
- }
-
- // Handle non array query parameters
- else {
- if ($value === true) {
- $requestUrl .= $key . '=true&';
- } elseif ($value === false) {
- $requestUrl .= $key . '=false&';
- } else {
- $requestUrl .= $key . '=' . $value . '&';
- }
+ } // Handle non array query parameters
+ elseif ($value === true) {
+ $requestUrl .= $key . '=true&';
+ } elseif ($value === false) {
+ $requestUrl .= $key . '=false&';
+ } else {
+ $requestUrl .= $key . '=' . $value . '&';
}
}
@@ -352,92 +365,112 @@ private function constructRequestUrl($resourcePath, $queryParameters)
return $requestUrl;
}
- private function constructHeaders($mimeType, $contentType = null, $contentLength = null)
- {
- $headers = array(
- "Content-type: " . ($contentType === null ? $mimeType : $contentType),
- "Accept: " . $mimeType,
- "Authorization: Basic " . $this->encodedApiKey,
- "Expect:"
- );
-
+ private function constructHeaders(
+ $mimeType,
+ $contentType = null,
+ $contentLength = null
+ ): array {
+ $headers = [
+ 'Content-type: ' . ($contentType ?? $mimeType),
+ 'Accept: ' . $mimeType,
+ 'Authorization: Basic ' . $this->encodedApiKey,
+ 'Expect:',
+ ];
+
if ($contentLength !== null) {
- $headers []= "Content-Length: " . $contentLength;
+ $headers [] = 'Content-Length: ' . $contentLength;
}
-
+
return $headers;
}
/**
* Perform the currently initialized request
*
- * @param CurlHandle $curlSession
- * the curl session
- * @param mixed $deserializationType
- * The name of the class this result should be deserialized as. Use
- * array( 'array', 'typename' ) to deserialize arrays of a type.
- * @return MaileonAPIResult
- * @throws MaileonAPIException
+ * @param $curlSession "CurlHandle" or resource the curl session
+ * @param mixed $deserializationType The name of the class this result should be deserialized as. Use array( 'array', 'typename' ) to
+ * deserialize arrays of a type.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- private function performRequest($curlSession, $deserializationType = null)
- {
+ private function performRequest(
+ $curlSession,
+ $deserializationType = null
+ ) {
$response = curl_exec($curlSession);
// coerce all false values to null
- $response = $response ? $response : null;
+ $response = $response ?: null;
try {
$result = new MaileonAPIResult($response, $curlSession, $this->throwException, $deserializationType);
$this->printDebugInformation($curlSession, $result);
curl_close($curlSession);
+
return $result;
} catch (MaileonAPIException $e) {
if ($this->debug) {
$this->printDebugInformation($curlSession, null, $this->throwException ? null : $e);
}
curl_close($curlSession);
+
if ($this->throwException) {
throw $e;
}
+
return null;
}
}
- protected function appendArrayFields($params, $name, $fieldValues)
- {
- if (isset($fieldValues) && is_array($fieldValues) && count($fieldValues) > 0) {
- $params ["$name"] = array();
+ protected function appendArrayFields(
+ $params,
+ $name,
+ $fieldValues
+ ) {
+ if (is_array($fieldValues) && ! empty($fieldValues)) {
+ $params [(string) $name] = [];
+
foreach ($fieldValues as $value) {
if ($value === true) {
- $params ["$name"] [] = "true";
- } else if ($value === false) {
- $params ["$name"] [] = "false";
- } else if ($value instanceof PreferenceCategory) {
- $params[$name] = urlencode((string)$value->name);
+ $params [(string) $name] [] = 'true';
+ } elseif ($value === false) {
+ $params [(string) $name] [] = 'false';
+ } elseif ($value instanceof PreferenceCategory) {
+ $params[$name] = urlencode((string) $value->name);
} else {
- $params ["$name"] [] = urlencode($value);
+ $params [(string) $name] [] = urlencode($value);
}
}
}
+
return $params;
}
- private function printDebugInformation($curlSession, $result = null, $exception = null)
- {
+ private function printDebugInformation(
+ $curlSession,
+ $result = null,
+ $exception = null
+ ) {
if ($this->debug) {
rewind($this->verboseOut);
$sessionLog = stream_get_contents($this->verboseOut);
$sessionLog = preg_replace("/^Authorization: .*$/m", "Authorization: ***redacted***", $sessionLog);
+
if (defined('RUNNING_IN_PHPUNIT') && RUNNING_IN_PHPUNIT) {
echo "\n";
echo "cURL session log:\n";
echo $sessionLog . "\n";
- if ($result != null) {
+
+ if ($result !== null) {
echo "Result:\n";
echo $result->toString() . "\n";
}
- if ($exception != null) {
+
+ if ($exception !== null) {
echo "Caught exception:\n";
echo $exception . "\n";
}
+
if (curl_errno($curlSession)) {
echo "cURL Error: \n";
echo htmlentities(curl_error($curlSession));
@@ -447,18 +480,21 @@ private function printDebugInformation($curlSession, $result = null, $exception
echo "
\n";
echo htmlentities($sessionLog);
echo "\n";
- if ($result != null) {
+
+ if ($result !== null) {
echo "Result
\n";
echo "\n";
echo htmlentities($result->toString());
echo "\n";
}
- if ($exception != null) {
+
+ if ($exception !== null) {
echo "Exception
\n";
echo "\n";
echo htmlentities($exception);
echo "\n";
}
+
if (curl_errno($curlSession)) {
echo "cURL Error
\n";
echo "\n";
@@ -466,6 +502,7 @@ private function printDebugInformation($curlSession, $result = null, $exception
echo "\n";
}
}
+
$this->verboseOut = null;
}
}
diff --git a/src/HTTPResponseCodes.php b/src/HTTPResponseCodes.php
index e5ad137..719b8e5 100644
--- a/src/HTTPResponseCodes.php
+++ b/src/HTTPResponseCodes.php
@@ -2,13 +2,13 @@
namespace de\xqueue\maileon\api\client;
+use function array_key_exists;
+
/**
- * This class allows translating between HTTP response codes and human readable strings
+ * This class allows translating between HTTP response codes and human-readable strings
*
- * @author Felix Heinrichs | Trusted Mails GmbH |
- * felix.heinrichs@trusted-mails.com
- * @author Marcus Ständer | Trusted Mails GmbH |
- * marcus.staender@trusted-mails.com
+ * @author Felix Heinrichs
+ * @author Marcus Beckerle | XQueue GmbH | marcus.beckerle@xqueue.com
*/
abstract class HTTPResponseCodes
{
@@ -126,42 +126,42 @@ abstract class HTTPResponseCodes
*/
const SERVICE_UNAVAILABLE = 503;
- protected static $codes = array(
- 200 => "OK",
- 201 => "Created",
- 202 => "Accepted",
- 204 => "No Content",
- 301 => "Moved Permanently",
- 303 => "See Other",
- 304 => "Not Modified",
- 307 => "Temporary Redirect",
- 400 => "Bad Request",
- 401 => "Unauthorized",
- 403 => "Forbidden",
- 404 => "Not Found",
- 406 => "Not Acceptable",
- 409 => "Conflict",
- 410 => "Gone",
- 412 => "Precondition Failed",
- 415 => "Unsupported Media Type",
- 500 => "Internal Server Error",
- 503 => "Service Unavailable"
- );
+ protected static $codes
+ = [
+ 200 => 'OK',
+ 201 => 'Created',
+ 202 => 'Accepted',
+ 204 => 'No Content',
+ 301 => 'Moved Permanently',
+ 303 => 'See Other',
+ 304 => 'Not Modified',
+ 307 => 'Temporary Redirect',
+ 400 => 'Bad Request',
+ 401 => 'Unauthorized',
+ 403 => 'Forbidden',
+ 404 => 'Not Found',
+ 406 => 'Not Acceptable',
+ 409 => 'Conflict',
+ 410 => 'Gone',
+ 412 => 'Precondition Failed',
+ 415 => 'Unsupported Media Type',
+ 500 => 'Internal Server Error',
+ 503 => 'Service Unavailable',
+ ];
/**
* Maps a numeric HTTP status code to the corresponding string message.
*
- * @param number $httpStatusCode
- * the HTTP status code to translate
- * @return string
- * the corresponding string message, or an error message if the status code is unkown
+ * @param int $httpStatusCode The HTTP status code to translate
+ *
+ * @return string The corresponding string message, or an error message if the status code is unkown
*/
public static function getStringFromHTTPStatusCode($httpStatusCode)
{
- if (array_key_exists($httpStatusCode, HTTPResponseCodes::$codes) === true) {
- return HTTPResponseCodes::$codes[$httpStatusCode];
- } else {
- return "unknown error code: " . $httpStatusCode;
+ if (array_key_exists($httpStatusCode, self::$codes) === true) {
+ return self::$codes[$httpStatusCode];
}
+
+ return 'unknown error code: ' . $httpStatusCode;
}
}
diff --git a/src/MaileonAPIException.php b/src/MaileonAPIException.php
index cd48f05..9a5d322 100644
--- a/src/MaileonAPIException.php
+++ b/src/MaileonAPIException.php
@@ -2,29 +2,29 @@
namespace de\xqueue\maileon\api\client;
+use Exception;
+use RuntimeException;
+
/**
* An exception that is thrown when a technical error has occurred either in the communication
* with Maileon's REST API or in the API itself.
*/
-class MaileonAPIException extends \RuntimeException
+class MaileonAPIException extends RuntimeException
{
private $response;
public function __construct(
- $message = "",
+ $message = '',
$response = false,
$code = 0,
- \Exception $previous = null
+ Exception $previous = null
) {
parent::__construct($message, $code, $previous);
$this->response = $response;
}
/**
- *
- * @return false|string
- * the HTTP response body if there was one, false otherwise.
- * If a CURL error occured, this returns the ID of the CURL exception, see e.g. https://curl.se/libcurl/c/libcurl-errors.html
+ * @return false|string The HTTP response body if there was one, false otherwise. If a CURL error occurred, this returns the ID of the CURL exception, see e.g. https://curl.se/libcurl/c/libcurl-errors.html
*/
public function getResponse()
{
diff --git a/src/MaileonAPIResult.php b/src/MaileonAPIResult.php
index fe1e9f7..cf9cd7f 100644
--- a/src/MaileonAPIResult.php
+++ b/src/MaileonAPIResult.php
@@ -4,18 +4,34 @@
use de\xqueue\maileon\api\client\json\JSONDeserializer;
use de\xqueue\maileon\api\client\xml\XMLDeserializer;
+use Exception;
+use SimpleXMLElement;
+
+use function array_change_key_case;
+use function curl_errno;
+use function curl_error;
+use function curl_getinfo;
+use function explode;
+use function get_class;
+use function gettype;
+use function is_array;
+use function strlen;
+use function strpos;
+use function strrpos;
+use function strtolower;
+use function substr;
+use function trim;
/**
* The result of making a call to the Maileon REST API.
*
* This class encapsulates the technical details of the REST API's HTTP response. In order
- * to retrieve the payload result in deserialized form, just call
- * com_maileon_api_MaileonAPIResult::getResult().
+ * to retrieve the payload result in deserialized form, just call MaileonAPIResult::getResult().
*
* However, this class also allows the underlying HTTP response information to be queried,
- * including the returned status code (com_maileon_api_MaileonAPIResult::getStatusCode())
- * and content type (com_maileon_api_MaileonAPIResult::getContentType()) as well as the raw
- * HTTP response body data (com_maileon_api_MaileonAPIResult::getBodyData()).
+ * including the returned status code (MaileonAPIResult::getStatusCode())
+ * and content type (MaileonAPIResult::getContentType()) as well as the raw
+ * HTTP response body data (MaileonAPIResult::getBodyData()).
*/
class MaileonAPIResult
{
@@ -24,86 +40,97 @@ class MaileonAPIResult
private $statusCode;
private $contentType;
- private $bodyData = null;
- private $responseHeaders = array();
- private $resultXML = null;
- private $result = null;
+ private $bodyData;
+ private $responseHeaders;
+ private $resultXML;
+ private $result;
- private $deserializationType = null;
+ private $deserializationType;
/**
* Creates a new result object from the curl response and session data.
*
- * @param string $response
- * the HTTP response data, null if there was none
- * @param mixed $curlSession
- * the cURL session that was used
- * @param bool $throwException
- * if true, an exception will be thrown in case of a connection or server error
- * @param mixed $deserializationType
- * The name of the class this result should be deserialized as. Use
- * array( 'array', 'typename' ) to deserialize arrays of a type.
- * @throws MaileonAPIException
- * if $throwException == true and there was a connection problem or a server error occurred
+ * @param string $response the HTTP response data, null if there was none
+ * @param mixed $curlSession the cURL session that was used
+ * @param bool $throwException if true, an exception will be thrown in case of a connection or server error
+ * @param mixed $deserializationType The name of the class this result should be deserialized as. Use array( 'array', 'typename' ) to
+ * deserialize arrays of a type.
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred (only if $throwException == true)
*/
- public function __construct($response, $curlSession, $throwException = true, $deserializationType = null)
- {
- $this->bodyData = $this->getBodyFromCurlResponse($curlSession, $response);
- $this->curlSession = $curlSession;
- $this->deserializationType = $deserializationType;
- $this->responseHeaders = $this->getHeaderArrayFromCurlResponse($curlSession, $response);
- $this->checkResult($throwException);
+ public function __construct(
+ $response,
+ $curlSession,
+ $throwException = true,
+ $deserializationType = null
+ ) {
+ $this->bodyData = $this->getBodyFromCurlResponse($curlSession, $response);
+ $this->curlSession = $curlSession;
+ $this->deserializationType = $deserializationType;
+ $this->responseHeaders = $this->getHeaderArrayFromCurlResponse($curlSession, $response);
+ $this->checkResult($throwException);
}
- private function getHeaderArrayFromCurlResponse($curlSession, $response)
- {
- $headers = array();
+ private function getHeaderArrayFromCurlResponse(
+ $curlSession,
+ $response
+ ): array {
+ $headers = [];
- $headerSize = curl_getinfo( $curlSession , CURLINFO_HEADER_SIZE );
+ $headerSize = curl_getinfo($curlSession, CURLINFO_HEADER_SIZE);
- // The header sectionsis separated by \n\r\n\r, so trim those 4 bytes from the header as we do not need them
- $header_text = substr($response, 0, $headerSize-4);
+ // The header section is separated by \n\r\n\r, so trim those 4 bytes from the header as we do not need them
+ $header_text = substr($response, 0, $headerSize - 4);
// Check if there is a proxy header section. If so, select last header section (from Maileon)
- // Maybe it makes sense to return an array with one entry for each header section (proxies, then normal headers), each containing the entries of the apropriate header section.
+ // Maybe it makes sense to return an array with one entry for each header section (proxies, then normal headers), each containing the entries of the appropriate header section.
// As this is not backwards compatible, skip for now.
if (strpos($header_text, "\r\n\r\n") !== false) {
- $start = strrpos($header_text, "\r\n\r\n")+4;
+ $start = strrpos($header_text, "\r\n\r\n") + 4;
$header_text = substr($header_text, $start);
}
foreach (explode("\r\n", $header_text) as $i => $line) {
if ($i === 0) {
$headers['http_code'] = $line;
- } else {
- if (strpos($line, ':') != 0) {
- list ($key, $value) = explode(': ', $line);
- $headers[$key] = $value;
- }
+ } elseif (strpos($line, ':') != 0) {
+ list ($key, $value) = explode(': ', $line);
+ $headers[$key] = $value;
}
}
return $headers;
}
-
- private function getBodyFromCurlResponse($curlSession, $response)
- {
+
+ private function getBodyFromCurlResponse(
+ $curlSession,
+ $response
+ ) {
if ($response === null) {
return null;
}
-
+
// In a recent case, a CMS2 mailing contained \r\n\r\n, so the old approach failed (https://stackoverflow.com/questions/10589889/returning-header-as-array-using-curl).
- // Now, we use CURLINFO_HEADER_SIZE (https://blog.devgenius.io/how-to-get-the-response-headers-with-curl-in-php-2173b10d4fc5) and only split up the headers at \r\n\r\n.
+ // Now, we use CURLINFO_HEADER_SIZE (https://blog.devgenius.io/how-to-get-the-response-headers-with-curl-in-php-2173b10d4fc5) and only split up the headers at \r\n\r\n.
// CURLINFO_HEADER_SIZE returns the size of the header including \r\n\r\n.
- $headerSize = curl_getinfo( $curlSession , CURLINFO_HEADER_SIZE);
+ $headerSize = curl_getinfo($curlSession, CURLINFO_HEADER_SIZE);
+
return substr($response, $headerSize);
}
+ /**
+ * @param $throwException
+ *
+ * @return void
+ *
+ * @throws Exception
+ */
private function checkResult($throwException)
{
- $this->statusCode = curl_getinfo($this->curlSession, CURLINFO_HTTP_CODE);
+ $this->statusCode = curl_getinfo($this->curlSession, CURLINFO_HTTP_CODE);
$this->contentType = curl_getinfo($this->curlSession, CURLINFO_CONTENT_TYPE);
$this->setResultFields();
+
if ($throwException === true) {
$this->checkForCURLError();
$this->checkForServerError();
@@ -114,9 +141,9 @@ private function checkForCURLError()
{
if (curl_errno($this->curlSession)) {
$curlErrorMessage = curl_error($this->curlSession);
- $curlErrorCode = curl_errno($this->curlSession);
+ $curlErrorCode = curl_errno($this->curlSession);
throw new MaileonAPIException(
- "An error occurred in the connection to the REST API. Original cURL error message: {$curlErrorMessage}",
+ "An error occurred in the connection to the REST API. Original cURL error message: $curlErrorMessage",
$curlErrorCode
);
}
@@ -125,31 +152,38 @@ private function checkForCURLError()
private function checkForServerError()
{
$statusCode = $this->statusCode;
+
if ($statusCode >= 500 && $statusCode <= 599) {
throw new MaileonAPIException(
- "A server error occurred in the REST API (HTTP status code {$statusCode}).",
+ "A server error occurred in the REST API (HTTP status code $statusCode).",
$this->bodyData
);
}
}
+ /**
+ * @return void
+ *
+ * @throws Exception
+ */
private function setResultFields()
{
if ($this->bodyData) {
// AddressCheck uses application/xml;charset=utf-8 content type
- if ($this->contentType == 'application/vnd.maileon.api+xml' ||
- $this->contentType == 'application/xml;charset=utf-8' ||
- $this->contentType == 'application/xml'
+ if ($this->contentType === 'application/vnd.maileon.api+xml'
+ || $this->contentType === 'application/xml;charset=utf-8'
+ || $this->contentType === 'application/xml'
) {
- if ($this->startsWith(trim($this->bodyData), "<")) {
- $this->resultXML = new \SimpleXMLElement($this->bodyData);
- $this->result = XMLDeserializer::deserialize($this->resultXML);
+ if ($this->startsWith(trim($this->bodyData), '<')) {
+ $this->resultXML = new SimpleXMLElement($this->bodyData);
+ $this->result = XMLDeserializer::deserialize($this->resultXML);
}
- if (!isset($this->result) && !is_array($this->result)) {
- $this->result = $this->bodyData;
+
+ if (! isset($this->result) && ! is_array($this->result)) {
+ $this->result = $this->bodyData;
}
- } elseif ($this->contentType == "application/json" ||
- $this->contentType == 'application/vnd.maileon.api+json'
+ } elseif ($this->contentType === 'application/json'
+ || $this->contentType === 'application/vnd.maileon.api+json'
) {
$this->result = JSONDeserializer::json_decode($this->bodyData, $this->deserializationType);
} else {
@@ -159,10 +193,7 @@ private function setResultFields()
}
/**
- * @return mixed
- * the deserialized result object as a subclass of com_maileon_api_xml_AbstractXMLWrapper,
- * or the free-form string result if the response body data was not a deserializable object,
- * or null if there was no response body data
+ * @return mixed The deserialized result object as a subclass of AbstractXMLWrapper, or the free-form string result if the response body data was not a deserializable object, or null if there was no response body data
*/
public function getResult()
{
@@ -170,44 +201,39 @@ public function getResult()
}
/**
- * @return int
- * the HTTP status code that was returned by the HTTP request
+ * @return int The HTTP status code that was returned by the HTTP request
*/
- public function getStatusCode()
+ public function getStatusCode(): int
{
return $this->statusCode;
}
/**
- * @return bool
- * true iff a 2xx status code (success) was returned by the HTTP request
+ * @return bool true if a 2xx status code (success) was returned by the HTTP request
*/
- public function isSuccess()
+ public function isSuccess(): bool
{
return $this->statusCode >= 200 and $this->statusCode <= 299;
}
/**
- * @return bool
- * true iff a 4xx status code (client error) was returned by the HTTP request
+ * @return bool true if a 4xx status code (client error) was returned by the HTTP request
*/
- public function isClientError()
+ public function isClientError(): bool
{
return $this->statusCode >= 400 and $this->statusCode <= 499;
}
/**
- * @return string
- * the content type returned by the HTTP request
+ * @return string The content type returned by the HTTP request
*/
- public function getContentType()
+ public function getContentType(): string
{
- return $this->getContentType();
+ return $this->contentType;
}
/**
- * @return string
- * the unprocessed HTTP body data, or null if there was no body
+ * @return string The unprocessed HTTP body data, or null if there was no body
*/
public function getBodyData()
{
@@ -215,8 +241,7 @@ public function getBodyData()
}
/**
- * @return \SimpleXMLElement
- * the HTTP body data parsed as a SimpleXMLElement, or null if there was no XML in the body
+ * @return SimpleXMLElement|null The HTTP body data parsed as a SimpleXMLElement, or null if there was no XML in the body
*/
public function getResultXML()
{
@@ -224,47 +249,72 @@ public function getResultXML()
}
/**
- * @return array of strings
- * an array of response headers
+ * @return array an array of response headers (strings)
*/
- public function getResponseHeaders()
+ public function getResponseHeaders(): array
{
return $this->responseHeaders;
}
/**
- * @return string
- * a human-readable representation of the HTTP request result
+ * @param string $header
+ *
+ * @return bool
+ */
+ public function hasResponseHeader($header): bool
+ {
+ $responseHeaders = array_change_key_case($this->responseHeaders);
+
+ return isset($responseHeaders[strtolower($header)]);
+ }
+
+ /**
+ * @param string $header
+ *
+ * @return string|null
*/
- public function toString()
+ public function getResponseHeader($header)
{
- $result = "";
- $result .= "status code: " . $this->getStatusCode() . " ";
+ $responseHeaders = array_change_key_case($this->responseHeaders);
+
+ return $responseHeaders[strtolower($header)] ?? null;
+ }
+
+ public function toString(): string
+ {
+ $result = 'status code: ' . $this->getStatusCode() . ' ';
$result .= HTTPResponseCodes::getStringFromHTTPStatusCode($this->getStatusCode()) . "\n";
- $result .= "is success: " . ($this->isSuccess() ? "true" : "false") . "\n";
- $result .= "is client error: " . ($this->isClientError() ? "true" : "false") . "\n";
+ $result .= 'is success: ' . ($this->isSuccess() ? 'true' : 'false') . "\n";
+ $result .= 'is client error: ' . ($this->isClientError() ? 'true' : 'false') . "\n";
+
if ($this->bodyData) {
- $result .= "\nbody data:\n";
- $result .= $this->bodyData;
- $result .= "\n\n";
+ $result .= "\nbody data:\n";
+ $result .= $this->bodyData;
+ $result .= "\n\n";
} else {
- $result .= "No body data.\n";
+ $result .= "No body data.\n";
}
+
if ($this->resultXML) {
- $result .= "Body contains XML.\n";
+ $result .= "Body contains XML.\n";
}
+
$resultType = gettype($this->result);
- if ($resultType == "object") {
- $result .= "Result type: " . get_class($this->result) . "\n";
+
+ if ($resultType === 'object') {
+ $result .= 'Result type: ' . get_class($this->result) . "\n";
} else {
- $result .= "result type: " . $resultType . "\n";
+ $result .= 'Result type: ' . $resultType . "\n";
}
+
return $result;
}
- private function startsWith($haystack, $needle)
- {
- // search backwards starting from haystack length characters from the end
- return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== false;
+ private function startsWith(
+ $haystack,
+ $needle
+ ): bool {
+ // search backwards starting from haystack length characters from the end
+ return $needle === '' || strrpos($haystack, $needle, -strlen($haystack)) !== false;
}
}
diff --git a/src/account/AccountPlaceholder.php b/src/account/AccountPlaceholder.php
index 7e591ee..db66cbb 100644
--- a/src/account/AccountPlaceholder.php
+++ b/src/account/AccountPlaceholder.php
@@ -3,6 +3,9 @@
namespace de\xqueue\maileon\api\client\account;
use de\xqueue\maileon\api\client\xml\AbstractXMLWrapper;
+use SimpleXMLElement;
+
+use function dom_import_simplexml;
/**
* The wrapper class for a Maileon account placeholder. This class wraps the XML structure.
@@ -24,57 +27,43 @@ public function __construct(
$key = null,
$value = null
) {
- $this->key = $key;
+ $this->key = $key;
$this->value = $value;
}
- /**
- * Initialization of the attachment from a simple xml element.
- *
- * @param \SimpleXMLElement $xmlElement
- * The xml element that is used to parse the attachment from.
- */
public function fromXML($xmlElement)
{
if (isset($xmlElement->key)) {
- $this->key = (string)$xmlElement->key;
+ $this->key = (string) $xmlElement->key;
}
+
if (isset($xmlElement->value)) {
- $this->value = (string)$xmlElement->value;
+ $this->value = (string) $xmlElement->value;
}
}
- /**
- * Creates the XML representation of an attachment
- *
- * @return \SimpleXMLElement
- */
public function toXML()
{
- $xml = new \SimpleXMLElement("");
+ $xml = new SimpleXMLElement('');
- //$xml->addChild("value", $this->value);
+ // $xml->addChild('value', $this->value);
- $xml->addChild("key", $this->key);
+ $xml->addChild('key', $this->key);
// Add value as CDATA as it can contain special characters
$xml->value = null;
- $node = dom_import_simplexml($xml->value);
- $no = $node->ownerDocument;
+ $node = dom_import_simplexml($xml->value);
+ $no = $node->ownerDocument;
$node->appendChild($no->createCDATASection($this->value));
return $xml;
}
-
- /**
- * Human readable representation of this wrapper.
- *
- * @return string
- * A human readable version of the mailing.
- */
- public function toString()
+
+ public function toString(): string
{
- return "AccountPlaceholder [key=" . $this->key . ", "
- . "value=" . $this->value . "]";
+ return 'AccountPlaceholder ['
+ . 'key=' . $this->key
+ . ', value=' . $this->value
+ . ']';
}
}
diff --git a/src/account/AccountService.php b/src/account/AccountService.php
index 75e62da..43add8b 100644
--- a/src/account/AccountService.php
+++ b/src/account/AccountService.php
@@ -3,7 +3,13 @@
namespace de\xqueue\maileon\api\client\account;
use de\xqueue\maileon\api\client\AbstractMaileonService;
+use de\xqueue\maileon\api\client\MaileonAPIException;
use de\xqueue\maileon\api\client\MaileonAPIResult;
+use Exception;
+use SimpleXMLElement;
+
+use function dom_import_simplexml;
+use function is_array;
/**
* Facade that wraps the REST service for accounts.
@@ -13,40 +19,46 @@
class AccountService extends AbstractMaileonService
{
/**
- * Get account informations
+ * Get account information
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @return MaileonAPIResult
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getAccountInfo()
{
return $this->get(
- "account/info",
+ 'account/info',
[],
- "application/json"
+ 'application/json'
);
}
-
+
/**
* Get list of all account placeholders.
*
- * @return MaileonAPIResult
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getAccountPlaceholders()
{
- return $this->get("account/placeholders");
+ return $this->get('account/placeholders');
}
-
/**
* Sets the list of account placeholders. All current account placeholders will be overwritten or removed,
* if not contained in the new array
*
* @param array $accountPlaceholders Array of AccountPlaceholder or single account placeholder
- * @return MaileonAPIResult
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function setAccountPlaceholders($accountPlaceholders)
{
- $xml = new \SimpleXMLElement("");
+ $xml = new SimpleXMLElement('');
if (is_array($accountPlaceholders)) {
foreach ($accountPlaceholders as $accountPlaceholder) {
@@ -56,21 +68,26 @@ public function setAccountPlaceholders($accountPlaceholders)
$this->sxmlAppend($xml, $accountPlaceholders->toXML());
}
- return $this->post("account/placeholders", $xml->asXML());
+ return $this->post(
+ 'account/placeholders',
+ $xml->asXML()
+ );
}
-
/**
* Update account placeholders. If account placeholder is not existing yet, it will be added.
- * If account placeholder with given name is avaliable the value will be updated.
+ * If account placeholder with given name is available the value will be updated.
* Other existing account placeholders will not be touched.
*
* @param array $accountPlaceholders Array of AccountPlaceholder or single account placeholder
- * @return MaileonAPIResult
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function updateAccountPlaceholders($accountPlaceholders)
{
- $xml = new \SimpleXMLElement("");
+ $xml = new SimpleXMLElement('');
if (is_array($accountPlaceholders)) {
foreach ($accountPlaceholders as $accountPlaceholder) {
@@ -80,46 +97,62 @@ public function updateAccountPlaceholders($accountPlaceholders)
$this->sxmlAppend($xml, $accountPlaceholders->toXML());
}
- return $this->put("account/placeholders", $xml->asXML());
+ return $this->put(
+ 'account/placeholders',
+ $xml->asXML()
+ );
}
-
/**
* Delete account placeholder with requested {@code name}
*
* @param string $name The name of the property to delete
- * @return MaileonAPIResult
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function deleteAccountPlaceholder($name)
{
- $queryParameters = array(
- 'name' => $name,
- );
+ $queryParameters = ['name' => $name];
- return $this->delete("account/placeholders", $queryParameters);
+ return $this->delete(
+ 'account/placeholders',
+ $queryParameters
+ );
}
/**
* Get list of all subdomains
- *
- * @return MaileonAPIResult
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getAccountMailingDomains()
{
- return $this->get("account/mailing_domains", [], "application/xml");
+ return $this->get(
+ 'account/mailing_domains',
+ [],
+ 'application/xml'
+ );
}
/**
* Append a SimpleXMLElement to another
- *
- * @param \SimpleXMLElement $to
- * @param \SimpleXMLElement $from
+ *
+ * @param SimpleXMLElement $to
+ * @param SimpleXMLElement $from
+ *
* @return void
*/
- public function sxmlAppend(\SimpleXMLElement $to, \SimpleXMLElement $from)
- {
- $toDom = dom_import_simplexml($to);
+ public function sxmlAppend(
+ SimpleXMLElement $to,
+ SimpleXMLElement $from
+ ) {
+ $toDom = dom_import_simplexml($to);
$fromDom = dom_import_simplexml($from);
+
$toDom->appendChild($toDom->ownerDocument->importNode($fromDom, true));
}
}
diff --git a/src/account/MailingDomain.php b/src/account/MailingDomain.php
index d0a326c..a258d26 100644
--- a/src/account/MailingDomain.php
+++ b/src/account/MailingDomain.php
@@ -3,11 +3,12 @@
namespace de\xqueue\maileon\api\client\account;
use de\xqueue\maileon\api\client\xml\AbstractXMLWrapper;
+use SimpleXMLElement;
/**
* The wrapper class for a Maileon account mailing domain. This class wraps the XML structure.
*
- * @author Andreas Lange | XQueue GmbH | andreas.lange@xqueue.com
+ * @author Andreas Lange
*/
class MailingDomain extends AbstractXMLWrapper
{
@@ -21,8 +22,12 @@ class MailingDomain extends AbstractXMLWrapper
/**
* Constructor initializing default values.
*
- * @param string $key
- * @param string $value
+ * @param $name
+ * @param $status
+ * @param $createdTime
+ * @param $httpReachable
+ * @param $httpsReachable
+ * @param $certificateExpires
*/
public function __construct(
$name = null,
@@ -32,57 +37,51 @@ public function __construct(
$httpsReachable = null,
$certificateExpires = null
) {
- $this->name = $name;
- $this->status = $status;
- $this->createdTime = $createdTime;
- $this->httpReachable = $httpReachable;
- $this->httpsReachable = $httpsReachable;
+ $this->name = $name;
+ $this->status = $status;
+ $this->createdTime = $createdTime;
+ $this->httpReachable = $httpReachable;
+ $this->httpsReachable = $httpsReachable;
$this->certificateExpires = $certificateExpires;
}
- /**
- * Initialization of the attachment from a simple xml element.
- *
- * @param \SimpleXMLElement $xmlElement
- * The xml element that is used to parse the attachment from.
- */
public function fromXML($xmlElement)
{
if (isset($xmlElement->name)) {
- $this->name = (string)$xmlElement->name;
+ $this->name = (string) $xmlElement->name;
}
+
if (isset($xmlElement->status)) {
- $this->status = (string)$xmlElement->status;
+ $this->status = (string) $xmlElement->status;
}
+
if (isset($xmlElement->created_time)) {
- $this->createdTime = (string)$xmlElement->created_time;
+ $this->createdTime = (string) $xmlElement->created_time;
}
+
if (isset($xmlElement->http_reachable)) {
- $this->httpReachable = boolval((string)$xmlElement->http_reachable);
+ $this->httpReachable = (bool) (string) $xmlElement->http_reachable;
}
+
if (isset($xmlElement->https_reachable)) {
- $this->httpsReachable = boolval((string)$xmlElement->https_reachable);
+ $this->httpsReachable = (bool) (string) $xmlElement->https_reachable;
}
+
if (isset($xmlElement->certificate_expires)) {
- $this->certificateExpires = (string)$xmlElement->certificate_expires;
+ $this->certificateExpires = (string) $xmlElement->certificate_expires;
}
}
- /**
- * Creates the XML representation of an attachment
- *
- * @return \SimpleXMLElement
- */
public function toXML()
{
- $xml = new \SimpleXMLElement("");
+ $xml = new SimpleXMLElement('');
- $xml->addChild("name", $this->name);
- $xml->addChild("status", $this->status);
- $xml->addChild("created_time", $this->createdTime);
- $xml->addChild("http_reachable", $this->httpReachable ? 'true' : 'false');
- $xml->addChild("https_reachable", $this->httpsReachable ? 'true' : 'false');
- $xml->addChild("certificate_expires", $this->certificateExpires);
+ $xml->addChild('name', $this->name);
+ $xml->addChild('status', $this->status);
+ $xml->addChild('created_time', $this->createdTime);
+ $xml->addChild('http_reachable', $this->httpReachable ? 'true' : 'false');
+ $xml->addChild('https_reachable', $this->httpsReachable ? 'true' : 'false');
+ $xml->addChild('certificate_expires', $this->certificateExpires);
// Add value as CDATA as it can contain special characters
// $xml->value = null;
@@ -92,20 +91,16 @@ public function toXML()
return $xml;
}
-
- /**
- * Human readable representation of this wrapper.
- *
- * @return string
- * A human readable version of the mailing.
- */
- public function toString()
+
+ public function toString(): string
{
- return "MailingDomain [name=" . $this->name . ", "
- . "status=" . $this->status . ", "
- . "created_time=" . $this->createdTime . ", "
- . "http_reachable=" . ($this->httpReachable ? 'true' : 'false') . ", "
- . "https_reachable=" . ($this->httpsReachable ? 'true' : 'false') . ", "
- . "certificate_expires=" . $this->certificateExpires . "]";
+ return 'MailingDomain ['
+ . 'name=' . $this->name
+ . ', status=' . $this->status
+ . ', created_time=' . $this->createdTime
+ . ', http_reachable=' . ($this->httpReachable ? 'true' : 'false')
+ . ', https_reachable=' . ($this->httpsReachable ? 'true' : 'false')
+ . ', certificate_expires=' . $this->certificateExpires
+ . ']';
}
}
diff --git a/src/blacklists/AddEntriesAction.php b/src/blacklists/AddEntriesAction.php
index 0871098..249e299 100644
--- a/src/blacklists/AddEntriesAction.php
+++ b/src/blacklists/AddEntriesAction.php
@@ -3,25 +3,30 @@
namespace de\xqueue\maileon\api\client\blacklists;
use de\xqueue\maileon\api\client\xml\AbstractXMLWrapper;
+use SimpleXMLElement;
+
+use function implode;
+use function is_array;
/**
* The wrapper class for a Blacklist import.
*
- * @author Viktor Balogh | Wanadis Kft. | balogh.viktor@maileon.hu
- * @author Marcus Ständer | Trusted Technologies GmbH |
- * marcus.staender@trusted-technologies.de
+ * @author Viktor Balogh | XQueue GmbH | viktor.balog@xqueue.com
+ * @author Marcus Beckerle | XQueue GmbH | marcus.beckerle@xqueue.com
*/
class AddEntriesAction extends AbstractXMLWrapper
{
/**
+ * the name of the blacklist import
+ *
* @var string
- * the name of the blacklist import
*/
public $importName;
/**
+ * the blacklist entries to add
+ *
* @var string[]
- * the blacklist entries to add
*/
public $entries;
@@ -32,25 +37,29 @@ public function fromXML($xmlElement)
public function toXML()
{
- $xml = new \SimpleXMLElement("");
+ $xml = new SimpleXMLElement('');
// Some fields are mandatory, especially when setting data to the API
if (isset($this->importName)) {
- $xml->addChild("import_name", $this->importName);
+ $xml->addChild('import_name', $this->importName);
}
if (is_array($this->entries)) {
- $entries = $xml->addChild("entries");
+ $entries = $xml->addChild('entries');
+
foreach ($this->entries as $entry) {
- $entries->addChild("entry", $entry);
+ $entries->addChild('entry', $entry);
}
}
+
return $xml;
}
- public function toString()
+ public function toString(): string
{
- return "AddEntriesAction [importName=" . $this->importName . ", entries=[" .
- (is_array($this->entries) ? implode(", ", $this->entries) : "") . "]]";
+ return 'AddEntriesAction ['
+ . 'importName=' . $this->importName
+ . ', entries=[' . (is_array($this->entries) ? implode(', ', $this->entries) : '') . ']'
+ . ']';
}
}
diff --git a/src/blacklists/Blacklist.php b/src/blacklists/Blacklist.php
index d10b2d3..9034da1 100644
--- a/src/blacklists/Blacklist.php
+++ b/src/blacklists/Blacklist.php
@@ -3,6 +3,10 @@
namespace de\xqueue\maileon\api\client\blacklists;
use de\xqueue\maileon\api\client\xml\AbstractXMLWrapper;
+use SimpleXMLElement;
+
+use function implode;
+use function is_array;
/**
* The wrapper class for a blacklist.
@@ -10,50 +14,48 @@
class Blacklist extends AbstractXMLWrapper
{
/**
- * @var integer
- * the id of the blacklist
+ * the id of the blacklist
+ *
+ * @var int
*/
public $id;
/**
+ * the name of the blacklist
+ *
* @var string
- * the name of the blacklist
*/
public $name;
/**
+ * the blacklist entries
+ *
* @var string[]
- * the blacklist entries
*/
public $entries;
- /**
- * @return string
- * a human-readable representation of this blacklist.
- */
- public function toString()
+ public function toString(): string
{
- return "Blacklist [id=" . $this->id . ", name=" . $this->name . ", entries=[" .
- (is_array($this->entries) ? implode(", ", $this->entries) : "") . "]]";
+ return 'Blacklist ['
+ . 'id=' . $this->id
+ . ', name=' . $this->name
+ . ', entries=[' . (is_array($this->entries) ? implode(', ', $this->entries) : '') . ']'
+ . ']';
}
- /**
- * Initializes this blacklist type from an XML representation.
- *
- * @param \SimpleXMLElement $xmlElement
- * the serialized XML representation to use
- */
public function fromXML($xmlElement)
{
if (isset($xmlElement->id)) {
$this->id = $xmlElement->id;
}
+
if (isset($xmlElement->name)) {
$this->name = $xmlElement->name;
}
if (isset($xmlElement->entries)) {
- $this->entries = array();
+ $this->entries = [];
+
foreach ($xmlElement->entries->children() as $entry) {
$this->entries[] = $entry;
}
@@ -62,18 +64,20 @@ public function fromXML($xmlElement)
public function toXML()
{
- $xmlString = "";
- $xml = new \SimpleXMLElement($xmlString);
+ $xmlString = '';
+ $xml = new SimpleXMLElement($xmlString);
if (isset($this->id)) {
- $xml->addChild("id", $this->id);
+ $xml->addChild('id', $this->id);
}
+
if (isset($this->name)) {
- $xml->addChild("name", $this->name);
+ $xml->addChild('name', $this->name);
}
if (isset($this->entries)) {
- $entries = $xml->addChild("entries", 'entries');
+ $entries = $xml->addChild('entries', 'entries');
+
foreach ($this->entries as $entry) {
$entries->addChild($entry, $entry);
}
diff --git a/src/blacklists/BlacklistsService.php b/src/blacklists/BlacklistsService.php
index f93eb01..a3e9c9e 100644
--- a/src/blacklists/BlacklistsService.php
+++ b/src/blacklists/BlacklistsService.php
@@ -5,7 +5,11 @@
use de\xqueue\maileon\api\client\AbstractMaileonService;
use de\xqueue\maileon\api\client\MaileonAPIException;
use de\xqueue\maileon\api\client\MaileonAPIResult;
-use de\xqueue\maileon\api\client\blacklists\AddEntriesAction;
+use Exception;
+
+use function mb_convert_encoding;
+use function rawurlencode;
+use function uniqid;
/**
* Facade that wraps the REST service for blacklists.
@@ -17,54 +21,61 @@ class BlacklistsService extends AbstractMaileonService
/**
* Retrieves the names and IDs of the custom blacklists in your account.
*
- * @return MaileonAPIResult
- * the result object of the API call, with a Blacklist[] available at MaileonAPIResult::getResult()
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @return MaileonAPIResult|null The result object of the API call, with a Blacklist[] available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getBlacklists()
{
- return $this->get("blacklists");
+ return $this->get('blacklists');
}
/**
* Retrieves a full blacklist (including entries) by id.
*
- * @param integer $id
- * the id of the blacklist to retrieve
- * @return MaileonAPIResult
- * the result object of the API call, with the requested Blacklist available at MaileonAPIResult::getResult()
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @param int $id the id of the blacklist to retrieve
+ *
+ * @return MaileonAPIResult|null The result object of the API call, with the requested Blacklist available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getBlacklist($id)
{
- return $this->get("blacklists/" . $id);
+ $encodedId = rawurlencode(mb_convert_encoding((string) $id, 'UTF-8'));
+
+ return $this->get("blacklists/$encodedId");
}
/**
* Adds a number of expressions to a blacklist.
*
- * @param integer $id
- * the id of the blacklist to add the entries to
- * @param string[] $entries
- * the blacklist entries to add to the blacklist
- * @param string $importName
- * a unique name for the import that will be displayed in Maileon's web user interface.
- * If this is null, a unique name will be generated.
- * @return MaileonAPIResult
- * the result object of the API call.
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @param int $id the id of the blacklist to add the entries to
+ * @param string[] $entries the blacklist entries to add to the blacklist
+ * @param string $importName a unique name for the import that will be displayed in Maileon's web user interface. If this is null, a
+ * unique name will be generated.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult().
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function addEntriesToBlacklist($id, $entries, $importName = null)
- {
- if ($importName == null) {
- $importName = "phpclient_import_" . uniqid();
+ public function addEntriesToBlacklist(
+ $id,
+ $entries,
+ $importName = null
+ ) {
+ $encodedId = rawurlencode(mb_convert_encoding((string) $id, 'UTF-8'));
+
+ if ($importName === null) {
+ $importName = 'phpclient_import_' . uniqid();
}
- $action = new AddEntriesAction();
+
+ $action = new AddEntriesAction();
$action->importName = $importName;
- $action->entries = $entries;
- return $this->post("blacklists/" . $id . "/actions", $action->toXMLString());
+ $action->entries = $entries;
+
+ return $this->post(
+ "blacklists/$encodedId/actions",
+ $action->toXMLString()
+ );
}
}
diff --git a/src/blacklists/mailings/FilteredMailingBlacklistExpression.php b/src/blacklists/mailings/FilteredMailingBlacklistExpression.php
index a0fe60f..4690ac0 100644
--- a/src/blacklists/mailings/FilteredMailingBlacklistExpression.php
+++ b/src/blacklists/mailings/FilteredMailingBlacklistExpression.php
@@ -1,23 +1,28 @@
marcus.beckerle@xqueue.com
*/
class FilteredMailingBlacklistExpression extends AbstractXMLWrapper
{
/**
- * The expressions
+ * The expression
+ *
* @var string
*/
public $expression;
-
+
/**
* The reason why it was not accepted
+ *
* @var string
*/
public $reason;
@@ -31,54 +36,43 @@ class FilteredMailingBlacklistExpression extends AbstractXMLWrapper
public function __construct(
$expression = null,
$reason = null
- ) {
- $this->expression = $expression;
- $this->reason = $reason;
+ ) {
+ $this->expression = $expression;
+ $this->reason = $reason;
}
- /**
- * Initialization of the filtered mailing blacklist expression from a simple xml element.
- *
- * @param \SimpleXMLElement $xmlElement
- * The xml element that is used to parse the attachment from.
- */
public function fromXML($xmlElement)
{
if (isset($xmlElement->expression)) {
$this->expression = $xmlElement->expression;
}
+
if (isset($xmlElement->reason)) {
$this->reason = $xmlElement->reason;
}
}
- /**
- * Creates the XML representation of the mailing blacklist expressions
- *
- * @return \SimpleXMLElement
- */
public function toXML()
{
- $xmlString = "";
- $xml = new \SimpleXMLElement($xmlString);
-
+ $xmlString = '';
+ $xml = new SimpleXMLElement($xmlString);
+
if (isset($this->expression)) {
- $xml->addChild("expression", $this->expression);
+ $xml->addChild('expression', $this->expression);
}
+
if (isset($this->reason)) {
- $xml->addChild("reason", $this->reason);
+ $xml->addChild('reason', $this->reason);
}
+
return $xml;
}
-
- /**
- * Human readable representation of this wrapper.
- *
- * @return string
- * A human readable version of the mailing.
- */
- public function toString()
+
+ public function toString(): string
{
- return "FilteredExpression [expression=" . $this->expression . ", reason=" . $this->reason . "]";
+ return 'FilteredExpression ['
+ . 'expression=' . $this->expression
+ . ', reason=' . $this->reason
+ . ']';
}
}
diff --git a/src/blacklists/mailings/MailingBlacklistExpression.php b/src/blacklists/mailings/MailingBlacklistExpression.php
index 48e4fbd..9751a71 100644
--- a/src/blacklists/mailings/MailingBlacklistExpression.php
+++ b/src/blacklists/mailings/MailingBlacklistExpression.php
@@ -5,9 +5,9 @@
use de\xqueue\maileon\api\client\json\AbstractJSONWrapper;
/**
- * A wrapper class for a list of mailing blacklist expressions. This class wraps a signle JSON structure.
+ * A wrapper class for a list of mailing blacklist expressions. This class wraps a single JSON structure.
*
- * @author Balogh Viktor | Maileon - Wanadis Kft.
+ * @author Viktor Balogh | XQueue GmbH | viktor.balog@xqueue.com
*/
class MailingBlacklistExpression extends AbstractJSONWrapper
{
diff --git a/src/blacklists/mailings/MailingBlacklistExpressions.php b/src/blacklists/mailings/MailingBlacklistExpressions.php
index c1404fd..08eb74b 100644
--- a/src/blacklists/mailings/MailingBlacklistExpressions.php
+++ b/src/blacklists/mailings/MailingBlacklistExpressions.php
@@ -1,7 +1,12 @@
expressions = $expressions;
}
- /**
- * Initialization of the mailing blacklist expression(s) from a simple xml element.
- *
- * @param \SimpleXMLElement $xmlElement
- * The xml element that is used to parse the attachment from.
- */
public function fromXML($xmlElement)
{
if (isset($xmlElement->expressions)) {
- $this->expressions = array();
+ $this->expressions = [];
+
foreach ($xmlElement->expressions->children() as $entry) {
$this->expressions[] = $entry;
}
}
}
- /**
- * Creates the XML representation of the mailing blacklist expressions
- *
- * @return \SimpleXMLElement
- */
public function toXML()
{
- $xmlString = "";
- $xml = new \SimpleXMLElement($xmlString);
+ $xmlString = '';
+ $xml = new SimpleXMLElement($xmlString);
if (isset($this->expressions)) {
- $expressions = $xml->addChild("expressions");
+ $expressions = $xml->addChild('expressions');
+
foreach ($this->expressions as $expression) {
- $expressions->addChild("expression", $expression);
+ $expressions->addChild('expression', $expression);
}
}
+
return $xml;
}
- /**
- * Human readable representation of this wrapper.
- *
- * @return string
- * A human readable version of the mailing.
- */
- public function toString()
+ public function toString(): string
{
- return "MailingBlacklist [expressions=[" .
- (is_array($this->expressions) ? implode(", ", $this->expressions) : "") . "]]";
+ return 'MailingBlacklist ['
+ . 'expressions=[' . (is_array($this->expressions) ? implode(', ', $this->expressions) : '') . ']'
+ . ']';
}
}
\ No newline at end of file
diff --git a/src/blacklists/mailings/MailingBlacklistsService.php b/src/blacklists/mailings/MailingBlacklistsService.php
index 2d6bb4d..d39554c 100644
--- a/src/blacklists/mailings/MailingBlacklistsService.php
+++ b/src/blacklists/mailings/MailingBlacklistsService.php
@@ -5,6 +5,11 @@
use de\xqueue\maileon\api\client\AbstractMaileonService;
use de\xqueue\maileon\api\client\MaileonAPIException;
use de\xqueue\maileon\api\client\MaileonAPIResult;
+use Exception;
+
+use function mb_convert_encoding;
+use function rawurlencode;
+use function urlencode;
/**
* Facade that wraps the REST service for mailing blacklists.
@@ -16,143 +21,161 @@ class MailingBlacklistsService extends AbstractMaileonService
/**
* Retrieves the IDs, names, create times and users who created the mailing blacklists.
*
- * @param number $page_index
- * the index of the result page to fetch
- * @param number $page_size
- * the number of results to fetch per page, maximum is 1000
+ * @param int $page_index the index of the result page to fetch
+ * @param int $page_size the number of results to fetch per page, maximum is 1000
+ *
+ * @return MaileonAPIResult|null The result object of the API call, with a MailingBlacklist available at MaileonAPIResult::getResult()
*
- * @return MaileonAPIResult
- * the result object of the API call, with a MailingBlacklist available at MaileonAPIResult::getResult()
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function getMailingBlacklists($page_index = 1, $page_size = 100)
- {
- $queryParameters = array(
+ public function getMailingBlacklists(
+ $page_index = 1,
+ $page_size = 100
+ ) {
+ $queryParameters = [
'page_index' => $page_index,
- 'page_size' => $page_size,
- );
+ 'page_size' => $page_size,
+ ];
- return $this->get("mailingblacklists", $queryParameters);
+ return $this->get(
+ 'mailingblacklists',
+ $queryParameters
+ );
}
/**
* Retrieves mailing blacklist details by id.
*
- * @param integer $id
- * the id of the mailing blacklist to retrieve
+ * @param int $id the id of the mailing blacklist to retrieve
+ *
+ * @return MaileonAPIResult|null The result object of the API call, with the requested MailingBlacklist available at MaileonAPIResult::getResult()
*
- * @return MaileonAPIResult
- * the result object of the API call, with the requested MailingBlacklist available at MaileonAPIResult::getResult()
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getMailingBlacklist($id)
{
- return $this->get("mailingblacklists/" . $id);
+ $encodedId = rawurlencode(mb_convert_encoding((string) $id, 'UTF-8'));
+
+ return $this->get("mailingblacklists/$encodedId");
}
/**
- * Creates a mailing blacklist with the given name..
+ * Creates a mailing blacklist with the given name.
*
- * @param string $name
- * the name of the mailing blacklist to create
+ * @param string $name the name of the mailing blacklist to create
*
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function createMailingBlacklist($name)
{
- $queryParameters = array(
- 'name' => urlencode($name),
+ $queryParameters = ['name' => urlencode($name)];
+
+ return $this->post(
+ 'mailingblacklists/',
+ '',
+ $queryParameters
);
- return $this->post("mailingblacklists/", "", $queryParameters);
}
/**
* Updates the mailing blacklist name for the list with the given ID.
*
- * @param integer $id
- * the id of the mailing blacklist to update
+ * @param int $id the id of the mailing blacklist to update
+ *
+ * @param string $name the name to set
*
- * @param string $name
- * the name to set
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function updateMailingBlacklist($id, $name)
- {
- $queryParameters = array(
- 'name' => urlencode($name),
+ public function updateMailingBlacklist(
+ $id,
+ $name
+ ) {
+ $encodedId = rawurlencode(mb_convert_encoding((string) $id, 'UTF-8'));
+
+ $queryParameters = ['name' => urlencode($name)];
+
+ return $this->put(
+ "mailingblacklists/$encodedId",
+ '',
+ $queryParameters
);
- return $this->put("mailingblacklists/" . $id, "", $queryParameters);
}
/**
* Deletes a mailing blacklist
*
- * @param integer $id
- * the id of the mailing blacklist to delete
+ * @param int $id the id of the mailing blacklist to delete
*
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function deleteMailingBlacklist($id)
{
- return $this->delete("mailingblacklists/" . $id);
+ $encodedId = rawurlencode(mb_convert_encoding((string) $id, 'UTF-8'));
+
+ return $this->delete("mailingblacklists/$encodedId");
}
/**
* Adds a number of expressions to a mailing blacklist.
*
- * @param integer $id
- * the id of the mailing blacklist to add the entries to
- * @param MailingBlacklistExpressions $expressions
- * the mailing blacklist expressions to add to the mailing blacklist
+ * @param int $id the id of the mailing blacklist to add the entries to
+ * @param MailingBlacklistExpressions $expressions the mailing blacklist expressions to add to the mailing blacklist
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult().
*
- * @return MaileonAPIResult
- * the result object of the API call.
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function addEntriesToBlacklist($id, $expressions)
- {
- return $this->post("mailingblacklists/" . $id . "/expressions", $expressions->toXMLString());
+ public function addEntriesToBlacklist(
+ $id,
+ $expressions
+ ) {
+ $encodedId = rawurlencode(mb_convert_encoding((string) $id, 'UTF-8'));
+
+ return $this->post(
+ "mailingblacklists/$encodedId/expressions",
+ $expressions->toXMLString()
+ );
}
/**
* Gets the expressions for a mailing blacklist.
*
- * @param integer $id
- * The ID of the mailing blacklist
- * @param integer $page_index
- * The index of the result page. The index must be greater or equal to 1.
- * @param integer $page_size
- * The maximum count of items in the result page. If provided, the value of page_size must be in the range 1 to 1000.
- *
- * @return MaileonAPIResult
- * the result object of the API call.
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @param int $id The ID of the mailing blacklist
+ * @param int $page_index The index of the result page. The index must be greater or equal to 1.
+ * @param int $page_size The maximum count of items in the result page. If provided, the value of page_size must be in the range 1 to
+ * 1000.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult().
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function getEntriesForBlacklist($id, $page_index = 1, $page_size = 100)
- {
- $queryParameters = array(
+ public function getEntriesForBlacklist(
+ $id,
+ $page_index = 1,
+ $page_size = 100
+ ) {
+ $encodedId = rawurlencode(mb_convert_encoding((string) $id, 'UTF-8'));
+
+ $queryParameters = [
'page_index' => $page_index,
- 'page_size' => $page_size
- );
+ 'page_size' => $page_size,
+ ];
- return $this->get("mailingblacklists/" . $id . "/expressions", $queryParameters, "application/json", [
- 'array',
- MailingBlacklistExpression::class
- ]);
+ return $this->get(
+ "mailingblacklists/$encodedId/expressions",
+ $queryParameters,
+ 'application/json',
+ [
+ 'array',
+ MailingBlacklistExpression::class,
+ ]
+ );
}
}
diff --git a/src/contactfilters/ContactFilter.php b/src/contactfilters/ContactFilter.php
index 333475f..8167e5d 100644
--- a/src/contactfilters/ContactFilter.php
+++ b/src/contactfilters/ContactFilter.php
@@ -3,14 +3,15 @@
namespace de\xqueue\maileon\api\client\contactfilters;
use de\xqueue\maileon\api\client\xml\AbstractXMLWrapper;
+use SimpleXMLElement;
+
+use function rtrim;
/**
* The wrapper class for a Maileon contact filter.
*
- * @author Felix Heinrichs | Trusted Mails GmbH |
- * felix.heinrichs@trusted-mails.com
- * @author Marcus Ständer | Trusted Mails GmbH |
- * marcus.staender@trusted-mails.com
+ * @author Felix Heinrichs
+ * @author Marcus Beckerle | XQueue GmbH | marcus.beckerle@xqueue.com
*/
class ContactFilter extends AbstractXMLWrapper
{
@@ -25,33 +26,34 @@ class ContactFilter extends AbstractXMLWrapper
public $rules;
// TODO document arguments
+
/**
* Creates a new contact filter wrapper object.
*
- * @param number $id
+ * @param int $id
* @param string $name
* @param string $author
- * @param number $countContacts
- * @param number $countRules
+ * @param int $countContacts
+ * @param int $countRules
* @param string $created
* @param string $state
*/
public function __construct(
$id = 0,
- $name = "",
- $author = "",
+ $name = '',
+ $author = '',
$countContacts = 0,
$countRules = 0,
- $created = "1970-01-01 00:00:00",
- $state = ""
+ $created = '1970-01-01 00:00:00',
+ $state = ''
) {
- $this->id = $id;
- $this->name = $name;
- $this->author = $author;
+ $this->id = $id;
+ $this->name = $name;
+ $this->author = $author;
$this->countContacts = $countContacts;
- $this->countRules = $countRules;
- $this->created = $created;
- $this->state = $state;
+ $this->countRules = $countRules;
+ $this->created = $created;
+ $this->state = $state;
}
/**
@@ -61,87 +63,82 @@ public function __construct(
*/
public function addRule($rule)
{
- if (!$this->rules) {
- $this->rules = array();
+ if (! $this->rules) {
+ $this->rules = [];
}
- array_push($this->rules, $rule);
+
+ $this->rules[] = $rule;
}
- /**
- * Initializes this contact filter from an XML representation.
- *
- * @param \SimpleXMLElement $xmlElement
- * the XML representation to use
- */
public function fromXML($xmlElement)
{
- $this->author = $xmlElement->author;
+ $this->author = $xmlElement->author;
$this->countContacts = $xmlElement->count_contacts;
- $this->countRules = $xmlElement->count_rules;
- $this->created = $xmlElement->created;
- $this->id = $xmlElement->id;
- $this->name = $xmlElement->name;
- $this->state = $xmlElement->state;
+ $this->countRules = $xmlElement->count_rules;
+ $this->created = $xmlElement->created;
+ $this->id = $xmlElement->id;
+ $this->name = $xmlElement->name;
+ $this->state = $xmlElement->state;
+
if ($xmlElement->rules) {
$rules = $xmlElement->rules;
+
foreach ($rules as $rule) {
- array_push(
- $this->rules,
- new Rule($rule->is_customfield, $rule->field, $rule->operator, $rule->value, $rule->type)
- );
+ $this->rules[] = new Rule($rule->is_customfield, $rule->field, $rule->operator, $rule->value, $rule->type);
}
}
}
- /**
- * @return \SimpleXMLElement
- * containing the serialized representation of this contact filter
- */
public function toXML()
{
- $xml = new \SimpleXMLElement("");
+ $xml = new SimpleXMLElement('');
- $xml->addChild("id", $this->id);
- $xml->addChild("name", $this->name);
- $xml->addChild("author", $this->author);
- $xml->addChild("count_contacts", $this->countContacts);
- $xml->addChild("count_rules", $this->countRules);
- $xml->addChild("created", $this->created);
- $xml->addChild("state", $this->state);
+ $xml->addChild('id', $this->id);
+ $xml->addChild('name', $this->name);
+ $xml->addChild('author', $this->author);
+ $xml->addChild('count_contacts', $this->countContacts);
+ $xml->addChild('count_rules', $this->countRules);
+ $xml->addChild('created', $this->created);
+ $xml->addChild('state', $this->state);
if (isset($this->rules)) {
- $rules = $xml->addChild("rules");
+ $rules = $xml->addChild('rules');
+
foreach ($this->rules as $rule) {
- $field = $rules->addChild("rule");
- $field->addChild("is_customfield", ($rule->isCustomfield) ? "true" : "false");
- $field->addChild("field", $rule->field);
- $field->addChild("operator", $rule->operator);
- $field->addChild("value", $rule->value);
- $field->addChild("type", $rule->type);
+ $field = $rules->addChild('rule');
+ $field->addChild('is_customfield', $rule->isCustomfield ? 'true' : 'false');
+ $field->addChild('field', $rule->field);
+ $field->addChild('operator', $rule->operator);
+ $field->addChild('value', $rule->value);
+ $field->addChild('type', $rule->type);
}
}
return $xml;
}
- /**
- * @return string
- * containing a human-readable representation of this contact filter
- */
- public function toString()
+ public function toString(): string
{
// Generate standard field string
- $rules = "";
+ $rules = '';
+
if (isset($this->rules)) {
foreach ($this->rules as $rule) {
- $rules .= $rule->toString() . ",";
+ $rules .= $rule->toString() . ',';
}
+
$rules = rtrim($rules, ',');
}
- return "ContactFilter [author=" . $this->author . ", countContacts="
- . $this->countContacts . ", countRules=" . $this->countRules . ", created="
- . $this->created . ", id=" . $this->id . ", name=" . $this->name . ", state="
- . $this->state . ", rules={" . $rules . "}]";
+ return 'ContactFilter ['
+ . 'author=' . $this->author
+ . ', countContacts=' . $this->countContacts
+ . ', countRules=' . $this->countRules
+ . ', created=' . $this->created
+ . ', id=' . $this->id
+ . ', name=' . $this->name
+ . ', state=' . $this->state
+ . ', rules={' . $rules . '}'
+ . ']';
}
}
diff --git a/src/contactfilters/ContactfiltersService.php b/src/contactfilters/ContactfiltersService.php
index bf4c248..2c57a90 100644
--- a/src/contactfilters/ContactfiltersService.php
+++ b/src/contactfilters/ContactfiltersService.php
@@ -3,24 +3,27 @@
namespace de\xqueue\maileon\api\client\contactfilters;
use de\xqueue\maileon\api\client\AbstractMaileonService;
+use de\xqueue\maileon\api\client\MaileonAPIException;
use de\xqueue\maileon\api\client\MaileonAPIResult;
+use Exception;
+
+use function mb_convert_encoding;
+use function rawurlencode;
// TODO explain contact filters
+
/**
* Facade that wraps the REST service for contact filters.
*
- * @author Felix Heinrichs | Trusted Mails GmbH |
- * felix.heinrichs@trusted-mails.com
- * @author Marcus Ständer | Trusted Mails GmbH |
- * marcus.staender@trusted-mails.com
+ * @author Felix Heinrichs
+ * @author Marcus Beckerle | XQueue GmbH | marcus.beckerle@xqueue.com
*/
class ContactfiltersService extends AbstractMaileonService
{
-
/**
- * @return MaileonAPIResult
- * the result object of the API call, with the count of defined contact filters available
- * at MaileonAPIResult::getResult()
+ * @return MaileonAPIResult|null The result object of the API call, with the count of defined contact filters available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getContactFiltersCount()
{
@@ -30,105 +33,141 @@ public function getContactFiltersCount()
/**
* Returns the defined contact filters.
*
- * @param number $page_index
- * the paging index of the page to fetch
- * @param number $page_size
- * the number of entries to return per page
- * @return MaileonAPIResult
- * the result object of the API call, with a ContactFilter[]
- * available at MaileonAPIResult::getResult()
+ * @param int $page_index the paging index of the page to fetch
+ * @param int $page_size the number of entries to return per page
+ *
+ * @return MaileonAPIResult|null The result object of the API call, with a ContactFilter[] available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function getContactFilters($page_index = 1, $page_size = 100)
- {
- $queryParameters = array(
+ public function getContactFilters(
+ $page_index = 1,
+ $page_size = 100
+ ) {
+ $queryParameters = [
'page_index' => $page_index,
- 'page_size' => $page_size
+ 'page_size' => $page_size,
+ ];
+
+ return $this->get(
+ 'contactfilters',
+ $queryParameters
);
- return $this->get('contactfilters', $queryParameters);
}
/**
* @param string $contactFilterId
- * @return MaileonAPIResult
- * the result object of the API call, with the ContactFilter
- * available at MaileonAPIResult::getResult()
+ *
+ * @return MaileonAPIResult|null The result object of the API call, with the ContactFilter available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getContactFilter($contactFilterId)
{
- return $this->get('contactfilters/contactfilter/' . $contactFilterId);
+ $encodedContactFilterId = rawurlencode(mb_convert_encoding((string) $contactFilterId, 'UTF-8'));
+
+ return $this->get("contactfilters/contactfilter/$encodedContactFilterId");
}
/**
* Updates a contact filter that is referenced by an ID.
*
- * @param contactFilterId
- * the ID of the contact filter to update
- * @param ContactFilter $newFilterObject
- * the new data. Currently, the only field that is actually updated is the name of the filter.
- * @return MaileonAPIResult
- * the result object of the API call
+ * @param int $contactFilterId the ID of the contact filter to update
+ * @param ContactFilter $newFilterObject the new data. Currently, the only field that is actually updated is the name of the filter.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function updateContactFilter($contactFilterId, $newFilterObject)
- {
- return $this->post("contactfilters/contactfilter/" . $contactFilterId, $newFilterObject->toXMLString());
+ public function updateContactFilter(
+ $contactFilterId,
+ $newFilterObject
+ ) {
+ $encodedContactFilterId = rawurlencode(mb_convert_encoding((string) $contactFilterId, 'UTF-8'));
+
+ return $this->post(
+ "contactfilters/contactfilter/$encodedContactFilterId",
+ $newFilterObject->toXMLString()
+ );
}
/**
* Creates a simple contact filter.
*
- * @param ContactFilter $newFilterObject
- * the data for the filter
- * @param bool $createTargetGroup
- * if true, also a target group will be created and the ID will be returned
- * @param number $version
- * version identifyer to use different versions of the create targetgroup resource
- * @return MaileonAPIResult
- * the result object of the API call
+ * @param ContactFilter $newFilterObject The data for the filter
+ * @param bool $createTargetGroup if true, also a target group will be created and the ID will be returned
+ * @param int|float|string $version version identifier to use different versions of the created target group resource
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function createContactFilter($newFilterObject, $createTargetGroup, $version = 1.0)
- {
- if ($version == 1.0) {
- $queryParameters = array(
- 'createTargetGroup' => ($createTargetGroup) ? "true" : "false"
+ public function createContactFilter(
+ $newFilterObject,
+ $createTargetGroup,
+ $version = 1.0
+ ) {
+ if ($version === 1.0) {
+ $queryParameters = ['createTargetGroup' => $createTargetGroup === true ? 'true' : 'false'];
+
+ return $this->put(
+ 'contactfilters/contactfilter',
+ $newFilterObject->toXMLString(),
+ $queryParameters
);
- $return = $this->put("contactfilters/contactfilter", $newFilterObject->toXMLString(), $queryParameters);
- } elseif ($version == 2.0) {
- $queryParameters = array(
- 'createTargetGroup' => ($createTargetGroup) ? "true" : "false"
+ }
+
+ if ($version === 2.0) {
+ $queryParameters = ['createTargetGroup' => $createTargetGroup === true ? 'true' : 'false'];
+
+ return $this->post(
+ 'contactfilters/v2',
+ $newFilterObject,
+ $queryParameters,
+ 'application/json'
);
- $return = $this->post("contactfilters/v2", $newFilterObject, $queryParameters, "application/json");
}
- return $return;
+
+ return null;
}
/**
* Deletes a contact filter that is referenced by an ID.
*
- * @param contactFilterId
- * the ID of the contact filter
- * @return MaileonAPIResult
- * the result object of the API call
+ * @param int $contactFilterId the ID of the contact filter
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function deleteContactFilter($contactFilterId)
{
- return $this->delete("contactfilters/contactfilter/" . $contactFilterId);
+ $encodedContactFilterId = rawurlencode(mb_convert_encoding((string) $contactFilterId, 'UTF-8'));
+
+ return $this->delete("contactfilters/contactfilter/$encodedContactFilterId");
}
/**
* Causes a refresh of the contact filter referenced by an ID. This means that the result set of
* contacts matched by the contact filter is recomputed.
*
- * @param contactFilterId
- * the ID of the contact filter to refresh
- * @param time
- * a timestamp for the request. If the contact filter was updated after the given timestamp,
- * the refresh is not performed. The default value will force the refresh to always be performed.
- * @return MaileonAPIResult
- * the result object of the API call
+ * @param int $contactFilterId The ID of the contact filter to refresh
+ * @param $time A timestamp for the request. If the contact filter was updated after the given timestamp, the refresh is
+ * not performed. The default value will force the refresh to always be performed.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function refreshContactFilterContacts($contactFilterId, $time)
- {
- return $this->get("contactfilters/contactfilter/" . $contactFilterId .
- "/refresh", ($time) ? array("time" => $time) : null);
+ public function refreshContactFilterContacts(
+ $contactFilterId,
+ $time
+ ) {
+ $encodedContactFilterId = rawurlencode(mb_convert_encoding((string) $contactFilterId, 'UTF-8'));
+
+ return $this->get(
+ "contactfilters/contactfilter/$encodedContactFilterId/refresh",
+ $time ? ['time' => $time] : null
+ );
}
}
diff --git a/src/contactfilters/Rule.php b/src/contactfilters/Rule.php
index 9301462..30ff330 100644
--- a/src/contactfilters/Rule.php
+++ b/src/contactfilters/Rule.php
@@ -5,8 +5,7 @@
/**
* The wrapper class for a contact filter rule
*
- * @author Marcus Ständer | Trusted Mails GmbH |
- * marcus.staender@trusted-mails.com
+ * @author Marcus Beckerle | XQueue GmbH | marcus.beckerle@xqueue.com
*/
class Rule
{
@@ -19,32 +18,34 @@ class Rule
/**
* Constructor initializing rule
*
- * @param bool $isCustomfield
+ * @param bool $isCustomfield
* @param string $field
- * @param string $operator The operator that should be used. Best: use EQUALS,
- * then STARTS_WITH, then, if not possible with these, use others.
- * Valid: EQUALS, NOTEQUALS, CONTAINS, NOTCONTAINS, STARTS_WITH
+ * @param string $operator The operator that should be used. Best: use EQUALS, then STARTS_WITH, then, if not possible with these,
+ * use others. Valid: EQUALS, NOTEQUALS, CONTAINS, NOTCONTAINS, STARTS_WITH
* @param string $value
*/
- public function __construct($isCustomfield, $field, $operator, $value, $type = "string")
- {
+ public function __construct(
+ $isCustomfield,
+ $field,
+ $operator,
+ $value,
+ $type = 'string'
+ ) {
$this->isCustomfield = $isCustomfield;
- $this->field = $field;
- $this->operator = $operator;
- $this->value = $value;
- $this->type = $type;
+ $this->field = $field;
+ $this->operator = $operator;
+ $this->value = $value;
+ $this->type = $type;
}
- /**
- * Human readable representation of this rule.
- *
- * @return string
- * A human readable version of the rule.
- */
- public function toString()
+ public function toString(): string
{
- return "Rule [isCustomfield=" . ($this->isCustomfield) ? "true" : "false" .
- ", field=" . $this->field . ", operator=" . $this->operator . ", value=" .
- $this->value . " (type = " . $this->type . ")";
+ return 'Rule ['
+ . 'isCustomfield=' . ($this->isCustomfield ? 'true' : 'false')
+ . ', field=' . $this->field
+ . ', operator=' . $this->operator
+ . ', value=' . $this->value
+ . ', type = ' . $this->type
+ . ']';
}
}
diff --git a/src/contacts/Contact.php b/src/contacts/Contact.php
index abcb1f8..b2e5d37 100644
--- a/src/contacts/Contact.php
+++ b/src/contacts/Contact.php
@@ -2,85 +2,82 @@
namespace de\xqueue\maileon\api\client\contacts;
-use de\xqueue\maileon\api\client\xml\XMLUtils;
use de\xqueue\maileon\api\client\xml\AbstractXMLWrapper;
+use de\xqueue\maileon\api\client\xml\XMLUtils;
+use Exception;
+use SimpleXMLElement;
+
+use function rtrim;
+use function trim;
/**
* The wrapper class for a Maileon contact. This class wraps the XML structure.
*
- * @author Felix Heinrichs | Trusted Mails GmbH |
- * felix.heinrichs@trusted-mails.com
- * @author Marcus Beckerle | XQueue GmbH |
- * marcus.beckerle@xqueue.com
+ * @author Felix Heinrichs
+ * @author Marcus Beckerle | XQueue GmbH | marcus.beckerle@xqueue.com
*/
class Contact extends AbstractXMLWrapper
{
/**
- * @var int $id
+ * @var int
*/
public $id;
/**
- * @var string $email
+ * @var string
*/
public $email;
/**
- * @var Permission $permission
+ * @var Permission
*/
public $permission;
/**
- * @var string $external_id
+ * @var string
*/
public $external_id;
/**
- * @var bool $anonymous
+ * @var bool
*/
public $anonymous;
/**
- * @var string $created
+ * @var string
*/
public $created;
-
+
/**
- * @var string updated
+ * @var string
*/
public $updated;
/**
- * @var array $standard_fields
+ * @var array
*/
public $standard_fields;
/**
- * @var array $custom_fields
+ * @var array
*/
public $custom_fields;
/**
- * @var array $preferences
+ * @var array
*/
public $preferences;
/**
* Constructor initializing default values.
*
- * @param int $id
- * The Maileon contact id.
- * @param string $email
- * The email-address of the contact.
- * @param Permission $permission
- * The permission NONE, SOI, COI, DOI, DOI_PLUS, OTHER.
- * @param string $external_id
- * The external id to identify the contact.
- * @param bool $anonymous
- * @param array $standard_fields
- * An array of standard fields.
- * @param array $custom_fields
- * An array of custom fields of the contact.
+ * @param int $id The Maileon contact id.
+ * @param string $email The email-address of the contact.
+ * @param Permission $permission The permission NONE, SOI, COI, DOI, DOI_PLUS, OTHER.
+ * @param string $external_id The external id to identify the contact.
+ * @param bool $anonymous
+ * @param array $standard_fields An array of standard fields.
+ * @param array $custom_fields An array of custom fields of the contact.
*/
public function __construct(
$id = null,
@@ -88,45 +85,44 @@ public function __construct(
$permission = null,
$external_id = -1,
$anonymous = false,
- $standard_fields = array(),
- $custom_fields = array(),
+ $standard_fields = [],
+ $custom_fields = [],
$created = null,
$updated = null,
- $preferences = array()
+ $preferences = []
) {
- $this->id = $id;
- $this->email = $email;
- $this->permission = $permission;
- $this->external_id = $external_id;
- $this->anonymous = $anonymous;
+ $this->id = $id;
+ $this->email = $email;
+ $this->permission = $permission;
+ $this->external_id = $external_id;
+ $this->anonymous = $anonymous;
$this->standard_fields = $standard_fields;
- $this->custom_fields = $custom_fields;
- $this->created = $created;
- $this->updated = $updated;
- $this->preferences = $preferences;
+ $this->custom_fields = $custom_fields;
+ $this->created = $created;
+ $this->updated = $updated;
+ $this->preferences = $preferences;
}
- /**
- * Initialization of the contact from a simple xml element.
- *
- * @param \SimpleXMLElement $xmlElement
- * The xml element that is used to parse the contact from.
- */
public function fromXML($xmlElement)
{
if (isset($xmlElement->id)) {
$this->id = $xmlElement->id;
}
- $this->email = (string)$xmlElement->email;
+
+ $this->email = (string) $xmlElement->email;
+
if (isset($xmlElement->permission)) {
- $this->permission = Permission::getPermission((string)$xmlElement->permission);
+ $this->permission = Permission::getPermission((string) $xmlElement->permission);
}
+
if (isset($xmlElement->external_id)) {
- (string)$this->external_id = $xmlElement->external_id;
+ (string) $this->external_id = $xmlElement->external_id;
}
+
if (isset($xmlElement->anonymous)) {
- (string)$this->anonymous = $xmlElement->anonymous;
+ (string) $this->anonymous = $xmlElement->anonymous;
}
+
if (isset($xmlElement['anonymous'])) {
$this->anonymous = $xmlElement['anonymous'];
}
@@ -134,31 +130,34 @@ public function fromXML($xmlElement)
if (isset($xmlElement->created)) {
$this->created = $xmlElement->created;
}
+
if (isset($xmlElement->updated)) {
$this->updated = $xmlElement->updated;
}
if (isset($xmlElement->standard_fields)) {
- $this->standard_fields = array();
+ $this->standard_fields = [];
+
foreach ($xmlElement->standard_fields->children() as $field) {
- $this->standard_fields[trim($field->name)] = (string)$field->value;
+ $this->standard_fields[trim($field->name)] = (string) $field->value;
// The trim is required to make a safer string from the object
}
}
if (isset($xmlElement->custom_fields)) {
foreach ($xmlElement->custom_fields->children() as $field) {
- $this->custom_fields[trim($field->name)] = (string)$field->value;
+ $this->custom_fields[trim($field->name)] = (string) $field->value;
// The trim is required to make a safer string from the object
}
}
if (isset($xmlElement->preferences)) {
- $this->preferences = array();
+ $this->preferences = [];
+
foreach ($xmlElement->preferences->children() as $preference) {
$preference_obj = new Preference();
$preference_obj->fromXML($preference);
- array_push($this->preferences, $preference_obj);
+ $this->preferences[] = $preference_obj;
}
}
}
@@ -168,17 +167,18 @@ public function fromXML($xmlElement)
*
* @param bool $addXMLDeclaration
*
- * @return \SimpleXMLElement
- * Generate a XML element from the contact object.
+ * @return SimpleXMLElement contains the serialized representation of the object
+ *
+ * @throws Exception
*/
public function toXML($addXMLDeclaration = true)
{
- $xmlString = $addXMLDeclaration ? "" : "";
- $xml = new \SimpleXMLElement($xmlString);
+ $xmlString = $addXMLDeclaration ? '' : '';
+ $xml = new SimpleXMLElement($xmlString);
// Some fields are mandatory, especially when setting data to the API
if (isset($this->id)) {
- $xml->addChild("id", $this->id);
+ $xml->addChild('id', $this->id);
}
// As shown in http://stackoverflow.com/questions/17027043/unterminated-entity-reference-php
@@ -189,170 +189,181 @@ public function toXML($addXMLDeclaration = true)
}
if (isset($this->permission)) {
- $xml->addChild("permission", $this->permission->getCode());
+ $xml->addChild('permission', $this->permission->getCode());
}
+
if (isset($this->external_id) && $this->external_id != -1) {
- $xml->addChild("external_id", $this->external_id);
+ $xml->addChild('external_id', $this->external_id);
}
+
if (isset($this->anonymous)) {
- $xml->addChild("anonymous", $this->anonymous);
+ $xml->addChild('anonymous', $this->anonymous);
}
+
if (isset($this->created)) {
- $xml->addChild("created", $this->created);
+ $xml->addChild('created', $this->created);
}
+
if (isset($this->updated)) {
- $xml->addChild("updated", $this->updated);
+ $xml->addChild('updated', $this->updated);
}
if (isset($this->standard_fields)) {
- $standard_fields = $xml->addChild("standard_fields");
+ $standard_fields = $xml->addChild('standard_fields');
+
foreach ($this->standard_fields as $index => $value) {
- $field = $standard_fields->addChild("field");
- $field->addChild("name", $index);
+ $field = $standard_fields->addChild('field');
+ $field->addChild('name', $index);
- XMLUtils::addChildAsCDATA($field, "value", $value);
- //$field->addChild("value", $value);
+ XMLUtils::addChildAsCDATA($field, 'value', $value);
+ // $field->addChild('value', $value);
}
}
if (isset($this->custom_fields)) {
- $customfields = $xml->addChild("custom_fields");
+ $custom_fields = $xml->addChild('custom_fields');
+
foreach ($this->custom_fields as $index => $value) {
- $field = $customfields->addChild("field");
- $field->addChild("name", $index);
+ $field = $custom_fields->addChild('field');
+ $field->addChild('name', $index);
- XMLUtils::addChildAsCDATA($field, "value", $value);
- //$field->addChild("value", $value);
+ XMLUtils::addChildAsCDATA($field, 'value', $value);
+ // $field->addChild('value', $value);
}
}
if (isset($this->preferences)) {
- $preferences_field = $xml->addChild("preferences");
+ $preferences_field = $xml->addChild('preferences');
+
foreach ($this->preferences as $preference) {
- $preference_field = $preferences_field->addChild("preference");
- $preference_field->addChild("name", $preference->name);
- $preference_field->addChild("category", $preference->category);
-
- XMLUtils::addChildAsCDATA($preference_field, "value", $preference->value);
+ $preference_field = $preferences_field->addChild('preference');
+ $preference_field->addChild('name', $preference->name);
+ $preference_field->addChild('category', $preference->category);
- $preference_field->addChild("source", $preference->source);
+ XMLUtils::addChildAsCDATA($preference_field, 'value', $preference->value);
+
+ $preference_field->addChild('source', $preference->source);
}
}
return $xml;
}
- /**
- * Serialization to a simple XML element as string
- *
- * @return string
- * The string representation of the XML document for this contact.
- */
- public function toXMLString()
- {
- $xml = $this->toXML();
- return $xml->asXML();
- }
-
- /**
- * Human readable representation of this wrapper.
- *
- * @return string
- * A human readable version of the contact.
- */
- public function toString()
+ public function toString(): string
{
// Generate standard field string
- $standard_fields = "";
+ $standard_fields = '';
+
if (isset($this->standard_fields)) {
foreach ($this->standard_fields as $index => $value) {
- $standard_fields .= $index . "=" . $value . ",";
+ $standard_fields .= $index . '=' . $value . ',';
}
+
$standard_fields = rtrim($standard_fields, ',');
}
// Generate custom field string
- $customfields = "";
+ $custom_fields = '';
+
if (isset($this->custom_fields)) {
foreach ($this->custom_fields as $index => $value) {
- $customfields .= $index . "=" . $value . ",";
+ $custom_fields .= $index . '=' . $value . ',';
}
- $customfields = rtrim($customfields, ',');
+
+ $custom_fields = rtrim($custom_fields, ',');
}
- $preferences = "";
+ $preferences = '';
+
if (isset($this->preferences)) {
foreach ($this->preferences as $preference) {
- $preferences .= $preference->toString() . ",";
+ $preferences .= $preference->toString() . ',';
}
+
$preferences = rtrim($preferences, ',');
}
- $permission = "";
+ $permission = '';
+
if (isset($this->permission)) {
$permission = $this->permission->getCode();
}
- return "Contact [id=" . $this->id . ", email="
- . $this->email . ", permission=" . $permission . ", external_id=" . $this->external_id
- . ", anonymous=" . (($this->anonymous == true) ? "true" : "false") .
- ", created=" . $this->created . ", updated=" . $this->updated
- . ", standard_fields={" . $standard_fields . "}, customfields={" . $customfields .
- "}, preferences={" . $preferences . "}]";
+ return 'Contact ['
+ . 'id=' . $this->id
+ . ', email=' . $this->email
+ . ', permission=' . $permission
+ . ', external_id=' . $this->external_id
+ . ', anonymous=' . ($this->anonymous === true ? 'true' : 'false')
+ . ', created=' . $this->created
+ . ', updated=' . $this->updated
+ . ', standard_fields={' . $standard_fields . '}'
+ . ', custom_fields={' . $custom_fields . '}'
+ . ', preferences={' . $preferences . '}'
+ . ']';
}
/**
* CSV representation of this wrapper.
*
* @return string
- * A csv version of the contact.
*/
- public function toCsvString()
+ public function toCsvString(): string
{
// Generate standard field string
- $standard_fields = "{";
+ $standard_fields = '{';
+
if (isset($this->standard_fields)) {
foreach ($this->standard_fields as $index => $value) {
- $standard_fields .= $index . "=" . $value . ",";
+ $standard_fields .= $index . '=' . $value . ',';
}
+
$standard_fields = rtrim($standard_fields, ',');
}
- $standard_fields .= "}";
+
+ $standard_fields .= '}';
// Generate custom field string
- $customfields = "{";
+ $custom_fields = '{';
+
if (isset($this->custom_fields)) {
foreach ($this->custom_fields as $index => $value) {
- $customfields .= $index . "=" . $value . ",";
+ $custom_fields .= $index . '=' . $value . ',';
}
- $customfields = rtrim($customfields, ',');
+
+ $custom_fields = rtrim($custom_fields, ',');
}
- $customfields .= "}";
+
+ $custom_fields .= '}';
// Generate preferences string
- $preferences = "{";
+ $preferences = '{';
+
if (isset($this->preferences)) {
foreach ($this->preferences as $preference) {
- $preferences .= "{" . $preference->toCsvString() . "},";
+ $preferences .= '{' . $preference->toCsvString() . '},';
}
+
$preferences = rtrim($preferences, ',');
}
- $preferences .= "}";
- $permission = "";
+ $preferences .= '}';
+
+ $permission = '';
+
if (isset($this->permission)) {
$permission = $this->permission->getCode();
}
return $this->id
- . ";" . $this->email
- . ";" . $permission
- . ";" . $this->external_id
- . ";" . (($this->anonymous == true) ? "true" : "false")
- . ";" . $this->created
- . ";" . $this->updated
- . ";\"" . $standard_fields . "\""
- . ";\"" . $customfields . "\""
- . ";\"" . $preferences . "\"";
+ . ';' . $this->email
+ . ';' . $permission
+ . ';' . $this->external_id
+ . ';' . ($this->anonymous === true ? 'true' : 'false')
+ . ';' . $this->created
+ . ';' . $this->updated
+ . ';"' . $standard_fields . '"'
+ . ';"' . $custom_fields . '"'
+ . ';"' . $preferences . '"';
}
}
diff --git a/src/contacts/Contacts.php b/src/contacts/Contacts.php
index 6ec289b..16c77fa 100644
--- a/src/contacts/Contacts.php
+++ b/src/contacts/Contacts.php
@@ -2,23 +2,28 @@
namespace de\xqueue\maileon\api\client\contacts;
+use ArrayIterator;
use de\xqueue\maileon\api\client\xml\AbstractXMLWrapper;
+use IteratorAggregate;
+use SimpleXMLElement;
+
+use function count;
+use function dom_import_simplexml;
/**
* A wrapper class for a list of Maileon contacts. To access the contacts
* contained within this list, iterate this object using foreach (i.e. IteratorAggregate is implemented).
*/
-class Contacts extends AbstractXMLWrapper implements \IteratorAggregate
+class Contacts extends AbstractXMLWrapper implements IteratorAggregate
{
private $contacts;
/**
* Creates a new list of contacts.
*
- * @param array $contacts
- * the contacts in the list of contacts
+ * @param array $contacts the contacts in the list of contacts
*/
- public function __construct($contacts = array())
+ public function __construct($contacts = [])
{
$this->contacts = $contacts;
}
@@ -30,36 +35,28 @@ public function __construct($contacts = array())
*/
public function addContact($contact)
{
- array_push($this->contacts, $contact);
+ $this->contacts[] = $contact;
}
-
+
/**
- * @return \ArrayIterator
- * an iterator for the contacts in this list of contacts
+ * @return ArrayIterator an iterator for the contacts in this list of contacts
*/
- public function getIterator(): \Traversable
+ public function getIterator()
{
- return new \ArrayIterator($this->contacts);
+ return new ArrayIterator($this->contacts);
}
-
+
/**
- * @return int
- * The number of contacts
+ * @return int The number of contacts
*/
- public function getCount()
+ public function getCount(): int
{
- return sizeof($this->contacts);
+ return count($this->contacts);
}
- /**
- * Initialization of the contact from a simple xml element. NOT YET IMPLEMENTED.
- *
- * @param \SimpleXMLElement $xmlElement
- * The xml element that is used to parse the contact list from.
- */
public function fromXML($xmlElement)
{
- if ($xmlElement->getName() == "contacts") {
+ if ($xmlElement->getName() === 'contacts') {
foreach ($xmlElement->children() as $contactXml) {
$contact = new Contact();
$contact->fromXML($contactXml);
@@ -68,15 +65,9 @@ public function fromXML($xmlElement)
}
}
- /**
- * Serialization to a simple XML element.
- *
- * @return \SimpleXMLElement
- * Generate a XML element from the contact object.
- */
public function toXML()
{
- $xml = new \SimpleXMLElement("");
+ $xml = new SimpleXMLElement('');
$contactsDom = dom_import_simplexml($xml);
foreach ($this->contacts as $contact) {
@@ -84,34 +75,19 @@ public function toXML()
$contactsDom->appendChild($contactsDom->ownerDocument->importNode($contactDom, true));
}
- return new \SimpleXMLElement($contactsDom->ownerDocument->saveXML());
+ return new SimpleXMLElement($contactsDom->ownerDocument->saveXML());
}
- /**
- * Serialization to a simple XML element as string
- *
- * @return string
- * The string representation of the XML document for this contact.
- */
- public function toXMLString()
- {
- $xml = $this->toXML();
- return $xml->asXML();
- }
-
- /**
- * Human readable representation of this wrapper.
- *
- * @return string
- * A human readable version of the contact list.
- */
- public function toString()
+ public function toString(): string
{
$result = "[\n";
+
foreach ($this->contacts as $contact) {
$result .= ' ' . $contact->toString() . "\n";
}
+
$result .= ']';
+
return $result;
}
}
diff --git a/src/contacts/ContactsService.php b/src/contacts/ContactsService.php
index ce7b803..c961b4a 100644
--- a/src/contacts/ContactsService.php
+++ b/src/contacts/ContactsService.php
@@ -5,14 +5,19 @@
use de\xqueue\maileon\api\client\AbstractMaileonService;
use de\xqueue\maileon\api\client\MaileonAPIException;
use de\xqueue\maileon\api\client\MaileonAPIResult;
+use Exception;
+
+use function is_array;
+use function mb_convert_encoding;
+use function rawurlencode;
+use function trim;
+use function urlencode;
/**
- * This service wrapps the REST API calls for the contact features.
+ * This service wraps the REST API calls for the contact features.
*
- * @author Felix Heinrichs | Trusted Mails GmbH |
- * felix.heinrichs@trusted-mails.com
- * @author Marcus Beckerle | XQueue GmbH |
- * marcus.beckerle@xqueue.com
+ * @author Felix Heinrichs
+ * @author Marcus Beckerle | XQueue GmbH | marcus.beckerle@xqueue.com
*/
class ContactsService extends AbstractMaileonService
{
@@ -21,52 +26,46 @@ class ContactsService extends AbstractMaileonService
* Creates or updates a contact and optionally triggers a double opt-in (doi) process.
* Note that none of the attributes is required.
*
- * @param Contact $contact
- * the contact to create or update; if no permission is set, the Maileon default permission "NONE" will be used
- * @param SynchronizationMode $syncMode
- * the synchronization mode to employ
- * @param string $src
- * A string intended to describe the source of the contact.
- * If provided, the string will be stored with the doi process.
- * @param string $subscriptionPage
- * In case where this method was called by a subscription page,
- * this string offers the possibility to keep track of it for use in reports.
- * @param bool $doi
- * Tells whether a double opt-in process should be started for the created contact.
- * Note that the status code returned for this request does not mean that the doi
- * process succeeded.
- * @param bool $doiPlus
- * This parameter is ignored if doi is not provided or false. In case the doi
- * process succeeds, Maileon will be allowed to track opens and clicks of the contact.
- * @param string $doiMailingKey
- * This parameter is ignored if doi is not provided or false. References the
- * doi mailing to be used. If not provided, the default doi mailing will be used.
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @param Contact $contact The contact to create or update; if no permission is set, the Maileon default
+ * permission "NONE" will be used
+ * @param SynchronizationMode $syncMode The synchronization mode to employ
+ * @param string $src A string intended to describe the source of the contact. If provided, the string will
+ * be stored with the doi process.
+ * @param string $subscriptionPage In case where this method was called by a subscription page, this string offers the
+ * possibility to keep track of it for use in reports.
+ * @param bool $doi Tells whether a double opt-in process should be started for the created contact. Note
+ * that the status code returned for this request does not mean that the doi process
+ * succeeded.
+ * @param bool $doiPlus This parameter is ignored if doi is not provided or false. In case the doi process
+ * succeeds, Maileon will be allowed to track opens and clicks of the contact.
+ * @param string $doiMailingKey This parameter is ignored if doi is not provided or false. References the doi mailing
+ * to be used. If not provided, the default doi mailing will be used.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function createContact(
$contact,
$syncMode,
- $src = "",
- $subscriptionPage = "",
+ $src = '',
+ $subscriptionPage = '',
$doi = false,
$doiPlus = false,
- $doiMailingKey = ""
+ $doiMailingKey = ''
) {
- $queryParameters = array(
- 'sync_mode' => $syncMode->getCode(),
- 'src' => urlencode($src),
+ $queryParameters = [
+ 'sync_mode' => $syncMode->getCode(),
+ 'src' => urlencode($src),
'subscription_page' => urlencode($subscriptionPage),
- 'doi' => ($doi == true) ? "true" : "false",
- 'doiplus' => ($doiPlus == true) ? "true" : "false"
- );
-
+ 'doi' => $doi === true ? 'true' : 'false',
+ 'doiplus' => $doiPlus === true ? 'true' : 'false',
+ ];
// As empty does not work with return values (sometimes?), first trim the variable, then check it
$doiMailingKey = trim((string) $doiMailingKey);
- if (!empty($doiMailingKey)) {
+
+ if (! empty($doiMailingKey)) {
$queryParameters['doimailing'] = $doiMailingKey;
}
@@ -88,7 +87,13 @@ public function createContact(
$contact->preferences
);
- return $this->post("contacts/email/" . $contactToSend->email, $contactToSend->toXMLString(), $queryParameters);
+ $encodedContactToSendEmail = rawurlencode(mb_convert_encoding((string) $contactToSend->email, 'UTF-8'));
+
+ return $this->post(
+ "contacts/email/$encodedContactToSendEmail",
+ $contactToSend->toXMLString(),
+ $queryParameters
+ );
}
/**
@@ -97,49 +102,42 @@ public function createContact(
* Also note: this call returns 409 Conflict if more then one contact with the given external ID
* exists as it is impossible to determine the correct contact to update.
*
- * @param Contact $contact
- * the contact to create or update
- * @param SynchronizationMode $syncMode
- * the synchronization mode to employ
- * @param string $src
- * A string intended to describe the source of the contact.
- * If provided, the string will be stored with the doi process.
- * @param string $subscriptionPage
- * In case where this method was called by a subscription page,
- * this string offers the possibility to keep track of it for use in reports.
- * @param bool $doi
- * Tells whether a double opt-in process should be started for the created contact.
- * Note that the status code returned for this request does not mean that the doi
- * process succeeded.
- * @param bool $doiPlus
- * This parameter is ignored if doi is not provided or false. In case the doi
- * process succeeds, Maileon will be allowed to track opens and clicks of the contact.
- * @param string $doiMailingKey
- * This parameter is ignored if doi is not provided or false. References the
- * doi mailing to be used. If not provided, the default doi mailing will be used.
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @param Contact $contact The contact to create or update
+ * @param SynchronizationMode $syncMode The synchronization mode to employ
+ * @param string $src A string intended to describe the source of the contact. If provided, the string will
+ * be stored with the doi process.
+ * @param string $subscriptionPage In case where this method was called by a subscription page, this string offers the
+ * possibility to keep track of it for use in reports.
+ * @param bool $doi Tells whether a double opt-in process should be started for the created contact. Note
+ * that the status code returned for this request does not mean that the doi process
+ * succeeded.
+ * @param bool $doiPlus This parameter is ignored if doi is not provided or false. In case the doi process
+ * succeeds, Maileon will be allowed to track opens and clicks of the contact.
+ * @param string $doiMailingKey This parameter is ignored if doi is not provided or false. References the doi mailing
+ * to be used. If not provided, the default doi mailing will be used.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function createContactByExternalId(
$contact,
$syncMode,
- $src = "",
- $subscriptionPage = "",
+ $src = '',
+ $subscriptionPage = '',
$doi = false,
$doiPlus = false,
- $doiMailingKey = ""
+ $doiMailingKey = ''
) {
- $queryParameters = array(
- 'permission' => $contact->permission->getCode(),
- 'sync_mode' => $syncMode->getCode(),
- 'src' => urlencode($src),
+ $queryParameters = [
+ 'permission' => $contact->permission->getCode(),
+ 'sync_mode' => $syncMode->getCode(),
+ 'src' => urlencode($src),
'subscription_page' => urlencode($subscriptionPage),
- 'doi' => ($doi == true) ? "true" : "false",
- 'doiplus' => ($doiPlus == true) ? "true" : "false",
- 'doimailing' => trim((string) $doiMailingKey)
- );
+ 'doi' => $doi === true ? 'true' : 'false',
+ 'doiplus' => $doiPlus === true ? 'true' : 'false',
+ 'doimailing' => trim((string) $doiMailingKey),
+ ];
// The API allows only some of the fields to be submitted
$contactToSend = new Contact(
@@ -155,8 +153,10 @@ public function createContactByExternalId(
$contact->preferences
);
+ $encodedContactToSendExternalId = rawurlencode(mb_convert_encoding((string) $contactToSend->external_id, 'UTF-8'));
+
return $this->post(
- "contacts/externalid/" . $contactToSend->external_id,
+ "contacts/externalid/$encodedContactToSendExternalId",
$contactToSend->toXMLString(),
$queryParameters
);
@@ -169,104 +169,96 @@ public function createContactByExternalId(
* Please refer to the documentation of the profile update pages for more details
* about how to get the maileon contact id and the corresponding checksum.
*
- * @param string $contactId
- * the maileon contact id
- * @param string $checksum
- * the checksum of the maileon contact id
- * @param array $standard_fields
- * the standard fields to retrieve with the contact
- * @param array $custom_fields
- * the custom fields to retrieve with the contact
- * @param bool $ignoreChecksum
- * if set to true, no checksum is required
- * @param array $preference_categories
- * the preference categories to return with the contact
- * @return MaileonAPIResult
- * the result object of the API call, with a Contact
- * available at MaileonAPIResult::getResult()
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @param string $contactId The maileon contact id
+ * @param string $checksum The checksum of the maileon contact id
+ * @param array $standard_fields The standard fields to retrieve with the contact
+ * @param array $custom_fields The custom fields to retrieve with the contact
+ * @param bool $ignoreChecksum if set to true, no checksum is required
+ * @param array $preference_categories The preference categories to return with the contact
+ *
+ * @return MaileonAPIResult|null The result object of the API call, with a Contact available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getContact(
$contactId,
$checksum,
- $standard_fields = array(),
- $custom_fields = array(),
+ $standard_fields = [],
+ $custom_fields = [],
$ignoreChecksum = false,
- $preference_categories = array()
+ $preference_categories = []
) {
- $queryParameters = array(
- 'id' => $contactId,
- 'checksum' => $checksum,
- 'standard_field' => $standard_fields,
- 'ignore_checksum' => $ignoreChecksum ? "true" : "false"
- );
+ $queryParameters = [
+ 'id' => $contactId,
+ 'checksum' => $checksum,
+ 'standard_field' => $standard_fields,
+ 'ignore_checksum' => $ignoreChecksum ? 'true' : 'false',
+ ];
$queryParameters = $this->appendArrayFields($queryParameters, 'custom_field', $custom_fields);
$queryParameters = $this->appendArrayFields($queryParameters, 'preference_categories', $preference_categories);
- return $this->get('contacts/contact', $queryParameters);
+ return $this->get(
+ 'contacts/contact',
+ $queryParameters
+ );
}
/**
* This method returns the number of contacts in the maileon newsletter account.
*
- * @param string $updatedAfter
- * returns contacts only, which were updated after the given datetime.
- * The format must be in SQL format: Y-m-d H:i:s
- * @return MaileonAPIResult
- * the result object of the API call, with the count of contacts
- * available at MaileonAPIResult::getResult()
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @param string $updatedAfter return only contacts, which were updated after the given datetime. The format must be in SQL format:
+ * Y-m-d H:i:s
+ *
+ * @return MaileonAPIResult|null The result object of the API call, with the count of contacts available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getContactsCount($updatedAfter = null)
{
- $queryParameters = array();
- if (!empty($updatedAfter)) {
+ $queryParameters = [];
+
+ if (! empty($updatedAfter)) {
// Currently, let API handle validation
$queryParameters['updated_after'] = urlencode($updatedAfter);
}
- return $this->get('contacts/count', $queryParameters);
+
+ return $this->get(
+ 'contacts/count',
+ $queryParameters
+ );
}
/**
* Returns a page of contacts in the account.
*
- * @param int $page_index
- * the index of the result page to fetch
- * @param int $page_size
- * the number of results to fetch per page
- * @param array $standard_fields
- * the standard fields to retrieve for the contacts
- * @param array $custom_fields
- * the custom fields to retrieve for the contacts
- * @param string $updatedAfter
- * returns contacts only, which were updated after the given datetime.
- * The format must be in SQL format: Y-m-d H:i:s
- * @param array $preference_categories
- * the preference categories to return with the contact
- * @return MaileonAPIResult
- * the result object of the API call, with a Contacts
- * available at MaileonAPIResult::getResult()
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @param int $page_index The index of the result page to fetch
+ * @param int $page_size The number of results to fetch per page
+ * @param array $standard_fields The standard fields to retrieve for the contacts
+ * @param array $custom_fields The custom fields to retrieve for the contacts
+ * @param string $updatedAfter returns contacts only, which were updated after the given datetime. The format must be in SQL
+ * format: Y-m-d H:i:s
+ * @param array $preference_categories The preference categories to return with the contact
+ *
+ * @return MaileonAPIResult|null The result object of the API call, with a Contacts available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getContacts(
$page_index = 1,
$page_size = 100,
- $standard_fields = array(),
- $custom_fields = array(),
+ $standard_fields = [],
+ $custom_fields = [],
$updatedAfter = null,
- $preference_categories = array()
+ $preference_categories = []
) {
- $queryParameters = array(
- 'page_index' => $page_index,
- 'page_size' => $page_size,
- 'standard_field' => $standard_fields
- );
-
- if (!empty($updatedAfter)) {
+ $queryParameters = [
+ 'page_index' => $page_index,
+ 'page_size' => $page_size,
+ 'standard_field' => $standard_fields,
+ ];
+
+ if (! empty($updatedAfter)) {
// Currently, let API handle validation
$queryParameters['updated_after'] = urlencode($updatedAfter);
}
@@ -274,234 +266,225 @@ public function getContacts(
$queryParameters = $this->appendArrayFields($queryParameters, 'custom_field', $custom_fields);
$queryParameters = $this->appendArrayFields($queryParameters, 'preference_categories', $preference_categories);
- return $this->get('contacts', $queryParameters);
+ return $this->get(
+ 'contacts',
+ $queryParameters
+ );
}
/**
* Returns a contact with the provided email address.
*
- * @param string $email
- * the email address to retrieve a contact for
- * @param array $standard_fields
- * the standard fields to return with the contact
- * @param array $custom_fields
- * the custom fields to return with the contact
- * @param array $preference_categories
- * the preference categories to return with the contact
- * @return MaileonAPIResult
- * the result object of the API call, with a Contact
- * available at MaileonAPIResult::getResult()
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @param string $email The email address to retrieve a contact for
+ * @param array $standard_fields The standard fields to return with the contact
+ * @param array $custom_fields The custom fields to return with the contact
+ * @param array $preference_categories The preference categories to return with the contact
+ *
+ * @return MaileonAPIResult|null The result object of the API call, with a Contact available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getContactByEmail(
$email,
- $standard_fields = array(),
- $custom_fields = array(),
- $preference_categories = array()
+ $standard_fields = [],
+ $custom_fields = [],
+ $preference_categories = []
) {
- $queryParameters = array(
- 'standard_field' => $standard_fields
- );
+ $encodedEmail = rawurlencode(mb_convert_encoding((string) $email, 'UTF-8'));
+
+ $queryParameters = ['standard_field' => $standard_fields];
$queryParameters = $this->appendArrayFields($queryParameters, 'custom_field', $custom_fields);
$queryParameters = $this->appendArrayFields($queryParameters, 'preference_categories', $preference_categories);
- return $this->get('contacts/email/' . mb_convert_encoding($email, "UTF-8"), $queryParameters);
+ return $this->get(
+ "contacts/email/$encodedEmail",
+ $queryParameters
+ );
}
/**
* Returns a list of contacts with the provided email address.
*
- * @param string $email
- * the email address to retrieve a contact for
- * @param array $standard_fields
- * the standard fields to return with the contact
- * @param array $custom_fields
- * the custom fields to return with the contact
- * @param array $preference_categories
- * the preference categories to return with the contact
- * @return MaileonAPIResult
- * the result object of the API call, with an array of Contact
- * available at MaileonAPIResult::getResult()
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @param string $email The email address to retrieve a contact for
+ * @param array $standard_fields The standard fields to return with the contact
+ * @param array $custom_fields The custom fields to return with the contact
+ * @param array $preference_categories The preference categories to return with the contact
+ *
+ * @return MaileonAPIResult|null The result object of the API call, with a Contacts available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getContactsByEmail(
$email,
- $standard_fields = array(),
- $custom_fields = array(),
- $preference_categories = array()
+ $standard_fields = [],
+ $custom_fields = [],
+ $preference_categories = []
) {
- $queryParameters = array(
- 'standard_field' => $standard_fields
- );
+ $encodedEmail = rawurlencode(mb_convert_encoding((string) $email, 'UTF-8'));
+
+ $queryParameters = ['standard_field' => $standard_fields];
$queryParameters = $this->appendArrayFields($queryParameters, 'custom_field', $custom_fields);
$queryParameters = $this->appendArrayFields($queryParameters, 'preference_categories', $preference_categories);
- return $this->get('contacts/emails/' . mb_convert_encoding($email, "UTF-8"), $queryParameters);
+ return $this->get(
+ "contacts/emails/$encodedEmail",
+ $queryParameters
+ );
}
/**
* Retrieves all contacts with a given external ID.
*
- * @param string $externalId
- * the external ID to search for
- * @param array $standard_fields
- * the standard fields to return with the contact
- * @param array $custom_fields
- * the custom fields to return with the contact
- * @param array $preference_categories
- * the preference categories to return with the contact
- * @return MaileonAPIResult
- * the result object of the API call, with a Contacts
- * available at MaileonAPIResult::getResult()
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @param string $externalId The external ID to search for
+ * @param array $standard_fields The standard fields to return with the contact
+ * @param array $custom_fields The custom fields to return with the contact
+ * @param array $preference_categories The preference categories to return with the contact
+ *
+ * @return MaileonAPIResult|null The result object of the API call, with a Contacts available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getContactsByExternalId(
$externalId,
- $standard_fields = array(),
- $custom_fields = array(),
- $preference_categories = array()
+ $standard_fields = [],
+ $custom_fields = [],
+ $preference_categories = []
) {
- $queryParameters = array(
- 'standard_field' => $standard_fields
- );
+ $encodedExternalId = rawurlencode(mb_convert_encoding((string) $externalId, 'UTF-8'));
+
+ $queryParameters = ['standard_field' => $standard_fields];
$queryParameters = $this->appendArrayFields($queryParameters, 'custom_field', $custom_fields);
$queryParameters = $this->appendArrayFields($queryParameters, 'preference_categories', $preference_categories);
- return $this->get('contacts/externalid/' . mb_convert_encoding($externalId, "UTF-8"), $queryParameters);
+ return $this->get(
+ "contacts/externalid/$encodedExternalId",
+ $queryParameters
+ );
}
/**
* Retrieves all contacts with a given contact filter ID.
*
- * @param string $filterId
- * the filter ID to use to select contacts
- * @param int $page_index
- * the index of the result page to fetch
- * @param int $page_size
- * the number of results to fetch per page
- * @param array $standard_fields
- * the standard fields to return with the contact
- * @param array $custom_fields
- * the custom fields to return with the contact
- * @param array $preference_categories
- * the preference categories to return with the contact
- * @return MaileonAPIResult
- * the result object of the API call, with a Contacts
- * available at MaileonAPIResult::getResult()
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @param string $filterId The filter ID to use to select contacts
+ * @param int $page_index The index of the result page to fetch
+ * @param int $page_size The number of results to fetch per page
+ * @param array $standard_fields The standard fields to return with the contact
+ * @param array $custom_fields The custom fields to return with the contact
+ * @param array $preference_categories The preference categories to return with the contact
+ *
+ * @return MaileonAPIResult|null The result object of the API call, with a Contacts available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getContactsByFilterId(
$filterId,
$page_index = 1,
$page_size = 100,
- $standard_fields = array(),
- $custom_fields = array(),
- $preference_categories = array()
+ $standard_fields = [],
+ $custom_fields = [],
+ $preference_categories = []
) {
- $queryParameters = array(
- 'page_index' => $page_index,
- 'page_size' => $page_size,
- 'standard_field' => $standard_fields
- );
+ $encodedFilterId = rawurlencode(mb_convert_encoding((string) $filterId, 'UTF-8'));
+
+ $queryParameters = [
+ 'page_index' => $page_index,
+ 'page_size' => $page_size,
+ 'standard_field' => $standard_fields,
+ ];
$queryParameters = $this->appendArrayFields($queryParameters, 'custom_field', $custom_fields);
$queryParameters = $this->appendArrayFields($queryParameters, 'preference_categories', $preference_categories);
- return $this->get('contacts/filter/' . mb_convert_encoding($filterId, "UTF-8"), $queryParameters);
+ return $this->get(
+ "contacts/filter/$encodedFilterId",
+ $queryParameters
+ );
}
/**
* Retrieves the number of contacts matching a given contact filter ID.
*
- * @param string $filterId
- * the filter ID to use to select contacts
- * @return MaileonAPIResult
- * the result object of the API call, with the number
- * available at MaileonAPIResult::getResult()
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @param string $filterId The filter ID to use to select contacts
+ *
+ * @return MaileonAPIResult|null The result object of the API call, with the number available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getCountContactsByFilterId($filterId)
{
- return $this->get('contacts/filter/' . mb_convert_encoding($filterId, "UTF-8") . '/count');
+ $encodedFilterId = rawurlencode(mb_convert_encoding((string) $filterId, 'UTF-8'));
+
+ return $this->get("contacts/filter/$encodedFilterId/count");
}
/**
* Retrieves the number of active contacts matching a given contact filter ID.
*
- * @param string $filterId
- * the filter ID to use to select contacts
- * @return MaileonAPIResult
- * the result object of the API call, with the number
- * available at MaileonAPIResult::getResult()
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @param string $filterId The filter ID to use to select contacts
+ *
+ * @return MaileonAPIResult|null The result object of the API call, with the number available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getCountActiveContactsByFilterId($filterId)
{
- return $this->get('contacts/filter/' . mb_convert_encoding($filterId, "UTF-8") . '/count/active');
+ $encodedFilterId = rawurlencode(mb_convert_encoding((string) $filterId, 'UTF-8'));
+
+ return $this->get("contacts/filter/$encodedFilterId/count/active");
}
/**
- * This methods updates the data of a Maileon contact identifying a contact by its internal Maileon ID
- *
- * @param Contact $contact
- * The contact object to send to Maileon.
- * @param string $checksum
- * This is the checksum that must be used when the request comes from a user,
- * see documentation under http://dev.maileon.com for details.
- * @param string $src
- * The source that shall be passed to the API.
- * @param string $subscriptionPage
- * The subscription page the request comes from.
- * @param bool $triggerDoi
- * If true, a DOI mailing will be triggered.
- * @param string $doiMailingKey
- * If this parameter is set, the DOI mailing with the given ID will be triggered.
- * If not set, the default DOI Mailing will be triggered.
- * @param bool $ignoreChecksum
- * If this is true, the checksum will not be validated.
- * This is only valid if the request is NOT triggered by the contact (e.g. on a profile change landing page)
- * but from a third party system.
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * This method updates the data of a Maileon contact identifying a contact by its internal Maileon ID
+ *
+ * @param Contact $contact The contact object to send to Maileon.
+ * @param string $checksum This is the checksum that must be used when the request comes from a user, see documentation under
+ * https://support.maileon.com/ for details.
+ * @param string $src The source that shall be passed to the API.
+ * @param string $subscriptionPage The subscription page the request comes from.
+ * @param bool $triggerDoi If true, a DOI mailing will be triggered.
+ * @param string $doiMailingKey If this parameter is set, the DOI mailing with the given ID will be triggered. If not set, the
+ * default DOI Mailing will be triggered.
+ * @param bool $ignoreChecksum If this is true, the checksum will not be validated. This is only valid if the request is NOT
+ * triggered by the contact (e.g. on a profile change landing page) but from a third party system.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function updateContact(
$contact,
- $checksum = "",
+ $checksum = '',
$src = null,
$subscriptionPage = null,
$triggerDoi = false,
$doiMailingKey = null,
$ignoreChecksum = false
) {
- $queryParameters = array(
- 'id' => $contact->id,
- 'checksum' => $checksum,
- 'triggerdoi' => ($triggerDoi == true) ? "true" : "false",
- 'ignore_checksum' => $ignoreChecksum ? "true" : "false"
- );
+ $queryParameters = [
+ 'id' => $contact->id,
+ 'checksum' => $checksum,
+ 'triggerdoi' => $triggerDoi === true ? 'true' : 'false',
+ 'ignore_checksum' => $ignoreChecksum ? 'true' : 'false',
+ ];
if (isset($contact->permission)) {
$queryParameters['permission'] = $contact->permission->getCode();
}
+
if (isset($src)) {
$queryParameters['src'] = urlencode($src);
}
+
if (isset($subscriptionPage)) {
$queryParameters['page_key'] = urlencode($subscriptionPage);
}
+
$doiMailingKey = trim((string) $doiMailingKey);
- if (!empty($doiMailingKey)) {
+
+ if (! empty($doiMailingKey)) {
$queryParameters['doimailing'] = $doiMailingKey;
}
@@ -519,40 +502,36 @@ public function updateContact(
$contact->preferences
);
- return $this->put("contacts/contact", $contactToSend->toXMLString(), $queryParameters);
+ return $this->put(
+ 'contacts/contact',
+ $contactToSend->toXMLString(),
+ $queryParameters
+ );
}
/**
* Synchronizes a list of contacts with the contacts in the account and returns a
* detailed report with stats and validation errors.
*
- * @param Contacts $contacts
- * the contacts to synchronize
- * @param Permission $permission
- * the permission to set for the contacts
- * @param SynchronizationMode $syncMode
- * the sync mode to use
- * @param bool $useExternalId
- * if set to true, the external id is used as identifier for the contacts.
- * Otherwise the email address is used as identifier.
- * @param bool $ignoreInvalidContacts
- * if set to true, invalid contacts are ignored and the synchronization
- * succeeds for valid contacts.
- * @param bool $reimportUnsubscribedContacts
- * if set to true, unsubscribed contacts will be imported, if false, they will be ommitted
- * @param bool $overridePermission
- * if set to true the permission of existing and non existing contacts will be overwridden,
- * if false, the permission will be used for new contacts only and existing contacts will not be influenced.
- * @param bool $updateOnly
- * If true, only existing contacts are updated and no new contacts are created
- * @param bool $preferMaileonId
- * If true, Maileon tries identifying contacts by Maileon-ID, if available. Fallback is always the email address.
- * @return MaileonAPIResult
- * the result object of the API call. The
- * response XML reports which contacts were successfully synchronized as well as any errors that
- * might have occurred.
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @param Contacts $contacts The contacts to synchronize
+ * @param Permission $permission The permission to set for the contacts
+ * @param SynchronizationMode $syncMode The sync mode to use
+ * @param bool $useExternalId if set to true, the external id is used as identifier for the contacts.
+ * Otherwise, the email address is used as identifier.
+ * @param bool $ignoreInvalidContacts if set to true, invalid contacts are ignored and the synchronization
+ * succeeds for valid contacts.
+ * @param bool $reimportUnsubscribedContacts if set to true, unsubscribed contacts will be imported, if false, they will
+ * be ommitted
+ * @param bool $overridePermission if set to true the permission of existing and non-existing contacts will be
+ * overwridden, if false, the permission will be used for new contacts only and
+ * existing contacts will not be influenced.
+ * @param bool $updateOnly If true, only existing contacts are updated and no new contacts are created
+ * @param bool $preferMaileonId If true, Maileon tries identifying contacts by Maileon-ID, if available.
+ * Fallback is always the email address.
+ *
+ * @return MaileonAPIResult|null The result object of the API call. The response XML reports which contacts were successfully synchronized as well as any errors that might have occurred.
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function synchronizeContacts(
$contacts,
@@ -565,18 +544,19 @@ public function synchronizeContacts(
$updateOnly = false,
$preferMaileonId = false
) {
- $queryParameters = array(
- 'permission' => ($permission == null) ? 1 : $permission->getCode(),
- 'sync_mode' => ($syncMode == null) ? 2 : $syncMode->getCode(),
- 'use_external_id' => ($useExternalId == true) ? "true" : "false",
- 'ignore_invalid_contacts' => ($ignoreInvalidContacts == true) ? "true" : "false",
- 'reimport_unsubscribed_contacts' => ($reimportUnsubscribedContacts == true) ? "true" : "false",
- 'override_permission' => ($overridePermission == true) ? "true" : "false",
- 'update_only' => ($updateOnly == true) ? "true" : "false",
- 'prefer_maileon_id' => ($preferMaileonId == true) ? "true" : "false"
- );
+ $queryParameters = [
+ 'permission' => $permission === null ? 1 : $permission->getCode(),
+ 'sync_mode' => $syncMode === null ? 2 : $syncMode->getCode(),
+ 'use_external_id' => $useExternalId === true ? 'true' : 'false',
+ 'ignore_invalid_contacts' => $ignoreInvalidContacts === true ? 'true' : 'false',
+ 'reimport_unsubscribed_contacts' => $reimportUnsubscribedContacts === true ? 'true' : 'false',
+ 'override_permission' => $overridePermission === true ? 'true' : 'false',
+ 'update_only' => $updateOnly === true ? 'true' : 'false',
+ 'prefer_maileon_id' => $preferMaileonId === true ? 'true' : 'false',
+ ];
$cleanedContacts = new Contacts();
+
foreach ($contacts as $contact) {
$cleanedContact = new Contact(
$contact->id,
@@ -593,28 +573,33 @@ public function synchronizeContacts(
$cleanedContacts->addContact($cleanedContact);
}
- return $this->post("contacts", $cleanedContacts->toXMLString(), $queryParameters);
+ return $this->post(
+ 'contacts',
+ $cleanedContacts->toXMLString(),
+ $queryParameters
+ );
}
-
- /**
- * This methods updates the data of a Maileon contact identifying a contact by its email
- *
- * @param string $email The (old) email address of the contact.
- * @param Contact $contact
- * The contact object to send to Maileon. If it has a permission, it will be overwritten.
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
- */
- public function updateContactByEmail($email, $contact)
- {
- $queryParameters = array();
-
+
+ /**
+ * This method updates the data of a Maileon contact identifying a contact by its email
+ *
+ * @param string $email The (old) email address of the contact.
+ * @param Contact $contact The contact object to send to Maileon. If it has a permission, it will be overwritten.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
+ */
+ public function updateContactByEmail(
+ $email,
+ $contact
+ ) {
+ $queryParameters = [];
+
if (isset($contact->permission)) {
$queryParameters['permission'] = $contact->permission->getCode();
}
-
+
// The API allows only some of the fields to be submitted
$contactToSend = new Contact(
null,
@@ -628,38 +613,46 @@ public function updateContactByEmail($email, $contact)
null,
$contact->preferences
);
-
- $encodedEmail = mb_convert_encoding($email, "UTF-8");
- return $this->put("contacts/email/{$encodedEmail}", $contactToSend->toXMLString(), $queryParameters);
+
+ $encodedEmail = rawurlencode(mb_convert_encoding((string) $email, 'UTF-8'));
+
+ return $this->put(
+ "contacts/email/$encodedEmail",
+ $contactToSend->toXMLString(),
+ $queryParameters
+ );
}
/**
- * This method unsubscribes a contact from Maileon using the contact's email adress.
- *
- * @param string $email The email address of the contact.
- * @param string $mailingId The ID of the mailing to assign the unsubscribe to.
- * The mailing must have been sent, i.e. be sealed.
- * @param array|string $reasons an array of reasons or a single reason (string).
- * Unsubscription reasons have two layers
- * of information, see http://dev.maileon.com/api/rest-api-1-0/contacts/unsubscribe-contacts-by-email
- * for more details about the format.
- * The parameter(s) will be url-encoded by the client, you do not need to provide urlencoded strings.
- * @param array $nlAccounts Optional parameter to define in which accounts the
- * email should be unsubscribed. Note: The accounts must belong to the owner of
- * the API key in use, otherwise they will be ignored.
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * This method unsubscribes a contact from Maileon using the contact's email address.
+ *
+ * @param string $email The email address of the contact.
+ * @param string $mailingId The ID of the mailing to assign the unsubscription to. The mailing must have been sent, i.e. be
+ * sealed.
+ * @param array|string $reasons an array of reasons or a single reason (string). Unsubscription reasons have two layers of
+ * information, see https://support.maileon.com/support/unsubscribe-contacts-by-email/ for
+ * more details about the format. The parameter(s) will be url-encoded by the client, you do not need
+ * to provide urlencoded strings.
+ * @param array $nlAccountIds Optional parameter to define in which accounts the email should be unsubscribed. Note: The accounts
+ * must belong to the owner of the API key in use, otherwise they will be ignored.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function unsubscribeContactByEmail($email, $mailingId = "", $reasons = null, $nlAccountIds = array())
- {
- $queryParameters = array();
- if (!empty($mailingId)) {
+ public function unsubscribeContactByEmail(
+ $email,
+ $mailingId = '',
+ $reasons = null,
+ $nlAccountIds = []
+ ) {
+ $queryParameters = [];
+
+ if (! empty($mailingId)) {
$queryParameters['mailingId'] = $mailingId;
}
- if (!empty($reasons)) {
+ if (! empty($reasons)) {
if (is_array($reasons)) {
$queryParameters = $this->appendArrayFields($queryParameters, 'reason', $reasons);
} else {
@@ -667,7 +660,7 @@ public function unsubscribeContactByEmail($email, $mailingId = "", $reasons = nu
}
}
- if (!empty($nlAccountIds)) {
+ if (! empty($nlAccountIds)) {
if (is_array($nlAccountIds)) {
$queryParameters = $this->appendArrayFields($queryParameters, 'nlaccountid', $nlAccountIds);
} else {
@@ -675,29 +668,31 @@ public function unsubscribeContactByEmail($email, $mailingId = "", $reasons = nu
}
}
- $queryParameters = $this->appendArrayFields($queryParameters, "nlaccountid", $nlAccountIds);
+ $queryParameters = $this->appendArrayFields($queryParameters, 'nlaccountid', $nlAccountIds);
- $encodedEmail = mb_convert_encoding($email, "UTF-8");
- return $this->delete("contacts/email/{$encodedEmail}/unsubscribe", $queryParameters);
+ $encodedEmail = rawurlencode(mb_convert_encoding((string) $email, 'UTF-8'));
+
+ return $this->delete(
+ "contacts/email/$encodedEmail/unsubscribe",
+ $queryParameters
+ );
}
/**
* This method adds unsubscription reasons to an unsubscribed contact.
* The contact must already be unsubscribed, otherwise 400 will be returned by the PAI
*
- * @param int $id The ID of the contact.
- * @param string $checksum The checksum generated by Maileon
- * @param array|string $reasons an array of reasons or a single reason (string).
- * Unsubscription reasons have two layers
- * of information, see http://dev.maileon.com/api/rest-api-1-0/contacts/unsubscribe-contacts-by-email
- * for more details about the format.
- * The parameter(s) will be url-encoded by the client, you do not need to provide urlencoded strings.
- * @param bool $ignore_checksum If the call comes from an authorized
- * system instead of the user you might ignore the checksum
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @param int $id The ID of the contact.
+ * @param string $checksum The checksum generated by Maileon
+ * @param array|string $reasons an array of reasons or a single reason (string). Unsubscription reasons have two layers of
+ * information, see https://support.maileon.com/support/unsubscribe-contacts-by-email/
+ * for more details about the format. The parameter(s) will be url-encoded by the client, you do
+ * not need to provide urlencoded strings.
+ * @param bool $ignore_checksum If the call comes from an authorized system instead of the user you might ignore the checksum
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function addUnsubscriptionReasonsToUnsubscribedContact(
$id,
@@ -705,16 +700,18 @@ public function addUnsubscriptionReasonsToUnsubscribedContact(
$reasons = null,
$ignore_checksum = false
) {
- $queryParameters = array();
+ $queryParameters = [];
$queryParameters['id'] = $id;
- if (!empty($checksum)) {
+
+ if (! empty($checksum)) {
$queryParameters['checksum'] = $checksum;
}
- if ($ignore_checksum===true) {
- $queryParameters['ignore_checksum'] = "true";
+
+ if ($ignore_checksum === true) {
+ $queryParameters['ignore_checksum'] = 'true';
}
- if (!empty($reasons)) {
+ if (! empty($reasons)) {
if (is_array($reasons)) {
$queryParameters = $this->appendArrayFields($queryParameters, 'reason', $reasons);
} else {
@@ -722,35 +719,40 @@ public function addUnsubscriptionReasonsToUnsubscribedContact(
}
}
- return $this->put("contacts/contact/unsubscribe/reasons", null, $queryParameters);
+ return $this->put(
+ 'contacts/contact/unsubscribe/reasons',
+ null,
+ $queryParameters
+ );
}
/**
* This method unsubscribes a contact from Maileon using the Maileon id.
*
- * @param int $id
- * @param int $mailingId The ID of the mailing to assign the unsubscribe to.
- * The mailing must have been sent, i.e. be sealed.
- * @param array|string $reasons an array of reasons or a single reason (string).
- * Unsubscription reasons have two layers
- * of information, see http://dev.maileon.com/api/rest-api-1-0/contacts/unsubscribe-contacts-by-maileon-id
- * for more details about the format.
- * The parameter(s) will be url-encoded by the client, you do not need to provide urlencoded strings.
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @param int $id
+ * @param int $mailingId The ID of the mailing to assign the unsubscription to. The mailing must have been sent, i.e. be
+ * sealed.
+ * @param array|string $reasons an array of reasons or a single reason (string). Unsubscription reasons have two layers of
+ * information, see https://support.maileon.com/support/unsubscribe-contact-by-maileon-id/
+ * for more details about the format. The parameter(s) will be url-encoded by the client, you do not need
+ * to provide urlencoded strings.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function unsubscribeContactById($id, $mailingId = "", $reasons = null)
- {
- $queryParameters = array(
- 'id' => $id
- );
+ public function unsubscribeContactById(
+ $id,
+ $mailingId = '',
+ $reasons = null
+ ) {
+ $queryParameters = ['id' => $id];
- if (!empty($mailingId)) {
+ if (! empty($mailingId)) {
$queryParameters['mailingId'] = $mailingId;
}
- if (!empty($reasons)) {
+
+ if (! empty($reasons)) {
if (is_array($reasons)) {
$queryParameters = $this->appendArrayFields($queryParameters, 'reason', $reasons);
} else {
@@ -758,28 +760,32 @@ public function unsubscribeContactById($id, $mailingId = "", $reasons = null)
}
}
- return $this->delete("contacts/contact/unsubscribe", $queryParameters);
+ return $this->delete(
+ 'contacts/contact/unsubscribe',
+ $queryParameters
+ );
}
-
+
/**
- * This methods updates the data of a Maileon contact identifying a contact by its external ID
- *
- * @param string $externalId The (old) external ID of the contact.
- * @param Contact $contact
- * The contact object to send to Maileon. If it has a permission, it will be overwritten.
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * This method updates the data of a Maileon contact identifying a contact by its external ID
+ *
+ * @param string $externalId The (old) external ID of the contact.
+ * @param Contact $contact The contact object to send to Maileon. If it has a permission, it will be overwritten.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function updateContactByExternalId($externalId, $contact)
- {
- $queryParameters = array();
-
+ public function updateContactByExternalId(
+ $externalId,
+ $contact
+ ) {
+ $queryParameters = [];
+
if (isset($contact->permission)) {
$queryParameters['permission'] = $contact->permission->getCode();
}
-
+
// The API allows only some of the fields to be submitted
$contactToSend = new Contact(
null,
@@ -793,35 +799,42 @@ public function updateContactByExternalId($externalId, $contact)
null,
$contact->preferences
);
-
- $encodedExternalId = urlencode($externalId);
- return $this->put("contacts/externalid/{$encodedExternalId}", $contactToSend->toXMLString(), $queryParameters);
+
+ $encodedExternalId = rawurlencode(mb_convert_encoding((string) $externalId, 'UTF-8'));
+
+ return $this->put(
+ "contacts/externalid/$encodedExternalId",
+ $contactToSend->toXMLString(),
+ $queryParameters
+ );
}
/**
* This method unsubscribes a contact from Maileon using the external id.
*
* @param string $externalId The external ID of the contact.
- * @param string $mailingId The ID of the mailing to assign the unsubscribe to.
- * The mailing must have been sent, i.e. be sealed.
- * @param array $reasons an array of reasons or a single reason (string).
- * Unsubscription reasons have two layers
- * of information, see http://dev.maileon.com/api/rest-api-1-0/contacts/unsubscribe-contacts-external-id
- * for more details about the format.
- * The parameter(s) will be url-encoded by the client, you do not need to provide urlencoded strings.
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @param string $mailingId The ID of the mailing to assign the unsubscription to. The mailing must have been sent, i.e. be sealed.
+ * @param array $reasons an array of reasons or a single reason (string). Unsubscription reasons have two layers of information,
+ * see https://support.maileon.com/support/unsubscribe-contacts-by-external-id/ for more details
+ * about the format. The parameter(s) will be url-encoded by the client, you do not need to provide urlencoded
+ * strings.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function unsubscribeContactByExternalId($externalId, $mailingId = "", $reasons = null)
- {
- $queryParameters = array();
- if (!empty($mailingId)) {
+ public function unsubscribeContactByExternalId(
+ $externalId,
+ $mailingId = '',
+ $reasons = null
+ ) {
+ $queryParameters = [];
+
+ if (! empty($mailingId)) {
$queryParameters['mailingId'] = $mailingId;
}
- if (!empty($reasons)) {
+ if (! empty($reasons)) {
if (is_array($reasons)) {
$queryParameters = $this->appendArrayFields($queryParameters, 'reason', $reasons);
} else {
@@ -829,8 +842,12 @@ public function unsubscribeContactByExternalId($externalId, $mailingId = "", $re
}
}
- $encodedExternalId = mb_convert_encoding($externalId, "UTF-8");
- return $this->delete("contacts/externalid/{$encodedExternalId}/unsubscribe", $queryParameters);
+ $encodedExternalId = rawurlencode(mb_convert_encoding((string) $externalId, 'UTF-8'));
+
+ return $this->delete(
+ "contacts/externalid/$encodedExternalId/unsubscribe",
+ $queryParameters
+ );
}
/**
@@ -838,20 +855,25 @@ public function unsubscribeContactByExternalId($externalId, $mailingId = "", $re
* (owner of API key must also be the same customer owning the other accounts).
*
* @param string $externalId
- * @param array $nlaccountid The ID of the mailing to assign the unsubscribe to.
- * The mailing must have been sent, i.e. be sealed.
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @param array $nlAccountIds The ID of the mailing to assign the unsubscription to. The mailing must have been sent, i.e. be sealed.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function unsubscribeContactByExternalIdFromMultipleAccounts($externalId, $nlAccountIds = array())
- {
- $queryParameters = array();
- $queryParameters = $this->appendArrayFields($queryParameters, "nlaccountid", $nlAccountIds);
+ public function unsubscribeContactByExternalIdFromMultipleAccounts(
+ $externalId,
+ $nlAccountIds = []
+ ) {
+ $queryParameters = [];
+ $queryParameters = $this->appendArrayFields($queryParameters, 'nlaccountid', $nlAccountIds);
+
+ $encodedExternalId = rawurlencode(mb_convert_encoding((string) $externalId, 'UTF-8'));
- $encodedExternalId = mb_convert_encoding($externalId, "UTF-8");
- return $this->delete("contacts/externalid/{$encodedExternalId}/unsubscribe", $queryParameters);
+ return $this->delete(
+ "contacts/externalid/$encodedExternalId/unsubscribe",
+ $queryParameters
+ );
}
/**
@@ -859,139 +881,143 @@ public function unsubscribeContactByExternalIdFromMultipleAccounts($externalId,
* but that are blocked for sendouts because of blacklist matches or similar reasons such as
* bounce policy.
*
- * @param array $standardFields
- * the standard fields to select
- * @param array $customFields
- * the custom fields to select
- * @param int $pageIndex
- * the paging index of the page to retrieve
- * @param int $pageSize
- * the number of results per page
- * @return MaileonAPIResult
- * the result object of the API call
- * @return MaileonAPIResult
- * the result object of the API call, with a com_maileon_api_co
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurredntacts_Contacts
- * available at MaileonAPIResult::getResult()
+ * @param array $standardFields The standard fields to select
+ * @param array $customFields The custom fields to select
+ * @param int $pageIndex The paging index of the page to retrieve
+ * @param int $pageSize The number of results per page
+ *
+ * @return MaileonAPIResult|null The result object of the API call, with a Contacts available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getBlockedContacts(
- $standardFields = array(),
- $customFields = array(),
+ $standardFields = [],
+ $customFields = [],
$pageIndex = 1,
$pageSize = 1000
) {
- $queryParameters = array(
+ $queryParameters = [
'standard_field' => $standardFields,
- 'page_index' => $pageIndex,
- 'page_size' => $pageSize
- );
+ 'page_index' => $pageIndex,
+ 'page_size' => $pageSize,
+ ];
$queryParameters = $this->appendArrayFields($queryParameters, 'custom_field', $customFields);
- return $this->get('contacts/blocked', $queryParameters);
+ return $this->get(
+ 'contacts/blocked',
+ $queryParameters
+ );
}
/**
* This method removes a contact completely from Maileon using the maileon ID.
* WARNING: the contact is COMPLETELY removed, not only unsubscribed. This means that not only the
* contact data is removed but also all statistics change.
- * For most usecases the unsubscribe method is more appropriate.
- *
- * @param string $id
- * The id of the contact to delete.
- * @return MaileonAPIResult
- * The result object of the API call
- * @throws MaileonAPIException
- * If there was a connection problem or a server error occurred
+ * For most use cases the unsubscribe method is more appropriate.
+ *
+ * @param string $id The ID of the contact to delete.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function deleteContact($id)
{
- $queryParameters = array('id' => $id);
- return $this->delete("contacts/contact", $queryParameters);
+ $queryParameters = ['id' => $id];
+
+ return $this->delete(
+ 'contacts/contact',
+ $queryParameters
+ );
}
/**
* This method removes all contacts completely from Maileon using the email address.
* WARNING: the contacts are COMPLETELY removed, not only unsubscribed. This means that not
* only the contact data is removed but also all statistics change.
- * For most usecases the unsubscribe method is more appropriate.
- *
- * @param string $email
- * The email address of the contact to delete. Does not need to be unique.
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * For most use cases the unsubscribe method is more appropriate.
+ *
+ * @param string $email The email address of the contact to delete. Does not need to be unique.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function deleteContactByEmail($email)
{
- return $this->delete("contacts/email/" . mb_convert_encoding($email, "UTF-8"));
+ $encodedEmail = rawurlencode(mb_convert_encoding((string) $email, 'UTF-8'));
+
+ return $this->delete("contacts/email/$encodedEmail");
}
/**
* This method removes the contacts completely from Maileon using the external id.
* WARNING: the contacts are COMPLETELY removed, not only unsubscribed. This means that not only
* the contact data is removed but also all statistics change.
- * For most usecases the unsubscribe method is more appropriate.
- *
- * @param string $external ID
- * The external ID of the contact to delete. Does not need to be unique.
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * For most use cases the unsubscribe method is more appropriate.
+ *
+ * @param string $externalId The external ID of the contact to delete. Does not need to be unique.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function deleteContactsByExternalId($externalId)
{
- return $this->delete("contacts/externalid/" . mb_convert_encoding($externalId, "UTF-8"));
+ $encodedExternalId = rawurlencode(mb_convert_encoding((string) $externalId, 'UTF-8'));
+
+ return $this->delete("contacts/externalid/$encodedExternalId");
}
/**
* This method DELETES ALL CONTACTS. Never ever call this unless you'd prefer a career change anyway.
*
- * @return MaileonAPIResult
- * the result object of the API call, with a Contact
- * available at MaileonAPIResult::getResult()
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @return MaileonAPIResult|null The result object of the API call, with a Contact available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function deleteAllContacts($authorized = "no")
+ public function deleteAllContacts($authorized = 'no')
{
- $queryParameters = array(
- 'authorized' => $authorized
+ $queryParameters = ['authorized' => $authorized];
+
+ return $this->delete(
+ 'contacts',
+ $queryParameters
);
- return $this->delete("contacts", $queryParameters);
}
/**
* Creates a custom contact field with the provided name and data type.
*
- * @param string $name
- * the name of the new field
- * @param string $type
- * the type of the new field. Valid values are 'string', 'integer', 'float', 'date' or 'boolean'.
- * @return MaileonAPIResult
- * the result object of the API call, with a Contact
- * available at MaileonAPIResult::getResult()
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @param string $name The name of the new field
+ * @param string $type The type of the new field. Valid values are 'string', 'integer', 'float', 'date' or 'boolean'.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, with a Contact available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function createCustomField($name, $type = 'string')
- {
- $queryParameters = array('type' => $type);
- $encodedName = rawurlencode(mb_convert_encoding($name, "UTF-8"));
- return $this->post("contacts/fields/custom/{$encodedName}", "", $queryParameters);
+ public function createCustomField(
+ $name,
+ $type = 'string'
+ ) {
+ $queryParameters = ['type' => $type];
+
+ $encodedName = rawurlencode(mb_convert_encoding((string) $name, 'UTF-8'));
+
+ return $this->post(
+ "contacts/fields/custom/$encodedName",
+ '',
+ $queryParameters
+ );
}
/**
* Returns the custom contact fields defined in the account.
*
- * @return MaileonAPIResult
- * the result object of the API call, with a com_maileon_api_contacts_CustomFields
- * available at MaileonAPIResult::getResult()
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @return MaileonAPIResult|null The result object of the API call, with a CustomFields available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getCustomFields()
{
@@ -999,81 +1025,80 @@ public function getCustomFields()
}
/**
- * Renames a custom contact field. The data type and the recorded values for
- * the contacts remain unchanged.
- *
- * @param string $oldName
- * the current name of the field
- * @param string $newName
- * the new name of the field
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * Renames a custom contact field. The data type and the recorded values for the contacts remain unchanged.
+ *
+ * @param string $oldName the current name of the field
+ * @param string $newName the new name of the field
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function renameCustomField($oldName, $newName)
- {
- $encodedOldName = rawurlencode(mb_convert_encoding($oldName, "UTF-8"));
- $encodedNewName = rawurlencode(mb_convert_encoding($newName, "UTF-8"));
- return $this->put("contacts/fields/custom/{$encodedOldName}/{$encodedNewName}");
+ public function renameCustomField(
+ $oldName,
+ $newName
+ ) {
+ $encodedOldName = rawurlencode(mb_convert_encoding((string) $oldName, 'UTF-8'));
+ $encodedNewName = rawurlencode(mb_convert_encoding((string) $newName, 'UTF-8'));
+
+ return $this->put("contacts/fields/custom/$encodedOldName/$encodedNewName");
}
/**
* Deletes the custom contact field with the provided name. Note that all the values of the
- * field get auotmatically deleted by this call.
- *
- * @param string $name
- * the name of the field to delete
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * field get automatically deleted by this call.
+ *
+ * @param string $name The name of the field to delete
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function deleteCustomField($name)
{
- $encodedName = rawurlencode(mb_convert_encoding($name, "UTF-8"));
- return $this->delete("contacts/fields/custom/{$encodedName}");
+ $encodedName = rawurlencode(mb_convert_encoding((string) $name, 'UTF-8'));
+
+ return $this->delete("contacts/fields/custom/$encodedName");
}
/**
* Deletes the values of the given standard contact field for all contacts.
*
- * @param string $name
- * the name of the field whose values to delete
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @param string $name The name of the field whose values to delete
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function deleteStandardFieldValues($name)
{
- $encodedName = urlencode(mb_convert_encoding($name, "UTF-8"));
- return $this->delete("contacts/fields/standard/{$encodedName}/values");
+ $encodedName = rawurlencode(mb_convert_encoding((string) $name, 'UTF-8'));
+
+ return $this->delete("contacts/fields/standard/$encodedName/values");
}
/**
* Deletes the values of the given custom contact field for all contacts.
*
- * @param string $name
- * the name of the field whose values to delete
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @param string $name The name of the field whose values to delete
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function deleteCustomFieldValues($name)
{
- $encodedName = rawurlencode(mb_convert_encoding($name, "UTF-8"));
- return $this->delete("contacts/fields/custom/{$encodedName}/values");
+ $encodedName = rawurlencode(mb_convert_encoding((string) $name, 'UTF-8'));
+
+ return $this->delete("contacts/fields/custom/$encodedName/values");
}
-
+
/**
* This method retrieves the list of contact preference categories.
*
- * @return MaileonAPIResult
- * The result object of the API call.
- * @throws MaileonAPIException
- * If there was a connection problem or a server error occurred.
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred.
*/
public function getContactPreferenceCategories()
{
@@ -1085,15 +1110,15 @@ public function getContactPreferenceCategories()
*
* @param PreferenceCategory $preferenceCategory
* The preference category model to create.
- * @return MaileonAPIResult
- * The result object of the API call.
- * @throws MaileonAPIException
- * If there was a connection problem or a server error occurred.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred.
*/
public function createContactPreferenceCategory($preferenceCategory)
{
return $this->post(
- "contacts/preference_categories/",
+ 'contacts/preference_categories/',
$preferenceCategory->toXMLString()
);
}
@@ -1101,38 +1126,37 @@ public function createContactPreferenceCategory($preferenceCategory)
/**
* Returns a preference category with the provided name.
*
- * @param string $categoryName
- * The name to retrieve a preference category for.
- * @return MaileonAPIResult
- * The result object of the API call.
- * @throws MaileonAPIException
- * If there was a connection problem or a server error occurred.
+ * @param string $categoryName The name to retrieve a preference category for.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred.
*/
public function getContactPreferenceCategoryByName($categoryName)
{
- $encodedCategoryName = rawurlencode(mb_convert_encoding($categoryName, "UTF-8"));
+ $encodedCategoryName = rawurlencode(mb_convert_encoding((string) $categoryName, 'UTF-8'));
- return $this->get("contacts/preference_categories/{$encodedCategoryName}");
+ return $this->get("contacts/preference_categories/$encodedCategoryName");
}
/**
* This method updates a contact preference category.
*
- * @param string $categoryName
- * The name of the contact preference category.
- * @param PreferenceCategory $preferenceCategory
- * The preference category model to update.
- * @return MaileonAPIResult
- * The result object of the API call.
- * @throws MaileonAPIException
- * If there was a connection problem or a server error occurred.
+ * @param string $categoryName The name of the contact preference category.
+ * @param PreferenceCategory $preferenceCategory The preference category model to update.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred.
*/
- public function updateContactPreferenceCategory($categoryName, $preferenceCategory)
- {
- $encodedCategoryName = rawurlencode(mb_convert_encoding($categoryName, "UTF-8"));
+ public function updateContactPreferenceCategory(
+ $categoryName,
+ $preferenceCategory
+ ) {
+ $encodedCategoryName = rawurlencode(mb_convert_encoding((string) $categoryName, 'UTF-8'));
return $this->put(
- "contacts/preference_categories/{$encodedCategoryName}",
+ "contacts/preference_categories/$encodedCategoryName",
$preferenceCategory->toXMLString()
);
}
@@ -1140,55 +1164,53 @@ public function updateContactPreferenceCategory($categoryName, $preferenceCatego
/**
* This method deletes a contact preference category.
*
- * @param string $categoryName
- * The name of the contact preference category.
- * @return MaileonAPIResult
- * The result object of the API call.
- * @throws MaileonAPIException
- * If there was a connection problem or a server error occurred.
+ * @param string $categoryName The name of the contact preference category.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred.
*/
public function deleteContactPreferenceCategory($categoryName)
{
- $encodedCategoryName = rawurlencode(mb_convert_encoding($categoryName, "UTF-8"));
+ $encodedCategoryName = rawurlencode(mb_convert_encoding((string) $categoryName, 'UTF-8'));
- return $this->delete("contacts/preference_categories/{$encodedCategoryName}");
+ return $this->delete("contacts/preference_categories/$encodedCategoryName");
}
/**
* This method retrieves information about the preferences of a contact preference category.
*
- * @param string $categoryName
- * The name of the contact preference category.
- * @return MaileonAPIResult
- * The result object of the API call.
- * @throws MaileonAPIException
- * If there was a connection problem or a server error occurred.
+ * @param string $categoryName The name of the contact preference category.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred.
*/
public function getPreferencesOfContactPreferencesCategory($categoryName)
{
- $encodedCategoryName = rawurlencode(mb_convert_encoding($categoryName, "UTF-8"));
+ $encodedCategoryName = rawurlencode(mb_convert_encoding((string) $categoryName, 'UTF-8'));
- return $this->get("contacts/preference_categories/{$encodedCategoryName}/preferences");
+ return $this->get("contacts/preference_categories/$encodedCategoryName/preferences");
}
/**
* This method creates a contact preference under a given contact preference category.
*
- * @param string $categoryName
- * The name of the contact preference category.
- * @param Preference $preference
- * The name of the contact preference.
- * @return MaileonAPIResult
- * The result object of the API call.
- * @throws MaileonAPIException
- * If there was a connection problem or a server error occurred.
+ * @param string $categoryName The name of the contact preference category.
+ * @param Preference $preference The name of the contact preference.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred.
*/
- public function createContactPreference($categoryName, $preference)
- {
- $encodedCategoryName = rawurlencode(mb_convert_encoding($categoryName, "UTF-8"));
+ public function createContactPreference(
+ $categoryName,
+ $preference
+ ) {
+ $encodedCategoryName = rawurlencode(mb_convert_encoding((string) $categoryName, 'UTF-8'));
return $this->post(
- "contacts/preference_categories/{$encodedCategoryName}/preferences",
+ "contacts/preference_categories/$encodedCategoryName/preferences",
$preference->toXMLString()
);
}
@@ -1196,67 +1218,64 @@ public function createContactPreference($categoryName, $preference)
/**
* This method gets details about a contact preference under a given contact preference category.
*
- * @param string $categoryName
- * The name of the contact preference category.
- * @param string $preferenceName
- * The name of the preference to retrieve.
- * @return MaileonAPIResult
- * The result object of the API call.
- * @throws MaileonAPIException
- * If there was a connection problem or a server error occurred.
+ * @param string $categoryName The name of the contact preference category.
+ * @param string $preferenceName The name of the preference to retrieve.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred.
*/
- public function getContactPreference($categoryName, $preferenceName)
- {
- $encodedCategoryName = rawurlencode(mb_convert_encoding($categoryName, "UTF-8"));
- $encodedPreferenceName = rawurlencode(mb_convert_encoding($preferenceName, "UTF-8"));
+ public function getContactPreference(
+ $categoryName,
+ $preferenceName
+ ) {
+ $encodedCategoryName = rawurlencode(mb_convert_encoding((string) $categoryName, 'UTF-8'));
+ $encodedPreferenceName = rawurlencode(mb_convert_encoding((string) $preferenceName, 'UTF-8'));
- return $this->get("contacts/preference_categories/{$encodedCategoryName}/preferences/{$encodedPreferenceName}");
+ return $this->get("contacts/preference_categories/$encodedCategoryName/preferences/$encodedPreferenceName");
}
/**
* This method updates a contact preference under a given contact preference category.
*
- * @param string $categoryName
- * The name of the contact preference category.
- * @param string $preferenceName
- * The name of the preference to update
- * @param Preference $preference
- * The updated preference model.
- * @return MaileonAPIResult
- * The result object of the API call.
- * @throws MaileonAPIException
- * If there was a connection problem or a server error occurred.
+ * @param string $categoryName The name of the contact preference category.
+ * @param string $preferenceName The name of the preference to update
+ * @param Preference $preference The updated preference model.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred.
*/
- public function updateContactPreference($categoryName, $preferenceName, $preference)
- {
- $encodedCategoryName = rawurlencode(mb_convert_encoding($categoryName, "UTF-8"));
- $encodedPreferenceName = rawurlencode(mb_convert_encoding($preferenceName, "UTF-8"));
+ public function updateContactPreference(
+ $categoryName,
+ $preferenceName,
+ $preference
+ ) {
+ $encodedCategoryName = rawurlencode(mb_convert_encoding((string) $categoryName, 'UTF-8'));
+ $encodedPreferenceName = rawurlencode(mb_convert_encoding((string) $preferenceName, 'UTF-8'));
return $this->put(
- "contacts/preference_categories/{$encodedCategoryName}/preferences/{$encodedPreferenceName}",
- $preference->toXMLString()
+ "contacts/preference_categories/$encodedCategoryName/preferences/$encodedPreferenceName", $preference->toXMLString()
);
}
/**
* This method deletes a contact preference under a given contact preference category.
*
- * @param string $categoryName
- * The name of the contact preference category.
- * @param string $preferenceName
- * The name of the preference to delete.
- * @return MaileonAPIResult
- * The result object of the API call.
- * @throws MaileonAPIException
- * If there was a connection problem or a server error occurred.
+ * @param string $categoryName The name of the contact preference category.
+ * @param string $preferenceName The name of the preference to delete.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred.
*/
- public function deleteContactPreference($categoryName, $preferenceName)
- {
- $encodedCategoryName = rawurlencode(mb_convert_encoding($categoryName, "UTF-8"));
- $encodedPreferenceName = rawurlencode(mb_convert_encoding($preferenceName, "UTF-8"));
+ public function deleteContactPreference(
+ $categoryName,
+ $preferenceName
+ ) {
+ $encodedCategoryName = rawurlencode(mb_convert_encoding((string) $categoryName, 'UTF-8'));
+ $encodedPreferenceName = rawurlencode(mb_convert_encoding((string) $preferenceName, 'UTF-8'));
- return $this->delete(
- "contacts/preference_categories/{$encodedCategoryName}/preferences/{$encodedPreferenceName}"
- );
+ return $this->delete("contacts/preference_categories/$encodedCategoryName/preferences/$encodedPreferenceName");
}
}
diff --git a/src/contacts/CustomFields.php b/src/contacts/CustomFields.php
index ba7c544..e2d47a9 100644
--- a/src/contacts/CustomFields.php
+++ b/src/contacts/CustomFields.php
@@ -3,12 +3,15 @@
namespace de\xqueue\maileon\api\client\contacts;
use de\xqueue\maileon\api\client\xml\AbstractXMLWrapper;
+use SimpleXMLElement;
+
+use function rtrim;
+use function trim;
/**
* The wrapper class for a list of custom fields.
*
- * @author Marcus Beckerle | XQueue GmbH |
- * marcus.beckerle@xqueue.com
+ * @author Marcus Beckerle | XQueue GmbH | marcus.beckerle@xqueue.com
*/
class CustomFields extends AbstractXMLWrapper
{
@@ -18,20 +21,13 @@ class CustomFields extends AbstractXMLWrapper
/**
* Constructor initializing the list from an array.
*
- * @param array $custom_fields
- * The list of custom fields. Empty array if no argument passed.
+ * @param array $custom_fields The list of custom fields. Empty array if no argument passed.
*/
- public function __construct($custom_fields = array())
+ public function __construct($custom_fields = [])
{
$this->custom_fields = $custom_fields;
}
- /**
- * Initialization of the custom fields from a simple xml element.
- *
- * @param \SimpleXMLElement $xmlElement
- * The xml element that is used to parse the custom fields from.
- */
public function fromXML($xmlElement)
{
foreach ($xmlElement->children() as $field) {
@@ -40,55 +36,34 @@ public function fromXML($xmlElement)
}
}
- /**
- * Serialization to a simple XML element.
- *
- * @return \SimpleXMLElement
- * Generate a XML element from the custom fields list.
- */
public function toXML()
{
- $xml = new \SimpleXMLElement("");
+ $xml = new SimpleXMLElement('');
+
if (isset($this->custom_fields)) {
foreach ($this->custom_fields as $index => $type) {
- $field = $xml->addChild("field");
- $field->addChild("name", $index);
- $field->addChild("type", $type);
+ $field = $xml->addChild('field');
+ $field->addChild('name', $index);
+ $field->addChild('type', $type);
}
}
return $xml;
}
- /**
- * Serialization to a simple XML element as string
- *
- * @return string
- * The string representation of the XML document for this list of custom fields.
- */
- public function toXMLString()
- {
- $xml = $this->toXML();
- return $xml->asXML();
- }
-
- /**
- * Human readable representation of this list of custom fields.
- *
- * @return string
- * The human readable representation of the list of custom fields.
- */
- public function toString()
+ public function toString(): string
{
// Generate custom field string
- $customfields = "";
+ $custom_fields = '';
+
if (isset($this->custom_fields)) {
foreach ($this->custom_fields as $index => $type) {
- $customfields .= $index . "=" . $type . ", ";
+ $custom_fields .= $index . '=' . $type . ', ';
}
- $customfields = rtrim($customfields, ', ');
+
+ $custom_fields = rtrim($custom_fields, ', ');
}
- return "CustomFields = {" . $customfields . "}";
+ return 'CustomFields = {' . $custom_fields . '}';
}
}
diff --git a/src/contacts/Permission.php b/src/contacts/Permission.php
index 6889da3..fc8f017 100644
--- a/src/contacts/Permission.php
+++ b/src/contacts/Permission.php
@@ -5,18 +5,17 @@
/**
* The wrapper class for a Maileon permission. 1 = NONE, 2 = SOI, 3 = COI, 4 = DOI, 5 = DOI+, 6 = OTHER.
*
- * @author Marcus Beckerle | XQueue GmbH |
- * marcus.beckerle@xqueue.com
+ * @author Marcus Beckerle | XQueue GmbH | marcus.beckerle@xqueue.com
*/
class Permission
{
- public static $NONE;
- public static $SOI;
- public static $COI;
- public static $DOI;
- public static $DOI_PLUS;
- public static $OTHER;
+ public static $NONE;
+ public static $SOI;
+ public static $COI;
+ public static $DOI;
+ public static $DOI_PLUS;
+ public static $OTHER;
private static $initialized = false;
public $code;
@@ -27,13 +26,13 @@ class Permission
*/
public static function init()
{
- if (self::$initialized == false) {
- self::$NONE = new Permission(1, "none");
- self::$SOI = new Permission(2, "soi");
- self::$COI = new Permission(3, "coi");
- self::$DOI = new Permission(4, "doi");
- self::$DOI_PLUS = new Permission(5, "doi+");
- self::$OTHER = new Permission(6, "other");
+ if (self::$initialized === false) {
+ self::$NONE = new Permission(1, 'none');
+ self::$SOI = new Permission(2, 'soi');
+ self::$COI = new Permission(3, 'coi');
+ self::$DOI = new Permission(4, 'doi');
+ self::$DOI_PLUS = new Permission(5, 'doi+');
+ self::$OTHER = new Permission(6, 'other');
self::$initialized = true;
}
}
@@ -41,12 +40,14 @@ public static function init()
/**
* Constructor initializing the code of the permission.
*
- * @param number $code
- * The code to use for the constructed permission.
+ * @param int $code The code to use for the constructed permission.
*/
- public function __construct($code = 0, $type = null)
- {
+ public function __construct(
+ $code = 0,
+ $type = null
+ ) {
$this->code = $code < 1 || $code > 6 ? 6 : $code;
+
if ($type === null) {
$this->type = $this->getType($code);
} else {
@@ -58,10 +59,9 @@ public function __construct($code = 0, $type = null)
* Get the code of this permission.
* 1 = NONE, 2 = SOI, 3 = COI, 4 = DOI, 5 = DOI+, 6 = OTHER.
*
- * @return int
- * the code of the permission object
+ * @return int The code of the permission object
*/
- public function getCode()
+ public function getCode(): int
{
return $this->code;
}
@@ -70,10 +70,9 @@ public function getCode()
* Get the type string of this permission.
* none = NONE, soi = SOI, coi = COI, doi = DOI, doi+ = DOI+, other = OTHER.
*
- * @return string
- * the type of the permission object
+ * @return string The type of the permission object
*/
- public function getString()
+ public function getString(): string
{
return $this->type;
}
@@ -92,51 +91,42 @@ private function getType($code)
case 5:
return 'doi+';
case 6:
- return 'other';
default:
return 'other';
}
}
-
+
/**
* Get the permission object from the code
*
- * @param integer $code
- * The code or type to get the permission object for.
- * @return Permission
- * The permission object for the given code.
+ * @param int $code The code or type to get the permission object for.
+ *
+ * @return Permission The permission object for the given code.
*/
public static function getPermission($code)
{
switch ($code) {
case 1:
- return self::$NONE;
- case "none":
+ case 'none':
return self::$NONE;
case 2:
- return self::$SOI;
- case "soi":
+ case 'soi':
return self::$SOI;
case 3:
- return self::$COI;
- case "coi":
+ case 'coi':
return self::$COI;
case 4:
- return self::$DOI;
- case "doi":
+ case 'doi':
return self::$DOI;
case 5:
- return self::$DOI_PLUS;
- case "doi+":
+ case 'doi+':
return self::$DOI_PLUS;
case 6:
- return self::$OTHER;
- case "other":
- return self::$OTHER;
-
+ case 'other':
default:
return self::$OTHER;
}
}
}
+
Permission::init();
diff --git a/src/contacts/Preference.php b/src/contacts/Preference.php
index eebfffd..3f29678 100644
--- a/src/contacts/Preference.php
+++ b/src/contacts/Preference.php
@@ -3,6 +3,8 @@
namespace de\xqueue\maileon\api\client\contacts;
use de\xqueue\maileon\api\client\xml\AbstractXMLWrapper;
+use Exception;
+use SimpleXMLElement;
/**
* The wrapper class for a Maileon Preference. This class wraps the XML structure.
@@ -10,50 +12,44 @@
class Preference extends AbstractXMLWrapper
{
/**
- * @var string $name
+ * @var string
*/
public $name;
-
+
/**
- * @var string $description
+ * @var string
*/
public $description;
/**
- * @var string $category
+ * @var string
*/
public $category;
/**
- * @var string $value
+ * @var string
*/
public $value;
/**
- * @var string $source
+ * @var string
*/
public $source;
/**
- * @var string $last_modified
+ * @var string
*/
public $last_modified;
/**
* Constructor initializing default values.
*
- * @param string $name
- * The preference name.
- * @param string $description
- * The preference description.
- * @param string $category
- * The preference category name.
- * @param string $value
- * The preference value.
- * @param string $source
- * The preference source.
- * @param string $last_modified
- * The preference last modified timestamp.
+ * @param string $name The preference name.
+ * @param string $description The preference description.
+ * @param string $category The preference category name.
+ * @param string $value The preference value.
+ * @param string $source The preference source.
+ * @param string $last_modified The preference last modified timestamp.
*/
public function __construct(
$name = null,
@@ -63,26 +59,20 @@ public function __construct(
$source = null,
$last_modified = null
) {
- $this->name = $name;
- $this->description = $description;
- $this->category = $category;
- $this->value = $value;
- $this->source = $source;
+ $this->name = $name;
+ $this->description = $description;
+ $this->category = $category;
+ $this->value = $value;
+ $this->source = $source;
$this->last_modified = $last_modified;
}
- /**
- * Initialization of the preference from a simple xml element.
- *
- * @param \SimpleXMLElement $xmlElement
- * The xml element that is used to parse the preference from.
- */
public function fromXML($xmlElement)
{
if (isset($xmlElement->name)) {
$this->name = $xmlElement->name;
}
-
+
if (isset($xmlElement->description)) {
$this->description = $xmlElement->description;
}
@@ -109,83 +99,71 @@ public function fromXML($xmlElement)
*
* @param bool $addXMLDeclaration
*
- * @return \SimpleXMLElement
- * Generate a XML element from the preference object.
+ * @return SimpleXMLElement contains the serialized representation of the object
+ *
+ * @throws Exception
*/
public function toXML($addXMLDeclaration = true)
{
if ($addXMLDeclaration) {
- $xmlString = "";
+ $xmlString = '';
} else {
- $xmlString = "";
+ $xmlString = '';
}
- $xml = new \SimpleXMLElement($xmlString);
+ $xml = new SimpleXMLElement($xmlString);
if (isset($this->name)) {
- $xml->addChild("name", $this->name);
+ $xml->addChild('name', $this->name);
}
+
if (isset($this->description)) {
- $xml->addChild("description", $this->description);
+ $xml->addChild('description', $this->description);
}
+
if (isset($this->category)) {
- $xml->addChild("category", $this->category);
+ $xml->addChild('category', $this->category);
}
+
if (isset($this->value)) {
- $xml->addChild("value", $this->value);
+ $xml->addChild('value', $this->value);
}
+
if (isset($this->source)) {
- $xml->addChild("source", $this->source);
+ $xml->addChild('source', $this->source);
}
+
if (isset($this->last_modified)) {
- $xml->addChild("last_modified", $this->last_modified);
+ $xml->addChild('last_modified', $this->last_modified);
}
return $xml;
}
- /**
- * Serialization to a simple XML element as string
- *
- * @return string
- * The string representation of the XML document for this preference.
- */
- public function toXMLString()
- {
- $xml = $this->toXML();
- return $xml->asXML();
- }
-
- /**
- * Human readable representation of this wrapper.
- *
- * @return string
- * A human readable version of the preference.
- */
- public function toString()
+ public function toString(): string
{
- return "Contact Preference [name=" . $this->name .
- ", description=" . $this->description .
- ", category=" . $this->category .
- ", value=" . $this->value .
- ", source=" . $this->source .
- ", last_modified=" . $this->last_modified .
- "]";
+ return 'Contact Preference ['
+ . 'name=' . $this->name
+ . ', description=' . $this->description
+ . ', category=' . $this->category
+ . ', value=' . $this->value
+ . ', source=' . $this->source
+ . ', last_modified=' . $this->last_modified
+ . ']';
}
/**
* CSV representation of this wrapper.
*
* @return string
- * A csv version of the reference.
*/
- public function toCsvString()
+ public function toCsvString(): string
{
- return $this->name .
- ";" . $this->description .
- ";" . $this->category .
- ";" . $this->value .
- ";" . $this->source .
- ";" . $this->last_modified;
+ return $this->name
+ . ';' . $this->description
+ . ';' . $this->category
+ . ';' . $this->value
+ . ';' . $this->source
+ . ';' . $this->last_modified;
}
}
diff --git a/src/contacts/PreferenceCategory.php b/src/contacts/PreferenceCategory.php
index 432fd1f..c3b2f39 100644
--- a/src/contacts/PreferenceCategory.php
+++ b/src/contacts/PreferenceCategory.php
@@ -3,6 +3,8 @@
namespace de\xqueue\maileon\api\client\contacts;
use de\xqueue\maileon\api\client\xml\AbstractXMLWrapper;
+use Exception;
+use SimpleXMLElement;
/**
* The wrapper class for a Maileon Preference Category. This class wraps the XML structure.
@@ -10,43 +12,35 @@
class PreferenceCategory extends AbstractXMLWrapper
{
/**
- * @var string $name
+ * @var string
*/
public $name;
/**
- * @var string $description
+ * @var string
*/
public $description;
/**
* Constructor initializing default values.
*
- * @param string $name
- * The preference category name.
- * @param string $description
- * The preference category description.
+ * @param string $name The preference category name.
+ * @param string $description The preference category description.
*/
public function __construct(
$name = null,
$description = null
) {
- $this->name = $name;
+ $this->name = $name;
$this->description = $description;
}
- /**
- * Initialization of the preference category from a simple xml element.
- *
- * @param \SimpleXMLElement $xmlElement
- * The xml element that is used to parse the preference category from.
- */
public function fromXML($xmlElement)
{
if (isset($xmlElement->name)) {
$this->name = $xmlElement->name;
}
-
+
if (isset($xmlElement->description)) {
$this->description = $xmlElement->description;
}
@@ -57,62 +51,47 @@ public function fromXML($xmlElement)
*
* @param bool $addXMLDeclaration
*
- * @return \SimpleXMLElement
- * Generate a XML element from the preference category object.
+ * @return SimpleXMLElement contains the serialized representation of the object
+ *
+ * @throws Exception
*/
public function toXML($addXMLDeclaration = true)
{
if ($addXMLDeclaration) {
- $xmlString = "";
+ $xmlString = '';
} else {
- $xmlString = "";
+ $xmlString = '';
}
- $xml = new \SimpleXMLElement($xmlString);
+ $xml = new SimpleXMLElement($xmlString);
if (isset($this->name)) {
- $xml->addChild("name", $this->name);
+ $xml->addChild('name', $this->name);
}
+
if (isset($this->description)) {
- $xml->addChild("description", $this->description);
+ $xml->addChild('description', $this->description);
}
return $xml;
}
- /**
- * Serialization to a simple XML element as string
- *
- * @return string
- * The string representation of the XML document for this preference category.
- */
- public function toXMLString()
- {
- $xml = $this->toXML();
- return $xml->asXML();
- }
-
- /**
- * Human readable representation of this wrapper.
- *
- * @return string
- * A human readable version of the preference category.
- */
- public function toString()
+ public function toString(): string
{
- return "Contact Preference Category [name=" . $this->name .
- ", description=" . $this->description . "]";
+ return 'Contact Preference Category ['
+ . 'name=' . $this->name
+ . ', description=' . $this->description
+ . ']';
}
/**
* CSV representation of this wrapper.
*
* @return string
- * A csv version of the category reference.
*/
- public function toCsvString()
+ public function toCsvString(): string
{
- return $this->name .
- ";" . $this->description;
+ return $this->name
+ . ';' . $this->description;
}
}
diff --git a/src/contacts/StandardContactField.php b/src/contacts/StandardContactField.php
index 4df721f..bafb6c6 100644
--- a/src/contacts/StandardContactField.php
+++ b/src/contacts/StandardContactField.php
@@ -10,72 +10,79 @@
class StandardContactField
{
/** The Constant ADDRESS. */
- public static $ADDRESS = "ADDRESS";
+ public static $ADDRESS = 'ADDRESS';
/** The Constant BIRTHDAY. */
- public static $BIRTHDAY = "BIRTHDAY";
+ public static $BIRTHDAY = 'BIRTHDAY';
/** The Constant CITY. */
- public static $CITY = "CITY";
+ public static $CITY = 'CITY';
/** The Constant COUNTRY. */
- public static $COUNTRY = "COUNTRY";
+ public static $COUNTRY = 'COUNTRY';
/** The Constant FIRSTNAME. */
- public static $FIRSTNAME = "FIRSTNAME";
+ public static $FIRSTNAME = 'FIRSTNAME';
/** The Constant FULLNAME. */
- public static $FULLNAME = "FULLNAME";
+ public static $FULLNAME = 'FULLNAME';
/** The Constant GENDER. */
- public static $GENDER = "GENDER";
+ public static $GENDER = 'GENDER';
/** The Constant HNR. */
- public static $HNR = "HNR";
+ public static $HNR = 'HNR';
/** The Constant LASTNAME. */
- public static $LASTNAME = "LASTNAME";
+ public static $LASTNAME = 'LASTNAME';
/** The Constant LOCALE. */
- public static $LOCALE = "LOCALE";
+ public static $LOCALE = 'LOCALE';
/** The Constant NAMEDAY. */
- public static $NAMEDAY = "NAMEDAY";
+ public static $NAMEDAY = 'NAMEDAY';
/** The Constant ORGANIZATION. */
- public static $ORGANIZATION = "ORGANIZATION";
+ public static $ORGANIZATION = 'ORGANIZATION';
/** The Constant REGION. */
- public static $REGION = "REGION";
+ public static $REGION = 'REGION';
/** The Constant SALUTATION. */
- public static $SALUTATION = "SALUTATION";
+ public static $SALUTATION = 'SALUTATION';
/** The Constant TITLE. */
- public static $TITLE = "TITLE";
+ public static $TITLE = 'TITLE';
/** The Constant ZIP. */
- public static $ZIP = "ZIP";
-
+ public static $ZIP = 'ZIP';
+
/** The Constant STATE. */
- public static $STATE = "STATE";
-
+ public static $STATE = 'STATE';
+
/** The Constant SENDOUT_STATUS. Sendout status can be "blocked" or "allowed" */
- public static $SENDOUT_STATUS = "SENDOUT_STATUS";
-
- /** The Constant PERMISSION_STATUS. Permission status can be "available" (permission != none and not unsubscribed), "none" (no permission given, yet), or "unsubscribed" */
- public static $PERMISSION_STATUS = "PERMISSION_STATUS";
-
- /** The Constant CUSTOM_SOURCE. The name of the source, as specified during creation of the contact (parameter src). */
- public static $CUSTOM_SOURCE = "CUSTOM_SOURCE";
-
- /** The Constant CHECKSUM. The checksum of the contact, used to retrieve or update contact information in insecure envorinments, e.g. publicly available landingpages (e.g. profile update pages) that use email, ID or external ID to identify a contact. As a second parameter, you can use the checksum to avoid users passing guessed identifyers. */
- public static $CHECKSUM = "CHECKSUM";
+ public static $SENDOUT_STATUS = 'SENDOUT_STATUS';
+
+ /**
+ * The Constant PERMISSION_STATUS. Permission status can be "available" (permission != none and not unsubscribed), "none"
+ * (no permission given, yet), or "unsubscribed"
+ */
+ public static $PERMISSION_STATUS = 'PERMISSION_STATUS';
+ /** The Constant CUSTOM_SOURCE. The name of the source, as specified during creation of the contact (parameter src). */
+ public static $CUSTOM_SOURCE = 'CUSTOM_SOURCE';
+
+ /**
+ * The Constant CHECKSUM. The checksum of the contact, used to retrieve or update contact information in insecure environments, e.g.
+ * publicly available landingpages (e.g. profile update pages) that use email, ID or external ID to identify a contact. As a second
+ * parameter, you can use the checksum to avoid users passing guessed identifyers.
+ */
+ public static $CHECKSUM = 'CHECKSUM';
public static function init()
{
// Nothing to initialize
}
}
+
StandardContactField::init();
diff --git a/src/contacts/SynchronizationMode.php b/src/contacts/SynchronizationMode.php
index 7c2bcaa..3d3382b 100644
--- a/src/contacts/SynchronizationMode.php
+++ b/src/contacts/SynchronizationMode.php
@@ -10,8 +10,8 @@
class SynchronizationMode
{
- public static $UPDATE;
- public static $IGNORE;
+ public static $UPDATE;
+ public static $IGNORE;
private static $initialized = false;
public $code;
@@ -21,9 +21,9 @@ class SynchronizationMode
*/
public static function init()
{
- if (self::$initialized == false) {
- self::$UPDATE = new SynchronizationMode(1);
- self::$IGNORE = new SynchronizationMode(2);
+ if (self::$initialized === false) {
+ self::$UPDATE = new SynchronizationMode(1);
+ self::$IGNORE = new SynchronizationMode(2);
self::$initialized = true;
}
}
@@ -31,8 +31,7 @@ public static function init()
/**
* Constructor initializing the code of the synchronization mode.
*
- * @param number $code
- * The code to use for the constructed synchronization mode.
+ * @param int $code The code to use for the constructed synchronization mode.
*/
public function __construct($code = 0)
{
@@ -42,10 +41,9 @@ public function __construct($code = 0)
/**
* Get the code of this synchronization mode. 1 = UPDATE, 2 = IGNORE.
*
- * @return number
- * the code of the synchronization mode object
+ * @return int The code of the synchronization mode object
*/
- public function getCode()
+ public function getCode(): int
{
return $this->code;
}
@@ -53,10 +51,9 @@ public function getCode()
/**
* Get the synchronization mode from the code
*
- * @param int $code
- * the code to get the synchronization mode for
- * @return SynchronizationMode
- * the synchronization mode for the given code
+ * @param int $code The code to get the synchronization mode for
+ *
+ * @return SynchronizationMode The synchronization mode for the given code
*/
public static function getSynchronizationMode($code)
{
@@ -64,11 +61,10 @@ public static function getSynchronizationMode($code)
case 1:
return self::$UPDATE;
case 2:
- return self::$IGNORE;
-
default:
return self::$IGNORE;
}
}
}
+
SynchronizationMode::init();
diff --git a/src/json/AbstractJSONWrapper.php b/src/json/AbstractJSONWrapper.php
index 9712f79..1cc207d 100644
--- a/src/json/AbstractJSONWrapper.php
+++ b/src/json/AbstractJSONWrapper.php
@@ -2,69 +2,83 @@
namespace de\xqueue\maileon\api\client\json;
+use function array_key_exists;
+use function array_map;
+use function class_exists;
+use function get_class;
+use function get_object_vars;
+use function implode;
+use function is_array;
+use function is_subclass_of;
+use function mb_substr;
+
/**
* Abstract base class for all JSON serializable elements.
*
* All classes derived from this must initialize their member classes in the
* constructor.
*
- * @author Balogh Viktor | Maileon - Wanadis Kft.
+ * @author Viktor Balogh | XQueue GmbH | viktor.balog@xqueue.com
*/
abstract class AbstractJSONWrapper
{
public function __construct($params = [])
{
$object_vars = get_object_vars($this);
+
foreach ($object_vars as $key => $value) {
- if(array_key_exists($key, $params)) {
+ if (array_key_exists($key, $params)) {
$this->{$key} = $params[$key];
}
}
}
- protected function elementToArray($value) {
+ protected function elementToArray($value)
+ {
// if $value is an object, we can call toArray on it, and it
// should be serialized (isEmpty returns true) than we call
// toArray and insert the result in our array;
// otherwise we insert the value as-is
- if (gettype($value) == "object" && is_subclass_of($value, 'de\xqueue\maileon\api\client\json\AbstractJSONWrapper')) {
+ if ($value instanceof self) {
if ($value->isEmpty()) {
return null;
}
return $value->toArray();
- } else if(is_array($value)) {
- $result = [];
+ }
- foreach ($value as $key => $element) {
- $result [$key]= $this->elementToArray($element);
- }
+ if (is_array($value)) {
+ $result = array_map(
+ function($element) {
+ return $this->elementToArray($element);
+ },
+ $value
+ );
- if(count($result) === 0) {
+ if (empty($result)) {
return null;
}
return $result;
- } else {
- // TODO: maybe deal with AbstractJSONWrapper
- // derived classes that have 'non-serializable' properties
- return $value;
}
+
+ // TODO: maybe deal with AbstractJSONWrapper
+ // derived classes that have 'non-serializable' properties
+ return $value;
}
/**
* Used to serialize this object to a JSON string. Override this to modify
* JSON parameters.
*
- * @return array
- * This class in array form
+ * @return array This class in array form
*/
- public function toArray()
+ public function toArray(): array
{
- $result = array();
+ $result = [];
$object_vars = get_object_vars($this);
- // copy each of this objects properties to an associative array
+ // copy each of this object's properties to an associative array
// indexed by the property names
foreach ($object_vars as $key => $value) {
$converted = $this->elementToArray($value);
@@ -82,16 +96,15 @@ public function toArray()
* Used to initialize this object from JSON. Override this to modify JSON
* parameters.
*
- * @param array $object_vars
- * The array from json_decode
+ * @param array $object_vars The array from json_decode
*/
public function fromArray($object_vars)
{
// copy each key to the property named the same way; if the property
// is a serializable Maileon class, call fromArray on it
foreach ($object_vars as $key => $value) {
- if (class_exists('de\xqueue\maileon\api\client\json\AbstractJSONWrapper') &&
- is_subclass_of($this->{$key}, 'de\xqueue\maileon\api\client\json\AbstractJSONWrapper' )) {
+ if (class_exists(__CLASS__)
+ && is_subclass_of($this->{$key}, __CLASS__)) {
$this->{$key}->fromArray($value);
} else {
$this->{$key} = $value;
@@ -108,18 +121,23 @@ public function fromArray($object_vars)
public function __toString()
{
$object_vars = get_object_vars($this);
- $elements = "";
+ $elements = '';
// add each property of this class to a string
foreach ($object_vars as $key => $value) {
- $flat = is_array($value) ? "[" . implode(',', $value) . "]" : $value;
- $elements .= $key . "=" . $flat . ", ";
+ $flat = is_array($value) ? '[' . implode(',', $value) . ']' : $value;
+ $elements .= $key . '=' . $flat . ', ';
}
- return get_class($this) . " [ " . mb_substr($elements, 0, mb_strlen($elements) - 2) . " ]";
+ return get_class($this) . ' [ ' . mb_substr($elements, 0, -2) . ' ]';
}
- public function toString()
+ /**
+ * Human-readable representation of this object
+ *
+ * @return string A human-readable representation of this object
+ */
+ public function toString(): string
{
return $this->__toString();
}
@@ -129,7 +147,7 @@ public function toString()
*
* @return boolean
*/
- public function isEmpty()
+ public function isEmpty(): bool
{
return false;
}
diff --git a/src/json/JSONDeserializer.php b/src/json/JSONDeserializer.php
index ef1cd56..a830e47 100644
--- a/src/json/JSONDeserializer.php
+++ b/src/json/JSONDeserializer.php
@@ -2,31 +2,37 @@
namespace de\xqueue\maileon\api\client\json;
+use function class_exists;
+use function count;
+use function get_class;
+use function is_array;
+use function json_decode;
+use function trigger_error;
+
/**
* Helper class for deserializing JSON data
*
- * @author Balogh Viktor | Maileon - Wanadis Kft.
+ * @author Viktor Balogh | XQueue GmbH | viktor.balog@xqueue.com
*/
class JSONDeserializer
{
/**
* Used to deserialize a Maileon class from JSON
*
- * @param string $jsonString
- * The JSON string to deserialize
- * @param mixed $deserializationType
- * The type of the deserialized object. For deserializing arrays use
- * array( 'array', 'typename' )
- * @return AbstractJSONWrapper|array
+ * @param string $jsonString The JSON string to deserialize
+ * @param mixed $deserializationType The type of the deserialized object. For deserializing arrays use array( 'array', 'typename' )
*
+ * @return AbstractJSONWrapper|array
*/
- public static function json_decode($jsonString, $deserializationType = null)
- {
+ public static function json_decode(
+ $jsonString,
+ $deserializationType = null
+ ) {
if (is_array($deserializationType) && count($deserializationType) > 1) {
- $type = $deserializationType[0];
+ $type = $deserializationType[0];
$innerType = $deserializationType[1];
} else {
- $type = $deserializationType;
+ $type = $deserializationType;
$innerType = null;
}
@@ -37,43 +43,47 @@ public static function json_decode($jsonString, $deserializationType = null)
/**
* Helper function used to build this class from an array.
*
- * @param array $object
- * The result of json_decode
- * @param string $type
- * The name of the type
- * @param string $innerType
- * The name of the inner type
- * @return array|AbstractJSONWrapper
- * The parsed object
+ * @param array $object The result of json_decode
+ * @param string $type The name of the type
+ * @param string $innerType The name of the inner type
+ *
+ * @return array|AbstractJSONWrapper The parsed object
*/
- private static function fromArray($object, $type = null, $innerType = null)
- {
- if ($type == 'array') {
+ private static function fromArray(
+ $object,
+ $type = null,
+ $innerType = null
+ ) {
+ if ($type === 'array') {
$result = [];
foreach ($object as $element) {
// call this method on each element
- $result[]= self::fromArray($element, $innerType);
+ $result[] = self::fromArray($element, $innerType);
}
// return the processed array
return $result;
- } elseif ($type !== null && class_exists($type)) {
+ }
+
+ if ($type !== null && class_exists($type)) {
// create the class we are deserializing
$class = new $type();
// if we can call fromArray on the class call it, otherwise
// return the object as-is and trigger a warning
- if (is_subclass_of($class, 'de\xqueue\maileon\api\client\json\AbstractJSONWrapper')) {
+ if ($class instanceof AbstractJSONWrapper) {
$class->fromArray($object);
+
return $class;
- } else {
- trigger_error(__CLASS__ . ": Trying to deserialize " . get_class($class));
- return $object;
}
- } else {
- // if this is not a class, we have nothing to do
+
+ trigger_error(__CLASS__ . ': Trying to deserialize ' . get_class($class));
+
return $object;
}
+
+ // if this is not a class, we have nothing to do
+ return $object;
}
}
diff --git a/src/json/JSONSerializer.php b/src/json/JSONSerializer.php
index ebf9122..cea6451 100644
--- a/src/json/JSONSerializer.php
+++ b/src/json/JSONSerializer.php
@@ -2,60 +2,66 @@
namespace de\xqueue\maileon\api\client\json;
+use function get_class;
+use function gettype;
+use function json_encode;
+use function trigger_error;
+
/**
* Helper class for serializing JSON data
*
- * @author Balogh Viktor | Maileon - Wanadis Kft.
+ * @author Viktor Balogh | XQueue GmbH | viktor.balog@xqueue.com
*/
class JSONSerializer
{
/**
* Used to serialize Maileon classes to JSON
*
- * @param AbstractJSONWrapper|array $object
- * The object to serialize
- * @returns string
- * The JSON representation of the object
+ * @param AbstractJSONWrapper|array $object The object to serialize
+ *
+ * @returns string The JSON representation of the object
*/
public static function json_encode($object)
{
return json_encode(self::toArray($object));
}
-
+
/**
* Helper function used to prepare this object for JSON serialization
*
- * @param array|AbstractJSONWrapper $object
- * The object to prepare
- * @return array
- * The array ready for json_encode
+ * @param array|AbstractJSONWrapper $object The object to prepare
+ *
+ * @return array The array ready for json_encode
*/
private static function toArray($object)
{
$type = gettype($object);
-
- if ($type == 'array') {
- $result = array();
-
+
+ if ($type === 'array') {
+ $result = [];
+
foreach ($object as $element) {
// call this method on each object in the array
- $result[]= self::toArray($element);
+ $result[] = self::toArray($element);
}
-
+
// return the processed array
return $result;
- } elseif ($type == 'object') {
+ }
+
+ if ($type === 'object') {
// if we can call toArray() on this object call it, otherwise return
// the object as-is and trigger a notice
- if (is_subclass_of($object, 'de\xqueue\maileon\api\client\json\AbstractJSONWrapper')) {
+ if ($object instanceof AbstractJSONWrapper) {
return $object->toArray();
- } else {
- trigger_error("Maileon\Json\JSONSerializer: Trying to serialize " . get_class($object));
- return $object;
}
- } else {
- // if this is not an object we have nothing to do
+
+ trigger_error('Maileon\Json\JSONSerializer: Trying to serialize ' . get_class($object));
+
return $object;
}
+
+ // if this is not an object we have nothing to do
+ return $object;
}
}
diff --git a/src/mailings/Attachment.php b/src/mailings/Attachment.php
index 0ad45d4..0d15e8c 100644
--- a/src/mailings/Attachment.php
+++ b/src/mailings/Attachment.php
@@ -8,7 +8,7 @@
/**
* The wrapper class for a Maileon attachment. This class wraps the XML structure.
*
- * @author Viktor Balogh | Wanadis Kft. | balogh.viktor@maileon.hu
+ * @author Viktor Balogh | XQueue GmbH | viktor.balog@xqueue.com
*/
class Attachment extends AbstractXMLWrapper
{
@@ -23,9 +23,9 @@ class Attachment extends AbstractXMLWrapper
/**
* Constructor initializing default values.
*
- * @param integer $id
+ * @param int $id
* @param string $filename
- * @param integer $sizekb
+ * @param int $sizekb
* @param string $mime_type
* @param string $diagnosis
* @param string $created
@@ -40,81 +40,75 @@ public function __construct(
$created = null,
$updated = null
) {
- $this->id = $id;
- $this->filename = $filename;
- $this->sizekb = $sizekb;
+ $this->id = $id;
+ $this->filename = $filename;
+ $this->sizekb = $sizekb;
$this->mime_type = $mime_type;
$this->diagnosis = $diagnosis;
- $this->created = $created;
- $this->updated = $updated;
+ $this->created = $created;
+ $this->updated = $updated;
}
- /**
- * Initialization of the attachment from a simple xml element.
- *
- * @param \SimpleXMLElement $xmlElement
- * The xml element that is used to parse the attachment from.
- */
public function fromXML($xmlElement)
{
if (isset($xmlElement->id)) {
- $this->id = (int)$xmlElement->id;
+ $this->id = (int) $xmlElement->id;
}
+
if (isset($xmlElement->filename)) {
- $this->filename = (string)$xmlElement->filename;
+ $this->filename = (string) $xmlElement->filename;
}
+
if (isset($xmlElement->sizekb)) {
- $this->sizekb = (int)$xmlElement->sizekb;
+ $this->sizekb = (int) $xmlElement->sizekb;
}
+
if (isset($xmlElement->mime_type)) {
- $this->mime_type = (string)$xmlElement->mime_type;
+ $this->mime_type = (string) $xmlElement->mime_type;
}
+
if (isset($xmlElement->diagnosis)) {
- $this->diagnosis = (string)$xmlElement->diagnosis;
+ $this->diagnosis = (string) $xmlElement->diagnosis;
}
+
if (isset($xmlElement->created)) {
- $this->created = (string)$xmlElement->created;
+ $this->created = (string) $xmlElement->created;
}
+
if (isset($xmlElement->updated)) {
- $this->updated = (string)$xmlElement->updated;
+ $this->updated = (string) $xmlElement->updated;
}
}
- /**
- * Creates the XML representation of an attachment
- *
- * @return \SimpleXMLElement
- */
public function toXML()
{
- /*$xml = new SimpleXMLElement("");
+ /*
+ $xml = new SimpleXMLElement('');
+
+ $xml->addChild('id', $this->id);
+ $xml->addChild('filename', $this->filename);
+ $xml->addChild('sizekb', $this->sizekb);
+ $xml->addChild('mime_type', $this->mime_type);
+ $xml->addChild('diagnosis', $this->diagnosis);
+ $xml->addChild('created', $this->created);
+ $xml->addChild('updated', $this->updated);
- $xml->addChild("id", $this->id);
- $xml->addChild("filename", $this->filename);
- $xml->addChild("sizekb", $this->sizekb);
- $xml->addChild("mime_type", $this->mime_type);
- $xml->addChild("diagnosis", $this->diagnosis);
- $xml->addChild("created", $this->created);
- $xml->addChild("updated", $this->updated);
+ return $xml;
+ */
- return $xml;*/
throw new MaileonAPIException('not implemented');
}
-
- /**
- * Human readable representation of this wrapper.
- *
- * @return string
- * A human readable version of the mailing.
- */
- public function toString()
+
+ public function toString(): string
{
- return "Attachment [id=" . $this->id . ", "
- . "filename=" . $this->filename . ", "
- . "sizekb=" . $this->sizekb . ", "
- . "mime_type=" . $this->mime_type . ", "
- . "diagnosis=" . $this->diagnosis . ", "
- . "created=" . $this->created . ", "
- . "updated=" . $this->updated . "]";
+ return 'Attachment ['
+ . 'id=' . $this->id
+ . ', filename=' . $this->filename
+ . ', sizekb=' . $this->sizekb
+ . ', mime_type=' . $this->mime_type
+ . ', diagnosis=' . $this->diagnosis
+ . ', created=' . $this->created
+ . ', updated=' . $this->updated
+ . ']';
}
}
diff --git a/src/mailings/CustomProperty.php b/src/mailings/CustomProperty.php
index 2726008..aa7fe92 100644
--- a/src/mailings/CustomProperty.php
+++ b/src/mailings/CustomProperty.php
@@ -3,6 +3,7 @@
namespace de\xqueue\maileon\api\client\mailings;
use de\xqueue\maileon\api\client\xml\AbstractXMLWrapper;
+use SimpleXMLElement;
/**
* The wrapper class for a Maileon custom property. This class wraps the XML structure.
@@ -20,52 +21,40 @@ class CustomProperty extends AbstractXMLWrapper
* @param string $key
* @param string $value
*/
- public function __construct($key = null, $value = null)
- {
- $this->key = $key;
+ public function __construct(
+ $key = null,
+ $value = null
+ ) {
+ $this->key = $key;
$this->value = $value;
}
- /**
- * Initialization of the attachment from a simple xml element.
- *
- * @param \SimpleXMLElement $xmlElement
- * The xml element that is used to parse the attachment from.
- */
public function fromXML($xmlElement)
{
if (isset($xmlElement->key)) {
- $this->key = (string)$xmlElement->key;
+ $this->key = (string) $xmlElement->key;
}
+
if (isset($xmlElement->value)) {
- $this->value = (string)$xmlElement->value;
+ $this->value = (string) $xmlElement->value;
}
}
- /**
- * Creates the XML representation of an attachment
- *
- * @return \SimpleXMLElement
- */
public function toXML()
{
- $xml = new \SimpleXMLElement("");
+ $xml = new SimpleXMLElement('');
- $xml->addChild("key", $this->key);
- $xml->addChild("value", $this->value);
+ $xml->addChild('key', $this->key);
+ $xml->addChild('value', $this->value);
return $xml;
}
-
- /**
- * Human readable representation of this wrapper.
- *
- * @return string
- * A human readable version of the mailing.
- */
- public function toString()
+
+ public function toString(): string
{
- return "CustomProperty [key=" . $this->key . ", "
- . "value=" . $this->value . "]";
+ return 'CustomProperty ['
+ . 'key=' . $this->key
+ . ', value=' . $this->value
+ . ']';
}
}
diff --git a/src/mailings/DispatchLogic.php b/src/mailings/DispatchLogic.php
index 7c8538b..d5f5e14 100644
--- a/src/mailings/DispatchLogic.php
+++ b/src/mailings/DispatchLogic.php
@@ -3,6 +3,10 @@
namespace de\xqueue\maileon\api\client\mailings;
use de\xqueue\maileon\api\client\xml\AbstractXMLWrapper;
+use Exception;
+use SimpleXMLElement;
+
+use function filter_var;
/**
* The wrapper class for a dispatch logic. This class wraps the XML structure.
@@ -12,172 +16,203 @@
class DispatchLogic extends AbstractXMLWrapper
{
/**
- * @var DispatchLogicType type
* The type of the trigger mail dispatch plan, this can be one of 'SINGLE' or 'MULTI'
+ *
+ * @var DispatchLogicType
*/
public $type;
/**
- * @var int event
- * The ID of the transaction event that is used to either start the instant mailing or to controll the mass mailing
+ * The ID of the transaction event that is used to either start the instant mailing or to control the mass mailing
+ *
+ * @var int
*/
public $event;
/**
- * @var DispatchLogicTarget target
- * Defines the target group of a intervall mailing. This can either be 'EVENT', 'CONTACTFILTER', or 'RSS'
+ * Defines the target group of an intervall mailing. This can either be 'EVENT', 'CONTACTFILTER', or 'RSS'
+ *
+ * @var DispatchLogicTarget
*/
public $target;
/**
- * @var DispatchLogicSpeedLevel speedLevel
* Valid values are 'LOW', 'MEDIUM', and 'HIGH'
+ *
+ * @var DispatchLogicSpeedLevel
*/
public $speedLevel;
/**
- * @var DispatchLogicInterval interval
* This defines the interval in which the mailing is sent. This can be one of 'HOUR', 'DAY', 'WEEK', or 'MONTH'
+ *
+ * @var DispatchLogicInterval
*/
public $interval;
/**
- * @var int dayOfMonth
- * Sets the day of the month the mailing will be sent. Range: [1..31] If you set a larger number than the month has days, the last day in the month will be used.
+ * Sets the day of the month the mailing will be sent. Range: [1..31] If you set a larger number than the month has days, the last day
+ * in the month will be used.
+ *
+ * @var int
*/
public $dayOfMonth;
/**
- * @var int dayOfWeek
- * Sets the day of the week the mailing will be sent. Range: [1..7] 1 = Sunday 2 = Monday 3 = Tuesday 4 = Wednesday 5 = Thursday 6 = Friday 7 = Saturday
+ * Sets the day of the week the mailing will be sent. Range: [1..7] 1 = Sunday, 2 = Monday, 3 = Tuesday, 4 = Wednesday, 5 = Thursday,
+ * 6 = Friday, 7 = Saturday
+ *
+ * @var int
*/
public $dayOfWeek;
/**
- * @var int hours
* Sets the tour of the day the mailing will be sent. Range: [0..23]
+ *
+ * @var int
*/
public $hours;
/**
- * @var int minutes
* Sets the minute of the hour the mailing will be sent. Range: [0..59]
+ *
+ * @var int
*/
public $minutes;
/**
- * @var int contactFilterId
* Sets contact filter ID
+ *
+ * @var int
*/
public $contactFilterId;
/**
- * @var bool startTrigger
* If set to true, the trigger will be instantly activated after setting the dispatching options.
+ *
+ * @var bool
*/
public $startTrigger;
/**
- * @var DispatchLogicRSSUniqueFeature rssUniqueFeature
* Defines the features that define an item as unique. Valid values are 'DEFAULT', 'PUBDATE', 'TITLE', and 'LINK'.
+ *
+ * @var DispatchLogicRSSUniqueFeature
*/
public $rssUniqueFeature;
/**
- * @var string rssFeedUrl
* The URL of the RSS feed.
+ *
+ * @var string
*/
public $rssFeedUrl;
/**
- * @var DispatchLogicRSSOrderBy rssOrderBy
* Defines the attribute to order elements by. Valid are 'PUBDATE', 'TITLE', and 'LINK'
+ *
+ * @var DispatchLogicRSSOrderBy
*/
public $rssOrderBy;
/**
- * @var bool rssOrderAsc
* Defines if the order direction is ASC or DESC. If 'true' elements are handled in ascending order.
+ *
+ * @var bool
*/
public $rssOrderAsc;
/**
- * @var int rssMinNewEntries
* The minimal number of new entries to trigger the RSS2Email mailing.
+ *
+ * @var int
*/
public $rssMinNewEntries;
/**
- * @var int deliveryLimit
- * The maximum of mailings a repeipient should receive in a given period. Default is 0, which means unlimited.
+ * The maximum of mailings a recipient should receive in a given period. Default is 0, which means unlimited.
+ *
+ * @var int
*/
public $deliveryLimit;
/**
- * @var DispatchLogicDeliveryLimitUnit deliveryLimitUnit
* The time period for the delivery limit. Can be one of 'DAY', 'WEEK', 'MONTH', or 'YEAR'.
+ *
+ * @var DispatchLogicDeliveryLimitUnit
*/
public $deliveryLimitUnit;
- /**
- * Initialization of the schedule from a simple xml element.
- *
- * @param \SimpleXMLElement $xmlElement
- * The xml element that is used to parse the schedule from.
- */
public function fromXML($xmlElement)
{
if (isset($xmlElement->type)) {
$this->type = DispatchLogicType::getObject($xmlElement->type);
}
+
if (isset($xmlElement->event)) {
$this->event = (int) $xmlElement->event;
}
+
if (isset($xmlElement->target)) {
$this->target = DispatchLogicTarget::getObject($xmlElement->target);
}
+
if (isset($xmlElement->speed_level)) {
$this->speedLevel = DispatchLogicSpeedLevel::getObject($xmlElement->speed_level);
}
+
if (isset($xmlElement->interval)) {
$this->interval = DispatchLogicInterval::getObject($xmlElement->interval);
}
+
if (isset($xmlElement->day_of_month)) {
$this->dayOfMonth = (int) $xmlElement->day_of_month;
}
+
if (isset($xmlElement->day_of_week)) {
$this->dayOfWeek = (int) $xmlElement->day_of_week;
}
+
if (isset($xmlElement->hours)) {
$this->hours = (int) $xmlElement->hours;
}
+
if (isset($xmlElement->minutes)) {
$this->minutes = (int) $xmlElement->minutes;
}
+
if (isset($xmlElement->contact_filter_id)) {
$this->contactFilterId = (int) $xmlElement->contact_filter_id;
}
+
if (isset($xmlElement->start_trigger)) {
$this->startTrigger = filter_var($xmlElement->start_trigger, FILTER_VALIDATE_BOOLEAN);
}
+
if (isset($xmlElement->rss_unique_feature)) {
$this->rssUniqueFeature = DispatchLogicRSSUniqueFeature::getObject($xmlElement->rss_unique_feature);
}
+
if (isset($xmlElement->rss_feed_url)) {
$this->rssFeedUrl = (string) $xmlElement->rss_feed_url;
}
+
if (isset($xmlElement->rss_order_by)) {
$this->rssOrderBy = DispatchLogicRSSOrderBy::getObject($xmlElement->rss_order_by);
}
+
if (isset($xmlElement->rss_order_asc)) {
$this->rssOrderAsc = filter_var($xmlElement->rss_order_asc, FILTER_VALIDATE_BOOLEAN);
}
+
if (isset($xmlElement->rss_min_new_entries)) {
$this->rssUniqueFeature = DispatchLogicRSSUniqueFeature::getObject($xmlElement->rss_unique_feature);
}
+
if (isset($xmlElement->delivery_limit)) {
$this->rssUniqueFeature = DispatchLogicRSSUniqueFeature::getObject($xmlElement->rss_unique_feature);
}
+
if (isset($xmlElement->delivery_limit_unit)) {
$this->rssUniqueFeature = DispatchLogicRSSUniqueFeature::getObject($xmlElement->rss_unique_feature);
}
@@ -188,94 +223,111 @@ public function fromXML($xmlElement)
*
* @param bool $addXMLDeclaration
*
- * @return \SimpleXMLElement
- * Generate a XML element from the contact object.
+ * @return SimpleXMLElement contains the serialized representation of the object
+ *
+ * @throws Exception
*/
public function toXML($addXMLDeclaration = true)
{
- $xmlString = $addXMLDeclaration ? "" : "";
- $xml = new \SimpleXMLElement($xmlString);
+ $xmlString = $addXMLDeclaration ? '' : '';
+ $xml = new SimpleXMLElement($xmlString);
if (isset($this->type)) {
- $xml->addChild("type", $this->type->getValue());
+ $xml->addChild('type', $this->type->getValue());
}
+
if (isset($this->event)) {
- $xml->addChild("event", $this->event);
+ $xml->addChild('event', $this->event);
}
+
if (isset($this->target)) {
- $xml->addChild("target", $this->target->getValue());
+ $xml->addChild('target', $this->target->getValue());
}
+
if (isset($this->speedLevel)) {
- $xml->addChild("speed_level", $this->speedLevel->getValue());
+ $xml->addChild('speed_level', $this->speedLevel->getValue());
}
+
if (isset($this->interval)) {
- $xml->addChild("interval", $this->interval->getValue());
+ $xml->addChild('interval', $this->interval->getValue());
}
+
if (isset($this->dayOfMonth)) {
- $xml->addChild("day_of_month", $this->dayOfMonth);
+ $xml->addChild('day_of_month', $this->dayOfMonth);
}
+
if (isset($this->dayOfWeek)) {
- $xml->addChild("day_of_week", $this->dayOfWeek);
+ $xml->addChild('day_of_week', $this->dayOfWeek);
}
+
if (isset($this->hours)) {
- $xml->addChild("hours", $this->hours);
+ $xml->addChild('hours', $this->hours);
}
- if (!empty($this->minutes)) {
- $xml->addChild("minutes", $this->minutes);
+
+ if (! empty($this->minutes)) {
+ $xml->addChild('minutes', $this->minutes);
}
+
if (isset($this->contactFilterId)) {
- $xml->addChild("contact_filter_id", $this->contactFilterId);
+ $xml->addChild('contact_filter_id', $this->contactFilterId);
}
+
if (isset($this->startTrigger)) {
- $xml->addChild("start_trigger", $this->startTrigger ? 'true' : 'false');
+ $xml->addChild('start_trigger', $this->startTrigger ? 'true' : 'false');
}
+
if (isset($this->rssUniqueFeature)) {
- $xml->addChild("rss_unique_feature", $this->rssUniqueFeature->getValue());
+ $xml->addChild('rss_unique_feature', $this->rssUniqueFeature->getValue());
}
+
if (isset($this->rssFeedUrl)) {
- $xml->addChild("rss_feed_url", $this->rssFeedUrl);
+ $xml->addChild('rss_feed_url', $this->rssFeedUrl);
}
+
if (isset($this->rssOrderBy)) {
- $xml->addChild("rss_order_by", $this->rssOrderBy->getValue());
+ $xml->addChild('rss_order_by', $this->rssOrderBy->getValue());
}
+
if (isset($this->rssOrderAsc)) {
- $xml->addChild("rss_order_asc", $this->rssOrderAsc ? 'true' : 'false');
+ $xml->addChild('rss_order_asc', $this->rssOrderAsc ? 'true' : 'false');
}
+
if (isset($this->rssMinNewEntries)) {
- $xml->addChild("rss_min_new_entries", $this->rssMinNewEntries);
+ $xml->addChild('rss_min_new_entries', $this->rssMinNewEntries);
}
+
if (isset($this->deliveryLimit)) {
- $xml->addChild("delivery_limit", $this->deliveryLimit);
+ $xml->addChild('delivery_limit', $this->deliveryLimit);
}
+
if (isset($this->deliveryLimitUnit)) {
- $xml->addChild("delivery_limit_unit", $this->deliveryLimitUnit->getValue());
+ $xml->addChild('delivery_limit_unit', $this->deliveryLimitUnit->getValue());
}
return $xml;
}
- /**
- * Serialization to a simple XML element as string
- *
- * @return string
- * The string representation of the XML document for this mailing.
- */
- public function toXMLString()
- {
- return $this->toXML()->asXML();
- }
-
- /**
- * Human readable representation of this wrapper.
- *
- * @return string
- * A human readable version of the dispatch logic.
- */
- public function toString()
+ public function toString(): string
{
- return "Dispatch Logic [type={$this->type}, event={$this->event}, target={$this->target}, speedLevel={$this->speedLevel}, interval={$this->interval}, ".
- "dayOfMonth={$this->dayOfMonth}, dayOfWeek={$this->dayOfWeek}, hours={$this->hours}, minutes={$this->minutes}, contactFilterId={$this->contactFilterId}, ".
- "startTrigger={($this->startTrigger)?'true':'false'}, rssUniqueFeature={$this->rssUniqueFeature}, rssFeedUrl={$this->rssFeedUrl}, rssOrderBy={$this->rssOrderBy}, ".
- "rssOrderAsc={($this->rssOrderAsc)?'true':'false'}, rssMinNewEntries={$this->rssMinNewEntries}, deliveryLimit={$this->deliveryLimit}, deliveryLimitUnit={$this->deliveryLimitUnit}]";
+ return 'Dispatch Logic ['
+ . 'type=' . $this->type->getValue()
+ . ', event=' . $this->event
+ . ', target=' . $this->target->getValue()
+ . ', speedLevel=' . $this->speedLevel->getValue()
+ . ', interval=' . $this->interval->getValue()
+ . ', dayOfMonth=' . $this->dayOfMonth
+ . ', dayOfWeek=' . $this->dayOfWeek
+ . ', hours=' . $this->hours
+ . ', minutes=' . $this->minutes
+ . ', contactFilterId=' . $this->contactFilterId
+ . ', startTrigger=' . ($this->startTrigger ? 'true' : 'false')
+ . ', rssUniqueFeature=' . $this->rssUniqueFeature->getValue()
+ . ', rssFeedUrl=' . $this->rssFeedUrl
+ . ', rssOrderBy=' . $this->rssOrderBy->getValue()
+ . ', rssOrderAsc=' . ($this->rssOrderAsc ? 'true' : 'false')
+ . ', rssMinNewEntries=' . $this->rssMinNewEntries
+ . ', deliveryLimit=' . $this->deliveryLimit
+ . ', deliveryLimitUnit=' . $this->deliveryLimitUnit->getValue()
+ . ']';
}
}
diff --git a/src/mailings/DispatchLogicDeliveryLimitUnit.php b/src/mailings/DispatchLogicDeliveryLimitUnit.php
index e8e1f2a..06818b9 100644
--- a/src/mailings/DispatchLogicDeliveryLimitUnit.php
+++ b/src/mailings/DispatchLogicDeliveryLimitUnit.php
@@ -7,7 +7,7 @@
*
* The supported RSS order are day, week, month and year.
*
- * @author Andreas Lange | XQueue GmbH | andreas.lange@xqueue.com
+ * @author Andreas Lange
*/
class DispatchLogicDeliveryLimitUnit
{
@@ -20,19 +20,19 @@ class DispatchLogicDeliveryLimitUnit
// TODO use a more sensible name for this concept, e.g. "type descriptor"
/**
- *
- * @var string $value
* A string that describes the RSS order. Valid values are day, week, month and year.
+ *
+ * @var string
*/
public $value;
public static function init()
{
- if (self::$initialized == false) {
- self::$DAY = new DispatchLogicDeliveryLimitUnit("day");
- self::$WEEK = new DispatchLogicDeliveryLimitUnit("week");
- self::$MONTH = new DispatchLogicDeliveryLimitUnit("month");
- self::$YEAR = new DispatchLogicDeliveryLimitUnit("year");
+ if (self::$initialized === false) {
+ self::$DAY = new DispatchLogicDeliveryLimitUnit('day');
+ self::$WEEK = new DispatchLogicDeliveryLimitUnit('week');
+ self::$MONTH = new DispatchLogicDeliveryLimitUnit('month');
+ self::$YEAR = new DispatchLogicDeliveryLimitUnit('year');
self::$initialized = true;
}
}
@@ -40,8 +40,7 @@ public static function init()
/**
* Creates a new DispatchLogicDeliveryLimitUnit object.
*
- * @param string $value
- * a string describing the RSS order. Valid values are day, week, month and year.
+ * @param string $value a string describing the RSS order. Valid values are day, week, month and year.
*/
public function __construct($value)
{
@@ -49,10 +48,9 @@ public function __construct($value)
}
/**
- * @return string
- * the type descriptor string of this DispatchLogicDeliveryLimitUnit. Can be day, week, month or year.
+ * @return string the type descriptor string of this DispatchLogicDeliveryLimitUnit. Can be day, week, month or year.
*/
- public function getValue()
+ public function getValue(): string
{
return $this->value;
}
@@ -60,26 +58,25 @@ public function getValue()
/**
* Get the RSS order object by type descriptor.
*
- * @param string $value
- * a type descriptor string. Can be day, week, month or year.
- * @return DispatchLogicDeliveryLimitUnit
- * the DispatchLogicDeliveryLimitUnit object
+ * @param string $value a type descriptor string. Can be day, week, month or year.
+ *
+ * @return DispatchLogicDeliveryLimitUnit|null the DispatchLogicDeliveryLimitUnit object
*/
public static function getObject($value)
{
switch ($value) {
- case "day":
+ case 'day':
return self::$DAY;
- case "week":
+ case 'week':
return self::$WEEK;
- case "month":
+ case 'month':
return self::$MONTH;
- case "year":
+ case 'year':
return self::$YEAR;
-
default:
return null;
}
}
}
+
DispatchLogicDeliveryLimitUnit::init();
diff --git a/src/mailings/DispatchLogicInterval.php b/src/mailings/DispatchLogicInterval.php
index 488af39..da59192 100644
--- a/src/mailings/DispatchLogicInterval.php
+++ b/src/mailings/DispatchLogicInterval.php
@@ -7,7 +7,7 @@
*
* The supported intervals are hour, day, week and month.
*
- * @author Andreas Lange | XQueue GmbH | andreas.lange@xqueue.com
+ * @author Andreas Lange
*/
class DispatchLogicInterval
{
@@ -20,19 +20,19 @@ class DispatchLogicInterval
// TODO use a more sensible name for this concept, e.g. "type descriptor"
/**
- *
- * @var string $value
* A string that describes the interval. Valid values are "hour", "day", "week" and "month".
+ *
+ * @var string
*/
public $value;
public static function init()
{
- if (self::$initialized == false) {
- self::$HOUR = new DispatchLogicInterval("hour");
- self::$DAY = new DispatchLogicInterval("day");
- self::$WEEK = new DispatchLogicInterval("week");
- self::$MONTH = new DispatchLogicInterval("month");
+ if (self::$initialized === false) {
+ self::$HOUR = new DispatchLogicInterval('hour');
+ self::$DAY = new DispatchLogicInterval('day');
+ self::$WEEK = new DispatchLogicInterval('week');
+ self::$MONTH = new DispatchLogicInterval('month');
self::$initialized = true;
}
}
@@ -40,8 +40,7 @@ public static function init()
/**
* Creates a new DispatchLogicInterval object.
*
- * @param string $value
- * a string describing the logic interval. Valid values are "hour", "day", "week" and "month".
+ * @param string $value a string describing the logic interval. Valid values are "hour", "day", "week" and "month".
*/
public function __construct($value)
{
@@ -49,10 +48,9 @@ public function __construct($value)
}
/**
- * @return string
- * the type descriptor string of this DispatchLogicInterval. Can be "hour", "day", "week" or "month".
+ * @return string the type descriptor string of this DispatchLogicInterval. Can be "hour", "day", "week" or "month".
*/
- public function getValue()
+ public function getValue(): string
{
return $this->value;
}
@@ -60,26 +58,25 @@ public function getValue()
/**
* Get the interval object by type descriptor.
*
- * @param string $value
- * a type descriptor string. Can be "hour", "day", "week" or "month".
- * @return DispatchLogicInterval
- * the DispatchLogicInterval object
+ * @param string $value a type descriptor string. Can be "hour", "day", "week" or "month".
+ *
+ * @return DispatchLogicInterval|null the DispatchLogicInterval object
*/
public static function getObject($value)
{
switch ($value) {
- case "hour":
+ case 'hour':
return self::$HOUR;
- case "day":
+ case 'day':
return self::$DAY;
- case "week":
+ case 'week':
return self::$WEEK;
- case "month":
+ case 'month':
return self::$MONTH;
-
default:
return null;
}
}
}
+
DispatchLogicInterval::init();
diff --git a/src/mailings/DispatchLogicRSSOrderBy.php b/src/mailings/DispatchLogicRSSOrderBy.php
index a8cdf6d..5768b9a 100644
--- a/src/mailings/DispatchLogicRSSOrderBy.php
+++ b/src/mailings/DispatchLogicRSSOrderBy.php
@@ -7,7 +7,7 @@
*
* The supported RSS orders are pubdate, title and link.
*
- * @author Andreas Lange | XQueue GmbH | andreas.lange@xqueue.com
+ * @author Andreas Lange
*/
class DispatchLogicRSSOrderBy
{
@@ -19,18 +19,18 @@ class DispatchLogicRSSOrderBy
// TODO use a more sensible name for this concept, e.g. "type descriptor"
/**
- *
- * @var string $value
* A string that describes the RSS order. Valid values are "pubdate", "title" and "link".
+ *
+ * @var string
*/
public $value;
public static function init()
{
- if (self::$initialized == false) {
- self::$PUBDATE = new DispatchLogicRSSOrderBy("pubdate");
- self::$TITLE = new DispatchLogicRSSOrderBy("title");
- self::$LINK = new DispatchLogicRSSOrderBy("link");
+ if (self::$initialized === false) {
+ self::$PUBDATE = new DispatchLogicRSSOrderBy('pubdate');
+ self::$TITLE = new DispatchLogicRSSOrderBy('title');
+ self::$LINK = new DispatchLogicRSSOrderBy('link');
self::$initialized = true;
}
}
@@ -38,8 +38,7 @@ public static function init()
/**
* Creates a new DispatchLogicRSSOrderBy object.
*
- * @param string $value
- * a string describing the RSS order. Valid values are "pubdate", "title" and "link".
+ * @param string $value a string describing the RSS order. Valid values are "pubdate", "title" and "link".
*/
public function __construct($value)
{
@@ -47,10 +46,9 @@ public function __construct($value)
}
/**
- * @return string
- * the type descriptor string of this DispatchLogicRSSOrderBy. Can be "pubdate", "title" or "link".
+ * @return string the type descriptor string of this DispatchLogicRSSOrderBy. Can be "pubdate", "title" or "link".
*/
- public function getValue()
+ public function getValue(): string
{
return $this->value;
}
@@ -58,24 +56,23 @@ public function getValue()
/**
* Get the RSS order object by type descriptor.
*
- * @param string $value
- * a type descriptor string. Can be "pubdate", "title" or "link".
- * @return DispatchLogicRSSOrderBy
- * the DispatchLogicRSSOrderBy object
+ * @param string $value a type descriptor string. Can be "pubdate", "title" or "link".
+ *
+ * @return DispatchLogicRSSOrderBy|null the DispatchLogicRSSOrderBy object
*/
public static function getObject($value)
{
switch ($value) {
- case "pubdate":
+ case 'pubdate':
return self::$PUBDATE;
- case "title":
+ case 'title':
return self::$TITLE;
- case "link":
+ case 'link':
return self::$LINK;
-
default:
return null;
}
}
}
+
DispatchLogicRSSOrderBy::init();
diff --git a/src/mailings/DispatchLogicRSSUniqueFeature.php b/src/mailings/DispatchLogicRSSUniqueFeature.php
index e07261a..91b0266 100644
--- a/src/mailings/DispatchLogicRSSUniqueFeature.php
+++ b/src/mailings/DispatchLogicRSSUniqueFeature.php
@@ -7,7 +7,7 @@
*
* The supported RSS unique features are default, pubdate, title and link.
*
- * @author Andreas Lange | XQueue GmbH | andreas.lange@xqueue.com
+ * @author Andreas Lange
*/
class DispatchLogicRSSUniqueFeature
{
@@ -20,19 +20,19 @@ class DispatchLogicRSSUniqueFeature
// TODO use a more sensible name for this concept, e.g. "type descriptor"
/**
- *
- * @var string $value
* A string that describes the RSS unique feature. Valid values are "default", "pubdate", "title" and "link".
+ *
+ * @var string
*/
public $value;
public static function init()
{
- if (self::$initialized == false) {
- self::$DEFAULT = new DispatchLogicRSSUniqueFeature("default");
- self::$PUBDATE = new DispatchLogicRSSUniqueFeature("pubdate");
- self::$TITLE = new DispatchLogicRSSUniqueFeature("title");
- self::$LINK = new DispatchLogicRSSUniqueFeature("link");
+ if (self::$initialized === false) {
+ self::$DEFAULT = new DispatchLogicRSSUniqueFeature('default');
+ self::$PUBDATE = new DispatchLogicRSSUniqueFeature('pubdate');
+ self::$TITLE = new DispatchLogicRSSUniqueFeature('title');
+ self::$LINK = new DispatchLogicRSSUniqueFeature('link');
self::$initialized = true;
}
}
@@ -40,8 +40,7 @@ public static function init()
/**
* Creates a new DispatchLogicRSSUniqueFeature object.
*
- * @param string $value
- * a string describing the RSS unique feature. Valid values are "default", "pubdate", "title" and "link".
+ * @param string $value a string describing the RSS unique feature. Valid values are "default", "pubdate", "title" and "link".
*/
public function __construct($value)
{
@@ -49,10 +48,9 @@ public function __construct($value)
}
/**
- * @return string
- * the type descriptor string of this DispatchLogicRSSUniqueFeature. Can be "default", "pubdate", "title" or "link".
+ * @return string the type descriptor string of this DispatchLogicRSSUniqueFeature. Can be "default", "pubdate", "title" or "link".
*/
- public function getValue()
+ public function getValue(): string
{
return $this->value;
}
@@ -60,26 +58,25 @@ public function getValue()
/**
* Get the RSS unique feature object by type descriptor.
*
- * @param string $value
- * a type descriptor string. Can be "default", "pubdate", "title" or "link".
- * @return DispatchLogicRSSUniqueFeature
- * the DispatchLogicRSSUniqueFeature object
+ * @param string $value a type descriptor string. Can be "default", "pubdate", "title" or "link".
+ *
+ * @return DispatchLogicRSSUniqueFeature|null the DispatchLogicRSSUniqueFeature object
*/
public static function getObject($value)
{
switch ($value) {
- case "default":
+ case 'default':
return self::$DEFAULT;
- case "pubdate":
+ case 'pubdate':
return self::$PUBDATE;
- case "title":
+ case 'title':
return self::$TITLE;
- case "link":
+ case 'link':
return self::$LINK;
-
default:
return null;
}
}
}
+
DispatchLogicRSSUniqueFeature::init();
diff --git a/src/mailings/DispatchLogicSpeedLevel.php b/src/mailings/DispatchLogicSpeedLevel.php
index ec36813..3a79c59 100644
--- a/src/mailings/DispatchLogicSpeedLevel.php
+++ b/src/mailings/DispatchLogicSpeedLevel.php
@@ -7,7 +7,7 @@
*
* The supported speed levels are low, medium and high.
*
- * @author Andreas Lange | XQueue GmbH | andreas.lange@xqueue.com
+ * @author Andreas Lange
*/
class DispatchLogicSpeedLevel
{
@@ -19,18 +19,18 @@ class DispatchLogicSpeedLevel
// TODO use a more sensible name for this concept, e.g. "type descriptor"
/**
- *
- * @var string $value
* A string that describes the speed level. Valid values are "low", "medium" and "high".
+ *
+ * @var string
*/
public $value;
public static function init()
{
- if (self::$initialized == false) {
- self::$LOW = new DispatchLogicInterval("low");
- self::$MEDIUM = new DispatchLogicInterval("medium");
- self::$HIGH = new DispatchLogicInterval("high");
+ if (self::$initialized === false) {
+ self::$LOW = new DispatchLogicInterval('low');
+ self::$MEDIUM = new DispatchLogicInterval('medium');
+ self::$HIGH = new DispatchLogicInterval('high');
self::$initialized = true;
}
}
@@ -38,8 +38,7 @@ public static function init()
/**
* Creates a new DispatchLogicSpeedLevel object.
*
- * @param string $value
- * a string describing the speed level. Valid values are "low", "medium" and "high".
+ * @param string $value a string describing the speed level. Valid values are "low", "medium" and "high".
*/
public function __construct($value)
{
@@ -47,10 +46,9 @@ public function __construct($value)
}
/**
- * @return string
- * the type descriptor string of this DispatchLogicSpeedLevel. Can be "low", "medium" or "high".
+ * @return string the type descriptor string of this DispatchLogicSpeedLevel. Can be "low", "medium" or "high".
*/
- public function getValue()
+ public function getValue(): string
{
return $this->value;
}
@@ -58,24 +56,23 @@ public function getValue()
/**
* Get the speed level object by type descriptor.
*
- * @param string $value
- * a type descriptor string. Can be "low", "medium" or "high".
- * @return DispatchLogicSpeedLevel
- * the DispatchLogicSpeedLevel object
+ * @param string $value a type descriptor string. Can be "low", "medium" or "high".
+ *
+ * @return DispatchLogicSpeedLevel|null the DispatchLogicSpeedLevel object
*/
public static function getObject($value)
{
switch ($value) {
- case "low":
+ case 'low':
return self::$LOW;
- case "medium":
+ case 'medium':
return self::$MEDIUM;
- case "high":
+ case 'high':
return self::$HIGH;
-
default:
return null;
}
}
}
+
DispatchLogicSpeedLevel::init();
diff --git a/src/mailings/DispatchLogicTarget.php b/src/mailings/DispatchLogicTarget.php
index 226c7a4..c0b8334 100644
--- a/src/mailings/DispatchLogicTarget.php
+++ b/src/mailings/DispatchLogicTarget.php
@@ -7,7 +7,7 @@
*
* The supported targets are event, contactfilter and rss.
*
- * @author Andreas Lange | XQueue GmbH | andreas.lange@xqueue.com
+ * @author Andreas Lange
*/
class DispatchLogicTarget
{
@@ -19,27 +19,26 @@ class DispatchLogicTarget
// TODO use a more sensible name for this concept, e.g. "type descriptor"
/**
- *
- * @var string $value
* A string that describes the target. Valid values are "event", "contactfilter" and "rss".
+ *
+ * @var string
*/
public $value;
public static function init()
{
- if (self::$initialized == false) {
- self::$EVENT = new DispatchLogicTarget("event");
- self::$CONTACTFILTER = new DispatchLogicTarget("contactfilter");
- self::$RSS = new DispatchLogicTarget("rss");
- self::$initialized = true;
+ if (self::$initialized === false) {
+ self::$EVENT = new DispatchLogicTarget('event');
+ self::$CONTACTFILTER = new DispatchLogicTarget('contactfilter');
+ self::$RSS = new DispatchLogicTarget('rss');
+ self::$initialized = true;
}
}
/**
* Creates a new DispatchLogicTarget object.
*
- * @param string $value
- * a string describing the target. Valid values are "event", "contactfilter" and "rss".
+ * @param string $value a string describing the target. Valid values are "event", "contactfilter" and "rss".
*/
public function __construct($value)
{
@@ -47,10 +46,9 @@ public function __construct($value)
}
/**
- * @return string
- * the type descriptor string of this DispatchLogicTarget. Can be "event", "contactfilter" or "rss".
+ * @return string the type descriptor string of this DispatchLogicTarget. Can be "event", "contactfilter" or "rss".
*/
- public function getValue()
+ public function getValue(): string
{
return $this->value;
}
@@ -58,24 +56,24 @@ public function getValue()
/**
* Get the target object by type descriptor.
*
- * @param string $value
- * a type descriptor string. Can be "event", "contactfilter" or "rss".
- * @return DispatchLogicTarget
- * the DispatchLogicTarget object
+ * @param string $value a type descriptor string. Can be "event", "contactfilter" or "rss".
+ *
+ * @return DispatchLogicTarget|null the DispatchLogicTarget object
*/
public static function getObject($value)
{
switch ($value) {
- case "event":
+ case 'event':
return self::$EVENT;
- case "contactfilter":
+ case 'contactfilter':
return self::$CONTACTFILTER;
- case "rss":
+ case 'rss':
return self::$RSS;
-
+
default:
return null;
}
}
}
+
DispatchLogicTarget::init();
diff --git a/src/mailings/DispatchLogicType.php b/src/mailings/DispatchLogicType.php
index fabd6e9..9903be0 100644
--- a/src/mailings/DispatchLogicType.php
+++ b/src/mailings/DispatchLogicType.php
@@ -7,7 +7,7 @@
*
* The supported DispatchLogicTypes are single and multi.
*
- * @author Andreas Lange | XQueue GmbH | andreas.lange@xqueue.com
+ * @author Andreas Lange
*/
class DispatchLogicType
{
@@ -18,17 +18,17 @@ class DispatchLogicType
// TODO use a more sensible name for this concept, e.g. "DispatchLogicType descriptor"
/**
+ * A string that describes the DispatchLogicType. Valid values are "single" and "multi".
*
- * @var string $value
- * A string that describes the DispatchLogicType. Valid values are "single" and "nulti".
+ * @var string
*/
public $value;
public static function init()
{
- if (self::$initialized == false) {
- self::$SINGLE = new DispatchLogicType("single");
- self::$MULTI = new DispatchLogicType("multi");
+ if (self::$initialized === false) {
+ self::$SINGLE = new DispatchLogicType('single');
+ self::$MULTI = new DispatchLogicType('multi');
self::$initialized = true;
}
}
@@ -36,8 +36,7 @@ public static function init()
/**
* Creates a new DispatchLogicType object.
*
- * @param string $value
- * a string describing the logic DispatchLogicType. Valid values are "single" and "multi".
+ * @param string $value a string describing the logic DispatchLogicType. Valid values are "single" and "multi".
*/
public function __construct($value)
{
@@ -45,10 +44,9 @@ public function __construct($value)
}
/**
- * @return string
- * the DispatchLogicType descriptor string of this DispatchLogicType. Can be "single" or "multi".
+ * @return string the DispatchLogicType descriptor string of this DispatchLogicType. Can be "single" or "multi".
*/
- public function getValue()
+ public function getValue(): string
{
return $this->value;
}
@@ -56,22 +54,21 @@ public function getValue()
/**
* Get the logic DispatchLogicType object by DispatchLogicType descriptor.
*
- * @param string $value
- * a DispatchLogicType descriptor string. Can be "single" or "multi".
- * @return DispatchLogicType
- * the DispatchLogicType object
+ * @param string $value a DispatchLogicType descriptor string. Can be "single" or "multi".
+ *
+ * @return DispatchLogicType|null the DispatchLogicType object
*/
public static function getObject($value)
{
switch ($value) {
- case "single":
+ case 'single':
return self::$SINGLE;
- case "multi":
+ case 'multi':
return self::$MULTI;
-
default:
return null;
}
}
}
+
DispatchLogicType::init();
diff --git a/src/mailings/ImageGrabbingResult.php b/src/mailings/ImageGrabbingResult.php
index 75ac77a..602d5b3 100644
--- a/src/mailings/ImageGrabbingResult.php
+++ b/src/mailings/ImageGrabbingResult.php
@@ -4,17 +4,18 @@
use de\xqueue\maileon\api\client\json\AbstractJSONWrapper;
+use function htmlentities;
+use function property_exists;
+
/**
* A wrapper class for an image grabbing result
*
- * @author Balogh Viktor | Maileon - Wanadis Kft.
+ * @author Viktor Balogh | XQueue GmbH | viktor.balog@xqueue.com
*/
class ImageGrabbingResult extends AbstractJSONWrapper
{
/**
* The modified content
- *
- * @var ReportContact
*/
public $modified_content = '';
diff --git a/src/mailings/Mailing.php b/src/mailings/Mailing.php
index 898aed0..12a2e4c 100644
--- a/src/mailings/Mailing.php
+++ b/src/mailings/Mailing.php
@@ -2,14 +2,18 @@
namespace de\xqueue\maileon\api\client\mailings;
-use de\xqueue\maileon\api\client\xml\XMLUtils;
use de\xqueue\maileon\api\client\xml\AbstractXMLWrapper;
+use de\xqueue\maileon\api\client\xml\XMLUtils;
+use Exception;
+use SimpleXMLElement;
+
+use function rtrim;
+use function trim;
/**
* The wrapper class for a Maileon mailing. This class wraps the XML structure.
*
- * @author Marcus Ständer | Trusted Technologies GmbH |
- * marcus.staender@trusted-technologies.de
+ * @author Marcus Beckerle | XQueue GmbH | marcus.beckerle@xqueue.com
*/
class Mailing extends AbstractXMLWrapper
{
@@ -19,23 +23,17 @@ class Mailing extends AbstractXMLWrapper
/**
* Constructor initializing default values.
*
- * @param number $id
- * The Maileon mailing id.
- * @param array $fields
- * An array of fields.
+ * @param int $id The Maileon mailing id.
+ * @param array $fields An array of fields.
*/
- public function __construct($id = null, $fields = array())
- {
- $this->id = $id;
+ public function __construct(
+ $id = null,
+ $fields = []
+ ) {
+ $this->id = $id;
$this->fields = $fields;
}
- /**
- * Initialization of the mailing from a simple xml element.
- *
- * @param \SimpleXMLElement $xmlElement
- * The xml element that is used to parse the mailing from.
- */
public function fromXML($xmlElement)
{
if (isset($xmlElement->id)) {
@@ -43,9 +41,10 @@ public function fromXML($xmlElement)
}
if (isset($xmlElement->fields)) {
- $this->fields = array();
+ $this->fields = [];
+
foreach ($xmlElement->fields->children() as $field) {
- $this->fields[trim($field->name)] = (string)$field->value;
+ $this->fields[trim($field->name)] = (string) $field->value;
// The trim is required to make a safer string from the object
}
}
@@ -54,19 +53,19 @@ public function fromXML($xmlElement)
/**
* Returns the value of the field with the given name
*
- * @param string fieldName
- * The field name of the element to return the value of
+ * @param string $fieldName The field name of the element to return the value of
*
- * @return string
- * The value or undefined, if not found
+ * @return string|null The value or undefined, if not found
*/
public function getFieldValue($fieldName)
{
$name = trim($fieldName);
+
if (isset($this->fields)) {
- return ($this->fields[$name]);
+ return $this->fields[$name];
}
- return;
+
+ return null;
}
/**
@@ -74,60 +73,49 @@ public function getFieldValue($fieldName)
*
* @param bool $addXMLDeclaration
*
- * @return \SimpleXMLElement
- * Generate a XML element from the contact object.
+ * @return SimpleXMLElement contains the serialized representation of the object
+ *
+ * @throws Exception
*/
public function toXML($addXMLDeclaration = true)
{
- $xmlString = $addXMLDeclaration ? "" : "";
- $xml = new \SimpleXMLElement($xmlString);
+ $xmlString = $addXMLDeclaration ? '' : '';
+ $xml = new SimpleXMLElement($xmlString);
if (isset($this->id)) {
- $xml->addChild("id", $this->id);
+ $xml->addChild('id', $this->id);
}
if (isset($this->fields)) {
- $standard_fields = $xml->addChild("fields");
+ $standard_fields = $xml->addChild('fields');
+
foreach ($this->fields as $index => $value) {
- $field = $standard_fields->addChild("field");
- $field->addChild("name", $index);
+ $field = $standard_fields->addChild('field');
+ $field->addChild('name', $index);
- XMLUtils::addChildAsCDATA($field, "value", $value);
+ XMLUtils::addChildAsCDATA($field, 'value', $value);
}
}
return $xml;
}
- /**
- * Serialization to a simple XML element as string
- *
- * @return string
- * The string representation of the XML document for this mailing.
- */
- public function toXMLString()
- {
- $xml = $this->toXML();
- return $xml->asXML();
- }
-
- /**
- * Human readable representation of this wrapper.
- *
- * @return string
- * A human readable version of the mailing.
- */
- public function toString()
+ public function toString(): string
{
// Generate standard field string
- $fields = "";
+ $fields = '';
+
if (isset($this->fields)) {
foreach ($this->fields as $index => $value) {
- $fields .= $index . "=" . $value . ",";
+ $fields .= $index . '=' . $value . ',';
}
+
$fields = rtrim($fields, ',');
}
- return "Mailing [id=" . $this->id . ", fields={" . $fields . "}]";
+ return 'Mailing ['
+ . 'id=' . $this->id
+ . ', fields={' . $fields . '}'
+ . ']';
}
}
diff --git a/src/mailings/MailingBlacklist.php b/src/mailings/MailingBlacklist.php
index 4bacdca..8845b13 100644
--- a/src/mailings/MailingBlacklist.php
+++ b/src/mailings/MailingBlacklist.php
@@ -3,6 +3,7 @@
namespace de\xqueue\maileon\api\client\mailings;
use de\xqueue\maileon\api\client\xml\AbstractXMLWrapper;
+use SimpleXMLElement;
/**
* The wrapper class for a Maileon mailing blacklist (Versandsperrliste in German). This class wraps the XML structure.
@@ -19,9 +20,9 @@ class MailingBlacklist extends AbstractXMLWrapper
/**
* Constructor initializing default values.
*
- * @param integer $id
+ * @param int $id
* @param string $name
- * @param integer $createdTime
+ * @param int $createdTime
* @param string $createdUser
*/
public function __construct(
@@ -30,71 +31,62 @@ public function __construct(
$createdTime = null,
$createdUser = null
) {
- $this->id = $id;
- $this->name = $name;
+ $this->id = $id;
+ $this->name = $name;
$this->createdTime = $createdTime;
$this->createdUser = $createdUser;
}
- /**
- * Initialization of the blacklist from a simple xml element.
- *
- * @param \SimpleXMLElement $xmlElement
- * The xml element that is used to parse the attachment from.
- */
public function fromXML($xmlElement)
{
if (isset($xmlElement->id)) {
- $this->id = (int)$xmlElement->id;
+ $this->id = (int) $xmlElement->id;
}
+
if (isset($xmlElement->name)) {
- $this->name = (string)$xmlElement->name;
+ $this->name = (string) $xmlElement->name;
}
+
if (isset($xmlElement->created_time)) {
- $this->createdTime = (int)$xmlElement->created_time;
+ $this->createdTime = (int) $xmlElement->created_time;
}
+
if (isset($xmlElement->created_user)) {
- $this->createdUser = (string)$xmlElement->created_user;
+ $this->createdUser = (string) $xmlElement->created_user;
}
}
- /**
- * Creates the XML representation of a mailing blacklist
- *
- * @return \SimpleXMLElement
- */
public function toXML()
{
- $xmlString = "";
- $xml = new \SimpleXMLElement($xmlString);
-
+ $xmlString = '';
+ $xml = new SimpleXMLElement($xmlString);
+
if (isset($this->id)) {
- $xml->addChild("id", $this->id);
+ $xml->addChild('id', $this->id);
}
+
if (isset($this->name)) {
- $xml->addChild("name", $this->name);
+ $xml->addChild('name', $this->name);
}
+
if (isset($this->createdTime)) {
- $xml->addChild("created_time", $this->createdTime);
+ $xml->addChild('created_time', $this->createdTime);
}
+
if (isset($this->createdUser)) {
- $xml->addChild("created_user", $this->createdUser);
+ $xml->addChild('created_user', $this->createdUser);
}
return $xml;
}
-
- /**
- * Human readable representation of this wrapper.
- *
- * @return string
- * A human readable version of the mailing.
- */
- public function toString()
+
+ public function toString(): string
{
- return "MailingBlacklist [id=" . $this->id . ", "
- . "name=" . $this->name . ", "
- . "createdTime=" . $this->createdTime . ", "
- . "createdUser=" . $this->createdUser . "]";
+ return 'MailingBlacklist ['
+ . 'id=' . $this->id
+ . ', name=' . $this->name
+ . ', createdTime=' . $this->createdTime
+ . ', createdUser=' . $this->createdUser
+ . ']';
}
}
\ No newline at end of file
diff --git a/src/mailings/MailingFields.php b/src/mailings/MailingFields.php
index 974bb3a..5e5e867 100644
--- a/src/mailings/MailingFields.php
+++ b/src/mailings/MailingFields.php
@@ -5,25 +5,23 @@
/**
* The class contains the valid names for Maileon mailing fields to request from the API
*
- * @author Marcus Ständer | Trusted Technologies GmbH |
- * marcus.staender@trusted-technologies.de
+ * @author Marcus Beckerle | XQueue GmbH | marcus.beckerle@xqueue.com
*
*/
class MailingFields
{
/** The Constant "type". */
- public static $TYPE = "type";
+ public static $TYPE = 'type';
/** The Constant "state". */
- public static $STATE = "state";
+ public static $STATE = 'state';
/** The Constant "name". */
- public static $NAME = "name";
+ public static $NAME = 'name';
/** The Constant "scheduleTime". */
- public static $SCHEDULE_TIME = "scheduleTime";
-
+ public static $SCHEDULE_TIME = 'scheduleTime';
public static function init()
{
diff --git a/src/mailings/MailingsService.php b/src/mailings/MailingsService.php
index 30f5d18..f82faff 100644
--- a/src/mailings/MailingsService.php
+++ b/src/mailings/MailingsService.php
@@ -5,38 +5,54 @@
use de\xqueue\maileon\api\client\AbstractMaileonService;
use de\xqueue\maileon\api\client\MaileonAPIException;
use de\xqueue\maileon\api\client\MaileonAPIResult;
+use Exception;
+use SimpleXMLElement;
+
+use function base64_encode;
+use function basename;
+use function dom_import_simplexml;
+use function fclose;
+use function feof;
+use function fopen;
+use function fread;
+use function implode;
+use function is_array;
+use function json_encode;
+use function mb_convert_encoding;
+use function rawurlencode;
+use function strlen;
+use function urlencode;
/**
* Facade that wraps the REST service for mailings.
*
- * @author Marcus Ständer | Trusted Mails GmbH |
- * marcus.staender@trusted-mails.com
- * @author Andreas Lange | XQueue GmbH | andreas.lange@xqueue.com
+ * @author Marcus Beckerle | XQueue GmbH | marcus.beckerle@xqueue.com
+ * @author Andreas Lange
*/
class MailingsService extends AbstractMaileonService
{
/**
* Creates a new mailing.
*
- * @param string $name
- * the name of the mailing
- * @param string $subject
- * the subject of the mailing
- * @param bool $deprecatedParameter
- * this parameter was never used by the API
- * @param string $type
- * the type of the mailing, which can be one of 'doi', 'trigger', or 'regular'.
- * @param string $editorVersion
- * the version of the CMS to create the mailing for.
- * Valid values for CMS1: 'v1', '1'.
- * Valid values for CMS2: 'v2', '2'.
- * By default (no value), the mailing will be created as a CMS2 template, if CMS2 is activated.
- *
- * @return MaileonAPIResult
- * the result of the operation
- */
- public function createMailing($name, $subject, $deprecatedParameter = false, $type = "regular", $editorVersion = "")
- {
+ * @param string $name The name of the mailing
+ * @param string $subject The subject of the mailing
+ * @param bool $deprecatedParameter this parameter was never used by the API
+ * @param string $type The type of the mailing, which can be one of 'doi', 'trigger', or 'regular'.
+ * @param string $editorVersion The version of the CMS to create the mailing for. Valid values for CMS1: 'v1', '1'. Valid values
+ * for CMS2: 'v2', '2'. By default (no value), the mailing will be created as a CMS2 template, if
+ * CMS2 is activated.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
+ */
+ public function createMailing(
+ $name,
+ $subject,
+ $deprecatedParameter = false,
+ $type = 'regular',
+ $editorVersion = ''
+ ) {
$queryParameters = [
'name' => urlencode($name),
'subject' => urlencode($subject),
@@ -49,51 +65,75 @@ public function createMailing($name, $subject, $deprecatedParameter = false, $ty
$queryParameters['editorVersion'] = urlencode($editorVersion);
}
- return $this->post('mailings', "", $queryParameters);
+ return $this->post(
+ 'mailings',
+ '',
+ $queryParameters
+ );
}
/**
* Get the ID of a mailing by its name
*
- * @param integer $mailingId the ID of the mailing
+ * @param string $mailingName
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getMailingIdByName($mailingName)
{
- return $this->get('mailings/name/' . rawurlencode($mailingName));
+ $encodedMailingName = rawurlencode(mb_convert_encoding((string) $mailingName, 'UTF-8'));
+
+ return $this->get("mailings/name/$encodedMailingName");
}
/**
- * Get the type of a mailing. It can be either 'doi', 'trigger', or 'regular
+ * Get the type of mailing. It can be either 'doi', 'trigger', or 'regular'
+ *
+ * @param int $mailingId
*
- * @param integer $mailingId the ID of the mailing
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @return \de\xqueue\maileon\api\client\MaileonAPIResult
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getType($mailingId)
{
- return $this->get('mailings/' . $mailingId . '/type');
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->get("mailings/$encodedMailingId/type");
}
/**
* Check if a mailing with the given name exists and return true or false
*
- * @param integer $mailingId the ID of the mailing
+ * @param $mailingName
+ *
+ * @return bool
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function checkIfMailingExistsByName($mailingName)
+ public function checkIfMailingExistsByName($mailingName): bool
{
- $response = $this->get('mailings/name/' . rawurlencode($mailingName));
+ $encodedMailingName = rawurlencode(mb_convert_encoding((string) $mailingName, 'UTF-8'));
- return ($response->isSuccess());
+ return $this->get("mailings/name/$encodedMailingName")->isSuccess();
}
/**
* Disable all QoS checks for a given mailing
*
- * @param integer $mailingId the ID of the mailing
+ * @param int $mailingId the ID of the mailing
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function disableQosChecks($mailingId)
{
- return $this->put('mailings/' . $mailingId . '/settings/disableQosChecks');
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->put("mailings/$encodedMailingId/settings/disableQosChecks");
}
/**
@@ -101,52 +141,71 @@ public function disableQosChecks($mailingId)
* This is only possible with transaction/trigger mails and be aware to NOT add advertisements
* in mails you send without advertisement permission. This is meant for order confirmations and the like.
*
- * @param integer $mailingId the ID of the mailing
- * @param boolean $ignorePermission can be either true or false
+ * @param int $mailingId
+ * @param $ignorePermission
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function setIgnorePermission($mailingId, $ignorePermission)
- {
+ public function setIgnorePermission(
+ $mailingId,
+ $ignorePermission
+ ) {
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
if ($ignorePermission === true) {
- $ignorePermission = "true";
+ $ignorePermission = 'true';
} elseif ($ignorePermission === false) {
- $ignorePermission = "false";
+ $ignorePermission = 'false';
}
return $this->post(
- 'mailings/' . $mailingId . '/settings/ignorepermission',
- "$ignorePermission"
+ "mailings/$encodedMailingId/settings/ignorepermission", "$ignorePermission"
);
}
/**
* Check if a (trigger) mail is set to ignore permission during sendout (order confirmation, invoices, ...)
*
- * @param integer $mailingId the ID of the mailing
+ * @param int $mailingId
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @return "true" or "false"
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function isIgnorePermission($mailingId)
{
- return $this->get('mailings/' . $mailingId . '/settings/ignorepermission');
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->get("mailings/$encodedMailingId/settings/ignorepermission");
}
/**
* Set cleanup option for post sendout processing.
* This flag defines if the used contact list and filter should be deleted after sendout.
*
- * @param integer $mailingId the ID of the mailing
+ * @param int $mailingId the ID of the mailing
* @param boolean $cleanup can be either true or false
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function setCleanupListsAndFilters($mailingId, $cleanup)
- {
+ public function setCleanupListsAndFilters(
+ $mailingId,
+ $cleanup
+ ) {
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
if ($cleanup === true) {
- $cleanup = "true";
+ $cleanup = 'true';
} elseif ($cleanup === false) {
- $cleanup = "false";
+ $cleanup = 'false';
}
return $this->post(
- 'mailings/' . $mailingId . '/settings/post_sendout_cleanup',
+ "mailings/$encodedMailingId/settings/post_sendout_cleanup",
"$cleanup"
);
}
@@ -155,341 +214,421 @@ public function setCleanupListsAndFilters($mailingId, $cleanup)
* Retrieve the cleanup option for post sendout processing.
* This flag defines if the used contact list and filter should be deleted after sendout.
*
- * @param integer $mailingId the ID of the mailing
+ * @param int $mailingId the ID of the mailing
*
- * @return "true" or "false"
+ * @return MaileonAPIResult|null The result object of the API call, with "true" or "false" available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function isCleanupListsAndFilters($mailingId)
{
- return $this->get('mailings/' . $mailingId . '/settings/post_sendout_cleanup');
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->get("mailings/$encodedMailingId/settings/post_sendout_cleanup");
}
/**
* Sets the dispatch logic for trigger mailings
*
- * @param integer $mailingId the ID of the mailing
- * @param string $logic the string representation of the logic (xml)
+ * @param int $mailingId the ID of the mailing
+ * @param string $logic the string representation of the logic (xml)
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function setTriggerDispatchLogic($mailingId, $logic)
- {
- $queryParameters = [];
+ public function setTriggerDispatchLogic(
+ $mailingId,
+ $logic
+ ) {
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
- return $this->put('mailings/' . $mailingId . '/dispatching', $logic, $queryParameters);
+ return $this->put(
+ "mailings/$encodedMailingId/dispatching",
+ $logic
+ );
}
/**
* Used for DOI Mailings
*
- * @param integer $mailingId the ID of the mailing
- * */
+ * @param int $mailingId the ID of the mailing
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
+ */
public function setTriggerActive($mailingId)
{
- return $this->post('mailings/' . $mailingId . '/dispatching/activate', "");
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->post("mailings/$encodedMailingId/dispatching/activate");
}
/**
* Deletes an active trigger mailing.
*
- * @param integer $mailingId the ID of the mailing
+ * @param int $mailingId the ID of the mailing
*
- * @return MaileonAPIResult
- * the result of the operation
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function deleteActiveTriggerMailing($mailingId)
{
- return $this->delete("mailings/" . $mailingId . "/dispatching");
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->delete("mailings/$encodedMailingId/dispatching");
}
/**
* Deletes a mailing by ID.
*
- * @param integer $mailingId the ID of the mailing
+ * @param int $mailingId the ID of the mailing
*
- * @return MaileonAPIResult
- * the result of the operation
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function deleteMailing($mailingId)
{
- return $this->delete("mailings/" . $mailingId);
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->delete("mailings/$encodedMailingId");
}
/**
* Updates the HTML content of the mailing referenced by the given ID.
*
- * @param integer $mailingId the ID of the mailing
- * @param string $html
- * the new HTML content of the mailing
- * @param bool $doImageGrabbing
- * specifies if image grabbing should be performed
- * @param bool $doLinkTracking
- * specifies if link tracking should be performed
+ * @param int $mailingId the ID of the mailing
+ * @param string $html the new HTML content of the mailing
+ * @param bool $doImageGrabbing specifies if image grabbing should be performed
+ * @param bool $doLinkTracking specifies if link tracking should be performed
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function setHTMLContent($mailingId, $html, $doImageGrabbing = true, $doLinkTracking = false)
- {
+ public function setHTMLContent(
+ $mailingId,
+ $html,
+ $doImageGrabbing = true,
+ $doLinkTracking = false
+ ) {
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
$queryParameters = [
- 'doImageGrabbing' => ($doImageGrabbing == true) ? "true" : "false",
- 'doLinkTracking' => ($doLinkTracking == true) ? "true" : "false",
+ 'doImageGrabbing' => $doImageGrabbing === true ? 'true' : 'false',
+ 'doLinkTracking' => $doLinkTracking === true ? 'true' : 'false',
];
- return $this->post('mailings/' . $mailingId . '/contents/html', $html, $queryParameters, "text/html");
+ return $this->post(
+ "mailings/$encodedMailingId/contents/html",
+ $html,
+ $queryParameters,
+ 'text/html'
+ );
}
/**
* Updates the TEXT content of the mailing referenced by the given ID.
*
- * @param integer $mailingId the ID of the mailing
- * @param string $text
- * the new TEXT content of the mailing
+ * @param int $mailingId the ID of the mailing
+ * @param string $text the new TEXT content of the mailing
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function setTextContent($mailingId, $text)
- {
- return $this->post('mailings/' . $mailingId . '/contents/text', $text, [], "text/plain");
+ public function setTextContent(
+ $mailingId,
+ $text
+ ) {
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->post(
+ "mailings/$encodedMailingId/contents/text",
+ $text,
+ [],
+ 'text/plain'
+ );
}
/**
* Fetches the HTML content of the mailing identified by the given ID.
*
- * @param integer $mailingId the ID of the mailing
+ * @param int $mailingId the ID of the mailing
*
- * @return MaileonAPIResult
- * the result object of the API call, with the HTML content string of the mailing
- * available at MaileonAPIResult::getResult()
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @return MaileonAPIResult|null The result object of the API call, with the HTML content string of the mailing available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getHTMLContent($mailingId)
{
- return $this->get('mailings/' . $mailingId . '/contents/html', null, "text/html");
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->get(
+ "mailings/$encodedMailingId/contents/html",
+ null,
+ 'text/html'
+ );
}
/**
* Fetches the TEXT content of the mailing identified by the given ID.
*
- * @param integer $mailingId the ID of the mailing
+ * @param int $mailingId the ID of the mailing
+ *
+ * @return MaileonAPIResult|null The result object of the API call, with the TEXT content string of the mailing available at MaileonAPIResult::getResult()
*
- * @return MaileonAPIResult
- * the result object of the API call, with the TEXT content string of the mailing
- * available at MaileonAPIResult::getResult()
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getTextContent($mailingId)
{
- return $this->get('mailings/' . $mailingId . '/contents/text', null, "text/plain");
- }
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+ return $this->get(
+ "mailings/$encodedMailingId/contents/text",
+ null,
+ 'text/plain'
+ );
+ }
/**
* Adds a contactfilter to the contact filter restrictions of the mailing with the given ID.
*
- * @param integer $mailingId the ID of the mailing
- * @param integer $contactFilterId the ID of the contact filter
+ * @param int $mailingId the ID of the mailing
+ * @param int $contactFilterId the ID of the contact filter
*
- * @return MaileonAPIResult
- * the result object of the API call available at MaileonAPIResult::getResult()
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function addContactFilterRestriction($mailingId, $contactFilterId)
- {
- return $this->post("mailings/$mailingId/restrictions/$contactFilterId", null);
+ public function addContactFilterRestriction(
+ $mailingId,
+ $contactFilterId
+ ) {
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+ $encodedContactFilterId = rawurlencode(mb_convert_encoding((string) $contactFilterId, 'UTF-8'));
+
+ return $this->post(
+ "mailings/$encodedMailingId/restrictions/$encodedContactFilterId",
+ null
+ );
}
/**
* Removes a contactfilter from the contact filter restrictions of the mailing with the given ID.
*
- * @param integer $mailingId the ID of the mailing
- * @param integer $contactFilterId the ID of the contact filter
+ * @param int $mailingId the ID of the mailing
+ * @param int $contactFilterId the ID of the contact filter
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @return MaileonAPIResult
- * the result object of the API call available at MaileonAPIResult::getResult()
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function deleteContactFilterRestriction($mailingId, $contactFilterId)
- {
- return $this->delete("mailings/$mailingId/restrictions/$contactFilterId", null);
+ public function deleteContactFilterRestriction(
+ $mailingId,
+ $contactFilterId
+ ) {
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+ $encodedContactFilterId = rawurlencode(mb_convert_encoding((string) $contactFilterId, 'UTF-8'));
+
+ return $this->delete(
+ "mailings/$encodedMailingId/restrictions/$encodedContactFilterId",
+ null
+ );
}
/**
* Retrieve the number of contact filter restrictions set for the mailing with the given ID.
*
- * @param integer $mailingId the ID of the mailing
+ * @param int $mailingId the ID of the mailing
*
- * @return MaileonAPIResult
- * the result object of the API call available at MaileonAPIResult::getResult()
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getContactFilterRestrictionsCount($mailingId)
{
- return $this->get('mailings/' . $mailingId . '/restrictions/count', null);
- }
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+ return $this->get(
+ "mailings/$encodedMailingId/restrictions/count",
+ null
+ );
+ }
/**
* Updates the target group id of the mailing referenced by the given ID.
*
- * @param integer $mailingId the ID of the mailing
- * @param string $targetGroupId
- * the ID of the target group to set
+ * @param int $mailingId the ID of the mailing
+ * @param string $targetGroupId the ID of the target group to set
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function setTargetGroupId($mailingId, $targetGroupId)
- {
+ public function setTargetGroupId(
+ $mailingId,
+ $targetGroupId
+ ) {
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
return $this->post(
- 'mailings/' . $mailingId . '/targetgroupid',
- "" . $targetGroupId . ""
+ "mailings/$encodedMailingId/targetgroupid",
+ "$targetGroupId"
);
}
/**
* Fetches the target group id of the mailing identified by the given ID.
*
- * @param integer $mailingId the ID of the mailing
+ * @param int $mailingId the ID of the mailing
*
- * @return MaileonAPIResult
- * the result object of the API call, with the target group id of the mailing
- * available at MaileonAPIResult::getResult()
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @return MaileonAPIResult|null The result object of the API call, with the target group id of the mailing available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getTargetGroupId($mailingId)
{
- return $this->get('mailings/' . $mailingId . '/targetgroupid', null);
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->get(
+ "mailings/$encodedMailingId/targetgroupid",
+ null
+ );
}
/**
* Updates the sender email address of the mailing referenced by the given ID.
* Note: if not only the local part but also the domain is provided, make sure that is exists in Maileon.
*
- * @param integer $mailingId the ID of the mailing
- * @param string $email
- * the ID of the target group to set
+ * @param int $mailingId the ID of the mailing
+ * @param string $email the ID of the target group to set
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function setSender($mailingId, $email)
- {
- return $this->post('mailings/' . $mailingId . '/contents/sender', "");
+ public function setSender(
+ $mailingId,
+ $email
+ ) {
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->post(
+ "mailings/$encodedMailingId/contents/sender",
+ ""
+ );
}
/**
* Fetches the sender email address of the mailing identified by the given ID.
*
- * @param integer $mailingId the ID of the mailing
+ * @param int $mailingId the ID of the mailing
*
- * @return MaileonAPIResult
- * the result object of the API call, with the sender email address of the mailing
- * available at MaileonAPIResult::getResult()
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @return MaileonAPIResult|null The result object of the API call, with the sender email address of the mailing available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getSender($mailingId)
{
- return $this->get('mailings/' . $mailingId . '/contents/sender');
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->get("mailings/$encodedMailingId/contents/sender");
}
/**
* Fetches the state of the mailing identified by the given ID.
*
- * @param integer $mailingId the ID of the mailing
+ * @param int $mailingId the ID of the mailing
+ *
+ * @return MaileonAPIResult|null The result object of the API call, with the state of the mailing available at MaileonAPIResult::getResult()
*
- * @return MaileonAPIResult
- * the result object of the API call, with the state of the mailing
- * available at MaileonAPIResult::getResult()
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getState($mailingId)
{
- return $this->get('mailings/' . $mailingId . '/state');
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->get("mailings/$encodedMailingId/state");
}
/**
* Updates the subject of the mailing referenced by the given ID.
*
- * @param integer $mailingId the ID of the mailing
- * @param string $subject
- * the subject of the mailing to set
+ * @param int $mailingId the ID of the mailing
+ * @param string $subject the subject of the mailing to set
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function setSubject($mailingId, $subject)
- {
- return $this->post('mailings/' . $mailingId . '/contents/subject', "");
+ public function setSubject(
+ $mailingId,
+ $subject
+ ) {
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->post(
+ "mailings/$encodedMailingId/contents/subject",
+ ""
+ );
}
/**
* Fetches the subject of the mailing identified by the given ID.
*
- * @param integer $mailingId the ID of the mailing
+ * @param int $mailingId the ID of the mailing
+ *
+ * @return MaileonAPIResult|null The result object of the API call, with the subject of the mailing available at MaileonAPIResult::getResult()
*
- * @return MaileonAPIResult
- * the result object of the API call, with the subject of the mailing
- * available at MaileonAPIResult::getResult()
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getSubject($mailingId)
{
- return $this->get('mailings/' . $mailingId . '/contents/subject');
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->get("mailings/$encodedMailingId/contents/subject");
}
/**
* Updates the preview text of the mailing referenced by the given ID.
*
- * @param integer $mailingId the ID of the mailing
- * @param string $previewText
- * the preview text of the mailing to set, limit: 255 characters
+ * @param int $mailingId the ID of the mailing
+ * @param string $previewText the preview text of the mailing to set, limit: 255 characters
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function setPreviewText($mailingId, $previewText)
- {
+ public function setPreviewText(
+ $mailingId,
+ $previewText
+ ) {
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
return $this->post(
- 'mailings/' . $mailingId . '/contents/previewtext',
- ""
+ "mailings/$encodedMailingId/contents/previewtext",
+ ""
);
}
/**
* Fetches the preview text of the mailing identified by the given ID.
*
- * @param integer $mailingId the ID of the mailing
+ * @param int $mailingId the ID of the mailing
+ *
+ * @return MaileonAPIResult|null The result object of the API call, with the preview text of the mailing available at MaileonAPIResult::getResult()
*
- * @return MaileonAPIResult
- * the result object of the API call, with the preview text of the mailing
- * available at MaileonAPIResult::getResult()
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getPreviewText($mailingId)
{
- return $this->get('mailings/' . $mailingId . '/contents/previewtext');
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->get("mailings/$encodedMailingId/contents/previewtext");
}
/**
@@ -500,18 +639,23 @@ public function getPreviewText($mailingId)
* correct path is to set the template
* manually and use getTemplate() to retrieve the name.
*
- * @param integer $mailingId the ID of the mailing
- * @param string $template
- * the template id of the mailing to set
+ * @param int $mailingId the ID of the mailing
+ * @param string $template the template id of the mailing to set
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function setTemplate($mailingId, $template)
- {
- return $this->put('mailings/' . $mailingId . '/template', "");
+ public function setTemplate(
+ $mailingId,
+ $template
+ ) {
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->put(
+ "mailings/$encodedMailingId/template",
+ ""
+ );
}
/**
@@ -520,20 +664,17 @@ public function setTemplate($mailingId, $template)
* in the form "my template" of with sub folders "someSubFolder/my template".
* For shared templates, an absolute path is returned.
*
+ * @param int $mailingId the ID of the mailing the ID of the mailing
*
+ * @return MaileonAPIResult|null The result object of the API call, with the the corresponding template id of the mailing available at MaileonAPIResult::getResult()
*
- * @param integer $mailingId the ID of the mailing
- * the ID of the mailing
- *
- * @return MaileonAPIResult
- * the result object of the API call, with the the corresponding template id of the mailing
- * available at MaileonAPIResult::getResult()
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getTemplate($mailingId)
{
- return $this->get('mailings/' . $mailingId . '/template');
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->get("mailings/$encodedMailingId/template");
}
/**
@@ -541,34 +682,36 @@ public function getTemplate($mailingId)
*
* @param string $mailingId the ID of the mailing
*
- * @return MaileonAPIResult
- * the result object of the API call
- * available at MaileonAPIResult::getResult()
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function resetContentsToTemplate($mailingId)
{
- return $this->put('mailings/' . $mailingId . '/contents/reset');
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->put("mailings/$encodedMailingId/contents/reset");
}
/**
* Updates the senderalias of the mailing referenced by the given ID.
*
- * @param string $mailingId the ID of the mailing
- * @param string $senderalias
- * the sender alias to set
+ * @param string $mailingId the ID of the mailing
+ * @param string $senderalias the sender alias to set
*
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function setSenderAlias($mailingId, $senderalias)
- {
+ public function setSenderAlias(
+ $mailingId,
+ $senderalias
+ ) {
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
return $this->post(
- 'mailings/' . $mailingId . '/contents/senderalias',
- ""
+ "mailings/$encodedMailingId/contents/senderalias",
+ ""
);
}
@@ -577,34 +720,36 @@ public function setSenderAlias($mailingId, $senderalias)
*
* @param string $mailingId the ID of the mailing
*
- * @return MaileonAPIResult
- * the result object of the API call, with the sender alias of the mailing
- * available at MaileonAPIResult::getResult()
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @return MaileonAPIResult|null The result object of the API call, with the sender alias of the mailing available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getSenderAlias($mailingId)
{
- return $this->get('mailings/' . $mailingId . '/contents/senderalias');
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->get("mailings/$encodedMailingId/contents/senderalias");
}
/**
* Updates the recipientalias of the mailing referenced by the given ID.
*
- * @param string $mailingId the ID of the mailing
- * @param string $recipientalias
- * the recipient alias to set
+ * @param string $mailingId the ID of the mailing
+ * @param string $recipientalias the recipient alias to set
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function setRecipientAlias($mailingId, $recipientalias)
- {
+ public function setRecipientAlias(
+ $mailingId,
+ $recipientalias
+ ) {
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
return $this->post(
- 'mailings/' . $mailingId . '/contents/recipientalias',
- ""
+ "mailings/$encodedMailingId/contents/recipientalias",
+ ""
);
}
@@ -613,69 +758,68 @@ public function setRecipientAlias($mailingId, $recipientalias)
*
* @param string $mailingId the ID of the mailing
*
- * @return MaileonAPIResult
- * the result object of the API call, with the reply-to address of the mailing
- * available at MaileonAPIResult::getResult()
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @return MaileonAPIResult|null The result object of the API call, with the reply-to address of the mailing available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getReplyToAddress($mailingId)
{
- return $this->get('mailings/' . $mailingId . '/settings/replyto');
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->get("mailings/$encodedMailingId/settings/replyto");
}
/**
* Sets the reply-to address of the mailing identified by the given ID.
*
* @param string $mailingId the ID of the mailing
- * @param bool $auto (default = true)
- * If true, the Maileon autorecognition will be used and emails will be saved within Maileon.
- * If false, a custom email address can be passed which gets all mails forwarded.
- * @param string $customEmail (default = empty)
- * If $auto is false, this email will be used for manual responses.
+ * @param bool $auto (default = true) If true, the Maileon autorecognition will be used and emails will be saved within
+ * Maileon. If false, a custom email address can be passed which gets all mails forwarded.
+ * @param string $customEmail (default = empty) If $auto is false, this email will be used for manual responses.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @return
- * @throws MaileonAPIException
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function setReplyToAddress($mailingId, $auto = true, $customEmail = null)
- {
+ public function setReplyToAddress(
+ $mailingId,
+ $auto = true,
+ $customEmail = null
+ ) {
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
$queryParameters = [
- 'auto' => ($auto == true) ? "true" : "false",
+ 'auto' => $auto === true ? 'true' : 'false',
'customEmail' => $customEmail,
];
- return $this->post('mailings/' . $mailingId . '/settings/replyto', null, $queryParameters);
+ return $this->post(
+ "mailings/$encodedMailingId/settings/replyto",
+ null,
+ $queryParameters
+ );
}
/**
*
- * Method to retrieve mailingy by scheduling time
+ * Method to retrieve mailings by scheduling time
+ *
+ * @param string $scheduleTime This is a date and time string that defines the filter for a mailing. The mailings before and
+ * after that time can be queried, see beforeSchedulingTime. The format is the standard SQL date:
+ * yyyy-MM-dd HH:mm:ss
+ * @param bool $beforeSchedulingTime (default = true) If true, the mailings before the given time will be returned, if false, the
+ * mailings at or after the given time will be returned.
+ * @param array $fields
+ * @param int $page_index
+ * @param int $page_size
+ * @param string $orderBy
+ * @param string $order
+ * @param bool $trash (default = null) {null, true, false} In case of null get all mailings. Value true will retrieve
+ * only mailings in the trash bin, and value false otherwise.
*
- * @param string $scheduleTime
- * This is a date and time string that defines the filter for a mailing.
- * The mailings before and after that time can be queried, see beforeSchedulingTime.
- * The format is the standard SQL date: yyyy-MM-dd HH:mm:ss
- * @param bool $beforeSchedulingTime (default = true)
- * If true, the mailings before the given time will be returned, if false,
- * the mailings at or after the given time will be returned.
- * @param string[] fields (default = empty)
- * This list contains the fields that shall be returned with the result.
- * If this list is empty, only the IDs will be returned. Valid fields are: state, type, name, and scheduleTime
- * @param number page_index (default = 1)
- * The index of the result page. The index must be greater or equal to 1.
- * @param number page_size (default = 100)
- * The maximum count of items in the result page. If provided, the value of page_size must
- * be in the range 1 to 1000.
- * @param string orderBy (default = id)
- * The field to order results by
- * @param string order (default = DESC)
- * The order
- * @param bool trash (default = null)
- * {null, true, false} In case of null get all mailings.
- * Value true will retrieve only mailings in the trash bin, and value false otherwise.
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @return
- * @throws MaileonAPIException
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getMailingsBySchedulingTime(
$scheduleTime,
@@ -683,15 +827,15 @@ public function getMailingsBySchedulingTime(
$fields = [],
$page_index = 1,
$page_size = 100,
- $orderBy = "id",
- $order = "DESC",
+ $orderBy = 'id',
+ $order = 'DESC',
$trash = null
) {
$queryParameters = [
'page_index' => $page_index,
'page_size' => $page_size,
'scheduleTime' => urlencode($scheduleTime),
- 'beforeSchedulingTime' => ($beforeSchedulingTime == true) ? "true" : "false",
+ 'beforeSchedulingTime' => $beforeSchedulingTime === true ? 'true' : 'false',
'orderBy' => $orderBy,
'order' => $order,
];
@@ -700,188 +844,196 @@ public function getMailingsBySchedulingTime(
$queryParameters['trash'] = $trash == true ? "true" : "false";
}
- $queryParameters = $this->appendArrayFields($queryParameters, "fields", $fields);
+ $queryParameters = $this->appendArrayFields($queryParameters, 'fields', $fields);
- return $this->get('mailings/filter/scheduletime', $queryParameters);
+ return $this->get(
+ 'mailings/filter/scheduletime',
+ $queryParameters
+ );
}
-
/**
*
- * Method to retrieve mailingy by keywords
+ * Method to retrieve mailings by keywords
+ *
+ * @param string[] $keywords This is the list of keywords to filter for
+ * @param string $keywordsOp
+ * @param array $fields
+ * @param int $page_index
+ * @param int $page_size
+ * @param bool $trash (default = null) {null, true, false} In case of null get all mailings. Value true will retrieve only
+ * mailings in the trash bin, and value false otherwise.
*
- * @param string[] $keywords
- * This is the list of keywords to filter for
- * @param string[] fields (default = empty)
- * This list contains the fields that shall be returned with the result.
- * If this list is empty, only the IDs will be returned. Valid fields are: state, type, name, and scheduleTime
- * @param number page_index (default = 1)
- * The index of the result page. The index must be greater or equal to 1.
- * @param number page_size (default = 100)
- * The maximum count of items in the result page. If provided, the value of page_size must
- * be in the range 1 to 1000.
- * @param bool trash (default = null)
- * {null, true, false} In case of null get all mailings.
- * Value true will retrieve only mailings in the trash bin, and value false otherwise.
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @return
- * @throws MaileonAPIException
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function getMailingsByKeywords($keywords, $keywordsOp = "and", $fields = [], $page_index = 1, $page_size = 100, $trash = null)
- {
+ public function getMailingsByKeywords(
+ $keywords,
+ $keywordsOp = 'and',
+ $fields = [],
+ $page_index = 1,
+ $page_size = 100,
+ $trash = null
+ ) {
$queryParameters = [
'page_index' => $page_index,
'page_size' => $page_size,
- 'order' => "DESC",
+ 'order' => 'DESC',
];
if (isset($trash)) {
$queryParameters['trash'] = $trash == true ? "true" : "false";
}
- $queryParameters = $this->appendArrayFields($queryParameters, "keywords", $keywords);
- $queryParameters = $this->appendArrayFields($queryParameters, "keywordsOp", $keywordsOp);
- $queryParameters = $this->appendArrayFields($queryParameters, "fields", $fields);
+ $queryParameters = $this->appendArrayFields($queryParameters, 'keywords', $keywords);
+ $queryParameters = $this->appendArrayFields($queryParameters, 'keywordsOp', $keywordsOp);
+ $queryParameters = $this->appendArrayFields($queryParameters, 'fields', $fields);
- return $this->get('mailings/filter/keywords', $queryParameters);
+ return $this->get(
+ 'mailings/filter/keywords',
+ $queryParameters
+ );
}
/**
*
- * Method to retrieve mailingy by types
+ * Method to retrieve mailings by types
*
- * Types can be selected from 'doi','trigger', 'trigger_template' or 'regular'
- *
+ * Types can be selected from 'doi','trigger', 'trigger_template' or 'regular'
*
- * @param string[] $types
- * This is the list of types to filter for
- * @param string[] fields (default = empty)
- * This list contains the fields that shall be returned with the result.
- * If this list is empty, only the IDs will be returned. Valid fields are: state, type, name, and scheduleTime
- * @param number page_index (default = 1)
- * The index of the result page. The index must be greater or equal to 1.
- * @param number page_size (default = 100)
- * The maximum count of items in the result page. If provided, the value of page_size must
- * be in the range 1 to 1000.
- * @param bool trash (default = null)
- * {null, true, false} In case of null get all mailings.
- * Value true will retrieve only mailings in the trash bin, and value false otherwise.
+ * @param string[] $types This is the list of types to filter for
+ * @param array $fields
+ * @param int $page_index
+ * @param int $page_size
+ * @param bool $trash (default = null) {null, true, false} In case of null get all mailings. Value true will retrieve only mailings
+ * in the trash bin, and value false otherwise.
*
- * @return
- * @throws MaileonAPIException
- * @see MailingFields
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
+ * @see MailingFields
*/
- public function getMailingsByTypes($types, $fields = [], $page_index = 1, $page_size = 100, $trash = null)
- {
+ public function getMailingsByTypes(
+ $types,
+ $fields = [],
+ $page_index = 1,
+ $page_size = 100,
+ $trash = null
+ ) {
$queryParameters = [
'page_index' => $page_index,
'page_size' => $page_size,
- 'order' => "DESC",
+ 'order' => 'DESC',
];
if (isset($trash)) {
$queryParameters['trash'] = $trash == true ? "true" : "false";
}
- $queryParameters = $this->appendArrayFields($queryParameters, "types", $types);
- $queryParameters = $this->appendArrayFields($queryParameters, "fields", $fields);
+ $queryParameters = $this->appendArrayFields($queryParameters, 'types', $types);
+ $queryParameters = $this->appendArrayFields($queryParameters, 'fields', $fields);
- return $this->get('mailings/filter/types', $queryParameters);
+ return $this->get(
+ 'mailings/filter/types',
+ $queryParameters
+ );
}
/**
* Method to retrieve mailings by states
*
- * States can be selected from 'draft', 'failed', 'queued', 'checks', 'blacklist', 'preparing', 'sending',
- * 'canceled', 'paused', 'done', 'archiving', 'archived', 'released', and 'scheduled' (=waiting to be sent)
- *
- *
- * @param string[] states
- * This is the list of states to filter for
- * @param string[] fields (default = empty)
- * This list contains the fields that shall be returned with the result.
- * If this list is empty, only the IDs will be returned. Valid fields are: state, type, name, and scheduleTime
- * @param number page_index (default = 1)
- * The index of the result page. The index must be greater or equal to 1.
- * @param number page_size (default = 100)
- * The maximum count of items in the result page. If provided, the value of page_size must
- * be in the range 1 to 1000.
- * @param bool trash (default = null)
- * {null, true, false} In case of null get all mailings.
- * Value true will retrieve only mailings in the trash bin, and value false otherwise.
- *
- * @return
- * @throws MaileonAPIException
- * @see MailingFields
+ * @param array $states States can be selected from 'draft', 'failed', 'queued', 'checks', 'blacklist', 'preparing', 'sending',
+ * 'canceled', 'paused', 'done', 'archiving', 'archived', 'released', and 'scheduled' (=waiting to be sent)
+ * @param array $fields
+ * @param int $page_index (default = 1) The index of the result page. The index must be greater or equal to 1.
+ * @param int $page_size
+ * @param bool $trash (default = null) {null, true, false} In case of null get all mailings. Value true will retrieve only
+ * mailings in the trash bin, and value false otherwise.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
+ * @see MailingFields
*/
- public function getMailingsByStates($states, $fields = [], $page_index = 1, $page_size = 100, $trash = null)
- {
+ public function getMailingsByStates(
+ $states,
+ $fields = [],
+ $page_index = 1,
+ $page_size = 100,
+ $trash = null
+ ) {
$queryParameters = [
'page_index' => $page_index,
'page_size' => $page_size,
- 'order' => "DESC",
+ 'order' => 'DESC',
];
if (isset($trash)) {
$queryParameters['trash'] = $trash == true ? "true" : "false";
}
- $queryParameters = $this->appendArrayFields($queryParameters, "states", $states);
- $queryParameters = $this->appendArrayFields($queryParameters, "fields", $fields);
+ $queryParameters = $this->appendArrayFields($queryParameters, 'states', $states);
+ $queryParameters = $this->appendArrayFields($queryParameters, 'fields', $fields);
- return $this->get('mailings/filter/states', $queryParameters);
+ return $this->get(
+ 'mailings/filter/states',
+ $queryParameters
+ );
}
/**
* Schedules the mailing to be instantly sent
*
- * @param number mailingId
- * The ID of the mailing to send now
+ * @param int $mailingId The ID of the mailing to send now
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @return
- * @throws MaileonAPIException
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function sendMailingNow($mailingId)
{
- return $this->post('mailings/' . $mailingId . '/sendnow');
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->post("mailings/$encodedMailingId/sendnow");
}
/**
* Schedules the mailing for a given time. If dispatchOption is set, the enhanced scheduling options are enabled.
*
- * @param number mailingId
- * The ID of the mailing to schedule
- * @param date date
- * The SQL conform date of the schedule day in the format YYYY-MM-DD
- * @param hours hours
- * The schedule hour in the format of HH, 24 hours format
- * @param minute minute
- * The schedule minutes in the format MM
- * @param string dispatchOption
- * The time distribution strategy to choose from {'hour', 'weekdayhour', 'uniform'}.
- * @param dispatchEndInHours Number of hours begining from the dispatch start util which the dispatch distribution over the time has to be finished. Used in case of 'hour'
- * dispatch option and 'uniform' option. Allowed values for the 'uniform' distribution are in [2..96], whereas for 'hour' strategy thery are ranging from [2..24].
- * @param dispatchEndInDays Number of days begining from the dispatch start util which the dispatch distribution over the time has to be finished. Used only with dispatch
- * option 'weekdayhour' and its acceptable range is [1..7].
- * @param dispatchEndExactDatetime The exact end date util which the dispatch time distribution has to be finished. It is used when none of the arguments above
- * dispatchEndInHours, dispatchEndInDays aren't set i.e. equals 0. Note that one of dispatchEndInHours, dispatchEndInDays,
- * dispatchEndExactDatetime argument should be used in the request according to the selected dispatch option. Format: yyyy-MM-dd HH:mm
- * @param boolean clicksAsResponseReference
- * The parameter determines the inclusion/exclusion of clicks as a response criteria when selecting {'hour', 'weekdayhour'} options.
- * @param int dispatchWavesGroup
- * The number determines how many consecutive sending waves will be grouped when using {'hour', 'weekdayhour'} distribution. Supported values are {1, 2, 3 (default)}.
- * @param string dispatchUniformInterval
- * The arguments controls the interval {'hour', '30m', '20m', '15m', '10m'} for the 'uniform' strategy indicating the frequency of mailing
- * distribution over time. It should equals null for {'hour', 'weekdayhour'} dispatch options.
- * @param string allowedHours
- * The value represents the allowed hours. Comma separated values for the allowed hours and can be combined with a range of hours. The required format looks
- * like 0,3,5,17-21 as an example. The acceptable values rane is 0..23. Note that the if this argument is not provided, all 24H of the day will be considered as acceptable
- * dispatch hours.
- *
- * @return MaileonAPIResult
- * @throws MaileonAPIException
+ * @param int $mailingId The ID of the mailing to schedule
+ * @param string $date The SQL conform date of the schedule day in the format YYYY-MM-DD
+ * @param string $hours The schedule hour in the format of HH, 24 hours format
+ * @param string $minutes The schedule minutes in the format MM
+ * @param string $dispatchOption The time distribution strategy to choose from {'hour', 'weekdayhour', 'uniform'}.
+ * @param $dispatchEndInHours Number of hours beginning from the dispatch start util which the dispatch distribution over
+ * the time has to be finished. Used in case of 'hour' dispatch option and 'uniform' option.
+ * Allowed values for the 'uniform' distribution are in [2..96], whereas for 'hour' strategy
+ * they are ranging from [2..24].
+ * @param $dispatchEndInDays Number of days beginning from the dispatch start util which the dispatch distribution over
+ * the time has to be finished. Used only with dispatch option 'weekdayhour' and its
+ * acceptable range is [1..7].
+ * @param $dispatchEndExactDatetime The exact end date util which the dispatch time distribution has to be finished. It is used
+ * when none of the arguments above dispatchEndInHours,
+ * dispatchEndInDays aren't set i.e. equals 0. Note that one of
+ * dispatchEndInHours, dispatchEndInDays,
+ * dispatchEndExactDatetime argument should be used in the request according to
+ * the selected dispatch option. Format: yyyy-MM-dd HH:mm
+ * @param boolean $clicksAsResponseReference The parameter determines the inclusion/exclusion of clicks as a response criteria when
+ * selecting {'hour', 'weekdayhour'} options.
+ * @param int $dispatchWavesGroup The number determines how many consecutive sending waves will be grouped when using
+ * {'hour', 'weekdayhour'} distribution. Supported values are {1, 2, 3 (default)}.
+ * @param string $dispatchUniformInterval The argument controls the interval {'hour', '30m', '20m', '15m', '10m'} for the 'uniform'
+ * strategy indicating the frequency of mailing distribution over time. It should equal null
+ * for {'hour', 'weekdayhour'} dispatch options.
+ * @param string $allowedHours The value represents the allowed hours. Comma separated values for the allowed hours and
+ * can be combined with a range of hours. The required format looks like 0,3,5,17-21 as an
+ * example. The acceptable values range is 0..23. Note that if this argument is not provided,
+ * all 24H of the day will be considered as acceptable dispatch hours.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function setMailingSchedule(
$mailingId,
@@ -897,6 +1049,8 @@ public function setMailingSchedule(
$dispatchUniformInterval = null,
$allowedHours = null
) {
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
$queryParameters = [
'date' => $date,
'hours' => $hours,
@@ -906,90 +1060,110 @@ public function setMailingSchedule(
if (! empty($dispatchOption)) {
$queryParameters ['dispatchOption'] = urlencode($dispatchOption);
}
+
if (! empty($dispatchEndInHours)) {
$queryParameters ['dispatchEndInHours'] = urlencode($dispatchEndInHours);
}
+
if (! empty($dispatchEndInDays)) {
$queryParameters ['dispatchEndInDays'] = urlencode($dispatchEndInDays);
}
+
if (! empty($dispatchEndExactDatetime)) {
$queryParameters ['dispatchEndExactDatetime'] = urlencode($dispatchEndExactDatetime);
}
+
if (! empty($clicksAsResponseReference)) {
- $queryParameters ['clicksAsResponseReference'] = (boolval($clicksAsResponseReference) === true) ? "true" : "false";
+ $queryParameters ['clicksAsResponseReference'] = ((bool) $clicksAsResponseReference === true) ? 'true' : 'false';
}
+
if (! empty($dispatchWavesGroup)) {
$queryParameters ['dispatchWavesGroup'] = urlencode($dispatchWavesGroup);
}
+
if (! empty($dispatchUniformInterval)) {
$queryParameters ['dispatchUniformInterval'] = urlencode($dispatchUniformInterval);
}
+
if (! empty($allowedHours)) {
$queryParameters ['allowedHours'] = urlencode($allowedHours);
}
- return $this->put('mailings/' . $mailingId . '/schedule', "", $queryParameters);
+ return $this->put(
+ "mailings/$encodedMailingId/schedule",
+ '',
+ $queryParameters
+ );
}
/**
* Delete the schedule for the given mailing
*
- * @param number mailingId
+ * @param int $mailingId
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @return
- * @throws MaileonAPIException
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function deleteMailingSchedule($mailingId)
{
- return $this->delete('mailings/' . $mailingId . '/schedule');
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->delete("mailings/$encodedMailingId/schedule");
}
/**
* Get the schedule for the given mailing
*
- * @param number mailingId
+ * @param int $mailingId
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @return
- * @throws MaileonAPIException
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getMailingSchedule($mailingId)
{
- return $this->get('mailings/' . $mailingId . '/schedule');
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->get("mailings/$encodedMailingId/schedule");
}
/**
* Update the schedule for the given mailing. If dispatchOption is set, the enhanced scheduling options are enabled.
*
- * @param number mailingId
- * @param date date
- * The SQL conform date of the schedule day in the format YYYY-MM-DD
- * @param hours hours
- * The schedule hour in the format of HH, 24 hours format
- * @param minute minute
- * The schedule minutes in the format MM
- * @param string dispatchOption
- * The time distribution strategy to choose from {'hour', 'weekdayhour', 'uniform'}.
- * @param dispatchEndInHours Number of hours begining from the dispatch start util which the dispatch distribution over the time has to be finished. Used in case of 'hour'
- * dispatch option and 'uniform' option. Allowed values for the 'uniform' distribution are in [2..96], whereas for 'hour' strategy thery are ranging from [2..24].
- * @param dispatchEndInDays Number of days begining from the dispatch start util which the dispatch distribution over the time has to be finished. Used only with dispatch
- * option 'weekdayhour' and its acceptable range is [1..7].
- * @param dispatchEndExactDatetime The exact end date util which the dispatch time distribution has to be finished. It is used when none of the arguments above
- * dispatchEndInHours, dispatchEndInDays aren't set i.e. equals 0. Note that one of dispatchEndInHours, dispatchEndInDays,
- * dispatchEndExactDatetime argument should be used in the request according to the selected dispatch option. Format: yyyy-MM-dd HH:mm
- * @param boolean clicksAsResponseReference
- * The parameter determines the inclusion/exclusion of clicks as a response criteria when selecting {'hour', 'weekdayhour'} options.
- * @param int dispatchWavesGroup
- * The number determines how many consecutive sending waves will be grouped when using {'hour', 'weekdayhour'} distribution. Supported values are {1, 2, 3 (default)}.
- * @param string dispatchUniformInterval
- * The arguments controls the interval {'hour', '30m', '20m', '15m', '10m'} for the 'uniform' strategy indicating the frequency of mailing
- * distribution over time. It should equals null for {'hour', 'weekdayhour'} dispatch options.
- * @param string allowedHours
- * The value represents the allowed hours. Comma separated values for the allowed hours and can be combined with a range of hours. The required format looks
- * like 0,3,5,17-21 as an example. The acceptable values rane is 0..23. Note that the if this argument is not provided, all 24H of the day will be considered as acceptable
- * dispatch hours.
- *
- * @return MaileonAPIResult
- * @throws MaileonAPIException
+ * @param int $mailingId
+ * @param date $date The SQL conform date of the schedule day in the format YYYY-MM-DD
+ * @param hours $hours The schedule hour in the format of HH, 24 hours format
+ * @param minute $minutes The schedule minutes in the format MM
+ * @param string $dispatchOption The time distribution strategy to choose from {'hour', 'weekdayhour', 'uniform'}.
+ * @param $dispatchEndInHours Number of hours beginning from the dispatch start util which the dispatch distribution over
+ * the time has to be finished. Used in case of 'hour' dispatch option and 'uniform' option.
+ * Allowed values for the 'uniform' distribution are in [2..96], whereas for 'hour' strategy
+ * they are ranging from [2..24].
+ * @param $dispatchEndInDays Number of days beginning from the dispatch start util which the dispatch distribution over
+ * the time has to be finished. Used only with dispatch option 'weekdayhour' and its
+ * acceptable range is [1..7].
+ * @param $dispatchEndExactDatetime The exact end date util which the dispatch time distribution has to be finished. It is used
+ * when none of the arguments above dispatchEndInHours,
+ * dispatchEndInDays aren't set i.e. equals 0. Note that one of
+ * dispatchEndInHours, dispatchEndInDays,
+ * dispatchEndExactDatetime argument should be used in the request according to
+ * the selected dispatch option. Format: yyyy-MM-dd HH:mm
+ * @param boolean $clicksAsResponseReference The parameter determines the inclusion/exclusion of clicks as a response criteria when
+ * selecting {'hour', 'weekdayhour'} options.
+ * @param int $dispatchWavesGroup The number determines how many consecutive sending waves will be grouped when using
+ * {'hour', 'weekdayhour'} distribution. Supported values are {1, 2, 3 (default)}.
+ * @param string $dispatchUniformInterval The argument controls the interval {'hour', '30m', '20m', '15m', '10m'} for the 'uniform'
+ * strategy indicating the frequency of mailing distribution over time. It should equal null
+ * for {'hour', 'weekdayhour'} dispatch options.
+ * @param string $allowedHours The value represents the allowed hours. Comma separated values for the allowed hours and
+ * can be combined with a range of hours. The required format looks like 0,3,5,17-21 as an
+ * example. The acceptable values range is 0..23. Note that if this argument is not provided,
+ * all 24H of the day will be considered as acceptable dispatch hours.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function updateMailingSchedule(
$mailingId,
@@ -1005,6 +1179,8 @@ public function updateMailingSchedule(
$dispatchUniformInterval = null,
$allowedHours = null
) {
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
$queryParameters = [
'date' => $date,
'hours' => $hours,
@@ -1014,218 +1190,276 @@ public function updateMailingSchedule(
if (! empty($dispatchOption)) {
$queryParameters ['dispatchOption'] = urlencode($dispatchOption);
}
+
if (! empty($dispatchEndInHours)) {
$queryParameters ['dispatchEndInHours'] = urlencode($dispatchEndInHours);
}
+
if (! empty($dispatchEndInDays)) {
$queryParameters ['dispatchEndInDays'] = urlencode($dispatchEndInDays);
}
+
if (! empty($dispatchEndExactDatetime)) {
$queryParameters ['dispatchEndExactDatetime'] = urlencode($dispatchEndExactDatetime);
}
+
if (! empty($clicksAsResponseReference)) {
- $queryParameters ['clicksAsResponseReference'] = (boolval($clicksAsResponseReference) === true) ? "true" : "false";
+ $queryParameters ['clicksAsResponseReference'] = ((bool) $clicksAsResponseReference === true) ? 'true' : 'false';
}
+
if (! empty($dispatchWavesGroup)) {
$queryParameters ['dispatchWavesGroup'] = urlencode($dispatchWavesGroup);
}
+
if (! empty($dispatchUniformInterval)) {
$queryParameters ['dispatchUniformInterval'] = urlencode($dispatchUniformInterval);
}
+
if (! empty($allowedHours)) {
$queryParameters ['allowedHours'] = urlencode($allowedHours);
}
- return $this->post('mailings/' . $mailingId . '/schedule', "", $queryParameters);
+ return $this->post(
+ "mailings/$encodedMailingId/schedule",
+ '',
+ $queryParameters
+ );
}
-
/**
* Fetches the DOI mailing key of the mailing identified by the given ID.
*
- * @param integer $mailingId The ID of the mailing
+ * @param int $mailingId The ID of the mailing
+ *
+ * @return MaileonAPIResult|null The result object of the API call, with the target group id of the mailing available at MaileonAPIResult::getResult()
*
- * @return MaileonAPIResult
- * the result object of the API call, with the target group id of the mailing
- * available at MaileonAPIResult::getResult()
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getDoiMailingKey($mailingId)
{
- return $this->get('mailings/' . $mailingId . '/settings/doi_key', null, "text/html");
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->get(
+ "mailings/$encodedMailingId/settings/doi_key",
+ null,
+ 'text/html'
+ );
}
/**
* Sets the key of the DOI mailing identified by the given ID.
*
- * @param integer $mailingId The ID of the mailing
- * @param string $doiKey
- * The new DOI key.
+ * @param int $mailingId The ID of the mailing
+ * @param string $doiKey The new DOI key.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @return
- * @throws MaileonAPIException
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function setDoiMailingKey($mailingId, $doiKey)
- {
- return $this->post('mailings/' . $mailingId . '/settings/doi_key', "$doiKey");
+ public function setDoiMailingKey(
+ $mailingId,
+ $doiKey
+ ) {
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->post(
+ "mailings/$encodedMailingId/settings/doi_key",
+ "$doiKey"
+ );
}
/**
* Deactivates a trigger mailing by ID.
*
- * @param integer $mailingId The ID of the mailing
+ * @param int $mailingId The ID of the mailing
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @return MaileonAPIResult
- * the result of the operation
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function deactivateTriggerMailing($mailingId)
{
- return $this->delete("mailings/{$mailingId}/dispatching");
- }
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+ return $this->delete("mailings/$encodedMailingId/dispatching");
+ }
/**
* Get the dispatch data for a trigger mailing by mailing ID.
*
- * @param integer $mailingId The ID of the mailing
+ * @param int $mailingId The ID of the mailing
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @return MaileonAPIResult
- * the result of the operation
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getTriggerDispatchLogic($mailingId)
{
- return $this->get("mailings/{$mailingId}/dispatching");
- }
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+ return $this->get("mailings/$encodedMailingId/dispatching");
+ }
/**
* Get the schedule for regular mailings by mailing ID.
*
- * @param integer $mailingId The ID of the mailing
+ * @param int $mailingId The ID of the mailing
*
- * @return MaileonAPIResult
- * the result of the operation
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getSchedule($mailingId)
{
- return $this->get("mailings/{$mailingId}/schedule");
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->get("mailings/$encodedMailingId/schedule");
}
/**
* Get the archive url for the mailing ID.
*
- * @param integer $mailingId The ID of the mailing
+ * @param int $mailingId The ID of the mailing
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @return MaileonAPIResult
- * the result of the operation
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getArchiveUrl($mailingId)
{
- return $this->get("mailings/{$mailingId}/archiveurl");
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->get("mailings/$encodedMailingId/archiveurl");
}
/**
* Get the report url for the mailing ID.
*
- * @param integer $mailingId The ID of the mailing
+ * @param int $mailingId The ID of the mailing
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @return MaileonAPIResult
- * the result of the operation
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getReportUrl($mailingId)
{
- return $this->get("mailings/{$mailingId}/reporturl");
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->get("mailings/$encodedMailingId/reporturl");
}
/**
* Updates the name of the mailing referenced by the given ID.
*
* @param string $mailingId the ID of the mailing
- * @param string $name
- * the name of the mailing to set
+ * @param string $name the name of the mailing to set
*
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function setName($mailingId, $name)
- {
- return $this->post('mailings/' . $mailingId . '/name', "");
+ public function setName(
+ $mailingId,
+ $name
+ ) {
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->post(
+ "mailings/$encodedMailingId/name",
+ ""
+ );
}
/**
* Get the name for the mailing by mailing ID.
*
- * @param integer $mailingId The ID of the mailing
+ * @param int $mailingId The ID of the mailing
*
- * @return MaileonAPIResult
- * the result of the operation
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getName($mailingId)
{
- return $this->get("mailings/{$mailingId}/name");
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->get("mailings/$encodedMailingId/name");
}
/**
* Updates the tags of the mailing referenced by the given ID.
*
* @param string $mailingId the ID of the mailing
- * @param array $tags
- * the tags
+ * @param array $tags the tags
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function setTags($mailingId, $tags)
- {
- return $this->post('mailings/' . $mailingId . '/settings/tags', "");
+ public function setTags(
+ $mailingId,
+ $tags
+ ) {
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->post(
+ "mailings/$encodedMailingId/settings/tags",
+ ''
+ );
}
/**
* Get the tags for the mailing identified by mailing ID.
*
- * @param integer $mailingId The ID of the mailing
+ * @param int $mailingId The ID of the mailing
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @return MaileonAPIResult
- * the result of the operation
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getTags($mailingId)
{
- return $this->get("mailings/{$mailingId}/settings/tags");
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->get("mailings/$encodedMailingId/settings/tags");
}
/**
* Updates the locale of the mailing referenced by the given ID.
*
* @param string $mailingId the ID of the mailing
- * @param string locale
- * the locale in the form xx: e.g. de, en, fr, �
+ * @param string $locale the locale in the form xx: e.g. de, en, fr, �
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function setLocale($mailingId, $locale)
- {
- return $this->post('mailings/' . $mailingId . '/settings/locale', "$locale");
+ public function setLocale(
+ $mailingId,
+ $locale
+ ) {
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->post(
+ "mailings/$encodedMailingId/settings/locale",
+ "$locale"
+ );
}
/**
- * Get the locale for the mailing identified by mailing ID in the form xx: e.g. de, en, fr, �
+ * Get the locale for the mailing identified by mailing ID in the form xx: e.g. de, en, fr
+ *
+ * @param int $mailingId The ID of the mailing
*
- * @param integer $mailingId The ID of the mailing
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @return MaileonAPIResult
- * the result of the operation
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getLocale($mailingId)
{
- return $this->get("mailings/{$mailingId}/settings/locale");
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->get("mailings/$encodedMailingId/settings/locale");
}
/**
@@ -1233,51 +1467,67 @@ public function getLocale($mailingId)
* Tags from the described RSS-Feeds.
* For more information about RSS-SmartMailing, please check our customer support at service@xqueue.com
*
- * @param integer $mailingId The ID of the mailing
+ * @param int $mailingId The ID of the mailing
*
- * @return MaileonAPIResult
- * the result of the operation
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function fillRssSmartContentTags($mailingId)
{
- return $this->post("mailings/{$mailingId}/contents/smartmailing/rss");
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->post("mailings/$encodedMailingId/contents/smartmailing/rss");
}
/**
* Copy the mailing with the given mailing ID.
*
- * @param integer $mailingId The ID of the mailing
+ * @param int $mailingId The ID of the mailing
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @return MaileonAPIResult
- * the result of the operation
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function copyMailing($mailingId)
{
- return $this->post("mailings/{$mailingId}/copy");
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->post("mailings/$encodedMailingId/copy");
}
/**
* Read a binary file from the file system and adds it as an attachment to this transaction.
*
- * @param integer $mailingId The ID of the mailing
- * @param string $filename
- * @param string $contentType
- * @param string $attachmentFileName Name of the file in the attachments
+ * @param int $mailingId The ID of the mailing
+ * @param string $filename
+ * @param string $contentType
+ * @param string $attachmentFileName Name of the file in the attachments
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @return MaileonAPIResult
- * @throws MaileonAPIException
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function addAttachmentFromFile($mailingId, $filename, $contentType, $attachmentFileName = null)
- {
+ public function addAttachmentFromFile(
+ $mailingId,
+ $filename,
+ $contentType,
+ $attachmentFileName = null
+ ) {
$handle = fopen($filename, "rb");
- if (false === $filename) {
- throw new MaileonAPIException("Cannot read file " . $filename . ".");
+
+ if (false === $handle) {
+ throw new MaileonAPIException("Cannot read file $filename.");
}
+
$contents = '';
+
while (! feof($handle)) {
$contents .= fread($handle, 8192);
}
+
fclose($handle);
+
if ($attachmentFileName === null) {
$attachmentFileName = basename($filename);
}
@@ -1288,21 +1538,28 @@ public function addAttachmentFromFile($mailingId, $filename, $contentType, $atta
/**
* Adds an attachment to the mailing with the provided id.
*
- * @param integer $mailingId The mailing id
- * @param string $filename Filename of the attachment to be displayed in sent emails.
- * It is recommended to keep the filename short and to use an extension corresponding
- * to the mime type of the attachment.
- * @param string $contentType The mime type of the attachment
- * @param string $contents The file content
+ * @param int $mailingId The mailing id
+ * @param string $filename Filename of the attachment to be displayed in sent emails. It is recommended to keep the filename short
+ * and to use an extension corresponding to the mime type of the attachment.
+ * @param string $contentType The mime type of the attachment
+ * @param string $contents The file content
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @return MaileonAPIResult
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function addAttachment($mailingId, $filename, $contentType, $contents)
- {
+ public function addAttachment(
+ $mailingId,
+ $filename,
+ $contentType,
+ $contents
+ ) {
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
$queryParameters = ['filename' => urlencode($filename)];
return $this->post(
- "mailings/{$mailingId}/attachments",
+ "mailings/$encodedMailingId/attachments",
$contents,
$queryParameters,
null,
@@ -1315,111 +1572,155 @@ public function addAttachment($mailingId, $filename, $contentType, $contents)
/**
* Returns a list of the registered attachments for the mailing with the provided id.
*
- * @param integer $mailingId The ID of the mailing
+ * @param int $mailingId The ID of the mailing
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @return MaileonAPIResult
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getAttachments($mailingId)
{
- return $this->get("mailings/{$mailingId}/attachments");
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->get("mailings/$encodedMailingId/attachments");
}
/**
* Returns the attachment with the provided id as a file.
*
- * @param integer $mailingId The ID of the mailing
- * @param integer $attachmentId
+ * @param int $mailingId The ID of the mailing
+ * @param int $attachmentId
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @return MaileonAPIResult
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function getAttachment($mailingId, $attachmentId)
- {
- return $this->get("mailings/{$mailingId}/attachments/{$attachmentId}");
+ public function getAttachment(
+ $mailingId,
+ $attachmentId
+ ) {
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+ $encodedAttachmentId = rawurlencode(mb_convert_encoding((string) $attachmentId, 'UTF-8'));
+
+ return $this->get("mailings/$encodedMailingId/attachments/$encodedAttachmentId");
}
/**
* Returns the count of available attachments in the mailing with the provided id.
*
- * @param integer $mailingId The ID of the mailing
+ * @param int $mailingId The ID of the mailing
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @return MaileonAPIResult
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getAttachmentsCount($mailingId)
{
- return $this->get("mailings/{$mailingId}/attachments/count");
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->get("mailings/$encodedMailingId/attachments/count");
}
/**
* Deletes all the attachments that belong to the mailing with the provided id. The mailing should not be sealed.
*
- * @param integer $mailingId The ID of the mailing
+ * @param int $mailingId The ID of the mailing
*
- * @return MaileonAPIResult
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function deleteAttachments($mailingId)
{
- return $this->delete("mailings/{$mailingId}/attachments/");
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->delete("mailings/$encodedMailingId/attachments/");
}
/**
* Deletes the attachment with the provided id from the mailing. The mailing should not be sealed.
*
- * @param integer $mailingId The ID of the mailing
- * @param integer $attachmentId
+ * @param int $mailingId The ID of the mailing
+ * @param int $attachmentId
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @return MaileonAPIResult
- * @throws MaileonAPIException
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function deleteAttachment($mailingId, $attachmentId)
- {
+ public function deleteAttachment(
+ $mailingId,
+ $attachmentId
+ ) {
if (empty($attachmentId)) {
- throw new MaileonAPIException("no attachment id specified");
+ throw new MaileonAPIException('no attachment id specified');
}
- return $this->delete("mailings/{$mailingId}/attachments/{$attachmentId}");
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+ $encodedAttachmentId = rawurlencode(mb_convert_encoding((string) $attachmentId, 'UTF-8'));
+
+ return $this->delete("mailings/$encodedMailingId/attachments/$encodedAttachmentId");
}
/**
* Copies the attachments of a source mailing into a target mailing. Note that the target
- * mailing should not be sealed and that the resulting total count of attachments in the
- * target mailing should not exceed 10.
+ * mailing should not be sealed and that the resulting total count of attachments in the
+ * target mailing should not exceed 10.
*
- * @param integer $mailingId The ID of the mailing
- * @param integer $srcMailingId
+ * @param int $mailingId The ID of the mailing
+ * @param int $srcMailingId
*
- * @return MaileonAPIResult
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function copyAttachments($mailingId, $srcMailingId)
- {
+ public function copyAttachments(
+ $mailingId,
+ $srcMailingId
+ ) {
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
$queryParameters = ['src_mailing_id' => $srcMailingId];
- return $this->put("mailings/{$mailingId}/attachments", "", $queryParameters);
+ return $this->put(
+ "mailings/$encodedMailingId/attachments",
+ '',
+ $queryParameters
+ );
}
/**
* Returns a list of custom properties for the mailing with the provided id.
*
- * @param integer $mailingId The ID of the mailing
+ * @param int $mailingId The ID of the mailing
*
- * @return MaileonAPIResult
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getCustomProperties($mailingId)
{
- return $this->get("mailings/{$mailingId}/settings/properties");
- }
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+ return $this->get("mailings/$encodedMailingId/settings/properties");
+ }
/**
* Adds a list of custom properties to the mailing with the provided id.
*
- * @param integer $mailingId The ID of the mailing
- * @param array $properties Array of CustomProperty or single property
+ * @param int $mailingId The ID of the mailing
+ * @param array $properties Array of CustomProperty or single property
*
- * @return MaileonAPIResult
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function addCustomProperties($mailingId, $properties)
- {
- $xml = new \SimpleXMLElement("");
+ public function addCustomProperties(
+ $mailingId,
+ $properties
+ ) {
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ $xml = new SimpleXMLElement('');
if (is_array($properties)) {
foreach ($properties as $property) {
@@ -1429,137 +1730,193 @@ public function addCustomProperties($mailingId, $properties)
$this->sxmlAppend($xml, $properties->toXML());
}
- return $this->post("mailings/{$mailingId}/settings/properties", $xml->asXML());
+ return $this->post(
+ "mailings/$encodedMailingId/settings/properties",
+ $xml->asXML()
+ );
}
-
/**
* Updates a custom property of the mailing with the provided id.
*
- * @param integer $mailingId The ID of the mailing
+ * @param int $mailingId The ID of the mailing
* @param CustomProperty $property
*
- * @return MaileonAPIResult
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function updateCustomProperty($mailingId, $property)
- {
+ public function updateCustomProperty(
+ $mailingId,
+ $property
+ ) {
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
$queryParameters = [
'name' => $property->key,
'value' => $property->value,
];
- return $this->put("mailings/{$mailingId}/settings/properties", "", $queryParameters);
+ return $this->put(
+ "mailings/$encodedMailingId/settings/properties",
+ '',
+ $queryParameters
+ );
}
-
/**
* Deletes a custom property of the mailing with the provided id.
*
- * @param integer $mailingId The ID of the mailing
- * @param string $propertyName The name of the property to delete
+ * @param int $mailingId The ID of the mailing
+ * @param string $propertyName The name of the property to delete
*
- * @return MaileonAPIResult
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function deleteCustomProperty($mailingId, $propertyName)
- {
- $queryParameters = [
- 'name' => $propertyName,
- ];
+ public function deleteCustomProperty(
+ $mailingId,
+ $propertyName
+ ) {
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
- return $this->delete("mailings/{$mailingId}/settings/properties", $queryParameters);
- }
+ $queryParameters = ['name' => $propertyName];
+ return $this->delete(
+ "mailings/$encodedMailingId/settings/properties",
+ $queryParameters
+ );
+ }
/**
* Sends a testmail for the mailing with the provided id to a given email address.
* If the email address does not exist within your contacts,
* the personalization is done according to your default personalization user configured in Maileon.
- * Documentation website
+ * Documentation website
*
- * @param mailingId id of existing mailing
- * @param email email address
+ * @param int $mailingId id of existing mailing
+ * @param $email email address
*
- * @throws MaileonAPIException
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function sendTestMail($mailingId, $email)
- {
- $queryParameters = [
- 'email' => $email,
- ];
+ public function sendTestMail(
+ $mailingId,
+ $email
+ ) {
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ $queryParameters = ['email' => $email];
- return $this->post("mailings/{$mailingId}/sendtestemail", "", $queryParameters);
+ return $this->post(
+ "mailings/$encodedMailingId/sendtestemail",
+ '',
+ $queryParameters
+ );
}
/**
- * Sends a testmail for the mailing with the provided id to a test-targetgroup givenby its ID.
+ * Sends a testmail for the mailing with the provided id to a test-targetgroup given by its ID.
+ *
+ * @param int $mailingId
+ * @param int $testTargetGroupId
*
- * @param mailingId
- * @param testTargetGroupId
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @throws MaileonAPIException
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function sendTestMailToTestTargetGroup($mailingId, $testTargetGroupId)
- {
- $queryParameters = [
- 'test_targetgroup_id' => $testTargetGroupId,
- ];
+ public function sendTestMailToTestTargetGroup(
+ $mailingId,
+ $testTargetGroupId
+ ) {
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ $queryParameters = ['test_targetgroup_id' => $testTargetGroupId];
- return $this->post("mailings/{$mailingId}/checks/testsendout", "", $queryParameters);
+ return $this->post(
+ "mailings/$encodedMailingId/checks/testsendout",
+ '',
+ $queryParameters
+ );
}
/**
* Assigns a mailing blacklist to a mailing.
*
- * @param mailingId id of the existing mailing
- * @param mailingBlacklistId id of the mailing blacklist to be assigned to the mailing
+ * @param int $mailingId id of the existing mailing
+ * @param int $mailingBlacklistId id of the mailing blacklist to be assigned to the mailing
*
- * @throws MaileonAPIException
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function addMailingBlacklist($mailingId, $mailingBlacklistId)
- {
- return $this->post("mailings/{$mailingId}/mailingblacklists/{$mailingBlacklistId}");
+ public function addMailingBlacklist(
+ $mailingId,
+ $mailingBlacklistId
+ ) {
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+ $encodedMailingBlacklistId = rawurlencode(mb_convert_encoding((string) $mailingBlacklistId, 'UTF-8'));
+
+ return $this->post("mailings/$encodedMailingId/mailingblacklists/$encodedMailingBlacklistId");
}
/**
* Deletes a mailing blacklist from a mailing.
*
- * @param mailingId
- * @param mailingBlacklistId
+ * @param int $mailingId
+ * @param int $mailingBlacklistId
*
- * @throws MaileonAPIException
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function deleteMailingBlacklist($mailingId, $mailingBlacklistId)
- {
- return $this->delete("mailings/{$mailingId}/mailingblacklists/{$mailingBlacklistId}");
- }
+ public function deleteMailingBlacklist(
+ $mailingId,
+ $mailingBlacklistId
+ ) {
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+ $encodedMailingBlacklistId = rawurlencode(mb_convert_encoding((string) $mailingBlacklistId, 'UTF-8'));
+ return $this->delete("mailings/$encodedMailingId/mailingblacklists/$encodedMailingBlacklistId");
+ }
/**
* Retrieve the domain of this mailing
*
- * @param mailingId
+ * @param int $mailingId
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @throws MaileonAPIException
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getMailingDomain($mailingId)
{
- return $this->get("mailings/{$mailingId}/domain/");
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->get("mailings/$encodedMailingId/domain/");
}
/**
* Retrieve all blacklists assigned to this mailing
*
- * @param mailingId
+ * @param int $mailingId
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @throws MaileonAPIException
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getMailingBlacklists($mailingId)
{
- return $this->get("mailings/{$mailingId}/mailingblacklists/");
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->get("mailings/$encodedMailingId/mailingblacklists/");
}
- public function sxmlAppend(\SimpleXMLElement $to, \SimpleXMLElement $from)
- {
+ public function sxmlAppend(
+ SimpleXMLElement $to,
+ SimpleXMLElement $from
+ ) {
$toDom = dom_import_simplexml($to);
$fromDom = dom_import_simplexml($from);
$toDom->appendChild($toDom->ownerDocument->importNode($fromDom, true));
@@ -1568,210 +1925,255 @@ public function sxmlAppend(\SimpleXMLElement $to, \SimpleXMLElement $from)
/**
* Get the configured recipient alias for the given mailing
*
- * @param mailingId
+ * @param int $mailingId
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @throws MaileonAPIException
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getRecipientAlias($mailingId)
{
- return $this->get("mailings/{$mailingId}/contents/recipientalias");
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->get("mailings/$encodedMailingId/contents/recipientalias");
}
/**
* Get the tracking strategy for the given mailing
*
- * @param number mailingId
+ * @param int $mailingId
*
- * @return
- * @throws MaileonAPIException
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getTrackingStrategy($mailingId)
{
- return $this->get("mailings/{$mailingId}/settings/trackingstrategy");
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->get("mailings/$encodedMailingId/settings/trackingstrategy");
}
/**
* Get the configured speed level for the given mailing
*
- * @param mailingId
+ * @param int $mailingId
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @throws MaileonAPIException
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getSpeedLevel($mailingId)
{
- return $this->get("mailings/{$mailingId}/settings/speedlevel");
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->get("mailings/$encodedMailingId/settings/speedlevel");
}
/**
* Get the configured post sendout cleanup state for the given mailing
*
- * @param mailingId
+ * @param int $mailingId
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @throws MaileonAPIException
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getPostSendoutCleanupState($mailingId)
{
- return $this->get("mailings/{$mailingId}/settings/post_sendout_cleanup");
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->get("mailings/$encodedMailingId/settings/post_sendout_cleanup");
}
/**
* Grabs images for the CMS2 media library from the specified HTML content for the mailing referenced by the given ID.
* Returns encountered errors and the transformed HTML.
*
- * @param integer $mailingId
- * the ID of the mailing
- * @param string $html
- * the HTML content to grab images from
- * @param bool $destinationFolder
- * specifies the media library path
+ * @param int $mailingId The ID of the mailing
+ * @param string $html The HTML content to grab images from
+ * @param bool $destinationFolder specifies the media library path
*
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function cms2GrabImages($mailingId, $html, $destinationFolder = '')
- {
- $queryParameters = [
- 'destinationFolder' => urlencode($destinationFolder),
- ];
+ public function cms2GrabImages(
+ $mailingId,
+ $html,
+ $destinationFolder = ''
+ ) {
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ $queryParameters = ['destinationFolder' => urlencode($destinationFolder)];
return $this->post(
- 'mailings/' . $mailingId . '/cms2/contents/grab_images', $html, $queryParameters, "application/json",
- ImageGrabbingResult::class, "text/html"
+ "mailings/$encodedMailingId/cms2/contents/grab_images",
+ $html,
+ $queryParameters,
+ 'application/json',
+ ImageGrabbingResult::class,
+ 'text/html'
);
}
/**
* Returns the mailing as a byte array as possible in the UI. The archive contains the HTML code as well as the linked images.
*
- * @param integer $mailingId
- * the ID of the mailing
- * @param boolean $removeTemplateLanguageMarkup
- * defines if the Maileon Markup Language should be removed from the HTML or not
+ * @param int $mailingId The ID of the mailing
+ * @param boolean $removeTemplateLanguageMarkup defines if the Maileon Markup Language should be removed from the HTML or not
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function cms2GetMailingAsZip($mailingId, $removeTemplateLanguageMarkup = true)
- {
- $queryParameters = [
- 'removeTemplateLanguageMarkup' => $removeTemplateLanguageMarkup ? 'true' : 'false',
- ];
+ public function cms2GetMailingAsZip(
+ $mailingId,
+ $removeTemplateLanguageMarkup = true
+ ) {
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ $queryParameters = ['removeTemplateLanguageMarkup' => $removeTemplateLanguageMarkup ? 'true' : 'false'];
- return $this->get('mailings/' . $mailingId . '/cms2/contents', $queryParameters, "application/json");
+ return $this->get(
+ "mailings/$encodedMailingId/cms2/contents",
+ $queryParameters,
+ 'application/json'
+ );
}
/**
* Upload the mailing content from a Maileon Zip file as possible in the UI.
* The archive contains the HTML code as well as the linked images.
*
- * @param integer $mailingId
- * the ID of the mailing
- * @param boolean $removeTemplateLanguageMarkup
- * defines if the Maileon Markup Language should be removed from the HTML or not
+ * @param int $mailingId The ID of the mailing
+ * @param string $filename
*
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function cms2SetMailingFromZipFromFile($mailingId, $filename)
- {
+ public function cms2SetMailingFromZipFromFile(
+ $mailingId,
+ $filename
+ ) {
// Read the file
$handle = fopen($filename, "rb");
- if (false === $filename) {
- throw new MaileonAPIException("Cannot read file " . $filename . ".");
+
+ if (false === $handle) {
+ throw new MaileonAPIException("Cannot read file $filename.");
}
+
$fileContent = '';
+
while (! feof($handle)) {
$fileContent .= fread($handle, 8192);
}
+
fclose($handle);
return $this->cms2SetMailingFromZipFromBase64($mailingId, base64_encode($fileContent));
}
- public function cms2SetMailingFromZipFromBase64($mailingId, $base64Content)
- {
+ /**
+ * @param int $mailingId
+ * @param $base64Content
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
+ */
+ public function cms2SetMailingFromZipFromBase64(
+ $mailingId,
+ $base64Content
+ ) {
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
$data = [
'content' => $base64Content,
];
$data = json_encode($data);
- $result = $this->put(
- "mailings/" . $mailingId . "/cms2/contents",
+ return $this->put(
+ "mailings/$encodedMailingId/cms2/contents",
$data,
[],
- "application/json"
+ 'application/json'
);
-
- return $result;
}
/**
* Saves a CMS2 mailing as a template in the media library for later access.
*
- * @param integer $mailingId
- * the ID of the mailing
- * @param string $templatePath
- * the path including the filename where the template will be placed inside the media library
- * @param boolean $removeTemplateLanguageMarkup
- * defines if the Maileon Markup Language should be removed from the HTML or not
+ * @param int $mailingId the ID of the mailing
+ * @param string $templatePath the path including the filename where the template will be placed inside the media
+ * library
+ * @param boolean $removeTemplateLanguageMarkup defines if the Maileon Markup Language should be removed from the HTML or not
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function cms2SaveMailingToFolder($mailingId, $templatePath, $removeTemplateLanguageMarkup = false)
- {
+ public function cms2SaveMailingToFolder(
+ $mailingId,
+ $templatePath,
+ $removeTemplateLanguageMarkup = false
+ ) {
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
$queryParameters = [
'templatePath' => urlencode($templatePath),
'removeTemplateLanguageMarkup' => $removeTemplateLanguageMarkup ? 'true' : 'false',
];
- return $this->post('mailings/' . $mailingId . '/cms2/contents', '', $queryParameters);
+ return $this->post(
+ "mailings/$encodedMailingId/cms2/contents", '',
+ $queryParameters
+ );
}
/**
* Sets a template from the media library to a CMS2 mailing.
*
- * @param integer $mailingId
- * the ID of the mailing
- * @param string $templatePath
- * the path including the filename where the template is in the media library
+ * @param int $mailingId the ID of the mailing
+ * @param string $templatePath the path including the filename where the template is in the media library
*
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function cms2SetTemplate($mailingId, $templatePath)
- {
- $queryParameters = array(
- 'templatePath' => urlencode($templatePath),
- );
+ public function cms2SetTemplate(
+ $mailingId,
+ $templatePath
+ ) {
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
- return $this->put('mailings/' . $mailingId . '/cms2/contents', '', $queryParameters);
+ $queryParameters = ['templatePath' => urlencode($templatePath)];
+
+ return $this->put(
+ "mailings/$encodedMailingId/cms2/contents", '',
+ $queryParameters
+ );
}
/**
* Returns the mailing thumbnail as a byte array.
*
- * @param integer $mailingId
- * the ID of the mailing
+ * @param int $mailingId The ID of the mailing
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function cms2GetThumbnail($mailingId)
{
- return $this->get('mailings/' . $mailingId . '/cms2/contents/thumbnail', [], "application/json");
+ $encodedMailingId = rawurlencode(mb_convert_encoding((string) $mailingId, 'UTF-8'));
+
+ return $this->get(
+ "mailings/$encodedMailingId/cms2/contents/thumbnail",
+ [],
+ 'application/json'
+ );
}
}
diff --git a/src/mailings/Schedule.php b/src/mailings/Schedule.php
index f85def2..e962c3e 100644
--- a/src/mailings/Schedule.php
+++ b/src/mailings/Schedule.php
@@ -3,124 +3,144 @@
namespace de\xqueue\maileon\api\client\mailings;
use de\xqueue\maileon\api\client\xml\AbstractXMLWrapper;
+use Exception;
+use SimpleXMLElement;
+
+use function str_pad;
/**
* The wrapper class for a Maileon schedule. This class wraps the XML structure.
*
- * @author Marcus Ständer
+ * @author Marcus Beckerle | XQueue GmbH | marcus.beckerle@xqueue.com
*/
class Schedule extends AbstractXMLWrapper
{
/**
- * @var integer minute
- * The schedule minutes in the format MM
+ * The schedule minutes in the format MM
+ *
+ * @var int
*/
public $minutes;
-
+
/**
- * @var integer hours
- * The schedule hour in the format of HH, 24 hours format
+ * The schedule hour in the format of HH, 24 hours format
+ *
+ * @var int
*/
public $hours;
-
+
/**
- * @var string state
- * The state of the schedule
+ * The state of the schedule
+ *
+ * @var string
*/
public $state;
-
+
/**
- * @var string date
- * The SQL conform date of the schedule day in the format YYYY-MM-DD
+ * The SQL conform date of the schedule day in the format YYYY-MM-DD
+ *
+ * @var string
*/
public $date;
-
+
/**
- * @var string dispatchOption
- * The time distribution strategy to choose from {'hour', 'weekdayhour', 'uniform'}.
+ * The time distribution strategy to choose from {'hour', 'weekdayhour', 'uniform'}.
+ *
+ * @var string
*/
public $dispatchOption;
-
+
/**
- * @var integer dispatchEndInHours
- * Number of hours begining from the dispatch start util which the dispatch distribution over the time has to be finished. Used in case of 'hour'
- * dispatch option and 'uniform' option. Allowed values for the 'uniform' distribution are in [2..96], whereas for 'hour' strategy thery are ranging from [2..24].
+ * Number of hours beginning from the dispatch start util which the dispatch distribution over the time has to be finished. Used in case
+ * of 'hour' dispatch option and 'uniform' option. Allowed values for the 'uniform' distribution are in [2..96], whereas for 'hour'
+ * strategy they are ranging from [2..24].
+ *
+ * @var int
*/
public $dispatchEndInHours;
-
+
/**
- * @var integer dispatchEndInDays
- * Number of days begining from the dispatch start util which the dispatch distribution over the time has to be finished. Used only with dispatch
- * option 'weekdayhour' and its acceptable range is [1..7].
+ * Number of days beginning from the dispatch start util which the dispatch distribution over the time has to be finished. Used only
+ * with dispatch option 'weekdayhour' and its acceptable range is [1..7].
+ *
+ * @var int
*/
public $dispatchEndInDays;
-
+
/**
- * @var string dispatchEndExactDatetime
- * The exact end date util which the dispatch time distribution has to be finished. It is used when none of the arguments above
- * dispatchEndInHours, dispatchEndInDays aren't set i.e. equals 0. Note that one of dispatchEndInHours, dispatchEndInDays,
- * dispatchEndExactDatetime argument should be used in the request according to the selected dispatch option. Format: yyyy-MM-dd HH:mm
+ * The exact end date util which the dispatch time distribution has to be finished. It is used when none of the arguments above
+ * dispatchEndInHours, dispatchEndInDays aren't set i.e. equals 0. Note that one of
+ * dispatchEndInHours, dispatchEndInDays, dispatchEndExactDatetime argument should be used in the
+ * request according to the selected dispatch option. Format: yyyy-MM-dd HH:mm
+ *
+ * @var string
*/
public $dispatchEndExactDatetime;
-
+
/**
- * @var boolean clicksAsResponseReference
- * The parameter determines the inclusion/exclusion of clicks as a response criteria when selecting {'hour', 'weekdayhour'} options.
+ * The parameter determines the inclusion/exclusion of clicks as a response criteria when selecting {'hour', 'weekdayhour'} options.
+ *
+ * @var boolean
*/
public $clicksAsResponseReference;
-
+
/**
- * @var int dispatchWavesGroup
- * The number determines how many consecutive sending waves will be grouped when using {'hour', 'weekdayhour'} distribution. Supported values are {1, 2, 3 (default)}.
+ * The number determines how many consecutive sending waves will be grouped when using {'hour', 'weekdayhour'} distribution. Supported
+ * values are {1, 2, 3 (default)}.
+ *
+ * @var int
*/
public $dispatchWavesGroup;
-
+
/**
- * @var string dispatchUniformInterval
- * The arguments controls the interval {'hour', '30m', '20m', '15m', '10m'} for the 'uniform' strategy indicating the frequency of mailing
- * distribution over time. It should equals null for {'hour', 'weekdayhour'} dispatch options.
+ * The argument controls the interval {'hour', '30m', '20m', '15m', '10m'} for the 'uniform' strategy indicating the frequency of
+ * mailing distribution over time. It should equal null for {'hour', 'weekdayhour'} dispatch options.
+ *
+ * @var string
*/
public $dispatchUniformInterval;
-
+
/**
- * @var string allowedHours
- * The value represents the allowed hours. Comma separated values for the allowed hours and can be combined with a range of hours. The required format looks
- * like 0,3,5,17-21 as an example. The acceptable values rane is 0..23. Note that the if this argument is not provided, all 24H of the day will be considered as acceptable
- * dispatch hours.
+ * The value represents the allowed hours. Comma separated values for the allowed hours and can be combined with a range of hours. The
+ * required format looks like 0,3,5,17-21 as an example. The acceptable values range is 0..23. Note that if this argument is not
+ * provided, all 24H of the day will be considered as acceptable dispatch hours.
+ *
+ * @var string
*/
public $allowedHours;
/**
* Constructor initializing values.
*
- * @param integer minute
- * The schedule minutes in the format MM
- * @param integer hours
- * The schedule hour in the format of HH, 24 hours format
- * @param string state
- * The state of the schedule
- * @param string date
- * The SQL conform date of the schedule day in the format YYYY-MM-DD
- * @param string dispatchOption
- * The time distribution strategy to choose from {'hour', 'weekdayhour', 'uniform'}.
- * @param dispatchEndInHours Number of hours begining from the dispatch start util which the dispatch distribution over the time has to be finished. Used in case of 'hour'
- * dispatch option and 'uniform' option. Allowed values for the 'uniform' distribution are in [2..96], whereas for 'hour' strategy thery are ranging from [2..24].
- * @param dispatchEndInDays Number of days begining from the dispatch start util which the dispatch distribution over the time has to be finished. Used only with dispatch
- * option 'weekdayhour' and its acceptable range is [1..7].
- * @param dispatchEndExactDatetime The exact end date util which the dispatch time distribution has to be finished. It is used when none of the arguments above
- * dispatchEndInHours, dispatchEndInDays aren't set i.e. equals 0. Note that one of dispatchEndInHours, dispatchEndInDays,
- * dispatchEndExactDatetime argument should be used in the request according to the selected dispatch option. Format: yyyy-MM-dd HH:mm
- * @param boolean clicksAsResponseReference
- * The parameter determines the inclusion/exclusion of clicks as a response criteria when selecting {'hour', 'weekdayhour'} options.
- * @param int dispatchWavesGroup
- * The number determines how many consecutive sending waves will be grouped when using {'hour', 'weekdayhour'} distribution. Supported values are {1, 2, 3 (default)}.
- * @param string dispatchUniformInterval
- * The arguments controls the interval {'hour', '30m', '20m', '15m', '10m'} for the 'uniform' strategy indicating the frequency of mailing
- * distribution over time. It should equals null for {'hour', 'weekdayhour'} dispatch options.
- * @param string allowedHours
- * The value represents the allowed hours. Comma separated values for the allowed hours and can be combined with a range of hours. The required format looks
- * like 0,3,5,17-21 as an example. The acceptable values rane is 0..23. Note that the if this argument is not provided, all 24H of the day will be considered as acceptable
- * dispatch hours.
+ * @param int $minutes The schedule minutes in the format MM
+ * @param int $hours The schedule hour in the format of HH, 24 hours format
+ * @param string $state The state of the schedule
+ * @param string $date The SQL conform date of the schedule day in the format YYYY-MM-DD
+ * @param string $dispatchOption The time distribution strategy to choose from {'hour', 'weekdayhour', 'uniform'}.
+ * @param $dispatchEndInHours Number of hours beginning from the dispatch start util which the dispatch distribution over
+ * the time has to be finished. Used in case of 'hour' dispatch option and 'uniform' option.
+ * Allowed values for the 'uniform' distribution are in [2..96], whereas for 'hour' strategy
+ * they are ranging from [2..24].
+ * @param $dispatchEndInDays Number of days beginning from the dispatch start util which the dispatch distribution over
+ * the time has to be finished. Used only with dispatch option 'weekdayhour' and its
+ * acceptable range is [1..7].
+ * @param $dispatchEndExactDatetime The exact end date util which the dispatch time distribution has to be finished. It is used
+ * when none of the arguments above dispatchEndInHours,
+ * dispatchEndInDays aren't set i.e. equals 0. Note that one of
+ * dispatchEndInHours, dispatchEndInDays,
+ * dispatchEndExactDatetime argument should be used in the request according to
+ * the selected dispatch option. Format: yyyy-MM-dd HH:mm
+ * @param boolean $clicksAsResponseReference The parameter determines the inclusion/exclusion of clicks as a response criteria when
+ * selecting {'hour', 'weekdayhour'} options.
+ * @param int $dispatchWavesGroup The number determines how many consecutive sending waves will be grouped when using
+ * {'hour', 'weekdayhour'} distribution. Supported values are {1, 2, 3 (default)}.
+ * @param string $dispatchUniformInterval The argument controls the interval {'hour', '30m', '20m', '15m', '10m'} for the 'uniform'
+ * strategy indicating the frequency of mailing distribution over time. It should equal null
+ * for {'hour', 'weekdayhour'} dispatch options.
+ * @param string $allowedHours The value represents the allowed hours. Comma separated values for the allowed hours and
+ * can be combined with a range of hours. The required format looks like 0,3,5,17-21 as an
+ * example. The acceptable values range is 0..23. Note that if this argument is not provided,
+ * all 24H of the day will be considered as acceptable dispatch hours.
*/
public function __construct(
$minutes = null,
@@ -129,70 +149,75 @@ public function __construct(
$date = null,
$dispatchOption = null,
$dispatchEndInHours = null,
- $dispatchEndInDays = null,
- $dispatchEndExactDatetime = null,
- $clicksAsResponseReference = null,
- $dispatchWavesGroup = null,
- $dispatchUniformInterval = null,
- $allowedHours = null)
- {
- $this->minutes = $minutes;
- $this->hours = $hours;
- $this->state = $state;
- $this->date = $date;
- $this->dispatchOption = $dispatchOption;
- $this->dispatchEndInHours = $dispatchEndInHours;
- $this->dispatchEndInDays = $dispatchEndInDays;
- $this->dispatchEndExactDatetime = $dispatchEndExactDatetime;
+ $dispatchEndInDays = null,
+ $dispatchEndExactDatetime = null,
+ $clicksAsResponseReference = null,
+ $dispatchWavesGroup = null,
+ $dispatchUniformInterval = null,
+ $allowedHours = null
+ ) {
+ $this->minutes = $minutes;
+ $this->hours = $hours;
+ $this->state = $state;
+ $this->date = $date;
+ $this->dispatchOption = $dispatchOption;
+ $this->dispatchEndInHours = $dispatchEndInHours;
+ $this->dispatchEndInDays = $dispatchEndInDays;
+ $this->dispatchEndExactDatetime = $dispatchEndExactDatetime;
$this->clicksAsResponseReference = $clicksAsResponseReference;
- $this->dispatchWavesGroup = $dispatchWavesGroup;
- $this->dispatchUniformInterval = $dispatchUniformInterval;
- $this->allowedHours = $allowedHours;
+ $this->dispatchWavesGroup = $dispatchWavesGroup;
+ $this->dispatchUniformInterval = $dispatchUniformInterval;
+ $this->allowedHours = $allowedHours;
}
- /**
- * Initialization of the schedule from a simple xml element.
- *
- * @param \SimpleXMLElement $xmlElement
- * The xml element that is used to parse the schedule from.
- */
public function fromXML($xmlElement)
{
if (isset($xmlElement->minutes)) {
$this->minutes = $xmlElement->minutes;
}
+
if (isset($xmlElement->hours)) {
$this->hours = $xmlElement->hours;
}
+
if (isset($xmlElement->state)) {
$this->state = $xmlElement->state;
}
+
if (isset($xmlElement->date)) {
$this->date = $xmlElement->date;
}
+
if (isset($xmlElement->dispatchOption)) {
- $this->dispatchOption = (string)$xmlElement->dispatchOption;
+ $this->dispatchOption = (string) $xmlElement->dispatchOption;
}
+
if (isset($xmlElement->dispatchEndInHours)) {
- $this->dispatchEndInHours = intval($xmlElement->dispatchEndInHours);
+ $this->dispatchEndInHours = (int) $xmlElement->dispatchEndInHours;
}
+
if (isset($xmlElement->dispatchEndInDays)) {
- $this->dispatchEndInDays = intval($xmlElement->dispatchEndInDays);
+ $this->dispatchEndInDays = (int) $xmlElement->dispatchEndInDays;
}
+
if (isset($xmlElement->dispatchEndExactDatetime)) {
- $this->dispatchEndExactDatetime = (string)$xmlElement->dispatchEndExactDatetime;
+ $this->dispatchEndExactDatetime = (string) $xmlElement->dispatchEndExactDatetime;
}
+
if (isset($xmlElement->clicksAsResponseReference)) {
- $this->clicksAsResponseReference = boolval($xmlElement->clicksAsResponseReference);
+ $this->clicksAsResponseReference = (bool) $xmlElement->clicksAsResponseReference;
}
+
if (isset($xmlElement->dispatchWavesGroup)) {
- $this->dispatchWavesGroup = intval($xmlElement->dispatchWavesGroup);
+ $this->dispatchWavesGroup = (int) $xmlElement->dispatchWavesGroup;
}
+
if (isset($xmlElement->dispatchUniformInterval)) {
- $this->dispatchUniformInterval = (string)$xmlElement->dispatchUniformInterval;
+ $this->dispatchUniformInterval = (string) $xmlElement->dispatchUniformInterval;
}
+
if (isset($xmlElement->allowedHours)) {
- $this->allowedHours = (string)$xmlElement->allowedHours;
+ $this->allowedHours = (string) $xmlElement->allowedHours;
}
}
@@ -201,88 +226,93 @@ public function fromXML($xmlElement)
*
* @param bool $addXMLDeclaration
*
- * @return \SimpleXMLElement
- * Generate a XML element from the contact object.
+ * @return SimpleXMLElement contains the serialized representation of the object
+ *
+ * @throws Exception
*/
public function toXML($addXMLDeclaration = true)
{
- $xmlString = $addXMLDeclaration ? "" : "";
- $xml = new \SimpleXMLElement($xmlString);
+ $xmlString = $addXMLDeclaration ? '' : '';
+ $xml = new SimpleXMLElement($xmlString);
if (isset($this->minutes)) {
- $xml->addChild("minutes", $this->minutes);
+ $xml->addChild('minutes', $this->minutes);
}
+
if (isset($this->hours)) {
- $xml->addChild("hours", $this->hours);
+ $xml->addChild('hours', $this->hours);
}
+
if (isset($this->state)) {
- $xml->addChild("state", $this->state);
+ $xml->addChild('state', $this->state);
}
+
if (isset($this->date)) {
- $xml->addChild("date", $this->date);
+ $xml->addChild('date', $this->date);
}
+
if (isset($this->dispatchOption)) {
- $xml->addChild("dispatchOption", $this->dispatchOption);
+ $xml->addChild('dispatchOption', $this->dispatchOption);
}
+
if (isset($this->dispatchEndInHours)) {
- $xml->addChild("dispatchEndInHours", $this->dispatchEndInHours);
+ $xml->addChild('dispatchEndInHours', $this->dispatchEndInHours);
}
+
if (isset($this->dispatchEndInDays)) {
- $xml->addChild("dispatchEndInDays", $this->dispatchEndInDays);
+ $xml->addChild('dispatchEndInDays', $this->dispatchEndInDays);
}
+
if (isset($this->dispatchEndExactDatetime)) {
- $xml->addChild("dispatchEndExactDatetime", $this->dispatchEndExactDatetime);
+ $xml->addChild('dispatchEndExactDatetime', $this->dispatchEndExactDatetime);
}
- if (!empty($this->clicksAsResponseReference)) {
- $xml->addChild("clicksAsResponseReference", ($this->clicksAsResponseReference)?"true":"false");
+
+ if (! empty($this->clicksAsResponseReference)) {
+ $xml->addChild('clicksAsResponseReference', $this->clicksAsResponseReference ? 'true' : 'false');
}
+
if (isset($this->dispatchWavesGroup)) {
- $xml->addChild("dispatchWavesGroup", $this->dispatchWavesGroup);
+ $xml->addChild('dispatchWavesGroup', $this->dispatchWavesGroup);
}
+
if (isset($this->dispatchUniformInterval)) {
- $xml->addChild("dispatchUniformInterval", $this->dispatchUniformInterval);
+ $xml->addChild('dispatchUniformInterval', $this->dispatchUniformInterval);
}
+
if (isset($this->allowedHours)) {
- $xml->addChild("allowedHours", $this->allowedHours);
+ $xml->addChild('allowedHours', $this->allowedHours);
}
return $xml;
}
- /**
- * Serialization to a simple XML element as string
- *
- * @return string
- * The string representation of the XML document for this mailing.
- */
- public function toXMLString()
- {
- $xml = $this->toXML();
- return $xml->asXML();
- }
-
- /**
- * Human readable representation of this wrapper.
- *
- * @return string
- * A human readable version of the schedule.
- */
- public function toString()
+ public function toString(): string
{
- return "Schedule [minutes={$this->minutes}, hours={$this->hours}, state={$this->state}, date={$this->date}, dispatchOption={$this->dispatchOption}, ".
- "dispatchEndInHours={$this->dispatchEndInHours}, dispatchEndInDays={$this->dispatchEndInDays}, dispatchEndExactDatetime={$this->dispatchEndExactDatetime}, clicksAsResponseReference={($this->clicksAsResponseReference)?'true':'false'},".
- " dispatchWavesGroup={$this->dispatchWavesGroup}, dispatchUniformInterval={$this->dispatchUniformInterval}, allowedHours={ $this->allowedHours}]";
+ return 'Schedule ['
+ . 'minutes=' . $this->minutes
+ . ', hours=' . $this->hours
+ . ', state=' . $this->state
+ . ', date=' . $this->date
+ . ', dispatchOption=' . $this->dispatchOption
+ . ', dispatchEndInHours=' . $this->dispatchEndInHours
+ . ', dispatchEndInDays=' . $this->dispatchEndInDays
+ . ', dispatchEndExactDatetime=' . $this->dispatchEndExactDatetime
+ . ', clicksAsResponseReference=' . ($this->clicksAsResponseReference ? 'true' : 'false')
+ . ', dispatchWavesGroup=' . $this->dispatchWavesGroup
+ . ', dispatchUniformInterval=' . $this->dispatchUniformInterval
+ . ', allowedHours=' . $this->allowedHours
+ . ']';
}
/**
* Date and time representation of this wrapper.
*
- * @return string
- * A date time version of the schedule.
+ * @return string A date time version of the schedule.
*/
- public function toDateTime()
+ public function toDateTime(): string
{
- return $this->date . " " . str_pad($this->hours, 2, '0', STR_PAD_LEFT) .
- ":" . str_pad($this->minutes, 2, '0', STR_PAD_LEFT);
+ return $this->date
+ . ' ' . str_pad($this->hours, 2, '0', STR_PAD_LEFT)
+ . ':' . str_pad($this->minutes, 2, '0', STR_PAD_LEFT);
}
}
diff --git a/src/marketingautomation/MarketingAutomationService.php b/src/marketingautomation/MarketingAutomationService.php
index d8babf9..7d459e0 100644
--- a/src/marketingautomation/MarketingAutomationService.php
+++ b/src/marketingautomation/MarketingAutomationService.php
@@ -3,43 +3,52 @@
namespace de\xqueue\maileon\api\client\marketingautomation;
use de\xqueue\maileon\api\client\AbstractMaileonService;
+use de\xqueue\maileon\api\client\MaileonAPIException;
use de\xqueue\maileon\api\client\MaileonAPIResult;
+use Exception;
+
+use function is_array;
+use function json_encode;
+use function mb_convert_encoding;
+use function rawurlencode;
/**
* Facade that wraps the REST service for marketing automation programs.
*
- * @author Viktor Balogh | Wanadis Kft. | balogh.viktor@maileon.hu
+ * @author Viktor Balogh | XQueue GmbH | viktor.balog@xqueue.com
* @author Marcus Beckerle | XQueue GmbH | marcus.beckerle@xqueue.com
*/
-
class MarketingAutomationService extends AbstractMaileonService
{
/**
* Starts a marketing automation program directly by its ID for a list of contacts (by email)
- *
- * @param int $programId The ID of the MA program
- * @param array $emails A list of emails to start a program for. Can also be a single email (string)
*
- * @return MaileonAPIResult
- * the result of the operation
+ * @param int $programId The ID of the MA program
+ * @param array $emails A list of emails to start a program for. Can also be a single email (string)
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function startMarketingAutomationProgram($programId, $emails)
- {
- $urlProgramId = urlencode($programId);
+ public function startMarketingAutomationProgram(
+ $programId,
+ $emails
+ ) {
+ $encodedProgramId = rawurlencode(mb_convert_encoding((string) $programId, 'UTF-8'));
- if (!empty($emails)) {
+ if (! empty($emails)) {
if (is_array($emails)) {
$bodyContent['emails'] = $emails;
} else {
- $bodyContent['emails'] = array($emails);
+ $bodyContent['emails'] = [$emails];
}
}
return $this->post(
- "marketing-automation/$urlProgramId",
- json_encode($bodyContent),
- array(),
- "application/json"
+ "marketing-automation/$encodedProgramId",
+ isset($bodyContent) ? json_encode($bodyContent) : '',
+ [],
+ 'application/json'
);
}
}
diff --git a/src/media/MediaService.php b/src/media/MediaService.php
index 2115743..1ceacdd 100644
--- a/src/media/MediaService.php
+++ b/src/media/MediaService.php
@@ -3,26 +3,28 @@
namespace de\xqueue\maileon\api\client\media;
use de\xqueue\maileon\api\client\AbstractMaileonService;
+use de\xqueue\maileon\api\client\MaileonAPIException;
use de\xqueue\maileon\api\client\MaileonAPIResult;
+use Exception;
/**
* Facade that wraps the REST service for media resources.
*
* @author Marcus Beckerle | XQueue GmbH | marcus.beckerle@xqueue.com
*/
-
class MediaService extends AbstractMaileonService
{
/**
* Retrieves a list of mailing templates from an account
*
- * @return MaileonAPIResult
- * the result of the operation
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred The result of the operation
*/
public function getMailingTemplates()
{
return $this->get(
- "media/templates/mailings",
+ 'media/templates/mailings',
null,
'application/vnd.maileon.api+json',
'array'
diff --git a/src/reports/Block.php b/src/reports/Block.php
index 0aa5fdd..974f2e6 100644
--- a/src/reports/Block.php
+++ b/src/reports/Block.php
@@ -3,18 +3,19 @@
namespace de\xqueue\maileon\api\client\reports;
use de\xqueue\maileon\api\client\xml\AbstractXMLWrapper;
+use Exception;
+use SimpleXMLElement;
/**
* This class represents a block containing the timestamp, the contact, and some details.
*
* @author Jannik Jochem
- * @author Marcus Ständer | Trusted Mails GmbH |
- * marcus.staender@trusted-mails.com
+ * @author Marcus Beckerle | XQueue GmbH | marcus.beckerle@xqueue.com
*/
class Block extends AbstractXMLWrapper
{
/**
- * @var integer
+ * @var int
*/
public $timestamp;
@@ -24,53 +25,46 @@ class Block extends AbstractXMLWrapper
public $contact;
/**
- * @var integer
+ * @var int
*/
public $oldStatus;
/**
- * @var integer
+ * @var int
*/
public $newStatus;
/**
- * @var String
+ * @var string
*/
public $reason;
-
- /**
- * @return string
- * containing a human-readable representation of this block
- */
- public function toString()
+ public function toString(): string
{
- return "Block [timestamp=" . $this->timestamp .
- ", contact=" . $this->contact->toString() .
- ", oldstatus=" . $this->oldStatus .
- ", newstatus=" . $this->newStatus .
- ", reason=" . $this->reason . "]";
+ return 'Block ['
+ . 'timestamp=' . $this->timestamp
+ . ', contact=' . $this->contact->toString()
+ . ', oldStatus=' . $this->oldStatus
+ . ', newStatus=' . $this->newStatus
+ . ', reason=' . $this->reason
+ . ']';
}
/**
+ * CSV representation of this wrapper.
+ *
* @return string
- * containing a csv pepresentation of this block
*/
- public function toCsvString()
+ public function toCsvString(): string
{
- return "block;" . $this->timestamp .
- ";" . $this->contact->toCsvString() .
- ";" . $this->oldStatus .
- ";" . $this->newStatus .
- ";" . $this->reason;
+ return 'block'
+ . ';' . $this->timestamp
+ . ';' . $this->contact->toCsvString()
+ . ';' . $this->oldStatus
+ . ';' . $this->newStatus
+ . ';' . $this->reason;
}
- /**
- * Initializes this bounce from an XML representation.
- *
- * @param \SimpleXMLElement $xmlElement
- * the XML representation to use
- */
public function fromXML($xmlElement)
{
$this->contact = new ReportContact();
@@ -79,12 +73,15 @@ public function fromXML($xmlElement)
if (isset($xmlElement->timestamp)) {
$this->timestamp = $xmlElement->timestamp;
}
+
if (isset($xmlElement->old_status)) {
$this->oldStatus = $xmlElement->old_status;
}
+
if (isset($xmlElement->new_status)) {
$this->newStatus = $xmlElement->new_status;
}
+
if (isset($xmlElement->reason)) {
$this->reason = $xmlElement->reason;
}
@@ -93,28 +90,35 @@ public function fromXML($xmlElement)
/**
* For future use, not implemented yet.
*
- * @return \SimpleXMLElement
- * containing the XML serialization of this object
+ * Serialization to a simple XML element.
+ *
+ * @return SimpleXMLElement contains the serialized representation of the object
+ *
+ * @throws Exception
*/
public function toXML()
{
- $xmlString = "";
- $xml = new \SimpleXMLElement($xmlString);
+ $xmlString = '';
+ $xml = new SimpleXMLElement($xmlString);
if (isset($this->contact)) {
- $xml->addChild("contact", $this->contact->toXML());
+ $xml->addChild('contact', $this->contact->toXML());
}
+
if (isset($this->timestamp)) {
- $xml->addChild("timestamp", $this->timestamp);
+ $xml->addChild('timestamp', $this->timestamp);
}
+
if (isset($this->old_status)) {
- $xml->addChild("old_status", $this->oldStatus);
+ $xml->addChild('old_status', $this->oldStatus);
}
+
if (isset($this->new_status)) {
- $xml->addChild("new_status", $this->newStatus);
+ $xml->addChild('new_status', $this->newStatus);
}
+
if (isset($this->reason)) {
- $xml->addChild("reason", $this->reason);
+ $xml->addChild('reason', $this->reason);
}
return $xml;
diff --git a/src/reports/Bounce.php b/src/reports/Bounce.php
index ee7ed2b..3eb750c 100644
--- a/src/reports/Bounce.php
+++ b/src/reports/Bounce.php
@@ -3,18 +3,19 @@
namespace de\xqueue\maileon\api\client\reports;
use de\xqueue\maileon\api\client\xml\AbstractXMLWrapper;
+use Exception;
+use SimpleXMLElement;
/**
* This class represents a bounce containing the timestamp, the contact, and the ID of the mailing.
*
* @author Jannik Jochem
- * @author Marcus Ständer | Trusted Mails GmbH |
- * marcus.staender@trusted-mails.com
+ * @author Marcus Beckerle | XQueue GmbH | marcus.beckerle@xqueue.com
*/
class Bounce extends AbstractXMLWrapper
{
/**
- * @var String
+ * @var string
*/
public $timestamp;
@@ -24,69 +25,65 @@ class Bounce extends AbstractXMLWrapper
public $contact;
/**
- * @var integer
+ * @var int
*/
public $mailingId;
/**
* Can be transient or permanent
- * @var String
+ *
+ * @var string
*/
public $type;
/**
* In the form of X.Y.Z
- * @var String
+ *
+ * @var string
*/
public $statusCode;
/**
* Can be mta-listener or inbound
- * @var String
+ *
+ * @var string
*/
public $source;
/**
- * @var integer
+ * @var int
*/
public $messageId;
- /**
- * @return string
- * containing a human-readable representation of this bounce
- */
- public function toString()
+ public function toString(): string
{
- return "Bounce [timestamp=" . $this->timestamp .
- ", contact=" . $this->contact->toString() .
- ", mailingId=" . $this->mailingId .
- ", type=" . $this->type .
- ", statusCode=" . $this->statusCode .
- ", source=" . $this->source .
- ", messageId=" . $this->messageId . "]";
+ return 'Bounce ['
+ . 'timestamp=' . $this->timestamp
+ . ', contact=' . $this->contact->toString()
+ . ', mailingId=' . $this->mailingId
+ . ', type=' . $this->type
+ . ', statusCode=' . $this->statusCode
+ . ', source=' . $this->source
+ . ', messageId=' . $this->messageId
+ . ']';
}
/**
+ * CSV representation of this wrapper.
+ *
* @return string
- * containing a csv pepresentation of this bounce
*/
- public function toCsvString()
+ public function toCsvString(): string
{
- return $this->timestamp .
- ";" . $this->contact->toCsvString() .
- ";" . $this->mailingId .
- ";" . $this->type .
- ";" . $this->statusCode .
- ";" . $this->source .
- ";" . $this->messageId;
+ return $this->timestamp
+ . ';' . $this->contact->toCsvString()
+ . ';' . $this->mailingId
+ . ';' . $this->type
+ . ';' . $this->statusCode
+ . ';' . $this->source
+ . ';' . $this->messageId;
}
- /**
- * Initializes this bounce from an XML representation.
- *
- * @param \SimpleXMLElement $xmlElement
- * the XML representation to use
- */
public function fromXML($xmlElement)
{
$this->contact = new ReportContact();
@@ -95,54 +92,68 @@ public function fromXML($xmlElement)
if (isset($xmlElement->mailing_id)) {
$this->mailingId = $xmlElement->mailing_id;
}
+
if (isset($xmlElement->timestamp)) {
$this->timestamp = $xmlElement->timestamp;
}
+
if (isset($xmlElement->type)) {
$this->type = $xmlElement->type;
}
+
if (isset($xmlElement->status_code)) {
$this->statusCode = $xmlElement->status_code;
}
+
if (isset($xmlElement->source)) {
$this->source = $xmlElement->source;
}
+
if (isset($xmlElement->msg_id)) {
- $this->messageId = $xmlElement->msg_id ;
+ $this->messageId = $xmlElement->msg_id;
}
}
/**
* For future use, not implemented yet.
*
- * @return \SimpleXMLElement
- * containing the XML serialization of this object
+ * Serialization to a simple XML element.
+ *
+ * @return SimpleXMLElement contains the serialized representation of the object
+ *
+ * @throws Exception
*/
public function toXML()
{
- $xmlString = "";
- $xml = new \SimpleXMLElement($xmlString);
+ $xmlString = '';
+ $xml = new SimpleXMLElement($xmlString);
if (isset($this->contact)) {
- $xml->addChild("contact", $this->contact->toXML());
- }
+ $xml->addChild('contact', $this->contact->toXML());
+ }
+
if (isset($this->mailing_id)) {
- $xml->addChild("mailing_id", $this->mailingId);
+ $xml->addChild('mailing_id', $this->mailingId);
}
+
if (isset($this->timestamp)) {
- $xml->addChild("timestamp", $this->timestamp);
+ $xml->addChild('timestamp', $this->timestamp);
}
+
if (isset($this->type)) {
- $xml->addChild("type", $this->type);
+ $xml->addChild('type', $this->type);
}
+
if (isset($this->status_code)) {
- $xml->addChild("status_code", $this->statusCode);
+ $xml->addChild('status_code', $this->statusCode);
}
+
if (isset($this->source)) {
- $xml->addChild("source", $this->source);
+ $xml->addChild('source', $this->source);
}
+
if (isset($this->msg_id)) {
- $xml->addChild("msg_id", $this->messageId);
+ $xml->addChild('msg_id', $this->messageId);
}
return $xml;
diff --git a/src/reports/Click.php b/src/reports/Click.php
index 4cc1af4..cfdd95f 100644
--- a/src/reports/Click.php
+++ b/src/reports/Click.php
@@ -3,18 +3,21 @@
namespace de\xqueue\maileon\api\client\reports;
use de\xqueue\maileon\api\client\xml\AbstractXMLWrapper;
+use Exception;
+use SimpleXMLElement;
+
+use function rtrim;
/**
* This class represents a click containing the timestamp, the contact, and the ID of the mailing.
*
* @author Jannik Jochem
- * @author Marcus Ständer | Trusted Mails GmbH |
- * marcus.staender@trusted-mails.com
+ * @author Marcus Beckerle | XQueue GmbH | marcus.beckerle@xqueue.com
*/
class Click extends AbstractXMLWrapper
{
/**
- * @var integer
+ * @var int
*/
public $timestamp;
@@ -24,12 +27,12 @@ class Click extends AbstractXMLWrapper
public $contact;
/**
- * @var integer
+ * @var int
*/
public $mailingId;
/**
- * @var integer
+ * @var int
*/
public $linkId;
@@ -47,19 +50,19 @@ class Click extends AbstractXMLWrapper
* @var array
*/
public $linkTags;
-
+
/**
* @var string
*/
public $transactionId;
-
+
/**
* @var string
*/
public $contactHash;
-
+
/**
- * @var integer
+ * @var int
*/
public $messageId;
@@ -72,55 +75,49 @@ class Click extends AbstractXMLWrapper
* @var string
*/
public $deviceType;
-
+
/**
+ * Information about the client of the contact
*
- * @var ReportClientInfos Information about the client of the contact
+ * @var ReportClientInfos
*/
public $clientInfos;
-
+
public function __construct()
{
$this->clientInfos = new ReportClientInfos();
}
- /**
- * @return string
- * containing a human-readable representation of this click
- */
- public function toString()
+ public function toString(): string
{
-
// Generate custom field string
- $linkTags = "";
+ $linkTags = '';
+
if (isset($this->linkTags)) {
foreach ($this->linkTags as $value) {
- $linkTags .= $value . "#";
+ $linkTags .= $value . '#';
}
+
$linkTags = rtrim($linkTags, '#');
}
- return "Click [timestamp=" . $this->timestamp .
- ", contact=" . $this->contact->toString() .
- ", mailingId=" . $this->mailingId .
- ", linkId=" . $this->linkId .
- ", linkType=" . $this->linkType .
- ", linkUrl=" . $this->linkUrl .
- ", linkTags=" . $linkTags .
- ", clientInfos=" . $this->clientInfos->toString() .
- ", transactionId=" . $this->transactionId .
- ", contactHash=" . $this->contactHash .
- ", messageId=" . $this->messageId .
- ", format=" . $this->format .
- ", deviceType=" . $this->deviceType . "]";
+ return 'Click ['
+ . 'timestamp=' . $this->timestamp
+ . ', contact=' . $this->contact->toString()
+ . ', mailingId=' . $this->mailingId
+ . ', linkId=' . $this->linkId
+ . ', linkType=' . $this->linkType
+ . ', linkUrl=' . $this->linkUrl
+ . ', linkTags=' . $linkTags
+ . ', clientInfos=' . $this->clientInfos->toString()
+ . ', transactionId=' . $this->transactionId
+ . ', contactHash=' . $this->contactHash
+ . ', messageId=' . $this->messageId
+ . ', format=' . $this->format
+ . ', deviceType=' . $this->deviceType
+ . ']';
}
- /**
- * Initializes this click from an XML representation.
- *
- * @param \SimpleXMLElement $xmlElement
- * the XML representation to use
- */
public function fromXML($xmlElement)
{
$this->contact = new ReportContact();
@@ -129,121 +126,145 @@ public function fromXML($xmlElement)
if (isset($xmlElement->mailing_id)) {
$this->mailingId = $xmlElement->mailing_id;
}
+
if (isset($xmlElement->timestamp)) {
$this->timestamp = $xmlElement->timestamp;
}
+
if (isset($xmlElement->link_id)) {
$this->linkId = $xmlElement->link_id;
}
+
if (isset($xmlElement->link_type)) {
$this->linkType = $xmlElement->link_type;
}
+
if (isset($xmlElement->link_url)) {
$this->linkUrl = $xmlElement->link_url;
}
+
if (isset($xmlElement->transaction_id)) {
$this->transactionId = $xmlElement->transaction_id;
}
+
if (isset($xmlElement->contact_hash)) {
$this->contactHash = $xmlElement->contact_hash;
}
+
if (isset($xmlElement->msg_id)) {
- $this->messageId = $xmlElement->msg_id ;
+ $this->messageId = $xmlElement->msg_id;
}
+
if (isset($xmlElement->format)) {
$this->format = $xmlElement->format;
}
+
if (isset($xmlElement->device_type)) {
$this->deviceType = $xmlElement->device_type;
}
if (isset($xmlElement->link_tags)) {
- $this->linkTags = array();
+ $this->linkTags = [];
+
foreach ($xmlElement->link_tags->children() as $field) {
- array_push($this->linkTags, $field[0]);
+ $this->linkTags[] = $field[0];
}
}
-
+
if (isset($xmlElement->client)) {
$this->clientInfos->fromXML($xmlElement->client);
}
}
/**
+ * CSV representation of this wrapper.
+ *
* @return string
- * containing a csv pepresentation of this click
*/
- public function toCsvString()
+ public function toCsvString(): string
{
- return $this->timestamp .
- ";" . $this->contact->toCsvString() .
- ";" . $this->mailingId .
- ";" . $this->linkId .
- ";" . $this->linkType .
- ";" . $this->linkUrl .
- ";" . $this->clientInfos->toCsvString() .
- ";" . $this->transactionId .
- ";" . $this->contactHash .
- ";" . $this->messageId .
- ";" . $this->format .
- ";" . $this->deviceType;
+ return $this->timestamp
+ . ';' . $this->contact->toCsvString()
+ . ';' . $this->mailingId
+ . ';' . $this->linkId
+ . ';' . $this->linkType
+ . ';' . $this->linkUrl
+ . ';' . $this->clientInfos->toCsvString()
+ . ';' . $this->transactionId
+ . ';' . $this->contactHash
+ . ';' . $this->messageId
+ . ';' . $this->format
+ . ';' . $this->deviceType;
}
/**
* For future use, not implemented yet.
*
- * @return \SimpleXMLElement
- * containing the XML serialization of this object
+ * Serialization to a simple XML element.
+ *
+ * @return SimpleXMLElement contains the serialized representation of the object
+ *
+ * @throws Exception
*/
public function toXML()
{
- $xmlString = "";
- $xml = new \SimpleXMLElement($xmlString);
+ $xmlString = '';
+ $xml = new SimpleXMLElement($xmlString);
if (isset($this->contact)) {
- $xml->addChild("contact", $this->contact->toXML());
- }
+ $xml->addChild('contact', $this->contact->toXML());
+ }
+
if (isset($this->mailingId)) {
- $xml->addChild("mailing_id", $this->mailingId);
+ $xml->addChild('mailing_id', $this->mailingId);
}
+
if (isset($this->timestamp)) {
- $xml->addChild("timestamp", $this->timestamp);
+ $xml->addChild('timestamp', $this->timestamp);
}
+
if (isset($this->linkId)) {
- $xml->addChild("link_id", $this->linkId);
+ $xml->addChild('link_id', $this->linkId);
}
+
if (isset($this->linkType)) {
- $xml->addChild("link_type", $this->linkType);
+ $xml->addChild('link_type', $this->linkType);
}
+
if (isset($this->linkUrl)) {
- $xml->addChild("link_url", $this->linkUrl);
+ $xml->addChild('link_url', $this->linkUrl);
}
+
if (isset($this->transactionId)) {
- $xml->addChild("transaction_id", $this->transactionId);
+ $xml->addChild('transaction_id', $this->transactionId);
}
+
if (isset($this->contactHash)) {
- $xml->addChild("contact_hash", $this->contactHash);
+ $xml->addChild('contact_hash', $this->contactHash);
}
+
if (isset($this->messageId)) {
- $xml->addChild("msg_id", $this->messageId);
+ $xml->addChild('msg_id', $this->messageId);
}
+
if (isset($this->format)) {
- $xml->addChild("format", $this->format);
+ $xml->addChild('format', $this->format);
}
+
if (isset($this->deviceType)) {
- $xml->addChild("device_type", $this->deviceType);
+ $xml->addChild('device_type', $this->deviceType);
}
if (isset($this->linkTags)) {
- $linkTags = $xml->addChild("link_tags");
+ $linkTags = $xml->addChild('link_tags');
foreach ($this->linkTags as $linkTag) {
- $linkTags->addChild("field", $linkTag);
+ $linkTags->addChild('field', $linkTag);
}
}
-
+
if (isset($this->clientInfos)) {
- $xml->addChild("client", $this->clientInfos->toXML());
+ $xml->addChild('client', $this->clientInfos->toXML());
}
return $xml;
diff --git a/src/reports/Conversion.php b/src/reports/Conversion.php
index c127580..dc74e70 100644
--- a/src/reports/Conversion.php
+++ b/src/reports/Conversion.php
@@ -3,6 +3,8 @@
namespace de\xqueue\maileon\api\client\reports;
use de\xqueue\maileon\api\client\xml\AbstractXMLWrapper;
+use Exception;
+use SimpleXMLElement;
/**
* This class represents a conversion
@@ -22,7 +24,7 @@ class Conversion extends AbstractXMLWrapper
public $timestampSql;
/**
- * @var integer
+ * @var int
*/
public $contactId;
@@ -52,7 +54,7 @@ class Conversion extends AbstractXMLWrapper
public $mailingSentTimestampSql;
/**
- * @var integer
+ * @var int
*/
public $mailingId;
@@ -62,7 +64,7 @@ class Conversion extends AbstractXMLWrapper
public $mailingName;
/**
- * @var integer
+ * @var int
*/
public $siteId;
@@ -72,7 +74,7 @@ class Conversion extends AbstractXMLWrapper
public $siteName;
/**
- * @var integer
+ * @var int
*/
public $goalId;
@@ -82,7 +84,7 @@ class Conversion extends AbstractXMLWrapper
public $goalName;
/**
- * @var integer
+ * @var int
*/
public $linkId;
@@ -91,171 +93,195 @@ class Conversion extends AbstractXMLWrapper
*/
public $linkUrl;
- /**
- * @return string
- * containing a human-readable representation of this conversion
- */
- public function toString()
+ public function toString(): string
{
-
- return "Conversion [" .
- "timestamp=" . $this->timestamp .
- ", timestampSql=" . $this->timestampSql .
- ", contactEmail=" . $this->contactEmail .
- ", contactExternalId=" . $this->contactExternalId .
- ", value=" . $this->value .
- ", mailingSentTimestamp=" . $this->mailingSentTimestamp .
- ", mailingSentTimestampSql=" . $this->mailingSentTimestampSql .
- ", mailingId=" . $this->mailingId .
- ", mailingName=" . $this->mailingName .
- ", siteId=" . $this->siteId .
- ", siteName=" . $this->siteName .
- ", goalId=" . $this->goalId .
- ", goalName=" . $this->goalName .
- ", linkId=" . $this->linkId .
- ", linkUrl=" . $this->linkUrl ."]";
+ return 'Conversion ['
+ . 'timestamp=' . $this->timestamp
+ . ', timestampSql=' . $this->timestampSql
+ . ', contactEmail=' . $this->contactEmail
+ . ', contactExternalId=' . $this->contactExternalId
+ . ', value=' . $this->value
+ . ', mailingSentTimestamp=' . $this->mailingSentTimestamp
+ . ', mailingSentTimestampSql=' . $this->mailingSentTimestampSql
+ . ', mailingId=' . $this->mailingId
+ . ', mailingName=' . $this->mailingName
+ . ', siteId=' . $this->siteId
+ . ', siteName=' . $this->siteName
+ . ', goalId=' . $this->goalId
+ . ', goalName=' . $this->goalName
+ . ', linkId=' . $this->linkId
+ . ', linkUrl=' . $this->linkUrl
+ . ']';
}
- /**
- * Initializes this conversion from an XML representation.
- *
- * @param \SimpleXMLElement $xmlElement
- * the XML representation to use
- */
public function fromXML($xmlElement)
{
if (isset($xmlElement->timestamp)) {
$this->timestamp = $xmlElement->timestamp;
}
+
if (isset($xmlElement->timestamp_sql)) {
$this->timestampSql = $xmlElement->timestamp_sql;
}
+
if (isset($xmlElement->contact_id)) {
$this->contactId = $xmlElement->contact_id;
}
+
if (isset($xmlElement->contact_email)) {
$this->contactEmail = $xmlElement->contact_email;
}
+
if (isset($xmlElement->contact_external_id)) {
$this->contactExternalId = $xmlElement->contact_external_id;
}
+
if (isset($xmlElement->value)) {
$this->value = $xmlElement->value;
}
+
if (isset($xmlElement->mailing_sent_date)) {
$this->mailingSentTimestamp = $xmlElement->mailing_sent_date;
}
+
if (isset($xmlElement->mailing_sent_date_sql)) {
$this->mailingSentTimestampSql = $xmlElement->mailing_sent_date_sql;
}
+
if (isset($xmlElement->mailing_id)) {
$this->mailingId = $xmlElement->mailing_id;
}
+
if (isset($xmlElement->mailing_name)) {
$this->mailingName = $xmlElement->mailing_name;
}
+
if (isset($xmlElement->site_id)) {
$this->siteId = $xmlElement->site_id;
}
+
if (isset($xmlElement->site_name)) {
$this->siteName = $xmlElement->site_name;
}
+
if (isset($xmlElement->goal_id)) {
$this->goalId = $xmlElement->goal_id;
}
+
if (isset($xmlElement->goal_name)) {
$this->goalName = $xmlElement->goal_name;
}
+
if (isset($xmlElement->link_id)) {
$this->linkId = $xmlElement->link_id;
}
+
if (isset($xmlElement->link_url)) {
$this->linkUrl = $xmlElement->link_url;
}
}
/**
+ * CSV representation of this wrapper.
+ *
* @return string
- * containing a csv pepresentation of this conversion
*/
- public function toCsvString()
+ public function toCsvString(): string
{
- return $this->timestamp .
- ";" . $this->timestampSql .
- ";" . $this->contactId .
- ";" . $this->contactEmail .
- ";" . $this->contactExternalId .
- ";" . $this->value .
- ";" . $this->mailingSentTimestamp .
- ";" . $this->mailingSentTimestampSql .
- ";" . $this->mailingId .
- ";" . $this->mailingName .
- ";" . $this->siteId .
- ";" . $this->siteName .
- ";" . $this->goalId .
- ";" . $this->goalName .
- ";" . $this->linkId .
- ";" . $this->linkUrl;
+ return $this->timestamp
+ . ';' . $this->timestampSql
+ . ';' . $this->contactId
+ . ';' . $this->contactEmail
+ . ';' . $this->contactExternalId
+ . ';' . $this->value
+ . ';' . $this->mailingSentTimestamp
+ . ';' . $this->mailingSentTimestampSql
+ . ';' . $this->mailingId
+ . ';' . $this->mailingName
+ . ';' . $this->siteId
+ . ';' . $this->siteName
+ . ';' . $this->goalId
+ . ';' . $this->goalName
+ . ';' . $this->linkId
+ . ';' . $this->linkUrl;
}
/**
* For future use, not implemented yet.
*
- * @return \SimpleXMLElement
- * containing the XML serialization of this object
+ * Serialization to a simple XML element.
+ *
+ * @return SimpleXMLElement contains the serialized representation of the object
+ *
+ * @throws Exception
*/
public function toXML()
{
- $xmlString = "";
- $xml = new \SimpleXMLElement($xmlString);
+ $xmlString = '';
+ $xml = new SimpleXMLElement($xmlString);
if (isset($this->timestamp)) {
- $xml->addChild("timestamp", $this->timestamp);
+ $xml->addChild('timestamp', $this->timestamp);
}
+
if (isset($this->timestamp_sql)) {
- $xml->addChild("timestamp_sql", $this->timestampSql);
+ $xml->addChild('timestamp_sql', $this->timestampSql);
}
+
if (isset($this->contact_id)) {
- $xml->addChild("contact_id", $this->contactId);
+ $xml->addChild('contact_id', $this->contactId);
}
+
if (isset($this->contact_email)) {
- $xml->addChild("contact_email", $this->contactEmail);
+ $xml->addChild('contact_email', $this->contactEmail);
}
+
if (isset($this->contact_external_id)) {
- $xml->addChild("contact_external_id", $this->contactExternalId);
+ $xml->addChild('contact_external_id', $this->contactExternalId);
}
+
if (isset($this->value)) {
- $xml->addChild("value", $this->value);
+ $xml->addChild('value', $this->value);
}
+
if (isset($this->mailing_sent_date)) {
- $xml->addChild("mailing_sent_date", $this->mailingSentTimestamp);
+ $xml->addChild('mailing_sent_date', $this->mailingSentTimestamp);
}
+
if (isset($this->mailing_sent_date_sql)) {
- $xml->addChild("mailing_sent_date_sql", $this->mailingSentTimestampSql);
+ $xml->addChild('mailing_sent_date_sql', $this->mailingSentTimestampSql);
}
+
if (isset($this->mailing_id)) {
- $xml->addChild("mailing_id", $this->mailingId);
+ $xml->addChild('mailing_id', $this->mailingId);
}
+
if (isset($this->mailing_name)) {
- $xml->addChild("mailing_name", $this->mailingName);
+ $xml->addChild('mailing_name', $this->mailingName);
}
+
if (isset($this->site_id)) {
- $xml->addChild("site_id", $this->siteId);
+ $xml->addChild('site_id', $this->siteId);
}
+
if (isset($this->site_name)) {
- $xml->addChild("site_name", $this->siteName);
+ $xml->addChild('site_name', $this->siteName);
}
+
if (isset($this->goal_id)) {
- $xml->addChild("goal_id", $this->goalId);
+ $xml->addChild('goal_id', $this->goalId);
}
+
if (isset($this->goal_name)) {
- $xml->addChild("goal_name", $this->goalName);
+ $xml->addChild('goal_name', $this->goalName);
}
+
if (isset($this->link_id)) {
- $xml->addChild("link_id", $this->linkId);
+ $xml->addChild('link_id', $this->linkId);
}
+
if (isset($this->link_url)) {
- $xml->addChild("link_url", $this->linkUrl);
+ $xml->addChild('link_url', $this->linkUrl);
}
return $xml;
diff --git a/src/reports/FieldBackup.php b/src/reports/FieldBackup.php
index 1475b98..b2790cf 100644
--- a/src/reports/FieldBackup.php
+++ b/src/reports/FieldBackup.php
@@ -6,11 +6,11 @@
* Field Backups are the values of contact fields that have been backed up for mailings
* because of a backup instruction. Note
* that this only applies for non anonymizable field backups.
- *
+ *
* @deprecated Backup instructions are no longer supported
*
- * @author Viktor Balogh (Wiera)
- * @author Marcus Beckerle | XQueue GmbH | marcus.beckerle@xqueue.com
+ * @author Viktor Balogh | XQueue GmbH | viktor.balog@xqueue.com
+ * @author Marcus Beckerle | XQueue GmbH | marcus.beckerle@xqueue.com
*/
class FieldBackup
{
@@ -23,23 +23,24 @@ class FieldBackup
/**
* Constructor initializing a field backup
*
- * @param String $type
- * Indicates the type of the contact field. Supported values are: "standard", "custom"
- * (custom contact fields) and "event" (contact event properties)
- * @param String $subtype
- * Backup instructions of type 'event' require a subtype field containing the event type
- * @param String $name
- * The name of the field
+ * @param String $type Indicates the type of the contact field. Supported values are: "standard", "custom" (custom contact fields)
+ * and "event" (contact event properties)
+ * @param String $subtype Backup instructions of type 'event' require a subtype field containing the event type
+ * @param String $name the name of the field
* @param String $option
- * @param String $value
- * the value of the backuped field
+ * @param String $value the value of the backed field
*/
- public function __construct($type, $subtype, $name, $option, $value)
- {
- $this->type = $type;
+ public function __construct(
+ $type,
+ $subtype,
+ $name,
+ $option,
+ $value
+ ) {
+ $this->type = $type;
$this->subtype = $subtype;
- $this->name = $name;
- $this->option = $option;
- $this->value = $value;
+ $this->name = $name;
+ $this->option = $option;
+ $this->value = $value;
}
}
diff --git a/src/reports/Open.php b/src/reports/Open.php
index a5e851a..7d433fe 100644
--- a/src/reports/Open.php
+++ b/src/reports/Open.php
@@ -3,17 +3,18 @@
namespace de\xqueue\maileon\api\client\reports;
use de\xqueue\maileon\api\client\xml\AbstractXMLWrapper;
+use Exception;
+use SimpleXMLElement;
/**
* This class represents an opener containing the timestamp, the contact, and the ID of the mailing the open.
*
- * @author Marcus Ständer | Trusted Mails GmbH |
- * marcus.staender@trusted-mails.com
+ * @author Marcus Beckerle | XQueue GmbH | marcus.beckerle@xqueue.com
*/
class Open extends AbstractXMLWrapper
{
/**
- * @var integer
+ * @var int
*/
public $timestamp;
@@ -21,24 +22,24 @@ class Open extends AbstractXMLWrapper
* @var ReportContact
*/
public $contact;
-
+
/**
- * @var integer
+ * @var int
*/
public $mailingId;
-
+
/**
* @var string
*/
public $transactionId;
-
+
/**
* @var string
*/
public $contactHash;
-
+
/**
- * @var integer
+ * @var int
*/
public $messageId;
@@ -51,58 +52,52 @@ class Open extends AbstractXMLWrapper
* @var string
*/
public $deviceType;
-
+
/**
+ * Information about the client of the contact
*
- * @var ReportClientInfos Information about the client of the contact
+ * @var ReportClientInfos
*/
public $clientInfos;
-
+
public function __construct()
{
$this->clientInfos = new ReportClientInfos();
}
- /**
- * @return string
- * containing a human-readable representation of this open
- */
- public function toString()
+ public function toString(): string
{
- return "Open [timestamp=" . $this->timestamp .
- ", contact=" . $this->contact->toString() .
- ", mailingId=" . $this->mailingId .
- ", clientInfos=" . $this->clientInfos->toString() .
- ", transactionId=" . $this->transactionId .
- ", contactHash=" . $this->contactHash .
- ", messageId=" . $this->messageId .
- ", format=" . $this->format .
- ", deviceType=" . $this->deviceType . "]";
+ return 'Open ['
+ . 'timestamp=' . $this->timestamp
+ . ', contact=' . $this->contact->toString()
+ . ', mailingId=' . $this->mailingId
+ . ', clientInfos=' . $this->clientInfos->toString()
+ . ', transactionId=' . $this->transactionId
+ . ', contactHash=' . $this->contactHash
+ . ', messageId=' . $this->messageId
+ . ', format=' . $this->format
+ . ', deviceType=' . $this->deviceType
+ . ']';
}
/**
+ * CSV representation of this wrapper.
+ *
* @return string
- * containing a csv pepresentation of this open
*/
- public function toCsvString()
+ public function toCsvString(): string
{
- return $this->timestamp .
- ";" . $this->contact->toCsvString() .
- ";" . $this->mailingId .
- ";" . $this->clientInfos->toCsvString() .
- ";" . $this->transactionId .
- ";" . $this->contactHash .
- ";" . $this->messageId .
- ";" . $this->format .
- ";" . $this->deviceType;
+ return $this->timestamp
+ . ';' . $this->contact->toCsvString()
+ . ';' . $this->mailingId
+ . ';' . $this->clientInfos->toCsvString()
+ . ';' . $this->transactionId
+ . ';' . $this->contactHash
+ . ';' . $this->messageId
+ . ';' . $this->format
+ . ';' . $this->deviceType;
}
- /**
- * Initializes this open from an XML representation.
- *
- * @param \SimpleXMLElement $xmlElement
- * the XML representation to use
- */
public function fromXML($xmlElement)
{
$this->contact = new ReportContact();
@@ -111,24 +106,31 @@ public function fromXML($xmlElement)
if (isset($xmlElement->mailing_id)) {
$this->mailingId = $xmlElement->mailing_id;
}
+
if (isset($xmlElement->timestamp)) {
$this->timestamp = $xmlElement->timestamp;
}
+
if (isset($xmlElement->transaction_id)) {
$this->transactionId = $xmlElement->transaction_id;
}
+
if (isset($xmlElement->contact_hash)) {
$this->contactHash = $xmlElement->contact_hash;
}
+
if (isset($xmlElement->msg_id)) {
$this->messageId = $xmlElement->msg_id;
}
+
if (isset($xmlElement->format)) {
$this->format = $xmlElement->format;
}
+
if (isset($xmlElement->device_type)) {
$this->deviceType = $xmlElement->device_type;
}
+
if (isset($xmlElement->client)) {
$this->clientInfos->fromXML($xmlElement->client);
}
@@ -137,37 +139,47 @@ public function fromXML($xmlElement)
/**
* For future use, not implemented yet.
*
- * @return \SimpleXMLElement
- * containing the XML serialization of this object
+ * Serialization to a simple XML element.
+ *
+ * @return SimpleXMLElement contains the serialized representation of the object
+ *
+ * @throws Exception
*/
public function toXML()
{
- $xmlString = "";
- $xml = new \SimpleXMLElement($xmlString);
+ $xmlString = '';
+ $xml = new SimpleXMLElement($xmlString);
if (isset($this->mailingId)) {
- $xml->addChild("mailing_id", $this->mailingId);
+ $xml->addChild('mailing_id', $this->mailingId);
}
+
if (isset($this->timestamp)) {
- $xml->addChild("timestamp", $this->timestamp);
+ $xml->addChild('timestamp', $this->timestamp);
}
+
if (isset($this->transactionId)) {
- $xml->addChild("transaction_id", $this->transactionId);
+ $xml->addChild('transaction_id', $this->transactionId);
}
+
if (isset($this->contactHash)) {
- $xml->addChild("contact_hash", $this->contactHash);
+ $xml->addChild('contact_hash', $this->contactHash);
}
+
if (isset($this->messageId)) {
- $xml->addChild("msg_id", $this->messageId);
+ $xml->addChild('msg_id', $this->messageId);
}
+
if (isset($this->format)) {
- $xml->addChild("format", $this->format);
+ $xml->addChild('format', $this->format);
}
+
if (isset($this->deviceType)) {
- $xml->addChild("device_type", $this->deviceType);
+ $xml->addChild('device_type', $this->deviceType);
}
+
if (isset($this->clientInfos)) {
- $xml->addChild("client", $this->clientInfos->toXML());
+ $xml->addChild('client', $this->clientInfos->toXML());
}
return $xml;
diff --git a/src/reports/Recipient.php b/src/reports/Recipient.php
index d8a47dd..2147570 100644
--- a/src/reports/Recipient.php
+++ b/src/reports/Recipient.php
@@ -3,17 +3,18 @@
namespace de\xqueue\maileon\api\client\reports;
use de\xqueue\maileon\api\client\xml\AbstractXMLWrapper;
+use Exception;
+use SimpleXMLElement;
/**
* This class represents a recipient containing the timestamp, the contact, and the ID of the mailing.
*
- * @author Marcus Ständer | Trusted Mails GmbH |
- * marcus.staender@trusted-mails.com
+ * @author Marcus Beckerle | XQueue GmbH | marcus.beckerle@xqueue.com
*/
class Recipient extends AbstractXMLWrapper
{
/**
- * @var integer
+ * @var int
*/
public $timestamp;
@@ -23,52 +24,45 @@ class Recipient extends AbstractXMLWrapper
public $contact;
/**
- * @var integer
+ * @var int
*/
public $mailingId;
-
+
/**
* @var string
*/
public $transactionId;
-
+
/**
- * @var integer
+ * @var int
*/
public $messageId;
- /**
- * @return string
- * containing a human-readable representation of this recipient
- */
- public function toString()
+ public function toString(): string
{
- return "Recipient [timestamp=" . $this->timestamp .
- ", contact=" . $this->contact->toString() .
- ", mailingId=" . $this->mailingId .
- ", transactionId=" . $this->transactionId .
- ", messageId=" . $this->messageId ."]";
+ return 'Recipient ['
+ . 'timestamp=' . $this->timestamp
+ . ', contact=' . $this->contact->toString()
+ . ', mailingId=' . $this->mailingId
+ . ', transactionId=' . $this->transactionId
+ . ', messageId=' . $this->messageId
+ . ']';
}
/**
+ * CSV representation of this wrapper.
+ *
* @return string
- * containing a csv pepresentation of this recipient
*/
- public function toCsvString()
+ public function toCsvString(): string
{
- return $this->timestamp .
- ";" . $this->contact->toCsvString() .
- ";" . $this->mailingId .
- ";" . $this->transactionId .
- ";" . $this->messageId;
+ return $this->timestamp
+ . ';' . $this->contact->toCsvString()
+ . ';' . $this->mailingId
+ . ';' . $this->transactionId
+ . ';' . $this->messageId;
}
- /**
- * Initializes this recipient from an XML representation.
- *
- * @param \SimpleXMLElement $xmlElement
- * the XML representation to use
- */
public function fromXML($xmlElement)
{
$this->contact = new ReportContact();
@@ -77,9 +71,11 @@ public function fromXML($xmlElement)
if (isset($xmlElement->mailing_id)) {
$this->mailingId = $xmlElement->mailing_id;
}
+
if (isset($xmlElement->timestamp)) {
$this->timestamp = $xmlElement->timestamp;
}
+
if (isset($xmlElement->transaction_id)) {
$this->transactionId = $xmlElement->transaction_id;
}
@@ -88,25 +84,31 @@ public function fromXML($xmlElement)
/**
* For future use, not implemented yet.
*
- * @return \SimpleXMLElement
- * containing the XML serialization of this object
+ * Serialization to a simple XML element.
+ *
+ * @return SimpleXMLElement contains the serialized representation of the object
+ *
+ * @throws Exception
*/
public function toXML()
{
- $xmlString = "";
- $xml = new \SimpleXMLElement($xmlString);
+ $xmlString = '';
+ $xml = new SimpleXMLElement($xmlString);
if (isset($this->contact)) {
- $xml->addChild("contact", $this->contact->toXML());
- }
+ $xml->addChild('contact', $this->contact->toXML());
+ }
+
if (isset($this->mailingId)) {
- $xml->addChild("mailing_id", $this->mailingId);
+ $xml->addChild('mailing_id', $this->mailingId);
}
+
if (isset($this->timestamp)) {
- $xml->addChild("timestamp", $this->timestamp);
+ $xml->addChild('timestamp', $this->timestamp);
}
+
if (isset($this->transactionId)) {
- $xml->addChild("transaction_id", $this->transactionId);
+ $xml->addChild('transaction_id', $this->transactionId);
}
return $xml;
diff --git a/src/reports/ReportClientInfos.php b/src/reports/ReportClientInfos.php
index 2304b19..5b0342d 100644
--- a/src/reports/ReportClientInfos.php
+++ b/src/reports/ReportClientInfos.php
@@ -2,8 +2,11 @@
namespace de\xqueue\maileon\api\client\reports;
-use de\xqueue\maileon\api\client\contacts\Contact;
use de\xqueue\maileon\api\client\xml\AbstractXMLWrapper;
+use Exception;
+use SimpleXMLElement;
+
+use function filter_var;
/**
* This class represents the client infos from a click or open in the reporting.
@@ -13,143 +16,156 @@
class ReportClientInfos extends AbstractXMLWrapper
{
/**
- * @var String Name of the operating system, e.g. WINDOWS_10
+ * Name of the operating system, e.g. WINDOWS_10
+ *
+ * @var string
*/
public $os;
-
+
/**
- * @var String Group of the operating system, e.g. WINDOWS, LINUX, ...
+ * Group of the operating system, e.g. WINDOWS, LINUX, ...
+ *
+ * @var string
*/
public $osGroup;
-
+
/**
- * @var String Browser name, e.g. CHROME
+ * Browser name, e.g. CHROME
+ *
+ * @var string
*/
public $browser;
-
+
/**
- * @var String Browser group, e.g. CHROME
+ * Browser group, e.g. CHROME
+ *
+ * @var string
*/
public $browserGroup;
-
+
/**
- * @var String Type of the browser, e.g. WebBrowser
+ * Type of the browser, e.g. WebBrowser
+ *
+ * @var string
*/
public $browserType;
-
- /**
- * @var String User-Agent
- */
- public $userAgent;
-
- /**
- * @var String Name of the rendering engine of the browser
- */
- public $renderingEngine;
-
/**
- * Constructor for initializing a Report Contact from a given contact
- * @param Contact $ctontact
+ * User-Agent
+ *
+ * @var string
*/
- public function __construct() {
-
- }
+ public $userAgent;
/**
- * Initialization of the client infos from a simple xml element.
+ * Name of the rendering engine of the browser
*
- * @param \SimpleXMLElement $xmlElement
- * The xml element that is used to parse the contact list from.
+ * @var string
*/
- public function fromXML($xmlElement) {
-
- if ($xmlElement) {
+ public $renderingEngine;
+ public function fromXML($xmlElement)
+ {
+ if ($xmlElement) {
if (isset($xmlElement->os_name)) {
$this->os = filter_var($xmlElement->os_name, FILTER_SANITIZE_STRING);
}
+
if (isset($xmlElement->os_group)) {
$this->osGroup = filter_var($xmlElement->os_group, FILTER_SANITIZE_STRING);
}
+
if (isset($xmlElement->browser)) {
$this->browser = filter_var($xmlElement->browser, FILTER_SANITIZE_STRING);
}
+
if (isset($xmlElement->browser_group)) {
$this->browserGroup = filter_var($xmlElement->browser_group, FILTER_SANITIZE_STRING);
}
+
if (isset($xmlElement->browser_type)) {
$this->browserType = filter_var($xmlElement->browser_type, FILTER_SANITIZE_STRING);
}
+
if (isset($xmlElement->user_agent)) {
$this->userAgent = filter_var($xmlElement->user_agent, FILTER_SANITIZE_STRING);
}
+
if (isset($xmlElement->rendering_engine)) {
$this->renderingEngine = filter_var($xmlElement->rendering_engine, FILTER_SANITIZE_STRING);
}
}
}
-
/**
+ * CSV representation of this wrapper.
+ *
* @return string
- * containing a csv pepresentation of the client infos
*/
- public function toCsvString() {
- return $this->os .
- ";" . $this->osGroup .
- ";" . $this->browser .
- ";" . $this->browserGroup .
- ";" . $this->browserType .
- ";" . $this->userAgent .
- ";" . $this->renderingEngine;
+ public function toCsvString(): string
+ {
+ return $this->os
+ . ';' . $this->osGroup
+ . ';' . $this->browser
+ . ';' . $this->browserGroup
+ . ';' . $this->browserType
+ . ';' . $this->userAgent
+ . ';' . $this->renderingEngine;
}
-
- /**
- * @return string
- * containing a human-readable representation of this client info
- */
- public function toString()
+
+ public function toString(): string
{
- return "ClientInfos [os=" . $this->os .
- ", osGroup=" . $this->osGroup .
- ", browser=" . $this->browser .
- ", browserGroup=" . $this->browserGroup .
- ", browserType=" . $this->browserType .
- ", userAgent=" . $this->userAgent .
- ", renderingEngine=" . $this->renderingEngine . "]";
+ return 'ClientInfos ['
+ . 'os=' . $this->os
+ . ', osGroup=' . $this->osGroup
+ . ', browser=' . $this->browser
+ . ', browserGroup=' . $this->browserGroup
+ . ', browserType=' . $this->browserType
+ . ', userAgent=' . $this->userAgent
+ . ', renderingEngine=' . $this->renderingEngine
+ . ']';
}
-
+
/**
* For future use, not implemented yet.
*
- * @return \SimpleXMLElement
- * containing the XML serialization of this object
+ * Serialization to a simple XML element.
+ *
+ * @return SimpleXMLElement contains the serialized representation of the object
+ *
+ * @throws Exception
*/
- public function toXML() {
- $xmlString = "";
- $xml = new \SimpleXMLElement($xmlString);
+ public function toXML()
+ {
+ $xmlString = '';
+ $xml = new SimpleXMLElement($xmlString);
if (isset($this->os)) {
- $xml->addChild("os_name", $this->os);
+ $xml->addChild('os_name', $this->os);
}
+
if (isset($this->osGroup)) {
- $xml->addChild("os_group", $this->osGroup);
+ $xml->addChild('os_group', $this->osGroup);
}
+
if (isset($this->browser)) {
- $xml->addChild("browser", $this->browser);
+ $xml->addChild('browser', $this->browser);
}
+
if (isset($this->browserGroup)) {
- $xml->addChild("browser_group", $this->browserGroup);
+ $xml->addChild('browser_group', $this->browserGroup);
}
+
if (isset($this->browserType)) {
- $xml->addChild("browser_type", $this->browserType);
+ $xml->addChild('browser_type', $this->browserType);
}
+
if (isset($this->userAgent)) {
- $xml->addChild("user_agent", $this->userAgent);
+ $xml->addChild('user_agent', $this->userAgent);
}
+
if (isset($this->renderingEngine)) {
- $xml->addChild("rendering_engine", $this->renderingEngine);
+ $xml->addChild('rendering_engine', $this->renderingEngine);
}
return $xml;
diff --git a/src/reports/ReportContact.php b/src/reports/ReportContact.php
index b56580c..cb18622 100644
--- a/src/reports/ReportContact.php
+++ b/src/reports/ReportContact.php
@@ -6,71 +6,74 @@
use de\xqueue\maileon\api\client\contacts\Permission;
use de\xqueue\maileon\api\client\xml\XMLDeserializer;
+use function trim;
+
/**
* This class represents a contact in the reporting. Such a contact not only contains the contact
* properties but also the field backups (at sending time).
*
- * @author Viktor Balogh (Wiera)
- * @author Marcus Ständer | Trusted Mails GmbH |
- * marcus.staender@trusted-mails.com
+ * @author Viktor Balogh | XQueue GmbH | viktor.balog@xqueue.com
+ * @author Marcus Beckerle | XQueue GmbH | marcus.beckerle@xqueue.com
*/
class ReportContact extends Contact
{
/**
* Field Backups are the values of contact fields that have been backed up for mailings
- * because of a backup instruction. Note
- * that this only applies for non anonymizable field backups.
+ * because of a backup instruction. Note that this only applies for non anonymizable field backups.
+ *
+ * FieldBackup[]
*
- * @var array of FieldBackup
+ * @var array
*/
- public $fieldBackups = array();
+ public $fieldBackups = [];
/**
* Constructor for initializing a Report Contact from a given contact
+ *
* @param Contact $contact
*/
public function __construct($contact = null)
{
+ // parent::__construct() ?
+
if (isset($contact)) {
- $this->anonymous = $contact->anonymous;
- $this->email = $contact->email;
- $this->external_id = $contact->external_id;
- $this->id = $contact->id;
- $this->created = $contact->created;
- $this->updated = $contact->updated;
- $this->permission = $contact->permission;
+ $this->anonymous = $contact->anonymous;
+ $this->email = $contact->email;
+ $this->external_id = $contact->external_id;
+ $this->id = $contact->id;
+ $this->created = $contact->created;
+ $this->updated = $contact->updated;
+ $this->permission = $contact->permission;
$this->standard_fields = $contact->standard_fields;
- $this->custom_fields = $contact->custom_fields;
+ $this->custom_fields = $contact->custom_fields;
}
}
- /**
- * Initialization of the report contact from a simple xml element.
- *
- * @param \SimpleXMLElement $xmlElement
- * The xml element that is used to parse the contact list from.
- */
public function fromXML($xmlElement)
{
parent::fromXML($xmlElement);
if (isset($xmlElement->permissionType)) {
- $this->permission = Permission::getPermission($xmlElement->permissionType);
+ $this->permission = Permission::getPermission((int) $xmlElement->permissionType);
}
+
if (isset($xmlElement->standard_fields)) {
- $this->standard_fields = array();
+ $this->standard_fields = [];
+
foreach ($xmlElement->standard_fields->children() as $field) {
- $this->standard_fields[trim($field->name)] = (string)$field->value;
+ $this->standard_fields[trim($field->name)] = (string) $field->value;
// The trim is required to make a safer string from the object
}
}
+
if (isset($xmlElement->custom_fields)) {
foreach ($xmlElement->custom_fields->children() as $field) {
- $this->custom_fields[trim($field->name)] = (string)$field->value;
+ $this->custom_fields[trim($field->name)] = (string) $field->value;
// The trim is required to make a safer string from the object
}
}
+
if (isset($xmlElement->field_backups)) {
$this->fieldBackups = XMLDeserializer::deserialize($xmlElement->field_backups);
}
diff --git a/src/reports/ReportsService.php b/src/reports/ReportsService.php
index 6f932d3..f608fbe 100644
--- a/src/reports/ReportsService.php
+++ b/src/reports/ReportsService.php
@@ -3,72 +3,60 @@
namespace de\xqueue\maileon\api\client\reports;
use de\xqueue\maileon\api\client\AbstractMaileonService;
+use de\xqueue\maileon\api\client\MaileonAPIException;
use de\xqueue\maileon\api\client\MaileonAPIResult;
+use Exception;
/**
*
*
- * @author Viktor Balogh (Wiera)
- * @author Marcus Ständer | Trusted Mails GmbH |
- * marcus.staender@trusted-mails.com
+ * @author Viktor Balogh | XQueue GmbH | viktor.balog@xqueue.com
+ * @author Marcus Beckerle | XQueue GmbH | marcus.beckerle@xqueue.com
*/
class ReportsService extends AbstractMaileonService
{
-
-
-
/**
* Returns a page of openers.
*
- * @param integer $fromDate
- * If provided, only the openers after the given date will be returned. The value of
- * from_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param integer $toDate
- * If provided, only the openers before the given date will be returned.
- * The value of to_date must be a numeric value representing a point in time
- * milliseconds afterJanuary 1, 1970 00:00:00
- * @param array $mailingIds
- * Multivalued parameter to filter the openers by mailings. Each value must correspond to a mailing id.
- * @param array $contactIds
- * Multivalued parameter to filter the openers by contacts. Each value must correspond to a contact id.
- * @param array $contactEmails
- * Multivalued parameter to filter the openers by email addresses.
- * @param array $contactExternalIds
- * Multivalued parameter to filter the openers by external ids. Each value must correspond
- * to a contacts external id.
- * @param string $formatFilter
- * Filters the opens by format. Possible values are: html / text.
- * @param array $socialNetworkFilter
- * Multivalued parameter to filter the opens by the social networks where they occurred.
- * @param array $deviceTypeFilter
- * Multivalued parameter to filter the opens by device type. Possible values for
- * device_type are: UNKNOWN / COMPUTER / TABLET / MOBILE
- * @param bool $embedEmailClientInfos
- * If the set to true, available email client details will be appended to each open.
- * @param bool $excludeAnonymousOpens
- * If this is set to true (default), only openers that have not yet been anonymized
- * (due to deletion/unsubscription) are returned.
- * @param array $standardFields
- * The list of standard contact fields to return.
- * @param array $customFields
- * The list of custom contact fields to return.
- * @param bool $embedFieldBackups
- * Supported values: true / false. Field Backups are the values of contact fields that have been
- * backed up for mailings because of a backup instruction. For each unsubscription, the corresponding
- * field backups will be returned if available. Note that this only applies for non anonymizable field backups.
- * @param integer $pageIndex
- * The index of the result page. The index must be greater or equal to 1.
- * @param integer $pageSize
- * The maximum count of items in the result page. If provided, the value of
- * page_size must be in the range 1 to 1000.
- * @param bool $embedTransactionId
- * If the set to true, the attribut "transaction_id" of a transaction will be returned that caused this open, if available.
- * @param bool $embedContactHash
- * If the set to true, anonymized contacts will be annotated with a random number that is the same for a contact within each sendout.
- * With this flag, it is possible to calculate unique opens from all opens, even if contacts are unsubscribed and therefore anonymized.
- * If in two opens of the same sendout the contact hash is the same, then the same contact opened twice.
- * In different mails the same contact hash might occur on an open but will most probably not belong to the same (anonymized) contact.
- * @return MaileonAPIResult
+ * @param int $fromDate If provided, only the openers after the given date will be returned. The value of from_date must
+ * be a numeric value representing a point in time milliseconds after January 1, 1970 00:00:00
+ * @param int $toDate If provided, only the openers before the given date will be returned. The value of to_date must
+ * be a numeric value representing a point in time milliseconds after January 1, 1970 00:00:00
+ * @param array $mailingIds Multivalued parameter to filter the openers by mailings. Each value must correspond to a mailing
+ * id.
+ * @param array $contactIds Multivalued parameter to filter the openers by contacts. Each value must correspond to a contact
+ * id.
+ * @param array $contactEmails Multivalued parameter to filter the openers by email addresses.
+ * @param array $contactExternalIds Multivalued parameter to filter the openers by external ids. Each value must correspond to a
+ * contacts external id.
+ * @param string $formatFilter Filters the opens by format. Possible values are: html / text.
+ * @param array $socialNetworkFilter Multivalued parameter to filter the opens by the social networks where they occurred.
+ * @param array $deviceTypeFilter Multivalued parameter to filter the opens by device type. Possible values for device_type are:
+ * UNKNOWN / COMPUTER / TABLET / MOBILE
+ * @param bool $embedEmailClientInfos If the set to true, available email client details will be appended to each open.
+ * @param bool $excludeAnonymousOpens If this is set to true (default), only openers that have not yet been anonymized (due to
+ * deletion/unsubscription) are returned.
+ * @param array $standardFields The list of standard contact fields to return.
+ * @param array $customFields The list of custom contact fields to return.
+ * @param bool $embedFieldBackups Supported values: true / false. Field Backups are the values of contact fields that have been
+ * backed up for mailings because of a backup instruction. For each unsubscription, the
+ * corresponding field backups will be returned if available. Note that this only applies for non
+ * anonymizable field backups.
+ * @param int $pageIndex The index of the result page. The index must be greater or equal to 1.
+ * @param int $pageSize The maximum count of items in the result page. If provided, the value of page_size must be in
+ * the range 1 to 1000.
+ * @param bool $embedTransactionId If the set to true, the attribut "transaction_id" of a transaction will be returned that caused
+ * this open, if available.
+ * @param bool $embedContactHash If the set to true, anonymized contacts will be annotated with a random number that is the same
+ * for a contact within each sendout. With this flag, it is possible to calculate unique opens from
+ * all opens, even if contacts are unsubscribed and therefore anonymized. If in two opens of the
+ * same sendout the contact hash is the same, then the same contact opened twice. In different
+ * mails the same contact hash might occur on an open but will most probably not belong to the same
+ * (anonymized) contact.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getOpens(
$fromDate = null,
@@ -103,69 +91,68 @@ public function getOpens(
$embedFieldBackups
);
- $params = $this->appendArrayFields($params, "standard_field", $standardFields);
- $params = $this->appendArrayFields($params, "custom_field", $customFields);
+ $params = $this->appendArrayFields($params, 'standard_field', $standardFields);
+ $params = $this->appendArrayFields($params, 'custom_field', $customFields);
+
if (isset($embedEmailClientInfos)) {
- $params['embed_email_client_infos'] = ($embedEmailClientInfos == true) ? "true" : "false";
+ $params['embed_email_client_infos'] = $embedEmailClientInfos === true ? 'true' : 'false';
}
+
if (isset($excludeAnonymousOpens)) {
- $params['exclude_anonymous_opens'] = ($excludeAnonymousOpens == true) ? "true" : "false";
+ $params['exclude_anonymous_opens'] = $excludeAnonymousOpens === true ? 'true' : 'false';
}
if (isset($formatFilter)) {
$params['format'] = $formatFilter;
}
+
if (isset($embedTransactionId)) {
- $params['embed_transaction_id'] = ($embedTransactionId == true) ? "true" : "false";
+ $params['embed_transaction_id'] = $embedTransactionId === true ? 'true' : 'false';
}
+
if (isset($embedContactHash)) {
- $params['embed_contact_hash'] = ($embedContactHash == true) ? "true" : "false";
+ $params['embed_contact_hash'] = $embedContactHash === true ? 'true' : 'false';
}
- $params = $this->appendArrayFields($params, "social_network", $socialNetworkFilter);
- $params = $this->appendArrayFields($params, "device_type", $deviceTypeFilter);
- return $this->get('reports/opens', $params);
+ $params = $this->appendArrayFields($params, 'social_network', $socialNetworkFilter);
+ $params = $this->appendArrayFields($params, 'device_type', $deviceTypeFilter);
+
+ return $this->get(
+ 'reports/opens',
+ $params
+ );
}
/**
* Returns a page of unique openers.
*
- * @param integer $fromDate
- * If provided, only the openers after the given date will be returned. The value of from_date
- * must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param integer $toDate
- * If provided, only the openers before the given date will be returned.
- * The value of to_date must be a numeric value representing a point in time
- * milliseconds afterJanuary 1, 1970 00:00:00
- * @param array $mailingIds
- * Multivalued parameter to filter the openers by mailings. Each value must correspond to a mailing id.
- * @param array $contactIds
- * Multivalued parameter to filter the openers by contacts. Each value must correspond to a contact id.
- * @param array $contactEmails
- * Multivalued parameter to filter the openers by email addresses.
- * @param array $contactExternalIds
- * Multivalued parameter to filter the openers by external ids. Each value must
- * correspond to a contacts external id.
- * @param bool $embedEmailClientInfos
- * If the set to true, available email client details will be appended to each open.
- * @param bool $excludeAnonymousOpens
- * If this is set to true (default), only openers that have not yet been
- * anonymized (due to deletion/unsubscription) are returned.
- * @param array $standardFields
- * The list of standard contact fields to return.
- * @param array $customFields
- * The list of custom contact fields to return.
- * @param bool $embedFieldBackups
- * Supported values: true / false. Field Backups are the values of contact fields that have
- * been backed up for mailings because of a backup instruction. For each unsubscription,
- * the corresponding field backups will be returned if available. Note that this only
- * applies for non anonymizable field backups.
- * @param integer $pageIndex
- * The index of the result page. The index must be greater or equal to 1.
- * @param integer $pageSize
- * The maximum count of items in the result page. If provided, the value of page_size
- * must be in the range 1 to 1000.
- * @return MaileonAPIResult
+ * @param int $fromDate If provided, only the openers after the given date will be returned. The value of from_date must
+ * be a numeric value representing a point in time milliseconds after January 1, 1970 00:00:00
+ * @param int $toDate If provided, only the openers before the given date will be returned. The value of to_date must
+ * be a numeric value representing a point in time milliseconds after January 1, 1970 00:00:00
+ * @param array $mailingIds Multivalued parameter to filter the openers by mailings. Each value must correspond to a mailing
+ * id.
+ * @param array $contactIds Multivalued parameter to filter the openers by contacts. Each value must correspond to a contact
+ * id.
+ * @param array $contactEmails Multivalued parameter to filter the openers by email addresses.
+ * @param array $contactExternalIds Multivalued parameter to filter the openers by external ids. Each value must correspond to a
+ * contacts external id.
+ * @param bool $embedEmailClientInfos If the set to true, available email client details will be appended to each open.
+ * @param bool $excludeAnonymousOpens If this is set to true (default), only openers that have not yet been anonymized (due to
+ * deletion/unsubscription) are returned.
+ * @param array $standardFields The list of standard contact fields to return.
+ * @param array $customFields The list of custom contact fields to return.
+ * @param bool $embedFieldBackups Supported values: true / false. Field Backups are the values of contact fields that have been
+ * backed up for mailings because of a backup instruction. For each unsubscription, The
+ * corresponding field backups will be returned if available. Note that this only applies for non
+ * anonymizable field backups.
+ * @param int $pageIndex The index of the result page. The index must be greater or equal to 1.
+ * @param int $pageSize The maximum count of items in the result page. If provided, the value of page_size must be in the
+ * range 1 to 1000.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getUniqueOpens(
$fromDate = null,
@@ -199,57 +186,60 @@ public function getUniqueOpens(
$embedFieldBackups
);
- $params = $this->appendArrayFields($params, "standard_field", $standardFields);
- $params = $this->appendArrayFields($params, "custom_field", $customFields);
+ $params = $this->appendArrayFields($params, 'standard_field', $standardFields);
+ $params = $this->appendArrayFields($params, 'custom_field', $customFields);
+
if (isset($embedEmailClientInfos)) {
- $params['embed_email_client_infos'] = ($embedEmailClientInfos == true) ? "true" : "false";
+ $params['embed_email_client_infos'] = $embedEmailClientInfos === true ? 'true' : 'false';
}
+
if (isset($excludeAnonymousOpens)) {
- $params['exclude_anonymous_opens'] = ($excludeAnonymousOpens == true) ? "true" : "false";
+ $params['exclude_anonymous_opens'] = $excludeAnonymousOpens === true ? 'true' : 'false';
}
+
if (isset($formatFilter)) {
$params['format'] = $formatFilter;
}
+
if (isset($embedTransactionId)) {
- $params['embed_transaction_id'] = ($embedTransactionId == true) ? "true" : "false";
+ $params['embed_transaction_id'] = $embedTransactionId === true ? 'true' : 'false';
}
- $params = $this->appendArrayFields($params, "social_network", $socialNetworkFilter);
- $params = $this->appendArrayFields($params, "device_type", $deviceTypeFilter);
- return $this->get('reports/opens/unique', $params);
+ $params = $this->appendArrayFields($params, 'social_network', $socialNetworkFilter);
+ $params = $this->appendArrayFields($params, 'device_type', $deviceTypeFilter);
+
+ return $this->get(
+ 'reports/opens/unique',
+ $params
+ );
}
/**
* Count openers.
*
- * @param integer $fromDate
- * If provided, only the openers after the given date will be returned.
- * The value of from_date must be a numeric value representing a point in time
- * milliseconds afterJanuary 1, 1970 00:00:00
- * @param integer $toDate
- * If provided, only the openers before the given date will be returned.
- * The value of to_date must be a numeric value representing a point in time
- * milliseconds afterJanuary 1, 1970 00:00:00
- * @param array $mailingIds
- * Multivalued parameter to filter the openers by mailings. Each value must correspond to a mailing id.
- * @param array $contactIds
- * Multivalued parameter to filter the openers by contacts. Each value must correspond to a contact id.
- * @param array $contactEmails
- * Multivalued parameter to filter the openers by email addresses.
- * @param array $contactExternalIds
- * Multivalued parameter to filter the openers by external ids. Each value must
- * correspond to a contacts external id.
- * @param string $formatFilter
- * Filters the opens by format. Possible values are: html / text.
- * @param array $socialNetworkFilter
- * Multivalued parameter to filter the opens by the social networks where they occurred.
- * @param array $deviceTypeFilter
- * Multivalued parameter to filter the opens by device type. Possible values for
- * device_type are: UNKNOWN / COMPUTER / TABLET / MOBILE
- * @param bool $excludeAnonymousOpens
- * If this is set to true (default), only openers that have not yet been
- * anonymized (due to deletion/unsubscription) are returned.
- * @return MaileonAPIResult
+ * @param int $fromDate If provided, only the openers after the given date will be returned. The value of from_date
+ * must be a numeric value representing a point in time milliseconds after
+ * January 1, 1970 00:00:00
+ * @param int $toDate If provided, only the openers before the given date will be returned. The value of to_date must
+ * be a numeric value representing a point in time milliseconds after
+ * January 1, 1970 00:00:00
+ * @param array $mailingIds Multivalued parameter to filter the openers by mailings. Each value must correspond to a mailing
+ * id.
+ * @param array $contactIds Multivalued parameter to filter the openers by contacts. Each value must correspond to a contact
+ * id.
+ * @param array $contactEmails Multivalued parameter to filter the openers by email addresses.
+ * @param array $contactExternalIds Multivalued parameter to filter the openers by external ids. Each value must correspond to a
+ * contacts external id.
+ * @param string $formatFilter Filters the opens by format. Possible values are: html / text.
+ * @param array $socialNetworkFilter Multivalued parameter to filter the opens by the social networks where they occurred.
+ * @param array $deviceTypeFilter Multivalued parameter to filter the opens by device type. Possible values for device_type are:
+ * UNKNOWN / COMPUTER / TABLET / MOBILE
+ * @param bool $excludeAnonymousOpens If this is set to true (default), only openers that have not yet been anonymized (due to
+ * deletion/unsubscription) are returned.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getOpensCount(
$fromDate = null,
@@ -274,41 +264,42 @@ public function getOpensCount(
);
if (isset($excludeAnonymousOpens)) {
- $params['exclude_anonymous_opens'] = ($excludeAnonymousOpens == true) ? "true" : "false";
+ $params['exclude_anonymous_opens'] = $excludeAnonymousOpens === true ? 'true' : 'false';
}
if (isset($formatFilter)) {
$params['format'] = $formatFilter;
}
- $params = $this->appendArrayFields($params, "social_network", $socialNetworkFilter);
- $params = $this->appendArrayFields($params, "device_type", $deviceTypeFilter);
- return $this->get('reports/opens/count', $params);
+ $params = $this->appendArrayFields($params, 'social_network', $socialNetworkFilter);
+ $params = $this->appendArrayFields($params, 'device_type', $deviceTypeFilter);
+
+ return $this->get(
+ 'reports/opens/count',
+ $params
+ );
}
/**
* Count unique openers.
*
- * @param integer $fromDate
- * If provided, only the openers after the given date will be returned. The value of
- * from_date must be a numeric value representing a point in time milliseconds
- * afterJanuary 1, 1970 00:00:00
- * @param integer $toDate
- * If provided, only the openers before the given date will be returned. The value
- * of to_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param array $mailingIds
- * Multivalued parameter to filter the openers by mailings. Each value must correspond to a mailing id.
- * @param array $contactIds
- * Multivalued parameter to filter the openers by contacts. Each value must correspond to a contact id.
- * @param array $contactEmails
- * Multivalued parameter to filter the openers by email addresses.
- * @param array $contactExternalIds
- * Multivalued parameter to filter the openers by external ids. Each value
- * must correspond to a contacts external id.
- * @param bool $excludeAnonymousOpens
- * If this is set to true (default), only openers that have not yet been anonymized
- * (due to deletion/unsubscription) are returned.
- * @return MaileonAPIResult
+ * @param int $fromDate If provided, only the openers after the given date will be returned. The value of from_date must
+ * be a numeric value representing a point in time milliseconds after January 1, 1970 00:00:00
+ * @param int $toDate If provided, only the openers before the given date will be returned. The value of to_date must
+ * be a numeric value representing a point in time milliseconds after January 1, 1970 00:00:00
+ * @param array $mailingIds Multivalued parameter to filter the openers by mailings. Each value must correspond to a mailing
+ * id.
+ * @param array $contactIds Multivalued parameter to filter the openers by contacts. Each value must correspond to a contact
+ * id.
+ * @param array $contactEmails Multivalued parameter to filter the openers by email addresses.
+ * @param array $contactExternalIds Multivalued parameter to filter the openers by external ids. Each value must correspond to a
+ * contacts external id.
+ * @param bool $excludeAnonymousOpens If this is set to true (default), only openers that have not yet been anonymized (due to
+ * deletion/unsubscription) are returned.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getUniqueOpensCount(
$fromDate = null,
@@ -333,53 +324,53 @@ public function getUniqueOpensCount(
);
if (isset($excludeAnonymousOpens)) {
- $params['exclude_anonymous_opens'] = ($excludeAnonymousOpens == true) ? "true" : "false";
+ $params['exclude_anonymous_opens'] = $excludeAnonymousOpens === true ? 'true' : 'false';
}
+
if (isset($formatFilter)) {
$params['format'] = $formatFilter;
}
- $params = $this->appendArrayFields($params, "social_network", $socialNetworkFilter);
- $params = $this->appendArrayFields($params, "device_type", $deviceTypeFilter);
- return $this->get('reports/opens/unique/count', $params);
+ $params = $this->appendArrayFields($params, 'social_network', $socialNetworkFilter);
+ $params = $this->appendArrayFields($params, 'device_type', $deviceTypeFilter);
+
+ return $this->get(
+ 'reports/opens/unique/count',
+ $params
+ );
}
/**
* Returns a page of recipients.
*
- * @param integer $fromDate
- * If provided, only the recipients after the given date will be returned. The value of
- * from_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param integer $toDate
- * If provided, only the recipients before the given date will be returned. The value of
- * to_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param array $mailingIds
- * Multivalued parameter to filter the recipients by mailings. Each value must correspond to a mailing id.
- * @param array $contactIds
- * Multivalued parameter to filter the recipients by contacts. Each value must correspond to a contact id.
- * @param array $contactEmails
- * Multivalued parameter to filter the recipients by email addresses.
- * @param array $contactExternalIds
- * Multivalued parameter to filter the recipients by external ids. Each value must
- * correspond to a contacts external id.
- * @param bool $excludeDeletedRecipients
- * Supported values: true / false. If set to true, the recipients that have been removed from
- * maileon will be excluded.
- * @param array $standardFields
- * The list of standard contact fields to return.
- * @param array $customFields
- * The list of custom contact fields to return.
- * @param bool $embedFieldBackups
- * Supported values: true / false. Field Backups are the values of contact fields that have
- * been backed up for mailings because of a backup instruction. For each unsubscription, the
- * corresponding field backups will be returned if available. Note that this only applies for
- * non anonymizable field backups.
- * @param integer $pageIndex
- * The index of the result page. The index must be greater or equal to 1.
- * @param integer $pageSize
- * The maximum count of items in the result page. If provided, the value of
- * page_size must be in the range 1 to 1000.
- * @return MaileonAPIResult
+ * @param int $fromDate If provided, only the recipients after the given date will be returned. The value of from_date
+ * must be a numeric value representing a point in time milliseconds after
+ * January 1, 1970 00:00:00
+ * @param int $toDate If provided, only the recipients before the given date will be returned. The value of to_date
+ * must be a numeric value representing a point in time milliseconds after
+ * January 1, 1970 00:00:00
+ * @param array $mailingIds Multivalued parameter to filter the recipients by mailings. Each value must correspond to a
+ * mailing id.
+ * @param array $contactIds Multivalued parameter to filter the recipients by contacts. Each value must correspond to a
+ * contact id.
+ * @param array $contactEmails Multivalued parameter to filter the recipients by email addresses.
+ * @param array $contactExternalIds Multivalued parameter to filter the recipients by external ids. Each value must correspond to
+ * a contacts external id.
+ * @param bool $excludeDeletedRecipients Supported values: true / false. If set to true, the recipients that have been removed from
+ * maileon will be excluded.
+ * @param array $standardFields The list of standard contact fields to return.
+ * @param array $customFields The list of custom contact fields to return.
+ * @param bool $embedFieldBackups Supported values: true / false. Field Backups are the values of contact fields that have been
+ * backed up for mailings because of a backup instruction. For each unsubscription, the
+ * corresponding field backups will be returned if available. Note that this only applies for non
+ * anonymizable field backups.
+ * @param int $pageIndex The index of the result page. The index must be greater or equal to 1.
+ * @param int $pageSize The maximum count of items in the result page. If provided, the value of page_size must be in
+ * the range 1 to 1000.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getRecipients(
$fromDate = null,
@@ -408,40 +399,45 @@ public function getRecipients(
null,
$embedFieldBackups
);
- $params = $this->appendArrayFields($params, "standard_field", $standardFields);
- $params = $this->appendArrayFields($params, "custom_field", $customFields);
+ $params = $this->appendArrayFields($params, 'standard_field', $standardFields);
+ $params = $this->appendArrayFields($params, 'custom_field', $customFields);
+
if (isset($excludeDeletedRecipients)) {
- $params['exclude_deleted_recipients'] = ($excludeDeletedRecipients == true) ? "true" : "false";
+ $params['exclude_deleted_recipients'] = $excludeDeletedRecipients === true ? 'true' : 'false';
}
+
if (isset($embedTransactionId)) {
- $params['embed_transaction_id'] = ($embedTransactionId == true) ? "true" : "false";
+ $params['embed_transaction_id'] = $embedTransactionId === true ? 'true' : 'false';
}
- return $this->get('reports/recipients', $params);
+ return $this->get(
+ 'reports/recipients',
+ $params
+ );
}
/**
* Count recipients.
*
- * @param integer $fromDate
- * If provided, only the recipients after the given date will be returned. The value of
- * from_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param integer $toDate
- * If provided, only the recipients before the given date will be returned. The value of
- * to_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param array $mailingIds
- * Multivalued parameter to filter the recipients by mailings. Each value must correspond to a mailing id.
- * @param array $contactIds
- * Multivalued parameter to filter the recipients by contacts. Each value must correspond to a contact id.
- * @param array $contactEmails
- * Multivalued parameter to filter the recipients by email addresses.
- * @param array $contactExternalIds
- * Multivalued parameter to filter the recipients by external ids. Each value must
- * correspond to a contacts external id.
- * @param bool $excludeDeletedRecipients
- * Supported values: true / false. If set to true, the recipients that have been
- * removed from maileon will be excluded.
- * @return MaileonAPIResult
+ * @param int $fromDate If provided, only the recipients after the given date will be returned. The value of from_date
+ * must be a numeric value representing a point in time milliseconds after
+ * January 1, 1970 00:00:00
+ * @param int $toDate If provided, only the recipients before the given date will be returned. The value of to_date
+ * must be a numeric value representing a point in time milliseconds after
+ * January 1, 1970 00:00:00
+ * @param array $mailingIds Multivalued parameter to filter the recipients by mailings. Each value must correspond to a
+ * mailing id.
+ * @param array $contactIds Multivalued parameter to filter the recipients by contacts. Each value must correspond to a
+ * contact id.
+ * @param array $contactEmails Multivalued parameter to filter the recipients by email addresses.
+ * @param array $contactExternalIds Multivalued parameter to filter the recipients by external ids. Each value must correspond to
+ * a contacts external id.
+ * @param bool $excludeDeletedRecipients Supported values: true / false. If set to true, the recipients that have been removed from
+ * maileon will be excluded.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getRecipientsCount(
$fromDate = null,
@@ -463,72 +459,63 @@ public function getRecipientsCount(
);
if (isset($excludeDeletedRecipients)) {
- $params['exclude_deleted_recipients'] = ($excludeDeletedRecipients == true) ? "true" : "false";
+ $params['exclude_deleted_recipients'] = $excludeDeletedRecipients === true ? 'true' : 'false';
}
- return $this->get('reports/recipients/count', $params);
+ return $this->get(
+ 'reports/recipients/count',
+ $params
+ );
}
-
/**
* Returns a page of clickers.
*
- * @param integer $fromDate
- * If provided, only the clickers after the given date will be returned. The value of
- * from_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param integer $toDate
- * If provided, only the clickers before the given date will be returned. The value of
- * to_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param array $mailingIds
- * Multivalued parameter to filter the clickers by mailings. Each value must correspond to a mailing id.
- * @param array $contactIds
- * Multivalued parameter to filter the clickers by contacts. Each value must correspond to a contact id.
- * @param array $contactEmails
- * Multivalued parameter to filter the clickers by email addresses.
- * @param array $contactExternalIds
- * Multivalued parameter to filter the clickers by external ids. Each value must correspond
- * to a contacts external id.
- * @param string $formatFilter
- * Filters the opens by format. Possible values are: html / text.
- * @param array $linkIdFilter
- * Multivalued parameter to filter the clicks by links. Each value must correspond to a link id.
- * @param string $linkUrlFilter
- * Filters the clicks by link url.
- * @param array $linkTagFilter
- * Multivalued parameter to filter the clicks by tags associated to the links.
- * @param array $socialNetworkFilter
- * Multivalued parameter to filter the opens by the social networks where they occurred.
- * @param array $deviceTypeFilter
- * Multivalued parameter to filter the opens by device type. Possible values for device_type
- * are: UNKNOWN / COMPUTER / TABLET / MOBILE
- * @param bool $embedEmailClientInfos
- * If the set to true, available email client details will be appended to each open.
- * @param bool $excludeAnonymousClicks
- * If this is set to true (default), only clicks that have not yet been anonymized
- * (due to deletion/unsubscription) are returned.
- * @param array $standardFields
- * The list of standard contact fields to return.
- * @param array $customFields
- * The list of custom contact fields to return.
- * @param bool $embedFieldBackups
- * Supported values: true / false. Field Backups are the values of contact fields that have been backed
- * up for mailings because of a backup instruction. For each unsubscription, the corresponding field
- * backups will be returned if available. Note that this only applies for non anonymizable field backups.
- * @param integer $pageIndex
- * The index of the result page. The index must be greater or equal to 1.
- * @param integer $pageSize
- * The maximum count of items in the result page. If provided, the value of page_size must be in
- * the range 1 to 1000.
- * @param bool $embedLinkTags
- * If the set to true, available link tags will be appended to each click.
- * @param bool $embedTransactionId
- * If the set to true, the attribut "transaction_id" of a transaction will be returned that caused this click, if available.
- * @param bool $embedContactHash
- * If the set to true, anonymized contacts will be annotated with a random number that is the same for a contact within each sendout.
- * With this flag, it is possible to calculate unique clicks from all clicks, even if contacts are unsubscribed and therefore anonymized.
- * If in two clicks of the same sendout the contact hash is the same, then the same contact clicked twice.
- * In different mails the same contact hash might occur on a click but will most probably not belong to the same (anonymized) contact.
- * @return MaileonAPIResult
+ * @param int $fromDate If provided, only the clickers after the given date will be returned. The value of from_date
+ * must be a numeric value representing a point in time milliseconds after
+ * January 1, 1970 00:00:00
+ * @param int $toDate If provided, only the clickers before the given date will be returned. The value of to_date
+ * must be a numeric value representing a point in time milliseconds after
+ * January 1, 1970 00:00:00
+ * @param array $mailingIds Multivalued parameter to filter the clickers by mailings. Each value must correspond to a
+ * mailing id.
+ * @param array $contactIds Multivalued parameter to filter the clickers by contacts. Each value must correspond to a
+ * contact id.
+ * @param array $contactEmails Multivalued parameter to filter the clickers by email addresses.
+ * @param array $contactExternalIds Multivalued parameter to filter the clickers by external ids. Each value must correspond to a
+ * contacts external id.
+ * @param string $formatFilter Filters the opens by format. Possible values are: html / text.
+ * @param array $linkIdFilter Multivalued parameter to filter the clicks by links. Each value must correspond to a link id.
+ * @param string $linkUrlFilter Filters the clicks by link url.
+ * @param array $linkTagFilter Multivalued parameter to filter the clicks by tags associated to the links.
+ * @param array $socialNetworkFilter Multivalued parameter to filter the opens by the social networks where they occurred.
+ * @param array $deviceTypeFilter Multivalued parameter to filter the opens by device type. Possible values for device_type are:
+ * UNKNOWN / COMPUTER / TABLET / MOBILE
+ * @param bool $embedEmailClientInfos If the set to true, available email client details will be appended to each open.
+ * @param bool $excludeAnonymousClicks If this is set to true (default), only clicks that have not yet been anonymized (due to
+ * deletion/unsubscription) are returned.
+ * @param array $standardFields The list of standard contact fields to return.
+ * @param array $customFields The list of custom contact fields to return.
+ * @param bool $embedFieldBackups Supported values: true / false. Field Backups are the values of contact fields that have been
+ * backed up for mailings because of a backup instruction. For each unsubscription, the
+ * corresponding field backups will be returned if
+ * available. Note that this only applies for non anonymizable field backups.
+ * @param int $pageIndex The index of the result page. The index must be greater or equal to 1.
+ * @param int $pageSize The maximum count of items in the result page. If provided, the value of page_size must be in
+ * the range 1 to 1000.
+ * @param bool $embedLinkTags If the set to true, available link tags will be appended to each click.
+ * @param bool $embedTransactionId If the set to true, the attribut "transaction_id" of a transaction will be returned that caused
+ * this click, if available.
+ * @param bool $embedContactHash If the set to true, anonymized contacts will be annotated with a random number that is the same
+ * for a contact within each sendout. With this flag, it is possible to calculate unique clicks
+ * from all clicks, even if contacts are unsubscribed and therefore anonymized. If in two clicks
+ * of the same sendout the contact hash is the same, then the same contact clicked twice. In
+ * different mails the same contact hash might occur on a click but will most probably not belong
+ * to the same (anonymized) contact.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getClicks(
$fromDate = null,
@@ -567,77 +554,80 @@ public function getClicks(
$embedFieldBackups
);
- $params = $this->appendArrayFields($params, "standard_field", $standardFields);
- $params = $this->appendArrayFields($params, "custom_field", $customFields);
+ $params = $this->appendArrayFields($params, 'standard_field', $standardFields);
+ $params = $this->appendArrayFields($params, 'custom_field', $customFields);
+
if (isset($embedEmailClientInfos)) {
- $params['embed_email_client_infos'] = ($embedEmailClientInfos == true) ? "true" : "false";
+ $params['embed_email_client_infos'] = $embedEmailClientInfos === true ? 'true' : 'false';
}
+
if (isset($embedLinkTags)) {
- $params['embed_link_tags'] = ($embedLinkTags == true) ? "true" : "false";
+ $params['embed_link_tags'] = $embedLinkTags === true ? 'true' : 'false';
}
+
if (isset($excludeAnonymousClicks)) {
- $params['exclude_anonymous_clicks'] = ($excludeAnonymousClicks == true) ? "true" : "false";
+ $params['exclude_anonymous_clicks'] = $excludeAnonymousClicks === true ? 'true' : 'false';
}
if (isset($formatFilter)) {
$params['format'] = $formatFilter;
}
- $params = $this->appendArrayFields($params, "link_id", $linkIdFilter);
+
+ $params = $this->appendArrayFields($params, 'link_id', $linkIdFilter);
+
if (isset($linkUrlFilter)) {
$params['link_url'] = $linkUrlFilter;
}
+
if (isset($embedTransactionId)) {
- $params['embed_transaction_id'] = ($embedTransactionId == true) ? "true" : "false";
+ $params['embed_transaction_id'] = $embedTransactionId === true ? 'true' : 'false';
}
+
if (isset($embedContactHash)) {
- $params['embed_contact_hash'] = ($embedContactHash == true) ? "true" : "false";
+ $params['embed_contact_hash'] = $embedContactHash === true ? 'true' : 'false';
}
- $params = $this->appendArrayFields($params, "link_tag", $linkTagFilter);
- $params = $this->appendArrayFields($params, "social_network", $socialNetworkFilter);
- $params = $this->appendArrayFields($params, "device_type", $deviceTypeFilter);
- return $this->get('reports/clicks', $params);
+ $params = $this->appendArrayFields($params, 'link_tag', $linkTagFilter);
+ $params = $this->appendArrayFields($params, 'social_network', $socialNetworkFilter);
+ $params = $this->appendArrayFields($params, 'device_type', $deviceTypeFilter);
+
+ return $this->get(
+ 'reports/clicks',
+ $params
+ );
}
/**
* Returns a page of unique clickers.
*
- * @param integer $fromDate
- * If provided, only the clickers after the given date will be returned. The value of
- * from_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param integer $toDate
- * If provided, only the clickers before the given date will be returned. The value of
- * to_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param array $mailingIds
- * Multivalued parameter to filter the clickers by mailings. Each value must correspond to a mailing id.
- * @param array $contactIds
- * Multivalued parameter to filter the clickers by contacts. Each value must correspond to a contact id.
- * @param array $contactEmails
- * Multivalued parameter to filter the clickers by email addresses.
- * @param array $contactExternalIds
- * Multivalued parameter to filter the clickers by external ids. Each value must correspond
- * to a contacts external id.
- * @param bool $embedEmailClientInfos
- * If the set to true, available email client details will be appended to each open.
- * @param bool $excludeAnonymousClicks
- * If this is set to true (default), only clicks that have not yet been anonymized (due to
- * deletion/unsubscription) are returned.
- * @param array $standardFields
- * The list of standard contact fields to return.
- * @param array $customFields
- * The list of custom contact fields to return.
- * @param bool $embedFieldBackups
- * Supported values: true / false. Field Backups are the values of contact fields that have been backed
- * up for mailings because of a backup instruction. For each unsubscription, the corresponding field
- * backups will be returned if available. Note that this only applies for non anonymizable field backups.
- * @param integer $pageIndex
- * The index of the result page. The index must be greater or equal to 1.
- * @param integer $pageSize
- * The maximum count of items in the result page. If provided, the value of page_size must be in the
- * range 1 to 1000.
- * @param bool $embedLinkTags
- * If the set to true, available link tags will be appended to each click.
- * @return MaileonAPIResult
+ * @param int $fromDate If provided, only the clickers after the given date will be returned. The value of from_date
+ * must be a numeric value representing a point in time milliseconds after January 1, 1970 00:00:00
+ * @param int $toDate If provided, only the clickers before the given date will be returned. The value of to_date must
+ * be a numeric value representing a point in time milliseconds after January 1, 1970 00:00:00
+ * @param array $mailingIds Multivalued parameter to filter the clickers by mailings. Each value must correspond to a
+ * mailing id.
+ * @param array $contactIds Multivalued parameter to filter the clickers by contacts. Each value must correspond to a
+ * contact id.
+ * @param array $contactEmails Multivalued parameter to filter the clickers by email addresses.
+ * @param array $contactExternalIds Multivalued parameter to filter the clickers by external ids. Each value must correspond to a
+ * contacts external id.
+ * @param bool $embedEmailClientInfos If the set to true, available email client details will be appended to each open.
+ * @param bool $excludeAnonymousClicks If this is set to true (default), only clicks that have not yet been anonymized (due to
+ * deletion/unsubscription) are returned.
+ * @param array $standardFields The list of standard contact fields to return.
+ * @param array $customFields The list of custom contact fields to return.
+ * @param bool $embedFieldBackups Supported values: true / false. Field Backups are the values of contact fields that have been
+ * backed up for mailings because of a backup instruction. For each unsubscription, the
+ * corresponding field backups will be returned if available. Note that this only applies for non
+ * anonymizable field backups.
+ * @param int $pageIndex The index of the result page. The index must be greater or equal to 1.
+ * @param int $pageSize The maximum count of items in the result page. If provided, the value of page_size must be in
+ * the range 1 to 1000.
+ * @param bool $embedLinkTags If the set to true, available link tags will be appended to each click.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getUniqueClicks(
$fromDate = null,
@@ -670,59 +660,59 @@ public function getUniqueClicks(
$embedFieldBackups
);
- $params = $this->appendArrayFields($params, "standard_field", $standardFields);
- $params = $this->appendArrayFields($params, "custom_field", $customFields);
+ $params = $this->appendArrayFields($params, 'standard_field', $standardFields);
+ $params = $this->appendArrayFields($params, 'custom_field', $customFields);
+
if (isset($embedEmailClientInfos)) {
- $params['embed_email_client_infos'] = ($embedEmailClientInfos == true) ? "true" : "false";
+ $params['embed_email_client_infos'] = $embedEmailClientInfos === true ? 'true' : 'false';
}
+
if (isset($embedLinkTags)) {
- $params['embed_link_tags'] = ($embedLinkTags == true) ? "true" : "false";
+ $params['embed_link_tags'] = $embedLinkTags === true ? 'true' : 'false';
}
+
if (isset($excludeAnonymousClicks)) {
- $params['exclude_anonymous_clicks'] = ($excludeAnonymousClicks == true) ? "true" : "false";
+ $params['exclude_anonymous_clicks'] = $excludeAnonymousClicks === true ? 'true' : 'false';
}
- $params = $this->appendArrayFields($params, "social_network", $socialNetworkFilter);
- $params = $this->appendArrayFields($params, "device_type", $deviceTypeFilter);
- return $this->get('reports/clicks/unique', $params);
- }
+ $params = $this->appendArrayFields($params, 'social_network', $socialNetworkFilter);
+ $params = $this->appendArrayFields($params, 'device_type', $deviceTypeFilter);
+ return $this->get(
+ 'reports/clicks/unique',
+ $params
+ );
+ }
/**
* Count clickers.
*
- * @param integer $fromDate
- * If provided, only the clickers after the given date will be returned. The value of from_date must
- * be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param integer $toDate
- * If provided, only the clickers before the given date will be returned. The value of to_date
- * must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param array $mailingIds
- * Multivalued parameter to filter the clickers by mailings. Each value must correspond to a mailing id.
- * @param array $contactIds
- * Multivalued parameter to filter the clickers by contacts. Each value must correspond to a contact id.
- * @param array $contactEmails
- * Multivalued parameter to filter the clickers by email addresses.
- * @param array $contactExternalIds
- * Multivalued parameter to filter the clickers by external ids. Each value must correspond to a contacts
- * external id.
- * @param string $formatFilter
- * Filters the opens by format. Possible values are: html / text.
- * @param array $linkIdFilter
- * Multivalued parameter to filter the clicks by links. Each value must correspond to a link id.
- * @param string $linkUrlFilter
- * Filters the clicks by link url.
- * @param array $linkTagFilter
- * Multivalued parameter to filter the clicks by tags associated to the links.
- * @param array $socialNetworkFilter
- * Multivalued parameter to filter the opens by the social networks where they occurred.
- * @param array $deviceTypeFilter
- * Multivalued parameter to filter the opens by device type. Possible values for device_type
- * are: UNKNOWN / COMPUTER / TABLET / MOBILE
- * @param bool $excludeAnonymousClicks
- * If this is set to true (default), only clicks that have not yet been anonymized
- * (due to deletion/unsubscription) are returned.
- * @return MaileonAPIResult
+ * @param int $fromDate If provided, only the clickers after the given date will be returned. The value of from_date
+ * must be a numeric value representing a point in time milliseconds after
+ * January 1, 1970 00:00:00
+ * @param int $toDate If provided, only the clickers before the given date will be returned. The value of to_date
+ * must be a numeric value representing a point in time milliseconds after
+ * January 1, 1970 00:00:00
+ * @param array $mailingIds Multivalued parameter to filter the clickers by mailings. Each value must correspond to a
+ * mailing id.
+ * @param array $contactIds Multivalued parameter to filter the clickers by contacts. Each value must correspond to a
+ * contact id.
+ * @param array $contactEmails Multivalued parameter to filter the clickers by email addresses.
+ * @param array $contactExternalIds Multivalued parameter to filter the clickers by external ids. Each value must correspond to a
+ * contacts external id.
+ * @param string $formatFilter Filters the opens by format. Possible values are: html / text.
+ * @param array $linkIdFilter Multivalued parameter to filter the clicks by links. Each value must correspond to a link id.
+ * @param string $linkUrlFilter Filters the clicks by link url.
+ * @param array $linkTagFilter Multivalued parameter to filter the clicks by tags associated to the links.
+ * @param array $socialNetworkFilter Multivalued parameter to filter the opens by the social networks where they occurred.
+ * @param array $deviceTypeFilter Multivalued parameter to filter the opens by device type. Possible values for device_type are:
+ * UNKNOWN / COMPUTER / TABLET / MOBILE
+ * @param bool $excludeAnonymousClicks If this is set to true (default), only clicks that have not yet been anonymized (due to
+ * deletion/unsubscription) are returned.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getClicksCount(
$fromDate = null,
@@ -750,45 +740,49 @@ public function getClicksCount(
);
if (isset($excludeAnonymousClicks)) {
- $params['exclude_anonymous_clicks'] = ($excludeAnonymousClicks == true) ? "true" : "false";
+ $params['exclude_anonymous_clicks'] = $excludeAnonymousClicks === true ? 'true' : 'false';
}
if (isset($formatFilter)) {
$params['format'] = $formatFilter;
}
- $params = $this->appendArrayFields($params, "link_id", $linkIdFilter);
+
+ $params = $this->appendArrayFields($params, 'link_id', $linkIdFilter);
+
if (isset($linkUrlFilter)) {
$params['link_url'] = $linkUrlFilter;
}
- $params = $this->appendArrayFields($params, "link_tag", $linkTagFilter);
- $params = $this->appendArrayFields($params, "social_network", $socialNetworkFilter);
- $params = $this->appendArrayFields($params, "device_type", $deviceTypeFilter);
- return $this->get('reports/clicks/count', $params);
+ $params = $this->appendArrayFields($params, 'link_tag', $linkTagFilter);
+ $params = $this->appendArrayFields($params, 'social_network', $socialNetworkFilter);
+ $params = $this->appendArrayFields($params, 'device_type', $deviceTypeFilter);
+
+ return $this->get(
+ 'reports/clicks/count',
+ $params
+ );
}
/**
* Count unique clickers.
*
- * @param integer $fromDate
- * If provided, only the clickers after the given date will be returned. The value of from_date
- * must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param integer $toDate
- * If provided, only the clickers before the given date will be returned. The value of to_date must be a
- * numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param array $mailingIds
- * Multivalued parameter to filter the clickers by mailings. Each value must correspond to a mailing id.
- * @param array $contactIds
- * Multivalued parameter to filter the clickers by contacts. Each value must correspond to a contact id.
- * @param array $contactEmails
- * Multivalued parameter to filter the clickers by email addresses.
- * @param array $contactExternalIds
- * Multivalued parameter to filter the clickers by external ids. Each value must correspond to a
- * contacts external id.
- * @param bool $excludeAnonymousClicks
- * If this is set to true (default), only clicks that have not yet been anonymized
- * (due to deletion/unsubscription) are returned.
- * @return MaileonAPIResult
+ * @param int $fromDate If provided, only the clickers after the given date will be returned. The value of from_date
+ * must be a numeric value representing a point in time milliseconds after January 1, 1970 00:00:00
+ * @param int $toDate If provided, only the clickers before the given date will be returned. The value of to_date must
+ * be a numeric value representing a point in time milliseconds after January 1, 1970 00:00:00
+ * @param array $mailingIds Multivalued parameter to filter the clickers by mailings. Each value must correspond to a
+ * mailing id.
+ * @param array $contactIds Multivalued parameter to filter the clickers by contacts. Each value must correspond to a
+ * contact id.
+ * @param array $contactEmails Multivalued parameter to filter the clickers by email addresses.
+ * @param array $contactExternalIds Multivalued parameter to filter the clickers by external ids. Each value must correspond to a
+ * contacts external id.
+ * @param bool $excludeAnonymousClicks If this is set to true (default), only clicks that have not yet been anonymized (due to
+ * deletion/unsubscription) are returned.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getUniqueClicksCount(
$fromDate = null,
@@ -812,55 +806,53 @@ public function getUniqueClicksCount(
);
if (isset($excludeAnonymousClicks)) {
- $params['exclude_anonymous_clicks'] = ($excludeAnonymousClicks == true) ? "true" : "false";
+ $params['exclude_anonymous_clicks'] = $excludeAnonymousClicks === true ? 'true' : 'false';
}
- $params = $this->appendArrayFields($params, "social_network", $socialNetworkFilter);
- $params = $this->appendArrayFields($params, "device_type", $deviceTypeFilter);
- return $this->get('reports/clicks/unique/count', $params);
+ $params = $this->appendArrayFields($params, 'social_network', $socialNetworkFilter);
+ $params = $this->appendArrayFields($params, 'device_type', $deviceTypeFilter);
+
+ return $this->get(
+ 'reports/clicks/unique/count',
+ $params
+ );
}
/**
* Returns a page of bouncers.
*
- * @param integer $fromDate
- * If provided, only the bouncers after the given date will be returned. The value of from_date
- * must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param integer $toDate
- * If provided, only the bouncers before the given date will be returned. The value of to_date must
- * be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param array $mailingIds
- * Multivalued parameter to filter the bouncers by mailings. Each value must correspond to a mailing id.
- * @param array $contactIds
- * Multivalued parameter to filter the bouncers by contacts. Each value must correspond to a contact id.
- * @param array $contactEmails
- * Multivalued parameter to filter the bouncers by email addresses.
- * @param array $contactExternalIds
- * Multivalued parameter to filter the bouncers by external ids. Each value must correspond
- * to a contacts external id.
- * @param array $statusCodeFilter
- * Filters the bounces by status codes. Status codes follow the pattern digit.digit.digit (example: 5.0.0).
- * @param string $typeFilter
- * Filters the bounces by type: permanent / transient.
- * @param string $sourceFilter
- * Filters the bounces by their source: mta-listener / reply.
- * @param bool $excludeAnonymousBounces
- * If this is set to true (default), only bounces that have not yet been anonymized
- * (due to deletion/unsubscription) are returned.
- * @param array $standardFields
- * The list of standard contact fields to return.
- * @param array $customFields
- * The list of custom contact fields to return.
- * @param bool $embedFieldBackups
- * Supported values: true / false. Field Backups are the values of contact fields that have been
- * backed up for mailings because of a backup instruction. For each unsubscription, the corresponding
- * field backups will be returned if available. Note that this only applies for non anonymizable field backups.
- * @param integer $pageIndex
- * The index of the result page. The index must be greater or equal to 1.
- * @param integer $pageSize
- * The maximum count of items in the result page. If provided, the value of page_size
- * must be in the range 1 to 1000.
- * @return MaileonAPIResult
+ * @param int $fromDate If provided, only the bouncers after the given date will be returned. The value of from_date
+ * must be a numeric value representing a point in time milliseconds after
+ * January 1, 1970 00:00:00
+ * @param int $toDate If provided, only the bouncers before the given date will be returned. The value of to_date
+ * must be a numeric value representing a point in time milliseconds after
+ * January 1, 1970 00:00:00
+ * @param array $mailingIds Multivalued parameter to filter the bouncers by mailings. Each value must correspond to a
+ * mailing id.
+ * @param array $contactIds Multivalued parameter to filter the bouncers by contacts. Each value must correspond to a
+ * contact id.
+ * @param array $contactEmails Multivalued parameter to filter the bouncers by email addresses.
+ * @param array $contactExternalIds Multivalued parameter to filter the bouncers by external ids. Each value must correspond to a
+ * contacts external id.
+ * @param array $statusCodeFilter Filters the bounces by status codes. Status codes follow the pattern digit.digit.digit
+ * (example: 5.0.0).
+ * @param string $typeFilter Filters the bounces by type: permanent / transient.
+ * @param string $sourceFilter Filters the bounces by their source: mta-listener / reply.
+ * @param bool $excludeAnonymousBounces If this is set to true (default), only bounces that have not yet been anonymized (due to
+ * deletion/unsubscription) are returned.
+ * @param array $standardFields The list of standard contact fields to return.
+ * @param array $customFields The list of custom contact fields to return.
+ * @param bool $embedFieldBackups Supported values: true / false. Field Backups are the values of contact fields that have been
+ * backed up for mailings because of a backup instruction. For each unsubscription, the
+ * corresponding field backups will be returned if available. Note that this only applies for non
+ * anonymizable field backups.
+ * @param int $pageIndex The index of the result page. The index must be greater or equal to 1.
+ * @param int $pageSize The maximum count of items in the result page. If provided, the value of page_size must be in
+ * the range 1 to 1000.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getBounces(
$fromDate = null,
@@ -891,58 +883,58 @@ public function getBounces(
null,
$embedFieldBackups
);
- $params = $this->appendArrayFields($params, "standard_field", $standardFields);
- $params = $this->appendArrayFields($params, "custom_field", $customFields);
+ $params = $this->appendArrayFields($params, 'standard_field', $standardFields);
+ $params = $this->appendArrayFields($params, 'custom_field', $customFields);
if (isset($excludeAnonymousBounces)) {
- $params['exclude_anonymous_bounces'] = ($excludeAnonymousBounces == true) ? "true" : "false";
+ $params['exclude_anonymous_bounces'] = $excludeAnonymousBounces === true ? 'true' : 'false';
}
if (isset($typeFilter)) {
$params['type'] = $typeFilter;
}
+
if (isset($sourceFilter)) {
$params['source_filter'] = $sourceFilter;
}
- return $this->get('reports/bounces', $params);
+ return $this->get(
+ 'reports/bounces',
+ $params
+ );
}
/**
* Returns a page of unique bouncers.
*
- * @param integer $fromDate
- * If provided, only the bouncers after the given date will be returned. The value of from_date
- * must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param integer $toDate
- * If provided, only the bouncers before the given date will be returned. The value of to_date must
- * be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param array $mailingIds
- * Multivalued parameter to filter the bouncers by mailings. Each value must correspond to a mailing id.
- * @param array $contactIds
- * Multivalued parameter to filter the bouncers by contacts. Each value must correspond to a contact id.
- * @param array $contactEmails
- * Multivalued parameter to filter the bouncers by email addresses.
- * @param array $contactExternalIds
- * Multivalued parameter to filter the bouncers by external ids. Each value must correspond to a
- * contacts external id.
- * @param bool $excludeAnonymousBounces
- * If this is set to true (default), only bounces that have not yet been anonymized
- * (due to deletion/unsubscription) are returned.
- * @param array $standardFields
- * The list of standard contact fields to return.
- * @param array $customFields
- * The list of custom contact fields to return.
- * @param bool $embedFieldBackups
- * Supported values: true / false. Field Backups are the values of contact fields that have been backed
- * up for mailings because of a backup instruction. For each unsubscription, the corresponding field
- * backups will be returned if available. Note that this only applies for non anonymizable field backups.
- * @param integer $pageIndex
- * The index of the result page. The index must be greater or equal to 1.
- * @param integer $pageSize
- * The maximum count of items in the result page. If provided, the value of page_size must be in
- * the range 1 to 1000.
- * @return MaileonAPIResult
+ * @param int $fromDate If provided, only the bouncers after the given date will be returned. The value of from_date
+ * must be a numeric value representing a point in time milliseconds after
+ * January 1, 1970 00:00:00
+ * @param int $toDate If provided, only the bouncers before the given date will be returned. The value of to_date
+ * must be a numeric value representing a point in time milliseconds after
+ * January 1, 1970 00:00:00
+ * @param array $mailingIds Multivalued parameter to filter the bouncers by mailings. Each value must correspond to a
+ * mailing id.
+ * @param array $contactIds Multivalued parameter to filter the bouncers by contacts. Each value must correspond to a
+ * contact id.
+ * @param array $contactEmails Multivalued parameter to filter the bouncers by email addresses.
+ * @param array $contactExternalIds Multivalued parameter to filter the bouncers by external ids. Each value must correspond to a
+ * contacts external id.
+ * @param bool $excludeAnonymousBounces If this is set to true (default), only bounces that have not yet been anonymized (due to
+ * deletion/unsubscription) are returned.
+ * @param array $standardFields The list of standard contact fields to return.
+ * @param array $customFields The list of custom contact fields to return.
+ * @param bool $embedFieldBackups Supported values: true / false. Field Backups are the values of contact fields that have been
+ * backed up for mailings because of a backup instruction. For each unsubscription, the
+ * corresponding field backups will be returned if available. Note that this only applies for non
+ * anonymizable field backups.
+ * @param int $pageIndex The index of the result page. The index must be greater or equal to 1.
+ * @param int $pageSize The maximum count of items in the result page. If provided, the value of page_size must be in
+ * The range 1 to 1000.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getUniqueBounces(
$fromDate = null,
@@ -971,44 +963,45 @@ public function getUniqueBounces(
$embedFieldBackups
);
- $params = $this->appendArrayFields($params, "standard_field", $standardFields);
- $params = $this->appendArrayFields($params, "custom_field", $customFields);
+ $params = $this->appendArrayFields($params, 'standard_field', $standardFields);
+ $params = $this->appendArrayFields($params, 'custom_field', $customFields);
if (isset($excludeAnonymousBounces)) {
- $params['exclude_anonymous_bounces'] = ($excludeAnonymousBounces == true) ? "true" : "false";
+ $params['exclude_anonymous_bounces'] = $excludeAnonymousBounces === true ? 'true' : 'false';
}
- return $this->get('reports/bounces/unique', $params);
+ return $this->get(
+ 'reports/bounces/unique',
+ $params
+ );
}
/**
* Count bouncers.
*
- * @param integer $fromDate
- * If provided, only the bouncers after the given date will be returned. The value of from_date
- * must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param integer $toDate
- * If provided, only the bouncers before the given date will be returned. The value of to_date must
- * be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param array $mailingIds
- * Multivalued parameter to filter the bouncers by mailings. Each value must correspond to a mailing id.
- * @param array $contactIds
- * Multivalued parameter to filter the bouncers by contacts. Each value must correspond to a contact id.
- * @param array $contactEmails
- * Multivalued parameter to filter the bouncers by email addresses.
- * @param array $contactExternalIds
- * Multivalued parameter to filter the bouncers by external ids. Each value must correspond
- * to a contacts external id.
- * @param array $statusCodeFilter
- * Filters the bounces by status codes. Status codes follow the pattern digit.digit.digit (example: 5.0.0).
- * @param string $typeFilter
- * Filters the bounces by type: permanent / transient.
- * @param string $sourceFilter
- * Filters the bounces by their source: mta-listener / reply.
- * @param bool $excludeAnonymousBounces
- * If this is set to true (default), only bounces that have not yet been anonymized
- * (due to deletion/unsubscription) are returned.
- * @return MaileonAPIResult
+ * @param int $fromDate If provided, only the bouncers after the given date will be returned. The value of from_date
+ * must be a numeric value representing a point in time milliseconds after
+ * January 1, 1970 00:00:00
+ * @param int $toDate If provided, only the bouncers before the given date will be returned. The value of to_date
+ * must be a numeric value representing a point in time milliseconds after
+ * January 1, 1970 00:00:00
+ * @param array $mailingIds Multivalued parameter to filter the bouncers by mailings. Each value must correspond to a
+ * mailing id.
+ * @param array $contactIds Multivalued parameter to filter the bouncers by contacts. Each value must correspond to a
+ * contact id.
+ * @param array $contactEmails Multivalued parameter to filter the bouncers by email addresses.
+ * @param array $contactExternalIds Multivalued parameter to filter the bouncers by external ids. Each value must correspond to a
+ * contacts external id.
+ * @param array $statusCodeFilter Filters the bounces by status codes. Status codes follow the pattern digit.digit.digit
+ * (example: 5.0.0).
+ * @param string $typeFilter Filters the bounces by type: permanent / transient.
+ * @param string $sourceFilter Filters the bounces by their source: mta-listener / reply.
+ * @param bool $excludeAnonymousBounces If this is set to true (default), only bounces that have not yet been anonymized (due to
+ * deletion/unsubscription) are returned.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getBouncesCount(
$fromDate = null,
@@ -1033,41 +1026,45 @@ public function getBouncesCount(
);
if (isset($excludeAnonymousBounces)) {
- $params['exclude_anonymous_bounces'] = ($excludeAnonymousBounces == true) ? "true" : "false";
+ $params['exclude_anonymous_bounces'] = $excludeAnonymousBounces === true ? 'true' : 'false';
}
if (isset($typeFilter)) {
$params['type'] = $typeFilter;
}
+
if (isset($sourceFilter)) {
$params['source_filter'] = $sourceFilter;
}
- return $this->get('reports/bounces/count', $params);
+ return $this->get(
+ 'reports/bounces/count',
+ $params
+ );
}
/**
* Count unique bouncers.
*
- * @param integer $fromDate
- * If provided, only the bouncers after the given date will be returned. The value of from_date
- * must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param integer $toDate
- * If provided, only the bouncers before the given date will be returned. The value of to_date must be
- * a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param array $mailingIds
- * Multivalued parameter to filter the bouncers by mailings. Each value must correspond to a mailing id.
- * @param array $contactIds
- * Multivalued parameter to filter the bouncers by contacts. Each value must correspond to a contact id.
- * @param array $contactEmails
- * Multivalued parameter to filter the bouncers by email addresses.
- * @param array $contactExternalIds
- * Multivalued parameter to filter the bouncers by external ids. Each value must correspond to a
- * contacts external id.
- * @param bool $excludeAnonymousBounces
- * If this is set to true (default), only bounces that have not yet been anonymized
- * (due to deletion/unsubscription) are returned.
- * @return MaileonAPIResult
+ * @param int $fromDate If provided, only the bouncers after the given date will be returned. The value of from_date
+ * must be a numeric value representing a point in time milliseconds after
+ * January 1, 1970 00:00:00
+ * @param int $toDate If provided, only the bouncers before the given date will be returned. The value of to_date
+ * must be a numeric value representing a point in time milliseconds after
+ * January 1, 1970 00:00:00
+ * @param array $mailingIds Multivalued parameter to filter the bouncers by mailings. Each value must correspond to a
+ * mailing id.
+ * @param array $contactIds Multivalued parameter to filter the bouncers by contacts. Each value must correspond to a
+ * contact id.
+ * @param array $contactEmails Multivalued parameter to filter the bouncers by email addresses.
+ * @param array $contactExternalIds Multivalued parameter to filter the bouncers by external ids. Each value must correspond to a
+ * contacts external id.
+ * @param bool $excludeAnonymousBounces If this is set to true (default), only bounces that have not yet been anonymized (due to
+ * deletion/unsubscription) are returned.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getUniqueBouncesCount(
$fromDate = null,
@@ -1089,47 +1086,41 @@ public function getUniqueBouncesCount(
);
if (isset($excludeAnonymousBounces)) {
- $params['exclude_anonymous_bounces'] = ($excludeAnonymousBounces == true) ? "true" : "false";
+ $params['exclude_anonymous_bounces'] = $excludeAnonymousBounces === true ? 'true' : 'false';
}
- return $this->get('reports/bounces/unique/count', $params);
+ return $this->get(
+ 'reports/bounces/unique/count',
+ $params
+ );
}
/**
* Returns a page of blocks.
*
- * @param integer $fromDate
- * If provided, only the blocks after the given date will be returned. The value of from_date must
- * be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param integer $toDate
- * If provided, only the blocks before the given date will be returned. The value of to_date must be
- * a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param array $contactIds
- * Multivalued parameter to filter the blocks by contacts. Each value must correspond to a contact id.
- * @param array $contactEmails
- * Multivalued parameter to filter the blocks by email addresses.
- * @param array $contactExternalIds
- * Multivalued parameter to filter the blocks by external ids. Each value must correspond to a
- * contacts external id.
- * @param array $reasons
- * Filter by reason, valid: blacklist, bounce_policy.
- * @param string $oldStatus
- * Filter by old status, valid: allowed, blocked.
- * @param string $newStatus
- * Filter by new status, valid: allowed, blocked.
- * @param bool $excludeAnonymousBlocks
- * If this is set to true (default), only bounces that have not yet been anonymized
- * (due to deletion/unsubscription) are returned.
- * @param array $standardFields
- * The list of standard contact fields to return.
- * @param array $customFields
- * The list of custom contact fields to return.
- * @param integer $pageIndex
- * The index of the result page. The index must be greater or equal to 1.
- * @param integer $pageSize
- * The maximum count of items in the result page. If provided, the value of page_size must be
- * in the range 1 to 1000.
- * @return MaileonAPIResult
+ * @param int $fromDate If provided, only the blocks after the given date will be returned. The value of from_date must
+ * be a numeric value representing a point in time milliseconds after January 1, 1970 00:00:00
+ * @param int $toDate If provided, only the blocks before the given date will be returned. The value of to_date must
+ * be a numeric value representing a point in time milliseconds after January 1, 1970 00:00:00
+ * @param array $contactIds Multivalued parameter to filter the blocks by contacts. Each value must correspond to a contact
+ * id.
+ * @param array $contactEmails Multivalued parameter to filter the blocks by email addresses.
+ * @param array $contactExternalIds Multivalued parameter to filter the blocks by external ids. Each value must correspond to a
+ * contacts external id.
+ * @param array $reasons Filter by reason, valid: blacklist, bounce_policy.
+ * @param string $oldStatus Filter by old status, valid: allowed, blocked.
+ * @param string $newStatus Filter by new status, valid: allowed, blocked.
+ * @param bool $excludeAnonymousBlocks If this is set to true (default), only bounces that have not yet been anonymized (due to
+ * deletion/unsubscription) are returned.
+ * @param array $standardFields The list of standard contact fields to return.
+ * @param array $customFields The list of custom contact fields to return.
+ * @param int $pageIndex The index of the result page. The index must be greater or equal to 1.
+ * @param int $pageSize The maximum count of items in the result page. If provided, the value of page_size must be in
+ * the range 1 to 1000.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getBlocks(
$fromDate = null,
@@ -1159,51 +1150,51 @@ public function getBlocks(
null
);
- $params = $this->appendArrayFields($params, "standard_field", $standardFields);
- $params = $this->appendArrayFields($params, "custom_field", $customFields);
+ $params = $this->appendArrayFields($params, 'standard_field', $standardFields);
+ $params = $this->appendArrayFields($params, 'custom_field', $customFields);
if (isset($excludeAnonymousBlocks)) {
- $params['exclude_anonymous_blocks'] = ($excludeAnonymousBlocks == true) ? "true" : "false";
+ $params['exclude_anonymous_blocks'] = $excludeAnonymousBlocks === true ? 'true' : 'false';
}
- $params = $this->appendArrayFields($params, "reasons", $reasons);
+ $params = $this->appendArrayFields($params, 'reasons', $reasons);
+
if (isset($oldStatus)) {
$params['old_status'] = $oldStatus;
}
+
if (isset($newStatus)) {
$params['new_status'] = $newStatus;
}
- return $this->get('reports/blocks', $params);
+ return $this->get(
+ 'reports/blocks',
+ $params
+ );
}
/**
* Count blocks.
*
- * @param integer $fromDate
- * If provided, only the blocks after the given date will be returned. The value of from_date
- * must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param integer $toDate
- * If provided, only the blocks before the given date will be returned. The value of to_date must
- * be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param array $contactIds
- * Multivalued parameter to filter the blocks by contacts. Each value must correspond to a contact id.
- * @param array $contactEmails
- * Multivalued parameter to filter the blocks by email addresses.
- * @param array $contactExternalIds
- * Multivalued parameter to filter the blocks by external ids. Each value must correspond to a
- * contacts external id.
- * @param array $reasons
- * Filter by reason, valid: blacklist, bounce_policy.
- * @param string $oldStatus
- * Filter by old status, valid: allowed, blocked.
- * @param string $newStatus
- * Filter by new status, valid: allowed, blocked.
- * Filters the bounces by their source: mta-listener / reply.
- * @param bool $excludeAnonymousBlocks
- * If this is set to true (default), only bounces that have not yet been anonymized
- * (due to deletion/unsubscription) are returned.
- * @return MaileonAPIResult
+ * @param int $fromDate If provided, only the blocks after the given date will be returned. The value of from_date must
+ * be a numeric value representing a point in time milliseconds after January 1, 1970 00:00:00
+ * @param int $toDate If provided, only the blocks before the given date will be returned. The value of to_date must
+ * be a numeric value representing a point in time milliseconds after January 1, 1970 00:00:00
+ * @param array $contactIds Multivalued parameter to filter the blocks by contacts. Each value must correspond to a contact
+ * id.
+ * @param array $contactEmails Multivalued parameter to filter the blocks by email addresses.
+ * @param array $contactExternalIds Multivalued parameter to filter the blocks by external ids. Each value must correspond to a
+ * contacts external id.
+ * @param array $reasons Filter by reason, valid: blacklist, bounce_policy.
+ * @param string $oldStatus Filter by old status, valid: allowed, blocked.
+ * @param string $newStatus Filter by new status, valid: allowed, blocked. Filters the bounces by their source:
+ * mta-listener / reply.
+ * @param bool $excludeAnonymousBlocks If this is set to true (default), only bounces that have not yet been anonymized (due to
+ * deletion/unsubscription) are returned.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getBlocksCount(
$fromDate = null,
@@ -1227,61 +1218,58 @@ public function getBlocksCount(
);
if (isset($excludeAnonymousBlocks)) {
- $params['exclude_anonymous_blocks'] = ($excludeAnonymousBlocks == true) ? "true" : "false";
+ $params['exclude_anonymous_blocks'] = $excludeAnonymousBlocks === true ? 'true' : 'false';
}
- $params = $this->appendArrayFields($params, "reasons", $reasons);
+ $params = $this->appendArrayFields($params, 'reasons', $reasons);
+
if (isset($oldStatus)) {
$params['old_status'] = $oldStatus;
}
+
if (isset($newStatus)) {
$params['new_status'] = $newStatus;
}
- return $this->get('reports/blocks/count', $params);
+ return $this->get(
+ 'reports/blocks/count',
+ $params
+ );
}
/**
- * Returns a page of unsubscriberss.
- *
- * @param integer $fromDate
- * If provided, only the unsubscriptions after the given date will be returned.
- * The value of from_date must be a numeric value representing a point in time milliseconds
- * afterJanuary 1, 1970 00:00:00
- * @param integer $toDate
- * If provided, only the unsubscriptions before the given date will be returned. The value of
- * to_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param array $mailingIds
- * Multivalued parameter to filter the unsubscriptions by mailings. Each value must correspond to a mailing id.
- * @param array $contactIds
- * Multivalued parameter to filter the unsubscriptions by contacts. Each value must correspond to a contact id.
- * @param array $contactEmails
- * Multivalued parameter to filter the unsubscriptions by email addresses.
- * @param array $contactExternalIds
- * Multivalued parameter to filter the unsubscriptions by external ids.
- * Each value must correspond to a contacts external id.
- * @param string $source
- * Filters the unsubscriptions by their source. The source can be an
- * unsubscription link (link), a reply mail (reply) or other.
- * @param bool $embedFieldBackups
- * Supported values: true / false. Field Backups are the values of contact fields that have been
- * backed up for mailings because of a backup instruction. For each unsubscription, the corresponding
- * field backups will be returned if available. Note that this only applies for non anonymizable field backups.
- * @param integer $pageIndex
- * The index of the result page. The index must be greater or equal to 1.
- * @param integer $pageSize
- * The maximum count of items in the result page. If provided, the value of page_size
- * must be in the range 1 to 1000.
- * @param array $standardFields
- * The list of standard contact fields to return. Please note, that those values are only available if
- * Maileon is set up to move those values to unsubscriber table on unsubscription.
- * @param array $customFields
- * The list of custom contact fields to return. Please note, that those values are only available if
- * Maileon is set up to move those values to unsubscriber table on unsubscription.
- * @param bool $exclude_anonymous
- * If this is set to true, only unsubscribers that have not yet been anonymized (due to setting) are returned.
- *
- * @return MaileonAPIResult
+ * Returns a page of unsubscribers.
+ *
+ * @param int $fromDate If provided, only the unsubscriptions after the given date will be returned. The value of from_date
+ * must be a numeric value representing a point in time milliseconds after January 1, 1970 00:00:00
+ * @param int $toDate If provided, only the unsubscriptions before the given date will be returned. The value of to_date
+ * must be a numeric value representing a point in time milliseconds after January 1, 1970 00:00:00
+ * @param array $mailingIds Multivalued parameter to filter the unsubscriptions by mailings. Each value must correspond to a
+ * mailing id.
+ * @param array $contactIds Multivalued parameter to filter the unsubscriptions by contacts. Each value must correspond to a
+ * contact id.
+ * @param array $contactEmails Multivalued parameter to filter the unsubscriptions by email addresses.
+ * @param array $contactExternalIds Multivalued parameter to filter the unsubscriptions by external ids. Each value must correspond to
+ * a contacts external id.
+ * @param string $source Filters the unsubscriptions by their source. The source can be an unsubscription link (link), a
+ * reply mail (reply) or other.
+ * @param bool $embedFieldBackups Supported values: true / false. Field Backups are the values of contact fields that have been
+ * backed up for mailings because of a backup instruction. For each unsubscription, the corresponding
+ * field backups will be returned if available. Note that this only applies for non anonymizable field
+ * backups.
+ * @param int $pageIndex The index of the result page. The index must be greater or equal to 1.
+ * @param int $pageSize The maximum count of items in the result page. If provided, the value of page_size must be in the
+ * range 1 to 1000.
+ * @param array $standardFields The list of standard contact fields to return. Please note, that those values are only available if
+ * Maileon is set up to move those values to unsubscriber table on unsubscription.
+ * @param array $customFields The list of custom contact fields to return. Please note, that those values are only available if
+ * Maileon is set up to move those values to unsubscriber table on unsubscription.
+ * @param bool $excludeAnonymous If this is set to true, only unsubscribers that have not yet been anonymized (due to setting) are
+ * returned.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getUnsubscribers(
$fromDate = null,
@@ -1312,40 +1300,40 @@ public function getUnsubscribers(
);
if (isset($excludeAnonymous)) {
- $params['exclude_anonymous'] = ($excludeAnonymous == true) ? "true" : "false";
+ $params['exclude_anonymous'] = $excludeAnonymous === true ? 'true' : 'false';
}
-
- $params = $this->appendArrayFields($params, "standard_field", $standardFields);
- $params = $this->appendArrayFields($params, "custom_field", $customFields);
- return $this->get('reports/unsubscriptions', $params);
+ $params = $this->appendArrayFields($params, 'standard_field', $standardFields);
+ $params = $this->appendArrayFields($params, 'custom_field', $customFields);
+
+ return $this->get(
+ 'reports/unsubscriptions',
+ $params
+ );
}
/**
* Count unsubscribers.
*
- * @param integer $fromDate
- * If provided, only the unsubscriptions after the given date will be returned. The value of from_date
- * must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param integer $toDate
- * If provided, only the unsubscriptions before the given date will be returned. The value of
- * to_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param array $mailingIds
- * Multivalued parameter to filter the unsubscriptions by mailings. Each value must correspond to a mailing id.
- * @param array $contactIds
- * Multivalued parameter to filter the unsubscriptions by contacts. Each value must correspond to a contact id.
- * @param array $contactEmails
- * Multivalued parameter to filter the unsubscriptions by email addresses.
- * @param array $contactExternalIds
- * Multivalued parameter to filter the unsubscriptions by external ids. Each value must correspond
- * to a contacts external id.
- * @param string $source
- * Filters the unsubscriptions by their source. The source can be an unsubscription link
- * (link), a reply mail (reply) or other.
- * @param bool $exclude_anonymous
- * If this is set to true, only unsubscribers that have not yet been anonymized (due to setting) are returned.
- *
- * @return MaileonAPIResult
+ * @param int $fromDate If provided, only the unsubscriptions after the given date will be returned. The value of from_date
+ * must be a numeric value representing a point in time milliseconds after January 1, 1970 00:00:00
+ * @param int $toDate If provided, only the unsubscriptions before the given date will be returned. The value of to_date
+ * must be a numeric value representing a point in time milliseconds after January 1, 1970 00:00:00
+ * @param array $mailingIds Multivalued parameter to filter the unsubscriptions by mailings. Each value must correspond to a
+ * mailing id.
+ * @param array $contactIds Multivalued parameter to filter the unsubscriptions by contacts. Each value must correspond to a
+ * contact id.
+ * @param array $contactEmails Multivalued parameter to filter the unsubscriptions by email addresses.
+ * @param array $contactExternalIds Multivalued parameter to filter the unsubscriptions by external ids. Each value must correspond to
+ * a contacts external id.
+ * @param string $source Filters the unsubscriptions by their source. The source can be an unsubscription link (link), a
+ * reply mail (reply) or other.
+ * @param bool $excludeAnonymous If this is set to true, only unsubscribers that have not yet been anonymized (due to setting) are
+ * returned.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getUnsubscribersCount(
$fromDate = null,
@@ -1368,109 +1356,109 @@ public function getUnsubscribersCount(
);
if (isset($excludeAnonymous)) {
- $params['exclude_anonymous'] = ($excludeAnonymous == true) ? "true" : "false";
+ $params['exclude_anonymous'] = $excludeAnonymous === true ? 'true' : 'false';
}
- return $this->get('reports/unsubscriptions/count', $params);
- } /**
- * Returns a page of unsubscriberss.
- *
- * @param integer $fromDate
- * If provided, only the unsubscriptions after the given date will be returned.
- * The value of from_date must be a numeric value representing a point in time milliseconds
- * afterJanuary 1, 1970 00:00:00
- * @param integer $toDate
- * If provided, only the unsubscriptions before the given date will be returned. The value of
- * to_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param string $order
- * String that describes the order. Possible values are: "count" or "name". Default is "count".
- * @param array $asc
- * Describes if results will be ordered ascending or descending. Can be true or false, default is true.
- * @param integer $pageIndex
- * The index of the result page. The index must be greater or equal to 1.
- * @param integer $pageSize
- * The maximum count of items in the result page. If provided, the value of page_size
- * must be in the range 1 to 1000.
- *
- * @return MaileonAPIResult
- */
+ return $this->get(
+ 'reports/unsubscriptions/count',
+ $params
+ );
+ }
+
+ /**
+ * Returns a page of unsubscribers.
+ *
+ * @param int $fromDate If provided, only the unsubscriptions after the given date will be returned. The value of from_date must be
+ * a numeric value representing a point in time milliseconds after January 1, 1970 00:00:00
+ * @param int $toDate If provided, only the unsubscriptions before the given date will be returned. The value of to_date must be
+ * a numeric value representing a point in time milliseconds after January 1, 1970 00:00:00
+ * @param string $order String that describes the order. Possible values are: "count" or "name". Default is "count".
+ * @param array $asc Describes if results will be ordered ascending or descending. Can be true or false, default is true.
+ * @param int $pageIndex The index of the result page. The index must be greater or equal to 1.
+ * @param int $pageSize The maximum count of items in the result page. If provided, the value of page_size must be in the range 1 to
+ * 1000.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
+ */
public function getUnsubscriberReasons(
$fromDate = null,
$toDate = null,
- $order = "count",
+ $order = 'count',
$asc = true,
$pageIndex = 1,
$pageSize = 100
- ) {
- $params = $this->createQueryParameters(
- $pageIndex,
- $pageSize,
- $fromDate,
- $toDate,
- null,
- null,
- null,
- null,
- null,
- null
- );
-
- if (isset($asc)) {
- $params['asc'] = ($asc == true) ? "true" : "false";
- }
- if (isset($order)) {
- $params['order'] = $order;
- }
-
- return $this->get('reports/unsubscriptions/reasons', $params);
+ ) {
+ $params = $this->createQueryParameters(
+ $pageIndex,
+ $pageSize,
+ $fromDate,
+ $toDate,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null
+ );
+
+ if (isset($asc)) {
+ $params['asc'] = $asc === true ? 'true' : 'false';
+ }
+
+ if (isset($order)) {
+ $params['order'] = $order;
+ }
+
+ return $this->get(
+ 'reports/unsubscriptions/reasons',
+ $params
+ );
}
/**
* Returns a page of subscribers.
*
- * @param integer $fromDate
- * If provided, only the unsubscriptions after the given date will be returned. The value of
- * from_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param integer $toDate
- * If provided, only the unsubscriptions before the given date will be returned. The value of to_date
- * must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param array $mailingIds
- * Multivalued parameter to filter the unsubscriptions by mailings. Each value must correspond to a mailing id.
- * @param array $contactIds
- * Multivalued parameter to filter the unsubscriptions by contacts. Each value must correspond to a contact id.
- * @param array $contactEmails
- * Multivalued parameter to filter the unsubscriptions by email addresses.
- * @param array $contactExternalIds
- * Multivalued parameter to filter the unsubscriptions by external ids. Each value must correspond to
- * a contacts external id.
- * @param bool $excludeAnonymousContacts
- * If this is set to true (default), only subscribers that have not yet been anonymized
- * (due to deletion) are returned.
- * @param array $standardFields
- * The list of standard contact fields to return.
- * @param array $customFields
- * The list of custom contact fields to return.
- * @param bool $embedFieldBackups
- * Supported values: true / false. Field Backups are the values of contact fields that have been backed
- * up for mailings because of a backup instruction. For each unsubscription, the corresponding field
- * backups will be returned if available. Note that this only applies for non anonymizable field backups.
- * @param integer $pageIndex
- * The index of the result page. The index must be greater or equal to 1.
- * @param integer $pageSize
- * The maximum count of items in the result page. If provided, the value of page_size must be in
- * the range 1 to 1000.
- * @return MaileonAPIResult
+ * @param int $fromDate If provided, only the unsubscriptions after the given date will be returned. The value of
+ * from_date must be a numeric value representing a point in time milliseconds after
+ * January 1, 1970 00:00:00
+ * @param int $toDate If provided, only the unsubscriptions before the given date will be returned. The value of
+ * to_date must be a numeric value representing a point in time milliseconds after
+ * January 1, 1970 00:00:00
+ * @param array $mailingIds Multivalued parameter to filter the unsubscriptions by mailings. Each value must correspond to
+ * a mailing id.
+ * @param array $contactIds Multivalued parameter to filter the unsubscriptions by contacts. Each value must correspond to
+ * a contact id.
+ * @param array $contactEmails Multivalued parameter to filter the unsubscriptions by email addresses.
+ * @param array $contactExternalIds Multivalued parameter to filter the unsubscriptions by external ids. Each value must
+ * correspond to a contacts external id.
+ * @param bool $excludeAnonymousContacts If this is set to true (default), only subscribers that have not yet been anonymized (due to
+ * deletion) are returned.
+ * @param array $standardFields The list of standard contact fields to return.
+ * @param array $customFields The list of custom contact fields to return.
+ * @param bool $embedFieldBackups Supported values: true / false. Field Backups are the values of contact fields that have been
+ * backed up for mailings because of a backup instruction. For each unsubscription, the
+ * corresponding field backups will be returned if available. Note that this only applies for non
+ * anonymizable field backups.
+ * @param int $pageIndex The index of the result page. The index must be greater or equal to 1.
+ * @param int $pageSize The maximum count of items in the result page. If provided, the value of page_size must be in
+ * The range 1 to 1000.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getSubscribers(
$fromDate = null,
$toDate = null,
- $mailingIds = array(),
- $contactIds = array(),
- $contactEmails = array(),
- $contactExternalIds = array(),
+ $mailingIds = [],
+ $contactIds = [],
+ $contactEmails = [],
+ $contactExternalIds = [],
$excludeAnonymousContacts = false,
- $standardFields = array(),
- $customFields = array(),
+ $standardFields = [],
+ $customFields = [],
$embedFieldBackups = false,
$pageIndex = 1,
$pageSize = 100
@@ -1488,45 +1476,49 @@ public function getSubscribers(
$embedFieldBackups
);
- $params = $this->appendArrayFields($params, "standard_field", $standardFields);
- $params = $this->appendArrayFields($params, "custom_field", $customFields);
+ $params = $this->appendArrayFields($params, 'standard_field', $standardFields);
+ $params = $this->appendArrayFields($params, 'custom_field', $customFields);
+
if (isset($excludeAnonymousContacts)) {
- $params ['exclude_anonymous_contacts'] = ($excludeAnonymousContacts == true) ? "true" : "false";
+ $params ['exclude_anonymous_contacts'] = $excludeAnonymousContacts === true ? 'true' : 'false';
}
- return $this->get('reports/subscribers', $params);
+ return $this->get(
+ 'reports/subscribers',
+ $params
+ );
}
/**
* Count subscribers.
*
- * @param integer $fromDate
- * If provided, only the unsubscriptions after the given date will be returned. The value of from_date
- * must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param integer $toDate
- * If provided, only the unsubscriptions before the given date will be returned. The value of to_date must
- * be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param array $mailingIds
- * Multivalued parameter to filter the unsubscriptions by mailings. Each value must correspond to a mailing id.
- * @param array $contactIds
- * Multivalued parameter to filter the unsubscriptions by contacts. Each value must correspond to a contact id.
- * @param array $contactEmails
- * Multivalued parameter to filter the unsubscriptions by email addresses.
- * @param array $contactExternalIds
- * Multivalued parameter to filter the unsubscriptions by external ids. Each value must correspond to a
- * contacts external id.
- * @param bool $excludeAnonymousContacts
- * If this is set to true (default), only subscribers that have not yet been anonymized
- * (due to deletion) are returned.
- * @return MaileonAPIResult
+ * @param int $fromDate If provided, only the unsubscriptions after the given date will be returned. The value of
+ * from_date must be a numeric value representing a point in time milliseconds after
+ * January 1, 1970 00:00:00
+ * @param int $toDate If provided, only the unsubscriptions before the given date will be returned. The value of
+ * to_date must be a numeric value representing a point in time milliseconds after
+ * January 1, 1970 00:00:00
+ * @param array $mailingIds Multivalued parameter to filter the unsubscriptions by mailings. Each value must correspond to
+ * a mailing id.
+ * @param array $contactIds Multivalued parameter to filter the unsubscriptions by contacts. Each value must correspond to
+ * a contact id.
+ * @param array $contactEmails Multivalued parameter to filter the unsubscriptions by email addresses.
+ * @param array $contactExternalIds Multivalued parameter to filter the unsubscriptions by external ids. Each value must
+ * correspond to a contacts external id.
+ * @param bool $excludeAnonymousContacts If this is set to true (default), only subscribers that have not yet been anonymized (due to
+ * deletion) are returned.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getSubscribersCount(
$fromDate = null,
$toDate = null,
- $mailingIds = array(),
- $contactIds = array(),
- $contactEmails = array(),
- $contactExternalIds = array(),
+ $mailingIds = [],
+ $contactIds = [],
+ $contactEmails = [],
+ $contactExternalIds = [],
$excludeAnonymousContacts = false
) {
$params = $this->createCountQueryParameters(
@@ -1540,53 +1532,53 @@ public function getSubscribersCount(
);
if (isset($excludeAnonymousContacts)) {
- $params ['exclude_anonymous_contacts'] = ($excludeAnonymousContacts == true) ? "true" : "false";
+ $params ['exclude_anonymous_contacts'] = $excludeAnonymousContacts === true ? 'true' : 'false';
}
- return $this->get('reports/subscribers/count', $params);
+ return $this->get(
+ 'reports/subscribers/count',
+ $params
+ );
}
/**
* Returns a page of conversions.
*
- * @param integer $fromDate
- * If provided, only the conversions after the given date will be returned. The value of from_date must
- * be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param integer $toDate
- * If provided, only the conversions before the given date will be returned. The value of to_date must
- * be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param array $mailingIds
- * Multivalued parameter to filter the conversions by mailings. Each value must correspond to a mailing id.
- * @param array $contactIds
- * Multivalued parameter to filter the conversions by contacts. Each value must correspond to a contact id.
- * @param array $contactEmails
- * Multivalued parameter to filter the conversions by email addresses.
- * @param array $contactExternalIds
- * Multivalued parameter to filter the conversions by external ids. Each value must correspond
- * to a contacts external id.
- * @param array $siteIds
- * Multivalued parameter to filter the conversions by site ids. Each value must correspond to a valid site id.
- * @param array $goalIds
- * Multivalued parameter to filter the conversions by goal ids. Each value must correspond to a valid goal id.
- * @param array $linkIds
- * Multivalued parameter to filter the conversions by link ids. Each value must correspond to a valid link id.
- * @param integer $pageIndex
- * The index of the result page. The index must be greater or equal to 1.
- * @param integer $pageSize
- * The maximum count of items in the result page. If provided, the value of page_size must
- * be in the range 1 to 1000.
- * @return MaileonAPIResult
+ * @param int $fromDate If provided, only the conversions after the given date will be returned. The value of from_date must
+ * be a numeric value representing a point in time milliseconds after January 1, 1970 00:00:00
+ * @param int $toDate If provided, only the conversions before the given date will be returned. The value of to_date must
+ * be a numeric value representing a point in time milliseconds after January 1, 1970 00:00:00
+ * @param array $mailingIds Multivalued parameter to filter the conversions by mailings. Each value must correspond to a mailing
+ * id.
+ * @param array $contactIds Multivalued parameter to filter the conversions by contacts. Each value must correspond to a contact
+ * id.
+ * @param array $contactEmails Multivalued parameter to filter the conversions by email addresses.
+ * @param array $contactExternalIds Multivalued parameter to filter the conversions by external ids. Each value must correspond to a
+ * contacts external id.
+ * @param array $siteIds Multivalued parameter to filter the conversions by site ids. Each value must correspond to a valid
+ * site id.
+ * @param array $goalIds Multivalued parameter to filter the conversions by goal ids. Each value must correspond to a valid
+ * goal id.
+ * @param array $linkIds Multivalued parameter to filter the conversions by link ids. Each value must correspond to a valid
+ * link id.
+ * @param int $pageIndex The index of the result page. The index must be greater or equal to 1.
+ * @param int $pageSize The maximum count of items in the result page. If provided, the value of page_size must be in the
+ * range 1 to 1000.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getConversions(
$fromDate = null,
$toDate = null,
- $mailingIds = array(),
- $contactIds = array(),
- $contactEmails = array(),
- $contactExternalIds = array(),
- $siteIds = array(),
- $goalIds = array(),
- $linkIds = array(),
+ $mailingIds = [],
+ $contactIds = [],
+ $contactEmails = [],
+ $contactExternalIds = [],
+ $siteIds = [],
+ $goalIds = [],
+ $linkIds = [],
$pageIndex = 1,
$pageSize = 100
) {
@@ -1603,49 +1595,51 @@ public function getConversions(
null
);
- $params = $this->appendArrayFields($params, "site_ids", $siteIds);
- $params = $this->appendArrayFields($params, "goal_ids", $goalIds);
- $params = $this->appendArrayFields($params, "link_ids", $linkIds);
+ $params = $this->appendArrayFields($params, 'site_ids', $siteIds);
+ $params = $this->appendArrayFields($params, 'goal_ids', $goalIds);
+ $params = $this->appendArrayFields($params, 'link_ids', $linkIds);
- return $this->get('reports/analytics/conversions', $params);
+ return $this->get(
+ 'reports/analytics/conversions',
+ $params
+ );
}
/**
* Returns the count of conversions.
*
- * @param integer $fromDate
- * If provided, only the conversions after the given date will be returned. The value of
- * from_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param integer $toDate
- * If provided, only the conversions before the given date will be returned. The value of
- * to_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param array $mailingIds
- * Multivalued parameter to filter the conversions by mailings. Each value must correspond to a mailing id.
- * @param array $contactIds
- * Multivalued parameter to filter the conversions by contacts. Each value must correspond to a contact id.
- * @param array $contactEmails
- * Multivalued parameter to filter the conversions by email addresses.
- * @param array $contactExternalIds
- * Multivalued parameter to filter the conversions by external ids. Each value must correspond to
- * a contacts external id.
- * @param array $siteIds
- * Multivalued parameter to filter the conversions by site ids. Each value must correspond to a valid site id.
- * @param array $goalIds
- * Multivalued parameter to filter the conversions by goal ids. Each value must correspond to a valid goal id.
- * @param array $linkIds
- * Multivalued parameter to filter the conversions by link ids. Each value must correspond to a valid link id.
- * @return number
+ * @param int $fromDate If provided, only the conversions after the given date will be returned. The value of from_date must
+ * be a numeric value representing a point in time milliseconds after January 1, 1970 00:00:00
+ * @param int $toDate If provided, only the conversions before the given date will be returned. The value of to_date must
+ * be a numeric value representing a point in time milliseconds after January 1, 1970 00:00:00
+ * @param array $mailingIds Multivalued parameter to filter the conversions by mailings. Each value must correspond to a mailing
+ * id.
+ * @param array $contactIds Multivalued parameter to filter the conversions by contacts. Each value must correspond to a contact
+ * id.
+ * @param array $contactEmails Multivalued parameter to filter the conversions by email addresses.
+ * @param array $contactExternalIds Multivalued parameter to filter the conversions by external ids. Each value must correspond to a
+ * contacts external id.
+ * @param array $siteIds Multivalued parameter to filter the conversions by site ids. Each value must correspond to a valid
+ * site id.
+ * @param array $goalIds Multivalued parameter to filter the conversions by goal ids. Each value must correspond to a valid
+ * goal id.
+ * @param array $linkIds Multivalued parameter to filter the conversions by link ids. Each value must correspond to a valid
+ * link id.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, conversion count as int available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getConversionsCount(
$fromDate = null,
$toDate = null,
- $mailingIds = array(),
- $contactIds = array(),
- $contactEmails = array(),
- $contactExternalIds = array(),
- $siteIds = array(),
- $goalIds = array(),
- $linkIds = array()
+ $mailingIds = [],
+ $contactIds = [],
+ $contactEmails = [],
+ $contactExternalIds = [],
+ $siteIds = [],
+ $goalIds = [],
+ $linkIds = []
) {
$params = $this->createCountQueryParameters(
$fromDate,
@@ -1657,57 +1651,56 @@ public function getConversionsCount(
null
);
- $params = $this->appendArrayFields($params, "site_ids", $siteIds);
- $params = $this->appendArrayFields($params, "goal_ids", $goalIds);
- $params = $this->appendArrayFields($params, "link_ids", $linkIds);
+ $params = $this->appendArrayFields($params, 'site_ids', $siteIds);
+ $params = $this->appendArrayFields($params, 'goal_ids', $goalIds);
+ $params = $this->appendArrayFields($params, 'link_ids', $linkIds);
- return $this->get('reports/analytics/conversions/count', $params);
+ return $this->get(
+ 'reports/analytics/conversions/count',
+ $params
+ );
}
/**
* Returns a page of unique conversions.
*
- * @param integer $fromDate
- * If provided, only the unique conversions after the given date will be returned. The value of from_date
- * must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param integer $toDate
- * If provided, only the unique conversions before the given date will be returned. The value of to_date
- * must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param array $mailingIds
- * Multivalued parameter to filter the unique conversions by mailings. Each value must correspond to a mailing id.
- * @param array $contactIds
- * Multivalued parameter to filter the unique conversions by contacts. Each value must correspond to a contact id.
- * @param array $contactEmails
- * Multivalued parameter to filter the unique conversions by email addresses.
- * @param array $contactExternalIds
- * Multivalued parameter to filter the unique conversions by external ids. Each value must
- * correspond to a contacts external id.
- * @param array $siteIds
- * Multivalued parameter to filter the unique conversions by site ids. Each value must correspond
- * to a valid site id.
- * @param array $goalIds
- * Multivalued parameter to filter the unique conversions by goal ids. Each value must correspond
- * to a valid goal id.
- * @param array $linkIds
- * Multivalued parameter to filter the unique conversions by link ids. Each value must correspond
- * to a valid link id.
- * @param integer $pageIndex
- * The index of the result page. The index must be greater or equal to 1.
- * @param integer $pageSize
- * The maximum count of items in the result page. If provided, the value of page_size must be in
- * the range 1 to 1000.
- * @return MaileonAPIResult
+ * @param int $fromDate If provided, only the unique conversions after the given date will be returned. The value of
+ * from_date must be a numeric value representing a point in time milliseconds after
+ * January 1, 1970 00:00:00
+ * @param int $toDate If provided, only the unique conversions before the given date will be returned. The value of
+ * to_date must be a numeric value representing a point in time milliseconds after
+ * January 1, 1970 00:00:00
+ * @param array $mailingIds Multivalued parameter to filter the unique conversions by mailings. Each value must correspond to a
+ * mailing id.
+ * @param array $contactIds Multivalued parameter to filter the unique conversions by contacts. Each value must correspond to a
+ * contact id.
+ * @param array $contactEmails Multivalued parameter to filter the unique conversions by email addresses.
+ * @param array $contactExternalIds Multivalued parameter to filter the unique conversions by external ids. Each value must correspond
+ * to a contacts external id.
+ * @param array $siteIds Multivalued parameter to filter the unique conversions by site ids. Each value must correspond to a
+ * valid site id.
+ * @param array $goalIds Multivalued parameter to filter the unique conversions by goal ids. Each value must correspond to a
+ * valid goal id.
+ * @param array $linkIds Multivalued parameter to filter the unique conversions by link ids. Each value must correspond to a
+ * valid link id.
+ * @param int $pageIndex The index of the result page. The index must be greater or equal to 1.
+ * @param int $pageSize The maximum count of items in the result page. If provided, the value of page_size must be in The
+ * range 1 to 1000.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getUniqueConversions(
$fromDate = null,
$toDate = null,
- $mailingIds = array(),
- $contactIds = array(),
- $contactEmails = array(),
- $contactExternalIds = array(),
- $siteIds = array(),
- $goalIds = array(),
- $linkIds = array(),
+ $mailingIds = [],
+ $contactIds = [],
+ $contactEmails = [],
+ $contactExternalIds = [],
+ $siteIds = [],
+ $goalIds = [],
+ $linkIds = [],
$pageIndex = 1,
$pageSize = 100
) {
@@ -1724,52 +1717,53 @@ public function getUniqueConversions(
null
);
- $params = $this->appendArrayFields($params, "site_ids", $siteIds);
- $params = $this->appendArrayFields($params, "goal_ids", $goalIds);
- $params = $this->appendArrayFields($params, "link_ids", $linkIds);
+ $params = $this->appendArrayFields($params, 'site_ids', $siteIds);
+ $params = $this->appendArrayFields($params, 'goal_ids', $goalIds);
+ $params = $this->appendArrayFields($params, 'link_ids', $linkIds);
- return $this->get('reports/analytics/conversions/unique', $params);
+ return $this->get(
+ 'reports/analytics/conversions/unique',
+ $params
+ );
}
/**
* Returns a page of unique conversions.
*
- * @param integer $fromDate
- * If provided, only the unique conversions after the given date will be returned. The value of
- * from_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param integer $toDate
- * If provided, only the unique conversions before the given date will be returned. The value of
- * to_date must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param array $mailingIds
- * Multivalued parameter to filter the unique conversions by mailings. Each value must correspond to a mailing id.
- * @param array $contactIds
- * Multivalued parameter to filter the unique conversions by contacts. Each value must correspond to a contact id.
- * @param array $contactEmails
- * Multivalued parameter to filter the unique conversions by email addresses.
- * @param array $contactExternalIds
- * Multivalued parameter to filter the unique conversions by external ids. Each value must
- * correspond to a contacts external id.
- * @param array $siteIds
- * Multivalued parameter to filter the unique conversions by site ids. Each value must correspond
- * to a valid site id.
- * @param array $goalIds
- * Multivalued parameter to filter the unique conversions by goal ids. Each value must correspond
- * to a valid goal id.
- * @param array $linkIds
- * Multivalued parameter to filter the unique conversions by link ids. Each value must correspond
- * to a valid link id.
- * @return number
+ * @param int $fromDate If provided, only the unique conversions after the given date will be returned. The value of
+ * from_date must be a numeric value representing a point in time milliseconds after
+ * January 1, 1970 00:00:00
+ * @param int $toDate If provided, only the unique conversions before the given date will be returned. The value of
+ * to_date must be a numeric value representing a point in time milliseconds after
+ * January 1, 1970 00:00:00
+ * @param array $mailingIds Multivalued parameter to filter the unique conversions by mailings. Each value must correspond to a
+ * mailing id.
+ * @param array $contactIds Multivalued parameter to filter the unique conversions by contacts. Each value must correspond to a
+ * contact id.
+ * @param array $contactEmails Multivalued parameter to filter the unique conversions by email addresses.
+ * @param array $contactExternalIds Multivalued parameter to filter the unique conversions by external ids. Each value must correspond
+ * to a contacts external id.
+ * @param array $siteIds Multivalued parameter to filter the unique conversions by site ids. Each value must correspond to a
+ * valid site id.
+ * @param array $goalIds Multivalued parameter to filter the unique conversions by goal ids. Each value must correspond to a
+ * valid goal id.
+ * @param array $linkIds Multivalued parameter to filter the unique conversions by link ids. Each value must correspond to a
+ * valid link id.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, unique conversion count as int available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getUniqueConversionsCount(
$fromDate = null,
$toDate = null,
- $mailingIds = array(),
- $contactIds = array(),
- $contactEmails = array(),
- $contactExternalIds = array(),
- $siteIds = array(),
- $goalIds = array(),
- $linkIds = array()
+ $mailingIds = [],
+ $contactIds = [],
+ $contactEmails = [],
+ $contactExternalIds = [],
+ $siteIds = [],
+ $goalIds = [],
+ $linkIds = []
) {
$params = $this->createCountQueryParameters(
$fromDate,
@@ -1781,49 +1775,51 @@ public function getUniqueConversionsCount(
null
);
- $params = $this->appendArrayFields($params, "site_ids", $siteIds);
- $params = $this->appendArrayFields($params, "goal_ids", $goalIds);
- $params = $this->appendArrayFields($params, "link_ids", $linkIds);
+ $params = $this->appendArrayFields($params, 'site_ids', $siteIds);
+ $params = $this->appendArrayFields($params, 'goal_ids', $goalIds);
+ $params = $this->appendArrayFields($params, 'link_ids', $linkIds);
- return $this->get('reports/analytics/conversions/unique/count', $params);
+ return $this->get(
+ 'reports/analytics/conversions/unique/count',
+ $params
+ );
}
/**
* Returns the revenue value.
*
- * @param integer $fromDate
- * If provided, only the revenues after the given date will be returned. The value of from_date
- * must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param integer $toDate
- * If provided, only the revenues before the given date will be returned. The value of to_date
- * must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param array $mailingIds
- * Multivalued parameter to filter the revenues by mailings. Each value must correspond to a mailing id.
- * @param array $contactIds
- * Multivalued parameter to filter the revenues by contacts. Each value must correspond to a contact id.
- * @param array $contactEmails
- * Multivalued parameter to filter the revenues by email addresses.
- * @param array $contactExternalIds
- * Multivalued parameter to filter the revenues by external ids. Each value must correspond to a
- * contacts external id.
- * @param array $siteIds
- * Multivalued parameter to filter the revenues by site ids. Each value must correspond to a valid site id.
- * @param array $goalIds
- * Multivalued parameter to filter the revenues by goal ids. Each value must correspond to a valid goal id.
- * @param array $linkIds
- * Multivalued parameter to filter the revenues by link ids. Each value must correspond to a valid link id.
- * @return MaileonAPIResult
+ * @param int $fromDate If provided, only the revenues after the given date will be returned. The value of from_date must be
+ * a numeric value representing a point in time milliseconds after January 1, 1970 00:00:00
+ * @param int $toDate If provided, only the revenues before the given date will be returned. The value of to_date must be
+ * a numeric value representing a point in time milliseconds after January 1, 1970 00:00:00
+ * @param array $mailingIds Multivalued parameter to filter the revenues by mailings. Each value must correspond to a mailing
+ * id.
+ * @param array $contactIds Multivalued parameter to filter the revenues by contacts. Each value must correspond to a contact
+ * id.
+ * @param array $contactEmails Multivalued parameter to filter the revenues by email addresses.
+ * @param array $contactExternalIds Multivalued parameter to filter the revenues by external ids. Each value must correspond to a
+ * contacts external id.
+ * @param array $siteIds Multivalued parameter to filter the revenues by site ids. Each value must correspond to a valid site
+ * id.
+ * @param array $goalIds Multivalued parameter to filter the revenues by goal ids. Each value must correspond to a valid goal
+ * id.
+ * @param array $linkIds Multivalued parameter to filter the revenues by link ids. Each value must correspond to a valid link
+ * id.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getRevenue(
$fromDate = null,
$toDate = null,
- $mailingIds = array(),
- $contactIds = array(),
- $contactEmails = array(),
- $contactExternalIds = array(),
- $siteIds = array(),
- $goalIds = array(),
- $linkIds = array()
+ $mailingIds = [],
+ $contactIds = [],
+ $contactEmails = [],
+ $contactExternalIds = [],
+ $siteIds = [],
+ $goalIds = [],
+ $linkIds = []
) {
$params = $this->createCountQueryParameters(
$fromDate,
@@ -1835,46 +1831,45 @@ public function getRevenue(
null
);
- $params = $this->appendArrayFields($params, "site_ids", $siteIds);
- $params = $this->appendArrayFields($params, "goal_ids", $goalIds);
- $params = $this->appendArrayFields($params, "link_ids", $linkIds);
+ $params = $this->appendArrayFields($params, 'site_ids', $siteIds);
+ $params = $this->appendArrayFields($params, 'goal_ids', $goalIds);
+ $params = $this->appendArrayFields($params, 'link_ids', $linkIds);
- return $this->get('reports/analytics/conversions/revenue', $params);
+ return $this->get(
+ 'reports/analytics/conversions/revenue',
+ $params
+ );
}
/**
* Creates the common query parameters
*
- * @param integer $pageIndex
- * The index of the result page. The index must be greater or equal to 1.
- * @param integer $pageSize
- * The maximum count of items in the result page. If provided, the value of page_size must be in
- * the range 1 to 1000.
- * @param integer $fromDate
- * If provided, only the unsubscriptions after the given date will be returned. The value of from_date
- * must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param integer $toDate
- * If provided, only the unsubscriptions before the given date will be returned. The value of to_date
- * must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param array $contactIds
- * Multivalued parameter to filter the unsubscriptions by contacts. Each value must correspond to a contact id.
- * @param array $contactEmails
- * Multivalued parameter to filter the unsubscriptions by email addresses.
- * @param array $contactExternalIds
- * Multivalued parameter to filter the unsubscriptions by external ids. Each value must
- * correspond to a contacts external id.
- * @param array $mailingIds
- * Multivalued parameter to filter the unsubscriptions by mailings. Each value must correspond to a mailing id.
- * @param string $source
- * Filters the unsubscriptions by their source. The source can be an unsubscription link
- * (link), a reply mail (reply) or other.
- * @param bool
- * $embedFieldBackups Supported values: true / false. Field Backups are the values of
- * contact fields that have been backed up for mailings because of a backup instruction.
- * For each unsubscription, the corresponding field backups will be returned if available.
- * Note that this only applies for non anonymizable field backups.
- *
- * @return MaileonAPIResult
+ * @param int $pageIndex The index of the result page. The index must be greater or equal to 1.
+ * @param int $pageSize The maximum count of items in the result page. If provided, the value of page_size must be in
+ * The range 1 to 1000.
+ * @param int $fromDate If provided, only the unsubscriptions after the given date will be returned. The value of
+ * from_date must be a numeric value representing a point in time milliseconds after
+ * January 1, 1970 00:00:00
+ * @param int $toDate If provided, only the unsubscriptions before the given date will be returned. The value of
+ * to_date must be a numeric value representing a point in time milliseconds after
+ * January 1, 1970 00:00:00
+ * @param array|null $contactIds Multivalued parameter to filter the unsubscriptions by contacts. Each value must correspond to
+ * a contact id.
+ * @param array|null $contactEmails Multivalued parameter to filter the unsubscriptions by email addresses.
+ * @param array|null $contactExternalIds Multivalued parameter to filter the unsubscriptions by external ids. Each value must
+ * correspond to a contacts external id.
+ * @param array|null $mailingIds Multivalued parameter to filter the unsubscriptions by mailings. Each value must correspond to
+ * a mailing id.
+ * @param string|null $source Filters the unsubscriptions by their source. The source can be an unsubscription link (link),
+ * a reply mail (reply) or other.
+ * @param bool|null $embedFieldBackups Supported values: true / false. Field Backups are the values of contact fields that have been
+ * backed up for mailings because of a backup instruction. For each unsubscription, the
+ * corresponding field backups will be returned if available. Note that this only applies for non
+ * anonymizable field backups.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
private function createQueryParameters(
$pageIndex,
@@ -1888,62 +1883,64 @@ private function createQueryParameters(
$source,
$embedFieldBackups
) {
- $queryParameters = array(
+ $queryParameters = [
'page_index' => $pageIndex,
- 'page_size' => $pageSize
- );
+ 'page_size' => $pageSize,
+ ];
if (isset($fromDate)) {
$queryParameters ['from_date'] = $fromDate;
}
+
if (isset($toDate)) {
$queryParameters ['to_date'] = $toDate;
}
+
if (isset($source)) {
$queryParameters ['source'] = $source;
}
- $queryParameters = $this->appendArrayFields($queryParameters, "ids", $contactIds);
- $queryParameters = $this->appendArrayFields($queryParameters, "emails", $contactEmails);
- $queryParameters = $this->appendArrayFields($queryParameters, "eids", $contactExternalIds);
+ $queryParameters = $this->appendArrayFields($queryParameters, 'ids', $contactIds);
+ $queryParameters = $this->appendArrayFields($queryParameters, 'emails', $contactEmails);
+ $queryParameters = $this->appendArrayFields($queryParameters, 'eids', $contactExternalIds);
if (isset($embedFieldBackups)) {
- $queryParameters ['embed_field_backups'] = ($embedFieldBackups == true) ? "true" : "false";
+ $queryParameters ['embed_field_backups'] = $embedFieldBackups === true ? 'true' : 'false';
}
if (isset($mailingIds)) {
- $queryParameters ['mailing_id'] = array();
+ $queryParameters ['mailing_id'] = [];
foreach ($mailingIds as $mailingId) {
$queryParameters ['mailing_id'] [] = $mailingId;
}
}
+
return $queryParameters;
}
/**
* Creates the common query parameters for count operations
*
- * @param integer $fromDate
- * If provided, only the unsubscriptions after the given date will be returned. The value of from_date
- * must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param integer $toDate
- * If provided, only the unsubscriptions before the given date will be returned. The value of to_date
- * must be a numeric value representing a point in time milliseconds afterJanuary 1, 1970 00:00:00
- * @param array $contactIds
- * Multivalued parameter to filter the unsubscriptions by contacts. Each value must correspond to a contact id.
- * @param array $contactEmails
- * Multivalued parameter to filter the unsubscriptions by email addresses.
- * @param array $contactExternalIds
- * Multivalued parameter to filter the unsubscriptions by external ids. Each value must
- * correspond to a contacts external id.
- * @param array $mailingIds
- * Multivalued parameter to filter the unsubscriptions by mailings. Each value must correspond to a mailing id.
- * @param string $source
- * Filters the unsubscriptions by their source. The source can be an unsubscription link
- * (link), a reply mail (reply) or other.
- *
- * @return MaileonAPIResult
+ * @param int $fromDate If provided, only the unsubscriptions after the given date will be returned. The value of
+ * from_date must be a numeric value representing a point in time milliseconds after
+ * January 1, 1970 00:00:00
+ * @param int $toDate If provided, only the unsubscriptions before the given date will be returned. The value of
+ * to_date must be a numeric value representing a point in time milliseconds after
+ * January 1, 1970 00:00:00
+ * @param array $contactIds Multivalued parameter to filter the unsubscriptions by contacts. Each value must correspond to
+ * a contact id.
+ * @param array $contactEmails Multivalued parameter to filter the unsubscriptions by email addresses.
+ * @param array $contactExternalIds Multivalued parameter to filter the unsubscriptions by external ids. Each value must correspond
+ * to a contacts external id.
+ * @param array|null $mailingIds Multivalued parameter to filter the unsubscriptions by mailings. Each value must correspond to
+ * a mailing id.
+ * @param string $source Filters the unsubscriptions by their source. The source can be an unsubscription link (link),
+ * a reply mail (reply) or other.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
private function createCountQueryParameters(
$fromDate,
@@ -1954,29 +1951,32 @@ private function createCountQueryParameters(
$mailingIds,
$source
) {
- $queryParameters = array();
+ $queryParameters = [];
if (isset($fromDate)) {
$queryParameters ['from_date'] = $fromDate;
}
+
if (isset($toDate)) {
$queryParameters ['to_date'] = $toDate;
}
+
if (isset($source)) {
$queryParameters ['source'] = $source;
}
- $queryParameters = $this->appendArrayFields($queryParameters, "ids", $contactIds);
- $queryParameters = $this->appendArrayFields($queryParameters, "emails", $contactEmails);
- $queryParameters = $this->appendArrayFields($queryParameters, "eids", $contactExternalIds);
+ $queryParameters = $this->appendArrayFields($queryParameters, 'ids', $contactIds);
+ $queryParameters = $this->appendArrayFields($queryParameters, 'emails', $contactEmails);
+ $queryParameters = $this->appendArrayFields($queryParameters, 'eids', $contactExternalIds);
if (isset($mailingIds)) {
- $queryParameters ['mailing_id'] = array();
+ $queryParameters ['mailing_id'] = [];
foreach ($mailingIds as $mailingId) {
$queryParameters ['mailing_id'] [] = $mailingId;
}
}
+
return $queryParameters;
}
}
diff --git a/src/reports/Subscriber.php b/src/reports/Subscriber.php
index 362a5d1..6d509d1 100644
--- a/src/reports/Subscriber.php
+++ b/src/reports/Subscriber.php
@@ -3,19 +3,20 @@
namespace de\xqueue\maileon\api\client\reports;
use de\xqueue\maileon\api\client\xml\AbstractXMLWrapper;
+use Exception;
+use SimpleXMLElement;
/**
* This class represents a subscriber containing the timestamp, the contact, and the ID of
* the mailing the subscriber was opted-in by.
*
- * @author Viktor Balogh (Wiera)
- * @author Marcus Ständer | Trusted Mails GmbH |
- * marcus.staender@trusted-mails.com
+ * @author Viktor Balogh | XQueue GmbH | viktor.balog@xqueue.com
+ * @author Marcus Beckerle | XQueue GmbH | marcus.beckerle@xqueue.com
*/
class Subscriber extends AbstractXMLWrapper
{
/**
- * @var integer
+ * @var int
*/
public $timestamp;
@@ -25,38 +26,31 @@ class Subscriber extends AbstractXMLWrapper
public $contact;
/**
- * @var integer
+ * @var int
*/
public $mailingId;
- /**
- * @return string
- * containing a human-readable representation of this subscriber
- */
- public function toString()
+ public function toString(): string
{
- return "Subscriber [timestamp=" . $this->timestamp .
- ", contact=" . $this->contact->toString() .
- ", mailingId=" . $this->mailingId . "]";
+ return 'Subscriber ['
+ . 'timestamp=' . $this->timestamp
+ . ', contact=' . $this->contact->toString()
+ . ', mailingId=' . $this->mailingId
+ . ']';
}
/**
+ * CSV representation of this wrapper.
+ *
* @return string
- * containing a csv pepresentation of this subscriber
*/
- public function toCsvString()
+ public function toCsvString(): string
{
- return $this->timestamp .
- ";" . $this->contact->toCsvString() .
- ";" . $this->mailingId;
+ return $this->timestamp
+ . ';' . $this->contact->toCsvString()
+ . ';' . $this->mailingId;
}
- /**
- * Initializes this subscriber from an XML representation.
- *
- * @param \SimpleXMLElement $xmlElement
- * the XML representation to use
- */
public function fromXML($xmlElement)
{
$this->contact = new ReportContact();
@@ -65,6 +59,7 @@ public function fromXML($xmlElement)
if (isset($xmlElement->mailing_id)) {
$this->mailingId = $xmlElement->mailing_id;
}
+
if (isset($xmlElement->timestamp)) {
$this->timestamp = $xmlElement->timestamp;
}
@@ -73,22 +68,27 @@ public function fromXML($xmlElement)
/**
* For future use, not implemented yet.
*
- * @return \SimpleXMLElement
- * containing the XML serialization of this object
+ * Serialization to a simple XML element.
+ *
+ * @return SimpleXMLElement contains the serialized representation of the object
+ *
+ * @throws Exception
*/
public function toXML()
{
- $xmlString = "";
- $xml = new \SimpleXMLElement($xmlString);
+ $xmlString = '';
+ $xml = new SimpleXMLElement($xmlString);
if (isset($this->contact)) {
- $xml->addChild("contact", $this->contact->toXML());
- }
+ $xml->addChild('contact', $this->contact->toXML());
+ }
+
if (isset($this->mailingId)) {
- $xml->addChild("mailing_id", $this->mailingId);
+ $xml->addChild('mailing_id', $this->mailingId);
}
+
if (isset($this->timestamp)) {
- $xml->addChild("timestamp", $this->timestamp);
+ $xml->addChild('timestamp', $this->timestamp);
}
return $xml;
diff --git a/src/reports/UniqueBounce.php b/src/reports/UniqueBounce.php
index 0c15a44..4324939 100644
--- a/src/reports/UniqueBounce.php
+++ b/src/reports/UniqueBounce.php
@@ -3,16 +3,18 @@
namespace de\xqueue\maileon\api\client\reports;
use de\xqueue\maileon\api\client\xml\AbstractXMLWrapper;
+use Exception;
+use SimpleXMLElement;
/**
* This class represents a unique bounce containing the timestamp, the contact, and the ID of the mailing.
*
- * @author Marcus Ständer
+ * @author Marcus Beckerle | XQueue GmbH | marcus.beckerle@xqueue.com
*/
class UniqueBounce extends AbstractXMLWrapper
{
/**
- * @var String
+ * @var string
*/
public $timestamp;
@@ -22,13 +24,12 @@ class UniqueBounce extends AbstractXMLWrapper
public $contact;
/**
- * @var integer
+ * @var int
*/
public $mailingId;
-
/**
- * @var String
+ * @var string
*/
public $lastType;
@@ -47,42 +48,35 @@ class UniqueBounce extends AbstractXMLWrapper
*/
public $countSoft;
- /**
- * @return string
- * containing a human-readable representation of this unique bounce
- */
- public function toString()
+ public function toString(): string
{
- return "UniqueBounce [timestamp=" . $this->timestamp .
- ", contact=" . $this->contact->toString() .
- ", mailingId=" . $this->mailingId .
- ", count=" . $this->count .
- ", countHard=" . $this->countHard .
- ", countSoft=" . $this->countSoft .
- ", lastType=" . $this->lastType . "]";
+ return 'UniqueBounce ['
+ . 'timestamp=' . $this->timestamp
+ . ', contact=' . $this->contact->toString()
+ . ', mailingId=' . $this->mailingId
+ . ', count=' . $this->count
+ . ', countHard=' . $this->countHard
+ . ', countSoft=' . $this->countSoft
+ . ', lastType=' . $this->lastType
+ . ']';
}
/**
+ * CSV representation of this wrapper.
+ *
* @return string
- * containing a csv pepresentation of this unique bounce
*/
- public function toCsvString()
+ public function toCsvString(): string
{
- return $this->timestamp .
- ";" . $this->contact->toCsvString() .
- ";" . $this->mailingId .
- ";" . $this->count .
- ";" . $this->countHard .
- ";" . $this->countSoft .
- ";" . $this->lastType;
+ return $this->timestamp
+ . ';' . $this->contact->toCsvString()
+ . ';' . $this->mailingId
+ . ';' . $this->count
+ . ';' . $this->countHard
+ . ';' . $this->countSoft
+ . ';' . $this->lastType;
}
- /**
- * Initializes this unique bounce from an XML representation.
- *
- * @param \SimpleXMLElement $xmlElement
- * the XML representation to use
- */
public function fromXML($xmlElement)
{
$this->contact = new ReportContact();
@@ -91,18 +85,23 @@ public function fromXML($xmlElement)
if (isset($xmlElement->mailing_id)) {
$this->mailingId = $xmlElement->mailing_id;
}
+
if (isset($xmlElement->timestamp)) {
$this->timestamp = $xmlElement->timestamp;
}
+
if (isset($xmlElement->last_type)) {
$this->lastType = $xmlElement->last_type;
}
+
if (isset($xmlElement->count)) {
$this->count = $xmlElement->count;
}
+
if (isset($xmlElement->count_hard)) {
$this->countHard = $xmlElement->count_hard;
}
+
if (isset($xmlElement->count_soft)) {
$this->countSoft = $xmlElement->count_soft;
}
@@ -111,34 +110,43 @@ public function fromXML($xmlElement)
/**
* For future use, not implemented yet.
*
- * @return \SimpleXMLElement
- * containing the XML serialization of this object
+ * Serialization to a simple XML element.
+ *
+ * @return SimpleXMLElement contains the serialized representation of the object
+ *
+ * @throws Exception
*/
public function toXML()
{
- $xmlString = "";
- $xml = new \SimpleXMLElement($xmlString);
+ $xmlString = '';
+ $xml = new SimpleXMLElement($xmlString);
if (isset($this->contact)) {
- $xml->addChild("contact", $this->contact->toXML());
- }
+ $xml->addChild('contact', $this->contact->toXML());
+ }
+
if (isset($this->mailingId)) {
- $xml->addChild("mailing_id", $this->mailingId);
+ $xml->addChild('mailing_id', $this->mailingId);
}
+
if (isset($this->timestamp)) {
- $xml->addChild("timestamp", $this->timestamp);
+ $xml->addChild('timestamp', $this->timestamp);
}
+
if (isset($this->lastType)) {
- $xml->addChild("last_type", $this->lastType);
+ $xml->addChild('last_type', $this->lastType);
}
+
if (isset($this->count)) {
- $xml->addChild("count", $this->count);
+ $xml->addChild('count', $this->count);
}
+
if (isset($this->countHard)) {
- $xml->addChild("count_hard", $this->countHard);
+ $xml->addChild('count_hard', $this->countHard);
}
+
if (isset($this->countSoft)) {
- $xml->addChild("count_soft", $this->countSoft);
+ $xml->addChild('count_soft', $this->countSoft);
}
return $xml;
diff --git a/src/reports/UniqueConversion.php b/src/reports/UniqueConversion.php
index 90b0122..85028af 100644
--- a/src/reports/UniqueConversion.php
+++ b/src/reports/UniqueConversion.php
@@ -3,6 +3,8 @@
namespace de\xqueue\maileon\api\client\reports;
use de\xqueue\maileon\api\client\xml\AbstractXMLWrapper;
+use Exception;
+use SimpleXMLElement;
/**
* This class represents a unique conversion
@@ -12,7 +14,7 @@
class UniqueConversion extends AbstractXMLWrapper
{
/**
- * @var integer
+ * @var int
*/
public $contactId;
@@ -32,80 +34,80 @@ class UniqueConversion extends AbstractXMLWrapper
public $revenue;
/**
- * @var integer
+ * @var int
*/
public $countTotal;
- /**
- * @return string
- * containing a human-readable representation of this conversion
- */
- public function toString()
+ public function toString(): string
{
-
- return "UniqueConversion [" .
- "contactId=" . $this->contactId .
- ", contactEmail=" . $this->contactEmail .
- ", revenue=" . $this->revenue .
- ", countTotal=" . $this->countTotal ."]";
+ return 'UniqueConversion ['
+ . 'contactId=' . $this->contactId
+ . ', contactEmail=' . $this->contactEmail
+ . ', revenue=' . $this->revenue
+ . ', countTotal=' . $this->countTotal
+ . ']';
}
- /**
- * Initializes this conversion from an XML representation.
- *
- * @param \SimpleXMLElement $xmlElement
- * the XML representation to use
- */
public function fromXML($xmlElement)
{
if (isset($xmlElement->contact_id)) {
$this->contactId = $xmlElement->contact_id;
}
+
if (isset($xmlElement->contact_email)) {
$this->contactEmail = $xmlElement->contact_email;
}
+
if (isset($xmlElement->revenue)) {
$this->revenue = $xmlElement->revenue;
}
+
if (isset($xmlElement->count_total)) {
$this->countTotal = $xmlElement->count_total;
}
}
/**
+ * CSV representation of this wrapper.
+ *
* @return string
- * containing a csv pepresentation of this conversion
*/
- public function toCsvString()
+ public function toCsvString(): string
{
- return $this->contactId .
- ";" . $this->contactEmail .
- ";" . $this->revenue .
- ";" . $this->countTotal;
+ return $this->contactId
+ . ';' . $this->contactEmail
+ . ';' . $this->revenue
+ . ';' . $this->countTotal;
}
/**
* For future use, not implemented yet.
*
- * @return \SimpleXMLElement
- * containing the XML serialization of this object
+ * Serialization to a simple XML element.
+ *
+ * @return SimpleXMLElement contains the serialized representation of the object
+ *
+ * @throws Exception
*/
public function toXML()
{
- $xmlString = "";
- $xml = new \SimpleXMLElement($xmlString);
+ $xmlString = '';
+ $xml = new SimpleXMLElement($xmlString);
if (isset($this->contactId)) {
- $xml->addChild("contact_id", $this->contactId);
+ $xml->addChild('contact_id', $this->contactId);
}
+
if (isset($this->contactEmail)) {
- $xml->addChild("contact_email", $this->contactEmail);
+ $xml->addChild('contact_email', $this->contactEmail);
}
+
if (isset($this->revenue)) {
- $xml->addChild("revenue", $this->revenue);
+ $xml->addChild('revenue', $this->revenue);
}
+
if (isset($this->countTotal)) {
- $xml->addChild("count_total", $this->countTotal);
+ $xml->addChild('count_total', $this->countTotal);
}
return $xml;
diff --git a/src/reports/Unsubscriber.php b/src/reports/Unsubscriber.php
index bb76340..377ec1f 100644
--- a/src/reports/Unsubscriber.php
+++ b/src/reports/Unsubscriber.php
@@ -3,19 +3,20 @@
namespace de\xqueue\maileon\api\client\reports;
use de\xqueue\maileon\api\client\xml\AbstractXMLWrapper;
+use Exception;
+use SimpleXMLElement;
/**
* This class represents an unsubscription containing the timestamp, the contact,
* the ID of the mailing the unsubscription came from, and the source.
*
- * @author Viktor Balogh (Wiera)
- * @author Marcus Ständer | Trusted Mails GmbH |
- * marcus.staender@trusted-mails.com
+ * @author Viktor Balogh | XQueue GmbH | viktor.balog@xqueue.com
+ * @author Marcus Beckerle | XQueue GmbH | marcus.beckerle@xqueue.com
*/
class Unsubscriber extends AbstractXMLWrapper
{
/**
- * @var integer
+ * @var int
*/
public $timestamp;
@@ -25,17 +26,17 @@ class Unsubscriber extends AbstractXMLWrapper
public $contact;
/**
- * @var integer
+ * @var int
*/
public $mailingId;
-
+
/**
* @var string
*/
public $transactionId;
-
+
/**
- * @var integer
+ * @var int
*/
public $messageId;
@@ -44,39 +45,33 @@ class Unsubscriber extends AbstractXMLWrapper
*/
public $source;
- /**
- * @return string
- * containing a human-readable representation of this unsubscription
- */
- public function toString()
+ public function toString(): string
{
- return "Unsubscriber [timestamp=" . $this->timestamp .
- ", contact=" . $this->contact->toString() .
- ", mailingId=" . $this->mailingId .
- ", source=" . $this->source .
- ", transactionId=" . $this->transactionId .
- ", messageId=" . $this->messageId ."]";
+ return 'Unsubscriber ['
+ . 'timestamp=' . $this->timestamp
+ . ', contact=' . $this->contact->toString()
+ . ', mailingId=' . $this->mailingId
+ . ', source=' . $this->source
+ . ', transactionId=' . $this->transactionId
+ . ', messageId=' . $this->messageId
+ . ']';
}
/**
- * @return string containing a csv pepresentation of this unsubscriber
+ * CSV representation of this wrapper.
+ *
+ * @return string
*/
- public function toCsvString()
+ public function toCsvString(): string
{
- return $this->timestamp .
- ";" . $this->contact->toCsvString() .
- ";" . $this->mailingId .
- ";" . $this->source .
- ";" . $this->transactionId .
- ";" . $this->messageId;
+ return $this->timestamp
+ . ';' . $this->contact->toCsvString()
+ . ';' . $this->mailingId
+ . ';' . $this->source
+ . ';' . $this->transactionId
+ . ';' . $this->messageId;
}
- /**
- * Initializes this unsubscription from an XML representation.
- *
- * @param \SimpleXMLElement $xmlElement
- * the XML representation to use
- */
public function fromXML($xmlElement)
{
$this->contact = new ReportContact();
@@ -85,48 +80,60 @@ public function fromXML($xmlElement)
if (isset($xmlElement->mailing_id)) {
$this->mailingId = $xmlElement->mailing_id;
}
+
if (isset($xmlElement->source)) {
$this->source = $xmlElement->source;
}
+
if (isset($xmlElement->timestamp)) {
$this->timestamp = $xmlElement->timestamp;
}
+
if (isset($xmlElement->transaction_id)) {
$this->transactionId = $xmlElement->transaction_id;
}
- if (isset($xmlElement->msg_id )) {
- $this->messageId = $xmlElement->msg_id ;
+
+ if (isset($xmlElement->msg_id)) {
+ $this->messageId = $xmlElement->msg_id;
}
}
/**
* For future use, not implemented yet.
*
- * @return \SimpleXMLElement
- * containing the XML serialization of this object
+ * Serialization to a simple XML element.
+ *
+ * @return SimpleXMLElement contains the serialized representation of the object
+ *
+ * @throws Exception
*/
public function toXML()
{
- $xmlString = "";
- $xml = new \SimpleXMLElement($xmlString);
+ $xmlString = '';
+ $xml = new SimpleXMLElement($xmlString);
if (isset($this->contact)) {
- $xml->addChild("contact", $this->contact->toXML());
- }
+ $xml->addChild('contact', $this->contact->toXML());
+ }
+
if (isset($this->timestamp)) {
- $xml->addChild("timestamp", $this->timestamp);
+ $xml->addChild('timestamp', $this->timestamp);
}
+
if (isset($this->mailingId)) {
- $xml->addChild("mailing_id", $this->mailingId);
+ $xml->addChild('mailing_id', $this->mailingId);
}
+
if (isset($this->transactionId)) {
- $xml->addChild("transaction_id", $this->transactionId);
+ $xml->addChild('transaction_id', $this->transactionId);
}
- if (isset($this->messageId )) {
- $xml->addChild("msg_id", $this->messageId);
+
+ if (isset($this->messageId)) {
+ $xml->addChild('msg_id', $this->messageId);
}
+
if (isset($this->source)) {
- $xml->addChild("source", $this->source);
+ $xml->addChild('source', $this->source);
}
return $xml;
diff --git a/src/reports/UnsubscriptionReason.php b/src/reports/UnsubscriptionReason.php
index ab050d8..b7e39d2 100644
--- a/src/reports/UnsubscriptionReason.php
+++ b/src/reports/UnsubscriptionReason.php
@@ -3,6 +3,8 @@
namespace de\xqueue\maileon\api\client\reports;
use de\xqueue\maileon\api\client\xml\AbstractXMLWrapper;
+use Exception;
+use SimpleXMLElement;
/**
* This class represents an unsubscription reason containing the value and count.
@@ -17,62 +19,60 @@ class UnsubscriptionReason extends AbstractXMLWrapper
public $reason;
/**
- * @var integer
+ * @var int
*/
public $count;
- /**
- * @return string
- * containing a human-readable representation of this unsubscription reason
- */
- public function toString()
+ public function toString(): string
{
- return "Unsubscriber [reason=" . $this->reason .
- ", count=" . $this->count ."]";
+ return 'Unsubscriber ['
+ . 'reason=' . $this->reason
+ . ', count=' . $this->count
+ . ']';
}
/**
- * @return string containing a csv pepresentation of this unsubscription reason
+ * CSV representation of this wrapper.
+ *
+ * @return string
*/
- public function toCsvString()
+ public function toCsvString(): string
{
- return $this->reason .
- ";" . $this->count;
+ return $this->reason
+ . ';' . $this->count;
}
- /**
- * Initializes this unsubscription reason from an XML representation.
- *
- * @param \SimpleXMLElement $xmlElement
- * the XML representation to use
- */
public function fromXML($xmlElement)
{
-
if (isset($xmlElement->reason)) {
- $this->reason = (string)$xmlElement->reason;
+ $this->reason = (string) $xmlElement->reason;
}
+
if (isset($xmlElement->count)) {
- $this->count = intval((string)$xmlElement->count);
+ $this->count = (int) (string) $xmlElement->count;
}
}
/**
* For future use, not implemented yet.
*
- * @return \SimpleXMLElement
- * containing the XML serialization of this object
+ * Serialization to a simple XML element.
+ *
+ * @return SimpleXMLElement contains the serialized representation of the object
+ *
+ * @throws Exception
*/
public function toXML()
{
- $xmlString = "";
- $xml = new \SimpleXMLElement($xmlString);
+ $xmlString = '';
+ $xml = new SimpleXMLElement($xmlString);
if (isset($this->reason)) {
- $xml->addChild("reason", $this->reason);
- }
+ $xml->addChild('reason', $this->reason);
+ }
+
if (isset($this->count)) {
- $xml->addChild("count", $this->count);
+ $xml->addChild('count', $this->count);
}
return $xml;
diff --git a/src/targetgroups/TargetGroup.php b/src/targetgroups/TargetGroup.php
index 9adda3f..8c1dd9e 100644
--- a/src/targetgroups/TargetGroup.php
+++ b/src/targetgroups/TargetGroup.php
@@ -3,6 +3,7 @@
namespace de\xqueue\maileon\api\client\targetgroups;
use de\xqueue\maileon\api\client\xml\AbstractXMLWrapper;
+use SimpleXMLElement;
/**
* The wrapper class for a Maileon target group.
@@ -26,124 +27,98 @@ class TargetGroup extends AbstractXMLWrapper
/**
* Creates a new target group wrapper object.
*
- * @param number $id
+ * @param int $id
* @param string $name
* @param string $author
* @param string $state
* @param string $type
* @param string $contactFilterName
- * @param number $contactFilterId
+ * @param int $contactFilterId
* @param string $evaluated
* @param string $created
* @param string $updated
- * @param number $countActiveContacts
- * @param number $countContacts
+ * @param int $countActiveContacts
+ * @param int $countContacts
*/
public function __construct(
$id = 0,
- $name = "",
- $author = "",
- $state = "",
- $type = "",
- $contactFilterName = "",
+ $name = '',
+ $author = '',
+ $state = '',
+ $type = '',
+ $contactFilterName = '',
$contactFilterId = 0,
- $evaluated = "1970-01-01 00:00:00",
- $created = "1970-01-01 00:00:00",
- $updated = "1970-01-01 00:00:00",
+ $evaluated = '1970-01-01 00:00:00',
+ $created = '1970-01-01 00:00:00',
+ $updated = '1970-01-01 00:00:00',
$countActiveContacts = 0,
$countContacts = 0
) {
- $this->id = $id;
- $this->name = $name;
- $this->author = $author;
- $this->state = $state;
- $this->type = $type;
- $this->contactFilterName = $contactFilterName;
- $this->contactFilterId = $contactFilterId;
- $this->evaluated = $evaluated;
- $this->created = $created;
- $this->updated = $updated;
+ $this->id = $id;
+ $this->name = $name;
+ $this->author = $author;
+ $this->state = $state;
+ $this->type = $type;
+ $this->contactFilterName = $contactFilterName;
+ $this->contactFilterId = $contactFilterId;
+ $this->evaluated = $evaluated;
+ $this->created = $created;
+ $this->updated = $updated;
$this->countActiveContacts = $countActiveContacts;
- $this->countContacts = $countContacts;
+ $this->countContacts = $countContacts;
}
- /**
- * Initializes this target group from an XML representation.
- *
- * @param \SimpleXMLElement $xmlElement
- * the XML representation to use
- */
public function fromXML($xmlElement)
{
- $this->id = $xmlElement->id;
- $this->name = $xmlElement->name;
- $this->author = $xmlElement->author;
- $this->state = $xmlElement->state;
- $this->type = $xmlElement->type;
- $this->contactFilterName = $xmlElement->contact_filter_name;
- $this->contactFilterId = $xmlElement->contact_filter_id;
- $this->evaluated = $xmlElement->evaluated;
- $this->created = $xmlElement->created;
- $this->updated = $xmlElement->updated;
+ $this->id = $xmlElement->id;
+ $this->name = $xmlElement->name;
+ $this->author = $xmlElement->author;
+ $this->state = $xmlElement->state;
+ $this->type = $xmlElement->type;
+ $this->contactFilterName = $xmlElement->contact_filter_name;
+ $this->contactFilterId = $xmlElement->contact_filter_id;
+ $this->evaluated = $xmlElement->evaluated;
+ $this->created = $xmlElement->created;
+ $this->updated = $xmlElement->updated;
$this->countActiveContacts = $xmlElement->count_active_contacts;
- $this->countContacts = $xmlElement->count_contacts;
+ $this->countContacts = $xmlElement->count_contacts;
}
- /**
- * @return \SimpleXMLElement
- * containing the serialized representation of this target group
- */
public function toXML()
{
- $xml = new \SimpleXMLElement("");
+ $xml = new SimpleXMLElement('');
- $xml->addChild("id", $this->id);
- $xml->addChild("name", $this->name);
- $xml->addChild("author", $this->author);
- $xml->addChild("state", $this->state);
- $xml->addChild("type", $this->type);
- $xml->addChild("contact_filter_name", $this->contactFilterName);
- $xml->addChild("contact_filter_id", $this->contactFilterId);
- $xml->addChild("evaluated", $this->evaluated);
- $xml->addChild("created", $this->created);
- $xml->addChild("updated", $this->updated);
- $xml->addChild("count_active_contacts", $this->countActiveContacts);
- $xml->addChild("count_contacts", $this->countContacts);
+ $xml->addChild('id', $this->id);
+ $xml->addChild('name', $this->name);
+ $xml->addChild('author', $this->author);
+ $xml->addChild('state', $this->state);
+ $xml->addChild('type', $this->type);
+ $xml->addChild('contact_filter_name', $this->contactFilterName);
+ $xml->addChild('contact_filter_id', $this->contactFilterId);
+ $xml->addChild('evaluated', $this->evaluated);
+ $xml->addChild('created', $this->created);
+ $xml->addChild('updated', $this->updated);
+ $xml->addChild('count_active_contacts', $this->countActiveContacts);
+ $xml->addChild('count_contacts', $this->countContacts);
return $xml;
}
- /**
- * Serialization to a simple XML element as string
- *
- * @return string
- * The string representation of the XML document.
- */
- public function toXMLString()
- {
- $xml = $this->toXML();
- return $xml->asXML();
- }
-
- /**
- * @return string
- * containing a human-readable representation of this target group
- */
- public function toString()
+ public function toString(): string
{
- return "ContactFilter [" .
- "id=" . $this->id .
- ", name=" . $this->name .
- ", author=" . $this->author .
- ", state=" . $this->state .
- ", type=" . $this->type .
- ", contactFilterName=" . $this->contactFilterName .
- ", contactFilterId=" . $this->contactFilterId .
- ", evaluated=" . $this->evaluated .
- ", created=" . $this->created .
- ", updated=" . $this->updated .
- ", countActiveContacts=" . $this->countActiveContacts .
- ", countContacts=" . $this->countContacts .
- "]";
+ return 'ContactFilter ['
+ . 'id=' . $this->id
+ . ', name=' . $this->name
+ . ', author=' . $this->author
+ . ', state=' . $this->state
+ . ', type=' . $this->type
+ . ', contactFilterName=' . $this->contactFilterName
+ . ', contactFilterId=' . $this->contactFilterId
+ . ', evaluated=' . $this->evaluated
+ . ', created=' . $this->created
+ . ', updated=' . $this->updated
+ . ', countActiveContacts=' . $this->countActiveContacts
+ . ', countContacts=' . $this->countContacts
+ . ']';
}
}
diff --git a/src/targetgroups/TargetGroupsService.php b/src/targetgroups/TargetGroupsService.php
index fd685b1..385ae59 100644
--- a/src/targetgroups/TargetGroupsService.php
+++ b/src/targetgroups/TargetGroupsService.php
@@ -3,21 +3,24 @@
namespace de\xqueue\maileon\api\client\targetgroups;
use de\xqueue\maileon\api\client\AbstractMaileonService;
+use de\xqueue\maileon\api\client\MaileonAPIException;
use de\xqueue\maileon\api\client\MaileonAPIResult;
+use Exception;
+
+use function mb_convert_encoding;
+use function rawurlencode;
/**
* Facade that wraps the REST service for target groups
*
- * @author Marcus Ständer
+ * @author Marcus Beckerle | XQueue GmbH | marcus.beckerle@xqueue.com
*/
class TargetGroupsService extends AbstractMaileonService
{
-
-
/**
- * @return MaileonAPIResult
- * the result object of the API call, with the count of defined target groups available
- * at MaileonAPIResult::getResult()
+ * @return MaileonAPIResult|null The result object of the API call, with the count of defined target groups available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getTargetGroupsCount()
{
@@ -27,54 +30,70 @@ public function getTargetGroupsCount()
/**
* Returns the defined target groups.
*
- * @param number $page_index
- * the paging index of the page to fetch
- * @param number $page_size
- * the number of entries to return per page
- * @return MaileonAPIResult
- * the result object of the API call, with a TargetGroup
- * available at MaileonAPIResult::getResult()
+ * @param int $page_index The paging index of the page to fetch
+ * @param int $page_size The number of entries to return per page
+ *
+ * @return MaileonAPIResult|null The result object of the API call, with a TargetGroup available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function getTargetGroups($page_index = 1, $page_size = 10)
- {
- $queryParameters = array(
+ public function getTargetGroups(
+ $page_index = 1,
+ $page_size = 10
+ ) {
+ $queryParameters = [
'page_index' => $page_index,
- 'page_size' => $page_size
+ 'page_size' => $page_size,
+ ];
+
+ return $this->get(
+ 'targetgroups',
+ $queryParameters
);
- return $this->get('targetgroups', $queryParameters);
}
/**
* @param string $targetGroupId
- * @return MaileonAPIResult
- * the result object of the API call, with the TargetGroup
- * available at MaileonAPIResult::getResult()
+ *
+ * @return MaileonAPIResult|null The result object of the API call, with the TargetGroup available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getTargetGroup($targetGroupId)
{
- return $this->get('targetgroups/targetgroup/' . $targetGroupId);
+ $encodedTargetGroupId = rawurlencode(mb_convert_encoding((string) $targetGroupId, 'UTF-8'));
+
+ return $this->get("targetgroups/targetgroup/$encodedTargetGroupId");
}
/**
* Create a target group
+ *
* @param TargetGroup $targetGroup
- * @return MaileonAPIResult
- * the result object of the API call, with the TargetGroup
- * available at MaileonAPIResult::getResult()
+ *
+ * @return MaileonAPIResult|null The result object of the API call, with the TargetGroup available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function createTargetGroup($targetGroup)
{
- return $this->post('targetgroups', $targetGroup->toXMLString());
+ return $this->post(
+ 'targetgroups',
+ $targetGroup->toXMLString()
+ );
}
/**
* @param string $targetGroupId
- * @return MaileonAPIResult
- * the result object of the API call, with the deleted TargetGroup
- * available at MaileonAPIResult::getResult()
+ *
+ * @return MaileonAPIResult|null The result object of the API call, with the deleted TargetGroup available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function deleteTargetGroup($targetGroupId)
{
- return $this->delete('targetgroups/targetgroup/' . $targetGroupId);
+ $encodedTargetGroupId = rawurlencode(mb_convert_encoding((string) $targetGroupId, 'UTF-8'));
+
+ return $this->delete("targetgroups/targetgroup/$encodedTargetGroupId");
}
}
diff --git a/src/transactions/Attachment.php b/src/transactions/Attachment.php
index 9aada81..022b903 100644
--- a/src/transactions/Attachment.php
+++ b/src/transactions/Attachment.php
@@ -16,20 +16,27 @@ class Attachment
/**
* Creates a new attachment. Please use the factory methods
* in Transaction instead of calling this constructor directly.
+ *
* @param $filename
* @param $mimetype
* @param $data
*/
- public function __construct($filename, $mimetype, $data)
- {
+ public function __construct(
+ $filename,
+ $mimetype,
+ $data
+ ) {
$this->filename = $filename;
$this->mimetype = $mimetype;
- $this->data = $data;
+ $this->data = $data;
}
- public function toString()
+ public function toString(): string
{
- return "Attachment [filename=" . $this->filename .
- ", mimetype=(" . $this->mimetype . "), data=(" . $this->data . ")]";
+ return 'Attachment ['
+ . 'filename=' . $this->filename
+ . ', mimetype=(' . $this->mimetype . ')'
+ . ', data=(' . $this->data . ')'
+ . ']';
}
}
diff --git a/src/transactions/AttributeType.php b/src/transactions/AttributeType.php
index d7e9aed..d2ee8a4 100644
--- a/src/transactions/AttributeType.php
+++ b/src/transactions/AttributeType.php
@@ -10,51 +10,60 @@
class AttributeType
{
/**
+ * The id of this attribute
*
- * @var integer The id of this attribute
+ * @var int
*/
public $id;
+
/**
+ * The name of this attribute
*
- * @var string The name of this attribute
+ * @var string
*/
public $name;
+
/**
+ * The description of this attribute
*
- * @var string The description of this attribute
+ * @var string
*/
public $description;
+
/**
+ * The type of this attribute
*
- * @var DataType The type of this attribute
+ * @var DataType
*/
public $type;
+
/**
+ * Whether the given attribute is required
*
- * @var boolean Whether the given attribute is required
+ * @var boolean
*/
public $required;
/**
* Creates a new AttributeType.
*
- * @param integer $id
- * the id of the attribute
- * @param string $name
- * the name of the attribute
- * @param DataType $type
- * the type of the attribute's value
- * @param bool $required
- * set to true if this attribute is required, false if it is optional
- * @param string $description
- * the description of the attribute
+ * @param int $id the id of the attribute
+ * @param string $name the name of the attribute
+ * @param DataType $type the type of the attribute's value
+ * @param bool $required set to true if this attribute is required, false if it is optional
+ * @param string $description the description of the attribute
*/
- public function __construct($id = null, $name = '', $type = '', $required = false, $description = "")
- {
- $this->id = $id;
- $this->name = $name;
- $this->type = $type;
- $this->required = $required;
+ public function __construct(
+ $id = null,
+ $name = '',
+ $type = '',
+ $required = false,
+ $description = ''
+ ) {
+ $this->id = $id;
+ $this->name = $name;
+ $this->type = $type;
+ $this->required = $required;
$this->description = $description;
}
}
diff --git a/src/transactions/ContactReference.php b/src/transactions/ContactReference.php
index 44ef98a..76e6622 100644
--- a/src/transactions/ContactReference.php
+++ b/src/transactions/ContactReference.php
@@ -2,71 +2,62 @@
namespace de\xqueue\maileon\api\client\transactions;
-use de\xqueue\maileon\api\client\json\AbstractJSONWrapper;
use de\xqueue\maileon\api\client\contacts\Permission;
+use de\xqueue\maileon\api\client\json\AbstractJSONWrapper;
/**
* A class for wrapping contact references.
*
- * @author Viktor Balogh | Wanadis Kft. | balogh.viktor@maileon.hu
+ * @author Viktor Balogh | XQueue GmbH | viktor.balog@xqueue.com
*/
class ContactReference extends AbstractJSONWrapper
{
/**
+ * The Maileon ID of the contact to send the transaction to
*
- * @var integer
- * the Maileon ID of the contact to send the transaction to
+ * @var int
*/
public $id;
+
/**
+ * The external ID of the contact to send the transaction to
*
* @var string
- * the external ID of the contact to send the transaction to
*/
public $external_id;
+
/**
+ * The email address of the contact to send the transaction to
*
* @var string
- * the email address of the contact to send the transaction to
*/
public $email;
/**
+ * The permission of this contact
*
* @var Permission
- * the permission of this contact
*/
public $permission;
-
- /**
- * @return string
- * a human-readable representation of this ContactReference
- */
- public function toString()
- {
- return parent::__toString();
- }
-
+
/**
* Signals to the JSON serializer whether this object should be serialized
*
* @return boolean
*/
- public function isEmpty()
+ public function isEmpty(): bool
{
- $result = !isset($this->id) && !isset($this->external_id) && !isset($this->email);
-
- return $result;
+ return ! isset($this->id) && ! isset($this->external_id) && ! isset($this->email);
}
-
- public function toArray()
+
+ public function toArray(): array
{
$array = parent::toArray();
-
+
if ($this->permission != null) {
$array['permission'] = $this->permission->code;
}
-
+
return $array;
}
}
diff --git a/src/transactions/DataType.php b/src/transactions/DataType.php
index 47d2558..e971046 100644
--- a/src/transactions/DataType.php
+++ b/src/transactions/DataType.php
@@ -8,8 +8,7 @@
* The supported data types are string, double, float, integer, boolean, timestamp and json.
*
* @author Viktor Balogh | Wanadis Kft. | balogh.viktor@maileon.hu
- * @author Marcus Ständer | Trusted Technologies GmbH |
- * marcus.staender@trusted-technologies.de
+ * @author Marcus Beckerle | XQueue GmbH | marcus.beckerle@xqueue.com
*/
class DataType
{
@@ -26,24 +25,23 @@ class DataType
// TODO use a more sensible name for this concept, e.g. "type descriptor"
/**
+ * A string that describes the datatype. Valid values are "string", "double", "float", "integer", "boolean", "timestamp" and "json".
*
- * @var string $value
- * A string that describes the datatype. Valid values are "string", "double", "float",
- * "integer", "boolean", "timestamp" and "json".
+ * @var string
*/
public $value;
public static function init()
{
- if (self::$initialized == false) {
- self::$STRING = new DataType("string");
- self::$DOUBLE = new DataType("double");
- self::$FLOAT = new DataType("float");
- self::$INTEGER = new DataType("integer");
- self::$BOOLEAN = new DataType("boolean");
- self::$TIMESTAMP = new DataType("timestamp");
- self::$DATE = new DataType("date");
- self::$JSON = new DataType("json");
+ if (self::$initialized === false) {
+ self::$STRING = new DataType('string');
+ self::$DOUBLE = new DataType('double');
+ self::$FLOAT = new DataType('float');
+ self::$INTEGER = new DataType('integer');
+ self::$BOOLEAN = new DataType('boolean');
+ self::$TIMESTAMP = new DataType('timestamp');
+ self::$DATE = new DataType('date');
+ self::$JSON = new DataType('json');
self::$initialized = true;
}
}
@@ -51,9 +49,9 @@ public static function init()
/**
* Creates a new DataType object.
*
+ * a string describing the data type. Valid values are "string", "double", "float", "integer", "boolean", "timestamp" and "json".
+ *
* @param string $value
- * a string describing the data type. Valid values are "string", "double", "float",
- * "integer", "boolean", "timestamp" and "json".
*/
public function __construct($value)
{
@@ -61,11 +59,9 @@ public function __construct($value)
}
/**
- * @return string
- * the type descriptor string of this DataType. Can be "string", "double", "float",
- * "integer", "boolean", "timestamp" or "json".
+ * @return string The type descriptor string of this DataType. Can be "string", "double", "float", "integer", "boolean", "timestamp" or "json".
*/
- public function getValue()
+ public function getValue(): string
{
return $this->value;
}
@@ -73,35 +69,33 @@ public function getValue()
/**
* Get the permission object by type descriptor.
*
- * @param string $value
- * a type descriptor string. Can be "string", "double", "float",
- * "integer", "boolean", "timestamp" or "json".
- * @return DataType
- * the DataType object
+ * @param string $value a type descriptor string. Can be "string", "double", "float", "integer", "boolean", "timestamp" or "json".
+ *
+ * @return DataType|null The DataType object
*/
public static function getDataType($value)
{
switch ($value) {
- case "string":
+ case 'string':
return self::$STRING;
- case "double":
+ case 'double':
return self::$DOUBLE;
- case "float":
+ case 'float':
return self::$FLOAT;
- case "integer":
+ case 'integer':
return self::$INTEGER;
- case "boolean":
+ case 'boolean':
return self::$BOOLEAN;
- case "timestamp":
+ case 'timestamp':
return self::$TIMESTAMP;
- case "date":
+ case 'date':
return self::$DATE;
- case "json":
+ case 'json':
return self::$JSON;
-
default:
return null;
}
}
}
+
DataType::init();
diff --git a/src/transactions/ImportContactReference.php b/src/transactions/ImportContactReference.php
index 0b2f872..7b683cb 100644
--- a/src/transactions/ImportContactReference.php
+++ b/src/transactions/ImportContactReference.php
@@ -5,59 +5,69 @@
/**
* A class for wrapping contact references.
*
- * @author Viktor Balogh | Wanadis Kft. | balogh.viktor@maileon.hu
+ * @author Viktor Balogh | XQueue GmbH | viktor.balog@xqueue.com
*/
class ImportContactReference
{
/**
+ * The Maileon ID of the contact to send the transaction to
*
- * @var integer
- * the Maileon ID of the contact to send the transaction to
+ * @var int
*/
public $id;
/**
+ * The external ID of the contact to send the transaction to
*
* @var string
- * the external ID of the contact to send the transaction to
*/
public $external_id;
/**
+ * The email address of the contact to send the transaction to
*
* @var string
- * the email address of the contact to send the transaction to
*/
public $email;
/**
+ * The permission of the contact if it should be created
*
* @var string
- * the permission of the contact if it should be created
*/
public $permission;
- /**
- * @return string
- * a human-readable representation of this ContactReference
- */
- public function toString()
+ public function toString(): string
{
- if (!empty($this->permission)) {
+ if (! empty($this->permission)) {
$permissionCode = $this->permission->getCode();
} else {
$permissionCode = -1;
}
- if (!empty($this->id)) {
- return "ImportContactReference [id=" . $this->id . ", permission=" . $permissionCode . "]";
- } elseif (!empty($this->email)) {
- return "ImportContactReference [email=" . $this->email . ", permission=" . $permissionCode . "]";
- } elseif (!empty($this->external_id)) {
- return "ImportContactReference [external_id=" .
- $this->external_id . "], permission=" . $permissionCode . "";
- } else {
- return "ImportContactReference [permission=" . $permissionCode . "]";
+ if (! empty($this->id)) {
+ return 'ImportContactReference ['
+ . 'id=' . $this->id
+ . ', permission=' . $permissionCode
+ . ']';
+ }
+
+ if (! empty($this->email)) {
+ return 'ImportContactReference ['
+ . 'email=' . $this->email
+ . ', permission=' . $permissionCode
+ . ']';
+ }
+
+ if (! empty($this->external_id)) {
+ return 'ImportContactReference ['
+ . 'external_id=' . $this->external_id
+ . ', permission=' . $permissionCode
+ . ']';
}
+
+ return 'ImportContactReference ['
+ . 'permission=' . $permissionCode
+ . ']';
}
}
diff --git a/src/transactions/ImportReference.php b/src/transactions/ImportReference.php
index eb2e8c2..9aaf70a 100644
--- a/src/transactions/ImportReference.php
+++ b/src/transactions/ImportReference.php
@@ -5,28 +5,24 @@
/**
* A class for wrapping import references.
*
- * @author Marcus Staender
+ * @author Marcus Beckerle | XQueue GmbH | marcus.beckerle@xqueue.com
*/
class ImportReference
{
/**
+ * An array identifying the contact that contains at least one of the following
+ * attributes: id/external_id/email and permission
*
* @var ImportContactReference
- * an array identifying the contact that contains at least one of the following
- * attributes: id/external_id/email and permission
*/
public $contact;
- /**
- * @return string
- * a human-readable representation of this ContactReference
- */
- public function toString()
- {
- if (!empty($this->contact)) {
- return "ImportReference [" . $this->contact->toString() . "]";
- } else {
- return "ImportReference []";
+ public function toString(): string
+ {
+ if (! empty($this->contact)) {
+ return 'ImportReference [' . $this->contact->toString() . ']';
}
+
+ return 'ImportReference []';
}
}
diff --git a/src/transactions/ProcessingReport.php b/src/transactions/ProcessingReport.php
index d9bfd0b..762eb30 100644
--- a/src/transactions/ProcessingReport.php
+++ b/src/transactions/ProcessingReport.php
@@ -7,7 +7,7 @@
/**
* A wrapper class for a single transaction processing report
*
- * @author Balogh Viktor | Maileon - Wanadis Kft.
+ * @author Viktor Balogh | XQueue GmbH | viktor.balog@xqueue.com
*/
class ProcessingReport extends AbstractJSONWrapper
{
@@ -17,14 +17,14 @@ class ProcessingReport extends AbstractJSONWrapper
* @var ReportContact
*/
public $contact;
-
+
/**
- * Whether this transaction was succesfully queued
+ * Whether this transaction was successfully queued
*
* @var boolean
*/
public $queued;
-
+
/**
* The identifier of the transaction.
* Available when generated automatically (generate_transaction_id=true) or generated externally
@@ -32,16 +32,18 @@ class ProcessingReport extends AbstractJSONWrapper
* @var string
*/
public $transaction_id;
-
+
/**
* The error message (if there was any)
*
* @var string
*/
public $message;
-
+
public function __construct()
{
+ // parent::__construct() ?
+
$this->contact = new ReportContact();
}
}
diff --git a/src/transactions/ProcessingReports.php b/src/transactions/ProcessingReports.php
index 9173e50..a8c27ce 100644
--- a/src/transactions/ProcessingReports.php
+++ b/src/transactions/ProcessingReports.php
@@ -4,37 +4,40 @@
use de\xqueue\maileon\api\client\json\AbstractJSONWrapper;
+use function property_exists;
+use function trigger_error;
+
/**
* A wrapper class for transaction processing reports
*
- * @author Balogh Viktor | Maileon - Wanadis Kft.
+ * @author Viktor Balogh | XQueue GmbH | viktor.balog@xqueue.com
*/
class ProcessingReports extends AbstractJSONWrapper
{
/**
- * An array of reports for the
+ * An array of reports
*
- * @var ProcessingReport|array
+ * @var ProcessingReport[]
*/
- public $reports = array();
-
+ public $reports = [];
+
public function fromArray($object_vars)
{
- if (!property_exists($object_vars, 'reports')) {
+ if (! property_exists($object_vars, 'reports')) {
trigger_error(
- __CLASS__ .
- "->" .
- __FUNCTION__ .
- ": failed to initialize object; passed object doesn't have a 'reports' property"
+ __CLASS__ . '->' . __FUNCTION__
+ . ': failed to initialize object'
+ . '; passed object doesn\'t have a "reports" property'
);
+
return;
}
-
+
foreach ($object_vars->reports as $report) {
$reportObject = new ProcessingReport();
$reportObject->fromArray($report);
-
- $this->reports []= $reportObject;
+
+ $this->reports[] = $reportObject;
}
}
}
diff --git a/src/transactions/RecentTransaction.php b/src/transactions/RecentTransaction.php
index 051297d..891ab25 100644
--- a/src/transactions/RecentTransaction.php
+++ b/src/transactions/RecentTransaction.php
@@ -7,7 +7,7 @@
/**
* A class for wrapping a recent transaction.
*
- * @author Viktor Balogh | Wanadis Kft. | balogh.viktor@maileon.hu
+ * @author Viktor Balogh | XQueue GmbH | viktor.balog@xqueue.com
*/
class RecentTransaction extends AbstractJSONWrapper
{
@@ -17,31 +17,25 @@ class RecentTransaction extends AbstractJSONWrapper
* @var array
*/
public $tx;
+
/**
* The id for this data
*
* @var int
*/
public $txId;
+
/**
* The contact id
*
- * @var integer
+ * @var int
*/
public $contactId;
+
/**
* The email address
*
* @var string
*/
public $email;
-
- /**
- * @return string
- * a human-readable representation of this recent transaction
- */
- public function toString()
- {
- return parent::__toString();
- }
}
diff --git a/src/transactions/ReportContact.php b/src/transactions/ReportContact.php
index 36515a9..254e69d 100644
--- a/src/transactions/ReportContact.php
+++ b/src/transactions/ReportContact.php
@@ -8,7 +8,7 @@
/**
* A wrapper for a transaction report contact
*
- * @author Balogh Viktor | Maileon - Wanadis Kft.
+ * @author Viktor Balogh | XQueue GmbH | viktor.balog@xqueue.com
*/
class ReportContact extends AbstractJSONWrapper
{
@@ -18,41 +18,46 @@ class ReportContact extends AbstractJSONWrapper
* @var int
*/
public $id;
+
/**
- * The extrenal id of this contact
+ * The external id of this contact
*
* @var string
*/
public $external_id;
+
/**
* The email address of this contact
*
* @var string
*/
public $email;
+
/**
* The type string of this contact
*
* @var string
*/
public $type;
+
/**
* The permission of the contact
*
* @var Permission
*/
public $permission;
+
/**
* Whether the contact was created
*
* @var boolean
*/
public $created;
-
+
public function fromArray($object_vars)
{
parent::fromArray($object_vars);
-
+
if ($this->permission !== null) {
$this->permission = new Permission($this->permission);
}
diff --git a/src/transactions/Transaction.php b/src/transactions/Transaction.php
index c0aa01e..f41c323 100644
--- a/src/transactions/Transaction.php
+++ b/src/transactions/Transaction.php
@@ -2,58 +2,65 @@
namespace de\xqueue\maileon\api\client\transactions;
-use de\xqueue\maileon\api\client\MaileonAPIException;
use de\xqueue\maileon\api\client\json\AbstractJSONWrapper;
+use de\xqueue\maileon\api\client\MaileonAPIException;
+
+use function base64_encode;
+use function basename;
+use function fclose;
+use function feof;
+use function fopen;
+use function fread;
+use function json_encode;
/**
* The wrapper class for a Maileon transaction.
*
- * @author Viktor Balogh | Wanadis Kft. | balogh.viktor@maileon.hu
- * @author Marcus Ständer | Trusted Technologies GmbH |
- * marcus.staender@trusted-technologies.de
+ * @author Viktor Balogh | XQueue GmbH | viktor.balog@xqueue.com
+ * @author Marcus Beckerle | XQueue GmbH | marcus.beckerle@xqueue.com
*/
-
class Transaction extends AbstractJSONWrapper
{
/**
- *
- * @var integer
* the numeric ID of the transaction type to use
+ *
+ * @var int
*/
public $type;
-
+
/**
+ * the name of the transaction type to use as an alternative to using the ID
*
* @var string
- * the name of the transaction type to use as an alternative to using the ID
*/
public $typeName;
/**
+ * an array identifying the contact that contains at least one of the following attributes: id/external_id/email
*
* @var ContactReference
- * an array identifying the contact that contains at least one of the following attributes: id/external_id/email
*/
public $contact;
/**
- *
- * @var ContactReference
* Used to control import settings. This array also contains the contact. If $contact AND $import exist,
* $contact will be ignored and the contact within $import will be used.
+ *
+ * @var ContactReference
*/
public $import;
/**
+ * an array that contains the transaction content as defined in the referenced transaction type
*
* @var array
- * an array that contains the transaction content as defined in the referenced transaction type
*/
public $content;
/**
- * @var array
* an array that contains the attachments for the transaction e-mail, if any
+ *
+ * @var array
*/
public $attachments;
@@ -62,85 +69,102 @@ class Transaction extends AbstractJSONWrapper
*/
public function __construct()
{
- $this->content = array();
- $this->attachments = array();
- $this->contact = new ContactReference();
- /**
- $this->import = new com_maileon_api_transactions_ImportReference();
- $this->import->contact = new com_maileon_api_transactions_ImportContactReference();
- $this->import->contact->permission = com_maileon_api_contacts_Permission::$NONE;
- **/
+ // parent::__construct() ?
+
+ $this->content = [];
+ $this->attachments = [];
+ $this->contact = new ContactReference();
+
+ // $this->import = new \de\xqueue\maileon\api\client\transactions\ImportReference();
+ // $this->import->contact = new \de\xqueue\maileon\api\client\transactions\ImportContactReference();
+ // $this->import->contact->permission = \de\xqueue\maileon\api\client\contacts\Permission::$NONE;
}
/**
* Read a binary file from the file system and adds it as an attachment to this transaction.
- * @param string $filename the file system path to read the attachment from
- * @param string $mimetype the mime type of the attachment
- * @param null $attachmentFileName the file name to use when sending the attachment as an e-mail. If this is null,
- * the basename of $filename is used instead.
+ *
+ * @param string $filename the file system path to read the attachment from
+ * @param string $mimetype the mime type of the attachment
+ * @param $attachmentFileName the file name to use when sending the attachment as an e-mail. If this is null, the basename of
+ * $filename is used instead.
*/
- public function addAttachmentFromFile($filename, $mimetype, $attachmentFileName = null)
- {
+ public function addAttachmentFromFile(
+ $filename,
+ $mimetype,
+ $attachmentFileName = null
+ ) {
$handle = fopen($filename, "rb");
- if (false === $filename) {
- throw new MaileonAPIException("Cannot read file " . $filename . ".");
+
+ if (false === $handle) {
+ throw new MaileonAPIException("Cannot read file $filename.");
}
+
$contents = '';
- while (!feof($handle)) {
+
+ while (! feof($handle)) {
$contents .= fread($handle, 8192);
}
fclose($handle);
+
if ($attachmentFileName === null) {
$attachmentFileName = basename($filename);
}
- $attachment = new Attachment($attachmentFileName, $mimetype, base64_encode($contents));
+
+ $attachment = new Attachment($attachmentFileName, $mimetype, base64_encode($contents));
$this->attachments[] = $attachment;
}
/**
* Adds an attachment to this transaction from a string that contains binary data.
+ *
* @param $filename string the file name to use when sending the attachment as an e-mail
* @param $mimetype string the mime type of the attachment
* @param $contents string a string containing binary data, e.g. as returned from fread().
*/
- public function addAttachmentFromBinaryData($filename, $mimetype, $contents)
- {
- $attachment = new Attachment($filename, $mimetype, base64_encode($contents));
+ public function addAttachmentFromBinaryData(
+ $filename,
+ $mimetype,
+ $contents
+ ) {
+ $attachment = new Attachment($filename, $mimetype, base64_encode($contents));
$this->attachments[] = $attachment;
}
/**
* Adds an attachment to this transaction from a string that contains base64-encoded data.
+ *
* @param $filename string the file name to use when sending the attachment as an e-mail
* @param $mimetype string the mime type of the attachment
* @param $contents string a string containing binary data, e.g. as returned from fread().
*/
- public function addAttachmentFromBase64Data($filename, $mimetype, $contents)
- {
- $attachment = new Attachment($filename, $mimetype, $contents);
+ public function addAttachmentFromBase64Data(
+ $filename,
+ $mimetype,
+ $contents
+ ) {
+ $attachment = new Attachment($filename, $mimetype, $contents);
$this->attachments[] = $attachment;
}
- /**
- * @return string
- * a human-readable representation listing all the attributes of this transaction and their respective values.
- */
- public function toString()
+ public function toString(): string
{
- return "Transaction [type=" . $this->type .
- ", contact=(" . ((empty($this->contact))?"":$this->contact->toString()) . "), import=(" .
- ((empty($this->import))?"":$this->import->toString()) . "), content=(" . json_encode($this->content) . ")]";
+ return 'Transaction ['
+ . 'type=' . $this->type
+ . ', contact=(' . ((empty($this->contact)) ? '' : $this->contact->toString()) . ')'
+ . ', import=(' . ((empty($this->import)) ? '' : $this->import->toString()) . ')'
+ . ', content=(' . json_encode($this->content) . ')'
+ . ']';
}
-
- public function toArray()
+
+ public function toArray(): array
{
$array = parent::toArray();
-
+
if (isset($array['import'])) {
unset($array['contact']);
- //$array['import'] = array( "contact" => $array['import'] );
+ // $array['import'] = array( 'contact' => $array['import'] );
}
-
+
return $array;
}
}
diff --git a/src/transactions/TransactionType.php b/src/transactions/TransactionType.php
index b157ac8..b91fabf 100644
--- a/src/transactions/TransactionType.php
+++ b/src/transactions/TransactionType.php
@@ -3,212 +3,222 @@
namespace de\xqueue\maileon\api\client\transactions;
use de\xqueue\maileon\api\client\xml\AbstractXMLWrapper;
+use SimpleXMLElement;
+
+use function is_array;
+use function rtrim;
+use function trim;
/**
* Wrapper class for Maileon transaction types.
*
- * @author Viktor Balogh | Wanadis Kft. | balogh.viktor@maileon.hu
+ * @author Viktor Balogh | XQueue GmbH | viktor.balog@xqueue.com
* @author Marcus Beckerle | XQueue GmbH | marcus.beckerle@xqueue.com
*/
class TransactionType extends AbstractXMLWrapper
{
/**
- *
- * @var integer
+ * @var int
*/
public $id;
/**
- *
* @var string
*/
public $name;
/**
- *
* @var string
*/
public $description;
/**
- *
* @var array
*/
public $attributes;
/**
+ * Archiving duration in days [1...n] after which the transaction events will be deleted, 0 and empty = forever (default)
*
- * @var integer Archiving duration in days [1..n] after which the transaction events will be deleted,
- * 0 and empty = forever (default)
+ * @var int
*/
public $archivingDuration;
/**
- *
- * @var boolean If true, event has extended limitations for data types
- * (see https://dev.maileon.com/api/rest-api-1-0/transactions/create-transaction-type/) but cannot
+ * If true, event has extended limitations for data types
+ * (see https://support.maileon.com/support/create-transaction-type/) but cannot
* be used in further logic like contact filters.
+ *
+ * @var boolean
*/
public $storeOnly;
/**
* Creates a new transaction type object.
*
- * @param string $id
- * the ID of the transaction type
- * @param string $name
- * the name of the transaction type
- * @param array $attributes
- * an array of com_maileon_api_transactions_AttributeType attributes associated with the transaction
- * @param integer $archivingDuration
- * Archiving duration in days [1..n] after which the transaction events will be deleted,
- * 0 and empty = forever (default)
- * @param integer $storeOnly
- * If nothing or false is specified, the limit for strings attributes of the transaction is set
- * to 1000 characters
- * and the transaction event can be used in any contactfilter, e.g. "give me all contacts that received contact
- * event X with value Y in attribute Z".
- * If storeOnly is set to true, the attributes of the transaction cannot be used as comparision inputs for
- * contactfilters but the allowed length is raised to 64.000 characters.
- * @param string $description
- * the description of the transaction type
+ * @param string $id the ID of the transaction type
+ * @param string $name the name of the transaction type
+ * @param array $attributes an array of \de\xqueue\maileon\api\client\transactions\AttributeType attributes associated with the
+ * transaction
+ * @param int $archivingDuration Archiving duration in days [1...n] after which the transaction events will be deleted,
+ * 0 and empty = forever (default)
+ * @param int $storeOnly If nothing or false is specified, the limit for strings attributes of the transaction is set to
+ * 1000 characters and the transaction event can be used in any contact filter, e.g. "give me all
+ * contacts that received contact event X with value Y in attribute Z". If storeOnly is set to true,
+ * the attributes of the transaction cannot be used as comparison inputs for contact filters but the
+ * allowed length is raised to 64.000 characters.
+ * @param string $description the description of the transaction type
*/
public function __construct(
$id = null,
$name = null,
- $attributes = array(),
+ $attributes = [],
$archivingDuration = null,
$storeOnly = false,
$description = null
) {
- $this->id = $id;
- $this->name = $name;
- $this->attributes = $attributes;
+ $this->id = $id;
+ $this->name = $name;
+ $this->attributes = $attributes;
$this->archivingDuration = $archivingDuration;
- $this->storeOnly = $storeOnly;
- $this->description = $description;
+ $this->storeOnly = $storeOnly;
+ $this->description = $description;
}
- /**
- * Initializes this transaction type from an XML representation.
- *
- * @param \SimpleXMLElement $xmlElement
- * the serialized XML representation to use
- */
public function fromXML($xmlElement)
{
if (isset($xmlElement->id)) {
- $this->id = (int)$xmlElement->id;
+ $this->id = (int) $xmlElement->id;
}
+
if (isset($xmlElement->name)) {
- $this->name = (string)$xmlElement->name;
+ $this->name = (string) $xmlElement->name;
}
+
if (isset($xmlElement->description)) {
- $this->description = (string)$xmlElement->description;
+ $this->description = (string) $xmlElement->description;
}
+
if (isset($xmlElement->archivingDuration)) {
- $this->archivingDuration = (int)$xmlElement->archivingDuration;
+ $this->archivingDuration = (int) $xmlElement->archivingDuration;
}
+
if (isset($xmlElement->storeOnly)) {
- $this->storeOnly = ((string)$xmlElement->storeOnly) === 'true';
+ $this->storeOnly = ((string) $xmlElement->storeOnly) === 'true';
}
if (isset($xmlElement->attributes)) {
- $this->attributes = array();
+ $this->attributes = [];
+
foreach ($xmlElement->attributes->children() as $xmlAttribute) {
$attribute = new AttributeType();
+
if (isset($xmlAttribute->id)) {
- $attribute->id = (int)$xmlAttribute->id;
+ $attribute->id = (int) $xmlAttribute->id;
}
+
if (isset($xmlAttribute->name)) {
- $attribute->name = trim((string)$xmlAttribute->name);
+ $attribute->name = trim((string) $xmlAttribute->name);
}
+
if (isset($xmlAttribute->description)) {
- $attribute->description = trim((string)$xmlAttribute->description);
+ $attribute->description = trim((string) $xmlAttribute->description);
}
+
if (isset($xmlAttribute->type)) {
$attribute->type = DataType::getDataType($xmlAttribute->type);
}
+
if (isset($xmlAttribute->required)) {
- $attribute->required = ((string)$xmlAttribute->required) === 'true';
+ $attribute->required = ((string) $xmlAttribute->required) === 'true';
}
- array_push($this->attributes, $attribute);
+ $this->attributes[] = $attribute;
}
}
}
- /**
- * @return string
- * a human-readable representation of this object
- */
- public function toString()
+ public function toString(): string
{
// Generate attributes string
- $attributes = "[";
+ $attributes = '[';
+
if (isset($this->attributes)) {
- foreach ($this->attributes as $index => $value) {
- $attributes .= "attribute (id=" . $value->id . ", name=" . $value->name .
- ", description=" . ((!empty($value->description))?$value->description:"") .
- ", type=" . $value->type->getValue() . ", required=" .
- (($value->required == true) ? "true" : "false") . "), ";
+ foreach ($this->attributes as $value) {
+ $attributes .= 'attribute ('
+ . 'id=' . $value->id
+ . ', name=' . $value->name
+ . ', description=' . ((! empty($value->description)) ? $value->description : '')
+ . ', type=' . $value->type->getValue()
+ . ', required=' . ($value->required === true ? 'true' : 'false')
+ . '), ';
}
+
$attributes = rtrim($attributes, ' ');
$attributes = rtrim($attributes, ',');
}
- $attributes .= "]";
- return "TransactionType [id=" . $this->id . ", name=" . $this->name . ", description="
- . $this->description . ", archivingDuration=" . $this->archivingDuration . ", storeOnly="
- . $this->storeOnly . ", attributes=" . $attributes . "]";
+ $attributes .= ']';
+
+ return 'TransactionType ['
+ . 'id=' . $this->id
+ . ', name=' . $this->name
+ . ', description=' . $this->description
+ . ', archivingDuration=' . $this->archivingDuration
+ . ', storeOnly=' . $this->storeOnly
+ . ', attributes=' . $attributes
+ . ']';
}
- /**
- * @return \SimpleXMLElement
- * containing the XML serialization of this object
- */
public function toXML()
{
- $xml = new \SimpleXMLElement("");
+ $xml = new SimpleXMLElement('');
// Some fields are mandatory, especially when setting data to the API
if (isset($this->id)) {
- $xml->addChild("id", $this->id);
+ $xml->addChild('id', $this->id);
}
+
if (isset($this->name)) {
- $xml->addChild("name", $this->name);
+ $xml->addChild('name', $this->name);
}
+
if (isset($this->description)) {
- $xml->addChild("description", $this->description);
+ $xml->addChild('description', $this->description);
}
+
if (isset($this->archivingDuration)) {
- $xml->addChild("archivingDuration", $this->archivingDuration);
+ $xml->addChild('archivingDuration', $this->archivingDuration);
}
+
if (isset($this->storeOnly)) {
- $xml->addChild("storeOnly", ($this->storeOnly === true || $this->storeOnly === "true")?"true":"false");
+ $xml->addChild('storeOnly', ($this->storeOnly === true || $this->storeOnly === 'true') ? 'true' : 'false');
}
- if (isset($this->attributes) && sizeof($this->attributes) > 0) {
- $attributes = $xml->addChild("attributes");
- foreach ($this->attributes as $index => $value) {
- $field = $attributes->addChild("attribute");
- if (!empty($value->id)) {
- $field->addChild("id", $value->id);
+ if (is_array($this->attributes) && ! empty($this->attributes)) {
+ $attributes = $xml->addChild('attributes');
+
+ foreach ($this->attributes as $value) {
+ $field = $attributes->addChild('attribute');
+
+ if (! empty($value->id)) {
+ $field->addChild('id', $value->id);
}
- if (!empty($value->name)) {
- $field->addChild("name", $value->name);
+
+ if (! empty($value->name)) {
+ $field->addChild('name', $value->name);
}
- if (!empty($value->description)) {
- $field->addChild("description", $value->description);
+
+ if (! empty($value->description)) {
+ $field->addChild('description', $value->description);
}
- if (!empty($value->type)) {
- $field->addChild("type", $value->type->getValue());
+
+ if (! empty($value->type)) {
+ $field->addChild('type', $value->type->getValue());
}
- if (!empty($value->required)) {
- $field->addChild(
- "required",
- ($value->required === true || $value->required === "true") ? "true" : "false"
- );
+
+ if (! empty($value->required)) {
+ $field->addChild('required', ($value->required === true || $value->required === 'true') ? 'true' : 'false');
}
}
}
@@ -217,26 +227,19 @@ public function toXML()
}
/**
- * @return string
- * containing the XML serialization of this object
- */
- public function toXMLString()
- {
- $xml = $this->toXML();
- return $xml->asXML();
- }
-
- /**
+ * sanitize this transaction type by removing the ID of every single attribute and return this object for more fluent programming styles
+ *
* @return TransactionType
- * sanitize this transaction type by removing the ID of ebery single sttribute and return this object for more fluent programming styles
*/
- public function sanitize() {
- if (isset($this->attributes) && sizeof($this->attributes) > 0) {
- /** @var AttributeType $value */
- foreach ($this->attributes as $index => $value) {
+ public function sanitize()
+ {
+ if (is_array($this->attributes) && ! empty($this->attributes)) {
+ /** @var AttributeType $value */
+ foreach ($this->attributes as $value) {
$value->id = null;
}
}
+
return $this;
}
}
diff --git a/src/transactions/TransactionsService.php b/src/transactions/TransactionsService.php
index 6606aa8..fae2925 100644
--- a/src/transactions/TransactionsService.php
+++ b/src/transactions/TransactionsService.php
@@ -2,10 +2,14 @@
namespace de\xqueue\maileon\api\client\transactions;
+use de\xqueue\maileon\api\client\AbstractMaileonService;
use de\xqueue\maileon\api\client\json\JSONSerializer;
use de\xqueue\maileon\api\client\MaileonAPIException;
use de\xqueue\maileon\api\client\MaileonAPIResult;
-use de\xqueue\maileon\api\client\AbstractMaileonService;
+use Exception;
+
+use function mb_convert_encoding;
+use function rawurlencode;
/**
* Facade that wraps the REST service for transactions.
@@ -13,15 +17,12 @@
* @author Viktor Balogh | Maileon Digital Kft. | balogh.viktor@maileon.hu
* @author Marcus Beckerle | XQueue GmbH | marcus.beckerle@xqueue.com
*/
-
class TransactionsService extends AbstractMaileonService
{
/**
- * @return MaileonAPIResult
- * the result object of the API call, with the count of transaction types available
- * at MaileonAPIResult::getResult()
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @return MaileonAPIResult|null The result object of the API call, with the count of transaction types available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getTransactionTypesCount()
{
@@ -31,54 +32,58 @@ public function getTransactionTypesCount()
/**
* Gets the TransactionTypes defined in the system.
*
- * @param number $page_index
- * the paging index number
- * @param number $page_size
- * the number of results per page
- * @return MaileonAPIResult
- * the result object of the API call, with a com_maileon_api_transactions_TransactionType[]
- * available at MaileonAPIResult::getResult()
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @param int $page_index the paging index number
+ * @param int $page_size the number of results per page
+ *
+ * @return MaileonAPIResult|null The result object of the API call, with a TransactionType[] available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function getTransactionTypes($page_index = 1, $page_size = 10)
- {
- $queryParameters = array(
- 'page_index' => $page_index,
- 'page_size' => $page_size
- );
+ public function getTransactionTypes(
+ $page_index = 1,
+ $page_size = 10
+ ) {
+ $queryParameters = [
+ 'page_index' => $page_index,
+ 'page_size' => $page_size,
+ ];
- return $this->get('transactions/types', $queryParameters);
+ return $this->get(
+ 'transactions/types',
+ $queryParameters
+ );
}
/**
* Gets information about a transaction type.
*
- * @param integer $id
- * the id of the transaction type to get information about
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @param int $id the id of the transaction type to get information about
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getTransactionType($id)
{
- return $this->get("transactions/types/" . $id);
+ $encodedId = rawurlencode(mb_convert_encoding((string) $id, 'UTF-8'));
+
+ return $this->get("transactions/types/$encodedId");
}
/**
* Gets information about a transaction type by its name.
*
- * @param string $name
- * the name of the transaction type to get information about
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @param string $name the name of the transaction type to get information about
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getTransactionTypeByName($name)
{
- return $this->get("transactions/types/" . urlencode($name));
+ $encodedName = rawurlencode(mb_convert_encoding((string) $name, 'UTF-8'));
+
+ return $this->get("transactions/types/$encodedName");
}
/**
@@ -86,19 +91,22 @@ public function getTransactionTypeByName($name)
*
* @param TransactionType $trt
* the TransactionType defining the new transaction type to create
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function createTransactionType($trt)
{
- return $this->post("transactions/types", $trt->sanitize()->toXMLString());
+ return $this->post(
+ 'transactions/types',
+ $trt->sanitize()->toXMLString()
+ );
}
/**
* Updates an existing transaction type with the given ID in the account.
- * Currently you can:
+ * Currently, you can:
* Add new attributes to transaction type
* Change the transaction type name
* Change the transaction type description
@@ -108,60 +116,67 @@ public function createTransactionType($trt)
*
* Please be aware: due to backwards compatibility of the types with regard to mailings or filters,
* you cannot change existing attributes or delete them. This means the definition in the update must
- * at least contain all attributes of the original transaction type but might contain 0..n new attributes.
+ * at least contain all attributes of the original transaction type but might contain 0...n new attributes.
* However, regarding old attributes, only the name is evaluated, all other attributes are ignored and
* not processed or even updated.
*
* @see https://support.maileon.com/support/update-transaction-type/
*
- * @param integer $id
- * the id of the transaction type
- * @param TransactionType $trt
- * the TransactionType defining the new transaction type to create
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @param int $id the id of the transaction type
+ * @param TransactionType $trt the TransactionType defining the new transaction type to create
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function updateTransactionType($id, $trt)
- {
- return $this->put("transactions/types/" . $id, $trt->sanitize()->toXMLString());
+ public function updateTransactionType(
+ $id,
+ $trt
+ ) {
+ $encodedId = rawurlencode(mb_convert_encoding((string) $id, 'UTF-8'));
+
+ return $this->put(
+ "transactions/types/$encodedId",
+ $trt->sanitize()->toXMLString()
+ );
}
/**
* Deletes a transaction type from the system.
*
- * @param integer $id
- * the id of the transaction type to delete
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @param int $id the id of the transaction type to delete
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function deleteTransactionType($id)
{
- return $this->delete("transactions/types/" . $id);
+ $encodedId = rawurlencode(mb_convert_encoding((string) $id, 'UTF-8'));
+
+ return $this->delete("transactions/types/$encodedId");
}
/**
* Deletes a transaction type from the system by name.
*
- * @param string $name
- * the name of the transaction type to delete
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @param string $name the name of the transaction type to delete
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function deleteTransactionTypeByName($name)
{
- return $this->delete("transactions/types/" . urlencode($name));
+ $encodedName = rawurlencode(mb_convert_encoding((string) $name, 'UTF-8'));
+
+ return $this->delete("transactions/types/$encodedName");
}
/**
* Creates a transaction
*
- * @param array $transactions
+ * @param array $transactions
* an array of Transaction objects
* @param boolean $release
* Deprecated parameter that is not used anymore
@@ -171,10 +186,10 @@ public function deleteTransactionTypeByName($name)
* If the transaction type contains the special attribute "transaction_id", setting this method to true will
* generate and fill a random ID in this field and return the ID in the report. This can be used if the ID
* is not generated externally.
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function createTransactions(
$transactions,
@@ -182,46 +197,49 @@ public function createTransactions(
$ignoreInvalidEvents = false,
$generateTransactionId = false
) {
- $queryParameters = array(
- 'ignore_invalid_transactions' => ($ignoreInvalidEvents == true)?'true':'false',
- 'generate_transaction_id' => ($generateTransactionId == true)?'true':'false',
- );
+ $queryParameters = [
+ 'ignore_invalid_transactions' => $ignoreInvalidEvents === true ? 'true' : 'false',
+ 'generate_transaction_id' => $generateTransactionId === true ? 'true' : 'false',
+ ];
$data = JSONSerializer::json_encode($transactions);
- $result = $this->post(
- "transactions",
+ return $this->post(
+ 'transactions',
$data,
$queryParameters,
- "application/json",
+ 'application/json',
'ProcessingReports'
);
-
- return $result;
}
/**
* Delete all transactions of a given type before a given date in the account.
* Any previously-released transactions will be ignored.
*
- * @param integer $type_id
+ * @param int $type_id
* the transaction type id of the transactions to delete
- * @param number $before_timestamp
+ * @param int $before_timestamp
* the timestamp to compare against, in milliseconds since the start of the UNIX Epoch
* (1970-01-01 00:00:00)
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function deleteTransactions($type_id, $before_timestamp = 9223372036854775807)
- {
- $queryParameters = array(
- 'type_id' => $type_id,
- 'before_timestamp' => $before_timestamp
- );
+ public function deleteTransactions(
+ $type_id,
+ $before_timestamp = 9223372036854775807
+ ) {
+ $queryParameters = [
+ 'type_id' => $type_id,
+ 'before_timestamp' => $before_timestamp,
+ ];
- return $this->delete("transactions", $queryParameters);
+ return $this->delete(
+ 'transactions',
+ $queryParameters
+ );
}
/**
@@ -229,10 +247,11 @@ public function deleteTransactions($type_id, $before_timestamp = 922337203685477
*
* @param string $type_name
* the transaction name to find
- * @return int
- * the id if the found transaction
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
+ *
* @deprecated $name can be used as ID, @see getTransactionType()
*/
public function findTransactionTypeByName($type_name)
@@ -241,91 +260,99 @@ public function findTransactionTypeByName($type_name)
}
/**
- * Gets the last $count transaction events of a given transaction type.
- *
- * @param int $type_id
- * the ID of the transaction type to get transaction events for
- * @param int $count
- * The number of last transactions to get. Valid range: [1..2000]
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
- */
- public function getRecentTransactions($type_id, $count = 1000, $minExcludedTxId = 0)
- {
+ * Gets the last $count transaction events of a given transaction type.
+ *
+ * @param int $type_id The ID of the transaction type to get transaction events for
+ * @param int $count The number of last transactions to get. Valid range: [1..2000]
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
+ */
+ public function getRecentTransactions(
+ $type_id,
+ $count = 1000,
+ $minExcludedTxId = 0
+ ) {
if ($count < 1 || $count > 2000) {
- throw new MaileonAPIException("the given count is not in the [1..2000] range");
+ throw new MaileonAPIException('the given count is not in the [1..2000] range');
}
+
if ($minExcludedTxId < 0) {
throw new MaileonAPIException("the given $minExcludedTxId must be greater or equal to 0");
}
- $queryParameters = array(
- 'type_id' => $type_id,
- 'count' => $count,
- 'min_excluded_transaction_id' => $minExcludedTxId
- );
+ $queryParameters = [
+ 'type_id' => $type_id,
+ 'count' => $count,
+ 'min_excluded_transaction_id' => $minExcludedTxId,
+ ];
return $this->get(
- "transactions",
+ 'transactions',
$queryParameters,
- "application/json",
- array('array', 'de\xqueue\maileon\api\client\transactions\RecentTransaction')
+ 'application/json',
+ ['array', RecentTransaction::class]
);
}
/**
- * Retreives the content of a transaction of the given type with the given ID.
+ * Retrieves the content of a transaction of the given type with the given ID.
* The ID of the transaction must be specified in a special transaction attribute “transaction_id”.
*
* If the transaction_id is generated externally, it is not guaranteed to be unique,
* in this case Maileon returns the first found result, only. As the same ID might be
* used in transactions of different transaction types, the type must also be specified.
*
- * @see https://maileon.com/support/create-transaction-type/#articleTOC_4.
+ * @see https://support.maileon.com/support/create-transaction-type/#articleTOC_4.
+ *
+ * @param string|int $type_id The ID of the transaction type.
+ * @param string $transaction_id The transaction ID. If not unique, the first found occurrence will be used.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
*
- * @param string|integer $type_id
- * The ID of the transaction type.
- * @param string $transaction_id
- * The transaction ID. If not unique, the first found occurence will be used.
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function getTransaction($type_id, $transaction_id)
- {
+ public function getTransaction(
+ $type_id,
+ $transaction_id
+ ) {
+ $encodedTypeId = rawurlencode(mb_convert_encoding((string) $type_id, 'UTF-8'));
+ $encodedTransactionId = rawurlencode(mb_convert_encoding((string) $transaction_id, 'UTF-8'));
+
return $this->get(
- "transactions/" . $type_id . "/transaction_id/" . urlencode($transaction_id),
+ "transactions/$encodedTypeId/transaction_id/$encodedTransactionId",
[],
'application/json'
);
}
/**
- * Retreives the content of a transaction of the given type with the given ID.
+ * Retrieves the content of a transaction of the given type with the given ID.
* The ID of the transaction must be specified in a special transaction attribute “transaction_id”.
*
* If the transaction_id is generated externally, it is not guaranteed to be unique,
* in this case Maileon returns the first found result, only. As the same ID might be
* used in transactions of different transaction types, the type must also be specified.
*
- * @see https://maileon.com/support/create-transaction-type/#articleTOC_4.
+ * @see https://support.maileon.com/support/create-transaction-type/#articleTOC_4.
+ *
+ * @param string|int $type_id The ID of the transaction type.
+ * @param string $transaction_id The transaction ID. If not unique, the first found occurrence will be used.
*
- * @param string|integer $type_id
- * The ID of the transaction type.
- * @param string $transaction_id
- * The transaction ID. If not unique, the first found occurence will be used.
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function deleteTransaction($type_id, $transaction_id)
- {
+ public function deleteTransaction(
+ $type_id,
+ $transaction_id
+ ) {
+ $encodedTypeId = rawurlencode(mb_convert_encoding((string) $type_id, 'UTF-8'));
+ $encodedTransactionId = rawurlencode(mb_convert_encoding((string) $transaction_id, 'UTF-8'));
+
return $this->delete(
- "transactions/" . $type_id . "/transaction_id/" . urlencode($transaction_id),
+ "transactions/$encodedTypeId/transaction_id/$encodedTransactionId"
[],
'application/json'
);
diff --git a/src/utils/PingService.php b/src/utils/PingService.php
index 8997fd6..d9dc9fd 100644
--- a/src/utils/PingService.php
+++ b/src/utils/PingService.php
@@ -5,26 +5,24 @@
use de\xqueue\maileon\api\client\AbstractMaileonService;
use de\xqueue\maileon\api\client\MaileonAPIException;
use de\xqueue\maileon\api\client\MaileonAPIResult;
+use Exception;
/**
* A facade that wraps the REST "ping" system interface monitoring service.
*
- * @author Felix Heinrichs | Trusted Mails GmbH |
- * felix.heinrichs@trusted-mails.com
- * @author Marcus Ständer | Trusted Mails GmbH |
- * marcus.staender@trusted-mails.com
+ * @author Felix Heinrichs
+ * @author Marcus Beckerle | XQueue GmbH | marcus.beckerle@xqueue.com
*/
class PingService extends AbstractMaileonService
{
- const PING_RESOURCE = "ping";
+ const PING_RESOURCE = 'ping';
/**
* Tests if sending GET requests to the REST API works.
*
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function pingGet()
{
@@ -34,36 +32,36 @@ public function pingGet()
/**
* Tests if sending PUT requests to the REST API works.
*
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function pingPut()
{
- return $this->put(self::PING_RESOURCE, "");
+ return $this->put(self::PING_RESOURCE);
}
/**
* Tests if sending POST requests to the REST API works.
*
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function pingPost()
{
- return $this->post(self::PING_RESOURCE, "foobar");
+ return $this->post(
+ self::PING_RESOURCE,
+ 'foobar'
+ );
}
/**
* Tests if sending DELETE requests to the REST API works.
*
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function pingDelete()
{
@@ -73,15 +71,14 @@ public function pingDelete()
/**
* Convenience method to check whether the API call succeeded or not.
*
- * @param array $result
- * a result wrapper as returned from one of the ping methods in this class
- * @return MaileonAPIResult
- * the result object of the API call
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @param array $result a result wrapper as returned from one of the ping methods in this class
+ *
+ * @return bool the result object of the API call
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function checkResult($result)
+ public function checkResult($result): bool
{
- return ($result['STATUS_CODE'] == '200');
+ return $result['STATUS_CODE'] === '200';
}
}
diff --git a/src/webhooks/Webhook.php b/src/webhooks/Webhook.php
index 9efd996..9cbf165 100644
--- a/src/webhooks/Webhook.php
+++ b/src/webhooks/Webhook.php
@@ -4,17 +4,22 @@
use de\xqueue\maileon\api\client\json\AbstractJSONWrapper;
+use function array_merge;
+use function get_object_vars;
+use function is_array;
+use function property_exists;
+
/**
* A wrapper class for a webhook
*
- * @author Balogh Viktor | Maileon - Wanadis Kft.
+ * @author Viktor Balogh | XQueue GmbH | viktor.balog@xqueue.com
*/
class Webhook extends AbstractJSONWrapper
{
- public static $EVENT_UNSUBSCRIPTION = 'unsubscription';
- public static $EVENT_DOI = 'doi';
- public static $EVENT_BOUNCE = 'bounce';
- public static $EVENT_FILTERED = 'filtered';
+ public static $EVENT_UNSUBSCRIPTION = 'unsubscription';
+ public static $EVENT_DOI = 'doi';
+ public static $EVENT_BOUNCE = 'bounce';
+ public static $EVENT_FILTERED = 'filtered';
public static $EVENT_CONTACT_FIELD_CHANGE = 'contact_field_change';
/**
@@ -22,21 +27,21 @@ class Webhook extends AbstractJSONWrapper
*
* @var WebhookBodySpecification
*/
- public $body = null;
+ public $body;
/**
* The id of this webhook
*
- * @var integer|null
+ * @var int|null
*/
- public $id = null;
+ public $id;
/**
* The newsletter account id of this webhook
*
- * @var integer|null
+ * @var int|null
*/
- public $newsletterAccountId = null;
+ public $newsletterAccountId;
/**
* The url of this webhook
@@ -61,32 +66,33 @@ class Webhook extends AbstractJSONWrapper
public function fromArray($object_vars)
{
- if (property_exists($object_vars, 'urlParams') && $object_vars->urlParams !== null && is_array($object_vars->urlParams)) {
+ if (property_exists($object_vars, 'urlParams') && is_array($object_vars->urlParams)) {
foreach ($object_vars->urlParams as $param) {
$paramObject = new WebhookUrlParameter();
$paramObject->fromArray($param);
- $this->urlParams []= $paramObject;
+ $this->urlParams [] = $paramObject;
}
unset($object_vars->urlParams);
}
$this->body = new WebhookBodySpecification();
+
if (property_exists($object_vars, 'bodySpec') && $object_vars->bodySpec !== null) {
$this->body->fromArray($object_vars->bodySpec);
unset($object_vars->bodySpec);
}
- foreach(get_object_vars($this->body) as $key => $value) {
- if(property_exists($object_vars, $key)) {
+ foreach (get_object_vars($this->body) as $key => $value) {
+ if (property_exists($object_vars, $key)) {
$this->body->{$key} = $object_vars->{$key};
unset($object_vars->{$key});
}
}
- if(property_exists($object_vars, 'nlAccountId')) {
+ if (property_exists($object_vars, 'nlAccountId')) {
$this->newsletterAccountId = $object_vars->nlAccountId;
unset($object_vars->nlAccountId);
}
@@ -94,12 +100,12 @@ public function fromArray($object_vars)
parent::fromArray($object_vars);
}
- public function toArray()
+ public function toArray(): array
{
$result = parent::toArray();
unset($result['body']);
// Body can be empty, if no body instantiated externally and no fromArray is used
- return array_merge($result, ($this->body)?$this->body->toArray():[]);
+ return array_merge($result, ($this->body) ? $this->body->toArray() : []);
}
}
diff --git a/src/webhooks/WebhookBodySpecification.php b/src/webhooks/WebhookBodySpecification.php
index 8903628..6e19853 100644
--- a/src/webhooks/WebhookBodySpecification.php
+++ b/src/webhooks/WebhookBodySpecification.php
@@ -4,19 +4,22 @@
use de\xqueue\maileon\api\client\json\AbstractJSONWrapper;
+use function array_map;
+use function strtolower;
+
/**
* A wrapper class for a webhook body specification
*
- * @author Balogh Viktor | Maileon - Wanadis Kft.
+ * @author Viktor Balogh | XQueue GmbH | viktor.balog@xqueue.com
*/
class WebhookBodySpecification extends AbstractJSONWrapper
{
- public static $EVENT_FIELD_TIMESTAMP = 'timestamp';
- public static $EVENT_FIELD_MSG_ID = 'msg_id';
+ public static $EVENT_FIELD_TIMESTAMP = 'timestamp';
+ public static $EVENT_FIELD_MSG_ID = 'msg_id';
public static $EVENT_FIELD_TRANSACTION_ID = 'transaction_id';
- public static $EVENT_FIELD_PROPERTY = 'property';
- public static $EVENT_FIELD_OLD_VALUE = 'old_value';
- public static $EVENT_FIELD_NEW_VALUE = 'new_value';
+ public static $EVENT_FIELD_PROPERTY = 'property';
+ public static $EVENT_FIELD_OLD_VALUE = 'old_value';
+ public static $EVENT_FIELD_NEW_VALUE = 'new_value';
/**
* The custom fields for the webhook body
@@ -39,13 +42,16 @@ class WebhookBodySpecification extends AbstractJSONWrapper
*/
public $eventFields = [];
- public function toArray()
+ public function toArray(): array
{
$result = parent::toArray();
- $result['standardFields'] = array_map(function ($name) {
- return strtolower($name);
- }, $result['standardFields']);
+ $result['standardFields'] = array_map(
+ static function($name) {
+ return strtolower($name);
+ },
+ $result['standardFields']
+ );
return $result;
}
diff --git a/src/webhooks/WebhookUrlParameter.php b/src/webhooks/WebhookUrlParameter.php
index 4fe76e3..a996ce7 100644
--- a/src/webhooks/WebhookUrlParameter.php
+++ b/src/webhooks/WebhookUrlParameter.php
@@ -4,10 +4,13 @@
use de\xqueue\maileon\api\client\json\AbstractJSONWrapper;
+use function property_exists;
+use function strtolower;
+
/**
* A wrapper class for a webhook URL parameter
*
- * @author Balogh Viktor | Maileon - Wanadis Kft.
+ * @author Viktor Balogh | XQueue GmbH | viktor.balog@xqueue.com
*/
class WebhookUrlParameter extends AbstractJSONWrapper
{
@@ -16,46 +19,46 @@ class WebhookUrlParameter extends AbstractJSONWrapper
*
* @var string|null
*/
- public $customContactField = null;
+ public $customContactField;
/**
* The standard contact field for this parameter
*
* @var string|null
*/
- public $standardContactField = null;
+ public $standardContactField;
/**
* The custom value for this parameter
*
* @var string|null
*/
- public $customValue = null;
+ public $customValue;
/**
* The name for this parameter
*
* @var string
*/
- public $name = null;
+ public $name;
- public function toArray()
+ public function toArray(): array
{
$result = [];
- if($this->name !== null) {
+ if ($this->name !== null) {
$result['name'] = $this->name;
}
- if($this->standardContactField !== null) {
+ if ($this->standardContactField !== null) {
$result['standard_contact_field'] = strtolower($this->standardContactField);
}
- if($this->standardContactField !== null) {
+ if ($this->standardContactField !== null) {
$result['custom_contact_field'] = $this->customContactField;
}
- if($this->customValue !== null) {
+ if ($this->customValue !== null) {
$result['custom_value'] = $this->customValue;
}
@@ -64,17 +67,17 @@ public function toArray()
public function fromArray($object_vars)
{
- if(property_exists($object_vars, 'standard_contact_field')) {
+ if (property_exists($object_vars, 'standard_contact_field')) {
$this->standardContactField = $object_vars->standard_contact_field;
unset($object_vars->standard_contact_field);
}
- if(property_exists($object_vars, 'custom_contact_field')) {
+ if (property_exists($object_vars, 'custom_contact_field')) {
$this->customContactField = $object_vars->custom_contact_field;
unset($object_vars->custom_contact_field);
}
- if(property_exists($object_vars, 'custom_value')) {
+ if (property_exists($object_vars, 'custom_value')) {
$this->customValue = $object_vars->custom_value;
unset($object_vars->custom_value);
}
diff --git a/src/webhooks/WebhooksService.php b/src/webhooks/WebhooksService.php
index 5e77bfb..e4baff7 100644
--- a/src/webhooks/WebhooksService.php
+++ b/src/webhooks/WebhooksService.php
@@ -6,6 +6,10 @@
use de\xqueue\maileon\api\client\json\JSONSerializer;
use de\xqueue\maileon\api\client\MaileonAPIException;
use de\xqueue\maileon\api\client\MaileonAPIResult;
+use Exception;
+
+use function mb_convert_encoding;
+use function rawurlencode;
/**
* Facade that wraps the REST service for webhooks
@@ -17,80 +21,105 @@ class WebhooksService extends AbstractMaileonService
/**
* Retrieves the webhook with the given ID.
*
- * @param number $id
- * The ID of the webhook.
+ * @param int $id The ID of the webhook.
+ *
+ * @return MaileonAPIResult|null The result object of the API call, with a MailingBlacklist available at MaileonAPIResult::getResult()
*
- * @return MaileonAPIResult
- * the result object of the API call, with a MailingBlacklist available at MaileonAPIResult::getResult()
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getWebhook($id)
{
- return $this->get("webhooks/" . $id, [], 'application/json', Webhook::class);
+ $encodedId = rawurlencode(mb_convert_encoding((string) $id, 'UTF-8'));
+
+ return $this->get(
+ "webhooks/$encodedId",
+ [],
+ 'application/json',
+ Webhook::class
+ );
}
/**
* Deletes the webhook with the given ID in the newsletter account.
*
- * @param number $id
- * The ID of the webhook.
+ * @param int $id The ID of the webhook.
*
- * @return MaileonAPIResult
- * the result object of the API call, with a MailingBlacklist available at MaileonAPIResult::getResult()
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @return MaileonAPIResult|null The result object of the API call, with a MailingBlacklist available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function deleteWebhook($id)
{
- return $this->delete("webhooks/" . $id, [], 'application/json');
+ $encodedId = rawurlencode(mb_convert_encoding((string) $id, 'UTF-8'));
+
+ return $this->delete(
+ "webhooks/$encodedId",
+ [],
+ 'application/json'
+ );
}
/**
* Updates the webhook with the given ID in the newsletter account.
*
- * @param number $id
- * The ID of the webhook.
- * @param Webhook $webhook
- * The updated webhook data.
+ * @param int $id The ID of the webhook.
+ * @param Webhook $webhook The updated webhook data.
*
- * @return MaileonAPIResult
- * the result object of the API call, with a MailingBlacklist available at MaileonAPIResult::getResult()
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @return MaileonAPIResult|null The result object of the API call, with a MailingBlacklist available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
- public function updateWebhook($id, $webhook)
- {
- return $this->put("webhooks/" . $id, JSONSerializer::json_encode($webhook), [], 'application/json');
+ public function updateWebhook(
+ $id,
+ $webhook
+ ) {
+ $encodedId = rawurlencode(mb_convert_encoding((string) $id, 'UTF-8'));
+
+ return $this->put(
+ "webhooks/$encodedId",
+ JSONSerializer::json_encode($webhook),
+ [],
+ 'application/json'
+ );
}
/**
* Creates a webhook in the newsletter account.
*
- * @param Webhook $webhook
- * The webhook data.
+ * @param Webhook $webhook The webhook data.
*
- * @return MaileonAPIResult
- * the result object of the API call, with a MailingBlacklist available at MaileonAPIResult::getResult()
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @return MaileonAPIResult|null The result object of the API call, with a MailingBlacklist available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function createWebhook($webhook)
{
- return $this->post("webhooks/", JSONSerializer::json_encode($webhook), [], 'application/json');
+ return $this->post(
+ 'webhooks/',
+ JSONSerializer::json_encode($webhook),
+ [],
+ 'application/json'
+ );
}
/**
* Retrieves a list of webhooks configured in the newsletter account.
*
- * @return MaileonAPIResult
- * the result object of the API call, with a MailingBlacklist available at MaileonAPIResult::getResult()
- * @throws MaileonAPIException
- * if there was a connection problem or a server error occurred
+ * @return MaileonAPIResult|null The result object of the API call, with a MailingBlacklist available at MaileonAPIResult::getResult()
+ *
+ * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred
*/
public function getWebhooks()
{
- return $this->get("webhooks/", [], 'application/json', ['array', Webhook::class]);
+ return $this->get(
+ 'webhooks/',
+ [],
+ 'application/json',
+ [
+ 'array',
+ Webhook::class,
+ ]
+ );
}
}
diff --git a/src/xml/AbstractXMLWrapper.php b/src/xml/AbstractXMLWrapper.php
index d43037c..800de6f 100644
--- a/src/xml/AbstractXMLWrapper.php
+++ b/src/xml/AbstractXMLWrapper.php
@@ -2,60 +2,63 @@
namespace de\xqueue\maileon\api\client\xml;
+use Exception;
+use SimpleXMLElement;
+
+use function simplexml_load_string;
+
/**
* Abstract base class for all XML wrapper elements.
*
- * @author Felix Heinrichs | Trusted Mails GmbH |
- * felix.heinrichs@trusted-mails.com
- * @author Marcus Ständer | Trusted Mails GmbH |
- * marcus.staender@trusted-mails.com
+ * @author Felix Heinrichs
+ * @author Marcus Beckerle | XQueue GmbH | marcus.beckerle@xqueue.com
*/
abstract class AbstractXMLWrapper
{
/**
* Initialization from a simple xml element.
*
- * @param \SimpleXMLElement $xmlElement
- * the SimpleXMLElement to initialize the object from
+ * @param SimpleXMLElement $xmlElement the SimpleXMLElement to initialize the object from
*/
abstract public function fromXML($xmlElement);
/**
* Initialization from a xml serialized string.
*
- * @param string $xmlString
- * the raw XML to initialize the object from
+ * @param string $xmlString the raw XML to initialize the object from
*/
public function fromXMLString($xmlString)
{
$xmlElement = simplexml_load_string($xmlString);
+
$this->fromXML($xmlElement);
}
/**
* Serialization to a simple XML element.
*
- * @return \SimpleXMLElement
- * contains the serialized representation of the object
+ * @return SimpleXMLElement contains the serialized representation of the object
+ *
+ * @throws Exception
*/
abstract public function toXML();
/**
* Serialization to an XML string.
*
- * @return string
- * contains the serialized representation of the object
+ * @return string the serialized representation of the object
*
+ * @throws Exception
*/
- public function toXMLString()
+ public function toXMLString(): string
{
- $result = $this->toXML();
- return $result->asXML();
+ return $this->toXML()->asXML();
}
/**
- * @return string
- * a human-readable representation of the object
+ * Human-readable representation of the object
+ *
+ * @return string A human-readable representation of the object
*/
- abstract public function toString();
+ abstract public function toString(): string;
}
diff --git a/src/xml/XMLDeserializer.php b/src/xml/XMLDeserializer.php
index faca829..301adc1 100644
--- a/src/xml/XMLDeserializer.php
+++ b/src/xml/XMLDeserializer.php
@@ -2,36 +2,38 @@
namespace de\xqueue\maileon\api\client\xml;
-use de\xqueue\maileon\api\client\reports\Open;
-use de\xqueue\maileon\api\client\reports\Block;
-use de\xqueue\maileon\api\client\reports\Click;
-use de\xqueue\maileon\api\client\reports\Bounce;
+use de\xqueue\maileon\api\client\account\AccountPlaceholder;
+use de\xqueue\maileon\api\client\account\MailingDomain;
+use de\xqueue\maileon\api\client\blacklists\Blacklist;
+use de\xqueue\maileon\api\client\blacklists\mailings\FilteredMailingBlacklistExpression;
+use de\xqueue\maileon\api\client\blacklists\mailings\MailingBlacklistExpressions;
+use de\xqueue\maileon\api\client\contactfilters\ContactFilter;
use de\xqueue\maileon\api\client\contacts\Contact;
-use de\xqueue\maileon\api\client\mailings\Mailing;
use de\xqueue\maileon\api\client\contacts\Contacts;
+use de\xqueue\maileon\api\client\contacts\CustomFields;
+use de\xqueue\maileon\api\client\contacts\Preference;
+use de\xqueue\maileon\api\client\contacts\PreferenceCategory;
+use de\xqueue\maileon\api\client\mailings\Attachment;
+use de\xqueue\maileon\api\client\mailings\CustomProperty;
+use de\xqueue\maileon\api\client\mailings\Mailing;
+use de\xqueue\maileon\api\client\mailings\MailingBlacklist;
use de\xqueue\maileon\api\client\mailings\Schedule;
-use de\xqueue\maileon\api\client\reports\Recipient;
+use de\xqueue\maileon\api\client\reports\Block;
+use de\xqueue\maileon\api\client\reports\Bounce;
+use de\xqueue\maileon\api\client\reports\Click;
use de\xqueue\maileon\api\client\reports\Conversion;
+use de\xqueue\maileon\api\client\reports\Open;
+use de\xqueue\maileon\api\client\reports\Recipient;
use de\xqueue\maileon\api\client\reports\Subscriber;
-use de\xqueue\maileon\api\client\mailings\Attachment;
-use de\xqueue\maileon\api\client\mailings\MailingBlacklist;
-use de\xqueue\maileon\api\client\reports\FieldBackup;
-use de\xqueue\maileon\api\client\blacklists\Blacklist;
use de\xqueue\maileon\api\client\reports\UniqueBounce;
+use de\xqueue\maileon\api\client\reports\UniqueConversion;
use de\xqueue\maileon\api\client\reports\Unsubscriber;
use de\xqueue\maileon\api\client\reports\UnsubscriptionReason;
-use de\xqueue\maileon\api\client\contacts\CustomFields;
-use de\xqueue\maileon\api\client\mailings\CustomProperty;
-use de\xqueue\maileon\api\client\reports\UniqueConversion;
use de\xqueue\maileon\api\client\targetgroups\TargetGroup;
-use de\xqueue\maileon\api\client\account\AccountPlaceholder;
-use de\xqueue\maileon\api\client\account\MailingDomain;
-use de\xqueue\maileon\api\client\contactfilters\ContactFilter;
use de\xqueue\maileon\api\client\transactions\TransactionType;
-use de\xqueue\maileon\api\client\contacts\Preference;
-use de\xqueue\maileon\api\client\contacts\PreferenceCategory;
-use de\xqueue\maileon\api\client\blacklists\mailings\MailingBlacklistExpressions;
-use de\xqueue\maileon\api\client\blacklists\mailings\FilteredMailingBlacklistExpression;
+
+use function explode;
+use function strtolower;
class XMLDeserializer
{
@@ -39,372 +41,221 @@ public static function deserialize($xmlElement)
{
if (isset($xmlElement)) {
$result = null;
+
switch (strtolower($xmlElement->getName())) {
- case "count":
- case "id":
- case "targetgroupid":
- case "count_attachments":
- case "count_filters":
- return (int)$xmlElement;
- // __toString() caused error (not found) on several servers
- // return (int)$xmlElement->__toString();
- case "doi_key":
- return $xmlElement;
- case "tags":
- return explode("#", $xmlElement);
- case "name":
- return $xmlElement;
- case "templateId":
+ // int
+ case 'count':
+ case 'id':
+ case 'targetgroupid':
+ case 'count_attachments':
+ case 'transaction_type_id':
+ case 'count_filters':
+ return (int) $xmlElement;
+ // __toString() caused error (not found) on several servers
+ // return (int) $xmlElement->__toString();
+
+ // as is
+ case 'name':
+ case 'locale':
+ case 'doi_key':
+ return $xmlElement; // (string) $xmlElement
+ case 'tags':
+ return explode('#', $xmlElement); // explode('#', (string) $xmlElement)
+ case 'templateId':
case 'templateid':
- case "previewtext":
- case "subject":
- case "sender":
- case "senderalias":
- case "ignore_permission":
- case "state":
- case "url":
- case "type":
- case "domain":
+ case 'previewtext':
+ case 'subject':
+ case 'sender':
+ case 'senderalias':
+ case 'ignore_permission':
+ case 'state':
+ case 'url':
+ case 'type':
+ case 'domain':
case 'tracking_strategy':
- case "speed_level":
+ case 'speed_level':
+ case 'template_path':
case 'recipientalias':
- return (string)$xmlElement;
- case "locale":
- return $xmlElement;
- case "event":
+ return (string) $xmlElement;
+ case 'events':
+ case 'event':
return false; // deserialization not yet supported.
+ case 'ignorepermission':
+ case 'cleanup':
+ return (bool) $xmlElement;
+ case 'result':
+ $result = [];
- case "events":
- return false; // deserialization not yet supported.
-
- case "ignorepermission":
- case "cleanup":
- return boolval($xmlElement);
-
- case "result":
- $result = array();
- if (!empty($xmlElement->contact_filter_id)) {
+ if (! empty($xmlElement->contact_filter_id)) {
$result['contact_filter_id'] = $xmlElement->contact_filter_id;
}
- if (!empty($xmlElement->target_group_id) && ($xmlElement->target_group_id!=-1)) {
+
+ if (! empty($xmlElement->target_group_id) && ($xmlElement->target_group_id != -1)) {
$result['target_group_id'] = $xmlElement->target_group_id;
}
- return $result;
- case "schedule":
+ return $result;
+ case 'schedule':
$result = new Schedule();
- break;
- case "targetgroup":
- $result = new TargetGroup();
break;
+ case 'targetgroup':
+ $result = new TargetGroup();
- case "targetgroups":
- $result = array();
- foreach ($xmlElement as $element) {
- $result[] = self::deserialize($element);
- }
- return $result;
-
- case "mailing_blacklist":
- $result = new MailingBlacklist();
break;
+ case 'mailing_blacklists':
+ case 'filtered_expressions':
+ case 'mailing_domains':
+ case 'account_placeholders':
+ case 'properties':
+ case 'unsubscription_reasons':
+ case 'unsubscriptions':
+ case 'blacklists':
+ case 'mailings':
+ case 'blocks':
+ case 'bounces':
+ case 'unique_bounces':
+ case 'clicks':
+ case 'opens':
+ case 'recipients':
+ case 'transaction_types':
+ case 'field_backups':
+ case 'subscribers':
+ case 'attachments':
+ case 'unique_conversions':
+ case 'conversions':
+ case 'preference_categories':
+ case 'preferences':
+ case 'contactfilters':
+ case 'targetgroups':
+ $result = [];
- case "mailing_blacklists":
- $result = array();
foreach ($xmlElement as $element) {
$result[] = self::deserialize($element);
}
- return $result;
- case "filtered_expression":
- $result = new FilteredMailingBlacklistExpression();
- break;
-
- case "filtered_expressions":
- $result = array();
- foreach ($xmlElement as $element) {
- $result[] = self::deserialize($element);
- }
return $result;
+ case 'mailing_blacklist':
+ $result = new MailingBlacklist();
- case "mailing_blacklist_expression":
break;
+ case 'filtered_expression':
+ $result = new FilteredMailingBlacklistExpression();
- case "mailing_blacklist_expressions":
- $result = new MailingBlacklistExpressions();
break;
+ case 'mailing_blacklist_expressions':
+ $result = new MailingBlacklistExpressions();
- case "contactfilter":
- $result = new ContactFilter();
break;
+ case 'contactfilter':
+ $result = new ContactFilter();
- case "contactfilters":
- $result = array();
- foreach ($xmlElement as $contactFilterElement) {
- $result[] = self::deserialize($contactFilterElement);
- }
- return $result;
-
- case "preference":
- $result = new Preference();
break;
+ case 'preference':
+ $result = new Preference();
- case "preferences":
- $result = array();
- foreach ($xmlElement as $preferenceCategoryElement) {
- $result[] = self::deserialize($preferenceCategoryElement);
- }
- return $result;
-
- case "preference_category":
- $result = new PreferenceCategory();
break;
+ case 'preference_category':
+ $result = new PreferenceCategory();
- case "preference_categories":
- $result = array();
- foreach ($xmlElement as $preferenceCategoryElement) {
- $result[] = self::deserialize($preferenceCategoryElement);
- }
- return $result;
-
- case "conversion":
- $result = new Conversion();
break;
+ case 'conversion':
+ $result = new Conversion();
- case "conversions":
- $result = array();
- foreach ($xmlElement as $conversionElement) {
- $result[] = self::deserialize($conversionElement);
- }
- return $result;
-
- case "unique_conversion":
- $result = new UniqueConversion();
break;
+ case 'unique_conversion':
+ $result = new UniqueConversion();
- case "unique_conversions":
- $result = array();
- foreach ($xmlElement as $conversionElement) {
- $result[] = self::deserialize($conversionElement);
- }
- return $result;
-
- case "contact":
- $result = new Contact();
break;
+ case 'contact':
+ $result = new Contact();
- case "contacts":
- $result = new Contacts();
break;
+ case 'contacts':
+ $result = new Contacts();
- case "attachment":
- $result = new Attachment();
break;
+ case 'attachment':
+ $result = new Attachment();
- case "attachments":
- $result = array();
- foreach ($xmlElement as $attachmentElement) {
- $result[] = self::deserialize($attachmentElement);
- }
- return $result;
-
- case "custom_fields":
- $result = new CustomFields();
break;
+ case 'custom_fields':
+ $result = new CustomFields();
- case "unsubscription":
- $result = new Unsubscriber();
break;
+ case 'unsubscription':
+ $result = new Unsubscriber();
- case "unsubscriptions":
- $result = array();
- foreach ($xmlElement as $unsubscriptionElement) {
- $result[] = self::deserialize($unsubscriptionElement);
- }
- return $result;
-
- case "unsubscription_reason":
- $result = new UnsubscriptionReason();
break;
+ case 'unsubscription_reason':
+ $result = new UnsubscriptionReason();
- case "unsubscription_reasons":
- $result = array();
- foreach ($xmlElement as $element) {
- $result[] = self::deserialize($element);
- }
- return $result;
-
- case "subscriber":
- $result = new Subscriber();
break;
+ case 'subscriber':
+ $result = new Subscriber();
- case "subscribers":
- $result = array();
- foreach ($xmlElement as $subscriberElement) {
- $result[] = self::deserialize($subscriberElement);
- }
- return $result;
-
- case "field_backup":
break;
-
- case "field_backups":
- $result = array();
- foreach ($xmlElement as $fieldBackupElement) {
- $result[] = self::deserialize($fieldBackupElement);
- }
- return $result;
-
- case "transaction_type":
+ case 'transaction_type':
$result = new TransactionType();
- break;
-
- case "transaction_types":
- $result = array();
- foreach ($xmlElement as $transactionTypeElement) {
- $result[] = self::deserialize($transactionTypeElement);
- }
- return $result;
-
- case "transaction_type_id":
- return (int)$xmlElement;
- case "recipient":
- $result = new Recipient();
break;
+ case 'recipient':
+ $result = new Recipient();
- case "recipients":
- $result = array();
- foreach ($xmlElement as $recipientElement) {
- $result[] = self::deserialize($recipientElement);
- }
- return $result;
-
- case "open":
- $result = new Open();
break;
+ case 'open':
+ $result = new Open();
- case "opens":
- $result = array();
- foreach ($xmlElement as $openElement) {
- $result[] = self::deserialize($openElement);
- }
- return $result;
-
- case "click":
- $result = new Click();
break;
+ case 'click':
+ $result = new Click();
- case "clicks":
- $result = array();
- foreach ($xmlElement as $clickElement) {
- $result[] = self::deserialize($clickElement);
- }
- return $result;
-
- case "bounce":
- $result = new Bounce();
break;
+ case 'bounce':
+ $result = new Bounce();
- case "bounces":
- $result = array();
- foreach ($xmlElement as $bounceElement) {
- $result[] = self::deserialize($bounceElement);
- }
- return $result;
-
- case "unique_bounce":
- $result = new UniqueBounce();
break;
+ case 'unique_bounce':
+ $result = new UniqueBounce();
- case "unique_bounces":
- $result = array();
- foreach ($xmlElement as $bounceElement) {
- $result[] = self::deserialize($bounceElement);
- }
- return $result;
-
- case "block":
- $result = new Block();
break;
+ case 'block':
+ $result = new Block();
- case "blocks":
- $result = array();
- foreach ($xmlElement as $blockElement) {
- $result[] = self::deserialize($blockElement);
- }
- return $result;
-
- case "mailing":
- $result = new Mailing();
break;
+ case 'mailing':
+ $result = new Mailing();
- case "mailings":
- $result = array();
- foreach ($xmlElement as $mailingElement) {
- $result[] = self::deserialize($mailingElement);
- }
- return $result;
-
- case "blacklist":
- $result = new Blacklist();
break;
+ case 'blacklist':
+ $result = new Blacklist();
- case "blacklists":
- $result = array();
- foreach ($xmlElement as $blacklistElement) {
- $result[] = self::deserialize($blacklistElement);
- }
- return $result;
-
-
- case "property":
- $result = new CustomProperty();
break;
+ case 'property':
+ $result = new CustomProperty();
- case "properties":
- $result = array();
- foreach ($xmlElement as $element) {
- $result[] = self::deserialize($element);
- }
- return $result;
-
-
- case "account_placeholder":
- $result = new AccountPlaceholder();
break;
+ case 'account_placeholder':
+ $result = new AccountPlaceholder();
- case "account_placeholders":
- $result = array();
- foreach ($xmlElement as $element) {
- $result[] = self::deserialize($element);
- }
- return $result;
-
- case "mailing_domain":
- $result = new MailingDomain();
break;
+ case 'mailing_domain':
+ $result = new MailingDomain();
- case "mailing_domains":
- $result = array();
- foreach ($xmlElement as $element) {
- $result[] = self::deserialize($element);
- }
- return $result;
-
- case "template_path":
- return (string)$xmlElement;
-
+ break;
+ case 'field_backup':
+ case 'mailing_blacklist_expression':
default:
- $result = null;
break;
}
- if ($result) {
+
+ if (null !== $result) {
$result->fromXML($xmlElement);
+
return $result;
}
}
+
return false;
}
}
diff --git a/src/xml/XMLUtils.php b/src/xml/XMLUtils.php
index 1cd179e..43f85d1 100644
--- a/src/xml/XMLUtils.php
+++ b/src/xml/XMLUtils.php
@@ -2,45 +2,56 @@
namespace de\xqueue\maileon\api\client\xml;
+use SimpleXMLElement;
+
+use function dom_import_simplexml;
+use function is_bool;
+
/**
* Utility class for XML elements
*
- * @author Felix Heinrichs | Trusted Mails GmbH |
- * felix.heinrichs@trusted-mails.com
- * @author Marcus Beckerle | XQueue GmbH |
- * marcus.beckerle@xqueue.com
+ * @author Felix Heinrichs
+ * @author Marcus Beckerle | XQueue GmbH | marcus.beckerle@xqueue.com
*/
abstract class XMLUtils
{
/**
* This function appends one SimpleXMLElement to another one as addChild does not support deep copies
- * @param \SimpleXMLElement $to
- * @param \SimpleXMLElement $from
+ *
+ * @param SimpleXMLElement $to
+ * @param SimpleXMLElement $from
*/
- public static function appendChild(\SimpleXMLElement $to, \SimpleXMLElement $from)
- {
- $toDom = dom_import_simplexml($to);
+ public static function appendChild(
+ SimpleXMLElement $to,
+ SimpleXMLElement $from
+ ) {
+ $toDom = dom_import_simplexml($to);
$fromDom = dom_import_simplexml($from);
+
$toDom->appendChild($toDom->ownerDocument->importNode($fromDom, true));
}
/**
* Adds a child with $value inside CDATA
- * @param \SimpleXMLElement $parent
- * @param string $name
- * @param string $value
+ *
+ * @param SimpleXMLElement $parent
+ * @param string $name
+ * @param string $value
*/
- public static function addChildAsCDATA($parent, $name, $value = null)
- {
+ public static function addChildAsCDATA(
+ $parent,
+ $name,
+ $value = null
+ ) {
$new_child = $parent->addChild($name);
if ($new_child !== null) {
$node = dom_import_simplexml($new_child);
- $no = $node->ownerDocument;
+ $no = $node->ownerDocument;
// createCDATASection() returns an empty CDATA if value is a false boolean
- // workaround: use intval of value instead
- $cdata = $no->createCDATASection((string)(is_bool($value) ? intval($value) : $value));
+ // workaround: use integer value of value instead
+ $cdata = $no->createCDATASection((string) (is_bool($value) ? (int) $value : $value));
$node->appendChild($cdata);
}
diff --git a/version.txt b/version.txt
index 77009bc..aef099f 100644
--- a/version.txt
+++ b/version.txt
@@ -1,2 +1,2 @@
-dist.version = 1.12.0
-dist.version.stable = 1.12.0
+dist.version = 1.12.1
+dist.version.stable = 1.12.1