Added Other AP

This commit is contained in:
dev-chiefworks
2022-04-26 11:30:34 -04:00
parent 5e006a6a21
commit 47f4fad75c
251 changed files with 29298 additions and 4 deletions
+45
View File
@@ -0,0 +1,45 @@
<?php
require './vendor/autoload.php';
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\ServerException;
class MailchimpAPI
{
private static function handleResponse($response)
{
$res = json_decode($response->getBody());
if (!isset($res)) {
return null;
}
return array_merge((array) $res);
}
public static function get($url, $params)
{
require_once('../../core/backend.php');
global $savvyext;
$token = $savvyext->cfgReadChar('mailchimp.api_key');
$baseUri = $savvyext->cfgReadChar('mailchimp.domain');
$client = new Client(['base_uri' => $baseUri]);
$header = ['Authorization' => "apikey $token"];
try {
$response = $client->request('GET', $url, [
'headers' => $header,
'query' => $params,
]);
} catch (ServerException $e) {
$response = $e->getResponse();
} catch (ClientException $e) {
$response = $e->getResponse();
}
return self::handleResponse($response);
}
}