Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Date 2025-11-19
Version 1.12.2
- Fix properties

Date 2025-11-17
Version 1.12.1
- Fix encoding issue in path for unsubscribeContactByExternalId
Expand Down
228 changes: 114 additions & 114 deletions src/AbstractMaileonService.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,96 +181,6 @@ public function get(
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|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 = [],
$mimeType = 'application/vnd.maileon.api+xml',
$deserializationType = null
) {
$curlSession = $this->prepareSession($resourcePath, $queryParameters, $mimeType);

/*
* PUT does not work as expected when passing post data, see
* 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_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|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 = [],
$mimeType = 'application/vnd.maileon.api+xml',
$deserializationType = null,
$contentType = null,
$contentLength = null
) {
$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|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 = [],
$mimeType = 'application/vnd.maileon.api+xml',
$deserializationType = null
) {
$curlSession = $this->prepareSession($resourcePath, $queryParameters, $mimeType);
curl_setopt($curlSession, CURLOPT_CUSTOMREQUEST, 'DELETE');

return $this->performRequest($curlSession, $deserializationType);
}

/**
* @param $resourcePath
* @param $queryParameters
Expand Down Expand Up @@ -422,30 +332,6 @@ private function performRequest(
}
}

protected function appendArrayFields(
$params,
$name,
$fieldValues
) {
if (is_array($fieldValues) && ! empty($fieldValues)) {
$params [(string) $name] = [];

foreach ($fieldValues as $value) {
if ($value === true) {
$params [(string) $name] [] = 'true';
} elseif ($value === false) {
$params [(string) $name] [] = 'false';
} elseif ($value instanceof PreferenceCategory) {
$params[$name] = urlencode((string) $value->name);
} else {
$params [(string) $name] [] = urlencode($value);
}
}
}

return $params;
}

private function printDebugInformation(
$curlSession,
$result = null,
Expand Down Expand Up @@ -506,4 +392,118 @@ private function printDebugInformation(
$this->verboseOut = null;
}
}

/**
* 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|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 = [],
$mimeType = 'application/vnd.maileon.api+xml',
$deserializationType = null
) {
$curlSession = $this->prepareSession($resourcePath, $queryParameters, $mimeType);

/*
* PUT does not work as expected when passing post data, see
* 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_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|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 = [],
$mimeType = 'application/vnd.maileon.api+xml',
$deserializationType = null,
$contentType = null,
$contentLength = null
) {
$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|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 = [],
$mimeType = 'application/vnd.maileon.api+xml',
$deserializationType = null
) {
$curlSession = $this->prepareSession($resourcePath, $queryParameters, $mimeType);
curl_setopt($curlSession, CURLOPT_CUSTOMREQUEST, 'DELETE');

return $this->performRequest($curlSession, $deserializationType);
}

protected function appendArrayFields(
$params,
$name,
$fieldValues
) {
if (is_array($fieldValues) && ! empty($fieldValues)) {
$params [(string) $name] = [];

foreach ($fieldValues as $value) {
if ($value === true) {
$params [(string) $name] [] = 'true';
} elseif ($value === false) {
$params [(string) $name] [] = 'false';
} elseif ($value instanceof PreferenceCategory) {
$params[$name] = urlencode((string) $value->name);
} else {
$params [(string) $name] [] = urlencode($value);
}
}
}

return $params;
}
}
Loading