Initial commit: CloudOps infrastructure platform

This commit is contained in:
root
2026-04-09 19:58:57 +02:00
commit 1166a52f26
7762 changed files with 839452 additions and 0 deletions

View File

@@ -0,0 +1,68 @@
<?php
namespace MauticPlugin\MauticEmailMarketingBundle\Api;
use Mautic\PluginBundle\Exception\ApiErrorException;
class ConstantContactApi extends EmailMarketingApi
{
private string $version = 'v2';
protected function request($endpoint, $parameters = [], $method = 'GET', $query = [])
{
$url = sprintf('https://api.constantcontact.com/%s/%s?api_key=%s', $this->version, $endpoint, $this->keys['client_id']);
$response = $this->integration->makeRequest($url, $parameters, $method, [
'encode_parameters' => 'json',
'append_auth_token' => true,
'query' => $query,
]);
if (is_array($response) && !empty($response[0]['error_message'])) {
$errors = [];
foreach ($response as $error) {
$errors[] = $error['error_message'];
}
throw new ApiErrorException(implode(' ', $errors));
} else {
return $response;
}
}
/**
* @return mixed|string
*
* @throws ApiErrorException
*/
public function getLists()
{
return $this->request('lists');
}
/**
* @param array $fields
* @param array $config
*
* @return mixed|string
*
* @throws ApiErrorException
*/
public function subscribeLead($email, $listId, $fields = [], $config = [])
{
$parameters = array_merge($fields, [
'lists' => [
['id' => "$listId"],
],
'email_addresses' => [
['email_address' => $email],
],
]);
$query = [
'action_by' => $config['action_by'],
];
return $this->request('contacts', $parameters, 'POST', $query);
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace MauticPlugin\MauticEmailMarketingBundle\Api;
use Mautic\PluginBundle\Integration\AbstractIntegration;
use Mautic\PluginBundle\Integration\UnifiedIntegrationInterface;
class EmailMarketingApi
{
protected $keys;
/**
* @param AbstractIntegration $integration
*/
public function __construct(
protected UnifiedIntegrationInterface $integration,
) {
$this->keys = $integration->getKeys();
}
}

View File

@@ -0,0 +1,72 @@
<?php
namespace MauticPlugin\MauticEmailMarketingBundle\Api;
use Mautic\PluginBundle\Exception\ApiErrorException;
class IcontactApi extends EmailMarketingApi
{
protected function request($endpoint, $parameters = [], $method = 'GET')
{
$url = sprintf('%s/%s/c/%s/%s', $this->integration->getApiUrl(), $this->keys['accountId'], $this->keys['clientFolderId'], $endpoint);
$response = $this->integration->makeRequest($url, $parameters, $method, [
'encode_parameters' => 'json',
'encoding_headers_set' => true,
]);
if (is_array($response) && !empty($response['errors'])) {
throw new ApiErrorException(implode(' ', $response['errors']));
} else {
return $response;
}
}
/**
* @return mixed|string
*
* @throws ApiErrorException
*/
public function getLists()
{
return $this->request('lists');
}
/**
* @return mixed|string
*
* @throws ApiErrorException
*/
public function getCustomFields()
{
return $this->request('customfields');
}
/**
* @param array $fields
*
* @return mixed|string
*
* @throws ApiErrorException
*/
public function subscribeLead($listId, $fields)
{
$fields['status'] = 'normal';
$contacts = $this->request('contacts', [$fields], 'POST');
if (!empty($contacts['contacts'][0]['contactId'])) {
$contactId = $contacts['contacts'][0]['contactId'];
$fields = [
'status' => 'normal',
'listId' => $listId,
'contactId' => $contactId,
];
return $this->request('subscriptions', [$fields], 'POST');
}
return $contacts;
}
}

View File

@@ -0,0 +1,90 @@
<?php
namespace MauticPlugin\MauticEmailMarketingBundle\Api;
use Mautic\PluginBundle\Exception\ApiErrorException;
class MailchimpApi extends EmailMarketingApi
{
private string $version = '3.0';
/**
* @param array $parameters
* @param string $method
*
* @return mixed|string
*
* @throws ApiErrorException
*/
protected function request($endpoint, $parameters = [], $method = 'GET')
{
if (isset($this->keys['password'])) {
// Extract the dc from the key
$parts = explode('-', $this->keys['password']);
if (2 !== count($parts)) {
throw new ApiErrorException('Invalid key');
}
$dc = $parts[1];
$apiUrl = 'https://'.$dc.'.api.mailchimp.com';
$parameters['apikey'] = $this->keys['password'];
} else {
$apiUrl = $this->keys['api_endpoint'];
$parameters['apikey'] = $this->keys['access_token'];
}
$url = sprintf('%s/%s/%s', $apiUrl, $this->version, $endpoint);
$response = $this->integration->makeRequest($url, $parameters, $method, ['encode_parameters' => 'json']);
if (is_array($response) && !empty($response['status']) && 'error' == $response['status']) {
throw new ApiErrorException($response['error']);
} elseif (is_array($response) && !empty($response['errors'])) {
$errors = [];
foreach ($response['errors'] as $error) {
$errors[] = $error['message'];
}
throw new ApiErrorException(implode(' ', $errors));
} else {
return $response;
}
}
public function getLists()
{
return $this->request('lists', ['limit' => 100]);
}
/**
* @return mixed|string
*
* @throws ApiErrorException
*/
public function getCustomFields($listId)
{
return $this->request('lists/'.$listId.'/merge-fields');
}
/**
* @param array $fields
* @param array $config
*
* @return mixed|string
*
* @throws ApiErrorException
*/
public function subscribeLead($email, $listId, $fields = [], $config = [])
{
$emailStruct = new \stdClass();
$emailStruct->email = $email;
$parameters = array_merge($config, [
'id' => $listId,
]);
if (!empty($fields)) {
$parameters = array_merge($parameters, ['merge_fields' => $fields]);
}
$parameters['email_address'] = $email;
return $this->request('lists/'.$listId.'/members', $parameters, 'POST');
}
}