2021-01-29 10:42:13 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Class ki vsebuje funkcije APIJA (prijava, registracija v 1ko)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
class SqualoApi {
|
|
|
|
|
|
|
|
// Squalo api url
|
|
|
|
var $api_url = 'https://api.squalomail.com/v1/';
|
|
|
|
|
|
|
|
|
|
|
|
public function __construct(){
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-24 11:11:25 +01:00
|
|
|
private function executeCall($action, $method, $data){
|
2021-01-29 10:42:13 +01:00
|
|
|
global $squalo_user;
|
|
|
|
global $squalo_key;
|
|
|
|
|
|
|
|
// Add credentials
|
|
|
|
$data['apiUser'] = $squalo_user;
|
2021-02-24 11:11:25 +01:00
|
|
|
$data['apiKey'] = $squalo_key;
|
2021-01-29 10:42:13 +01:00
|
|
|
|
|
|
|
// GET call - set url params
|
|
|
|
if($method == 'GET'){
|
2021-02-24 11:11:25 +01:00
|
|
|
$response = $this->executeGET($action, $data);
|
|
|
|
}
|
|
|
|
// POST call
|
|
|
|
else{
|
|
|
|
$response = $this->executePOST($action, $data);
|
|
|
|
}
|
2021-01-29 10:42:13 +01:00
|
|
|
|
2021-02-24 11:11:25 +01:00
|
|
|
// Decode json response
|
|
|
|
$response_array = json_decode($response, true);
|
2021-01-29 10:42:13 +01:00
|
|
|
|
2021-02-24 11:11:25 +01:00
|
|
|
// Error
|
|
|
|
if($response_array['errorCode'] != '0'){
|
|
|
|
$result['error'] = $response_array["errorMessage"]. ' (code '.$response_array["errorCode"].')';
|
|
|
|
$result['success'] = false;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
$result = $response_array;
|
|
|
|
$result['success'] = true;
|
2021-01-29 10:42:13 +01:00
|
|
|
}
|
|
|
|
|
2021-02-24 11:11:25 +01:00
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Izvedemo post klic
|
|
|
|
private function executePOST($action, $data){
|
|
|
|
|
|
|
|
// Nastavimo url
|
|
|
|
$url = $this->api_url.$action;
|
|
|
|
|
|
|
|
|
2021-01-29 10:42:13 +01:00
|
|
|
// Init curl
|
2021-02-24 11:11:25 +01:00
|
|
|
$ch = curl_init($url);
|
|
|
|
|
|
|
|
// JSON string za POST
|
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
|
2021-01-29 10:42:13 +01:00
|
|
|
|
2021-02-24 11:11:25 +01:00
|
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
|
curl_setopt($ch, CURLOPT_POST, true);
|
2021-01-29 10:42:13 +01:00
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
2021-02-24 11:11:25 +01:00
|
|
|
|
|
|
|
// for debug only!
|
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
|
|
|
|
|
$headers = array(
|
|
|
|
"Content-Type: application/json",
|
|
|
|
);
|
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
2021-01-29 10:42:13 +01:00
|
|
|
|
|
|
|
|
2021-02-24 11:11:25 +01:00
|
|
|
// Izvedemo klic
|
|
|
|
$response = curl_exec($ch);
|
|
|
|
curl_close($ch);
|
|
|
|
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Izvedemo get klic
|
|
|
|
private function executeGET($action, $data){
|
2021-01-29 10:42:13 +01:00
|
|
|
|
2021-02-24 11:11:25 +01:00
|
|
|
// GET params
|
|
|
|
$params = '?';
|
|
|
|
foreach($data as $name => $value){
|
|
|
|
$params .= $name.'='.$value.'&';
|
|
|
|
}
|
|
|
|
$params = substr($params, 0, -1);
|
|
|
|
|
|
|
|
// Nastavimo celoten url s parametri
|
|
|
|
$url = $this->api_url.$action.$params;
|
|
|
|
|
|
|
|
|
|
|
|
// Init curl
|
|
|
|
$ch = curl_init($url);
|
|
|
|
|
|
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
|
2021-01-29 10:42:13 +01:00
|
|
|
|
|
|
|
// Izvedemo klic
|
2021-02-24 11:11:25 +01:00
|
|
|
$response = curl_exec($ch);
|
2021-01-29 10:42:13 +01:00
|
|
|
|
2021-02-24 11:11:25 +01:00
|
|
|
return $response;
|
2021-01-29 10:42:13 +01:00
|
|
|
}
|
|
|
|
|
2021-02-24 11:11:25 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
Ustvarimo seznam uporabnikov za pošiljanje
|
|
|
|
create-list
|
|
|
|
|
|
|
|
"name":"String content",
|
|
|
|
"description":"String content",
|
|
|
|
"listTag":"String content",
|
|
|
|
"color":"String content",
|
|
|
|
"ordering":2147483647,
|
|
|
|
"published":true
|
|
|
|
|
|
|
|
{subtag:name}
|
|
|
|
{subtag:code}
|
|
|
|
{subtag:url}
|
|
|
|
|
|
|
|
{date:4}
|
|
|
|
|
|
|
|
{unsubscribe}{/unsubscribe}
|
|
|
|
*/
|
|
|
|
public function createList($list_name){
|
|
|
|
|
|
|
|
$action = 'create-list';
|
|
|
|
$method = 'POST';
|
|
|
|
|
|
|
|
$data = array(
|
|
|
|
'name' => $list_name,
|
|
|
|
'ordering' => $list_number,
|
|
|
|
'published' => true
|
|
|
|
);
|
|
|
|
|
|
|
|
$response = $this->executeCall($action, $method, $data);
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Ustvarimo email,ki se bo poslal
|
|
|
|
|
|
|
|
"altBody":"String content",
|
|
|
|
"body":"String content",
|
|
|
|
"fromEmail":"String content",
|
|
|
|
"fromName":"String content",
|
|
|
|
"language":"String content",
|
|
|
|
"listIds":[2147483647],
|
|
|
|
"published":2147483647,
|
|
|
|
"replyToEmail":"String content",
|
|
|
|
"replyToName":"String content",
|
|
|
|
"subject":"String content",
|
|
|
|
"visible":true
|
|
|
|
*/
|
|
|
|
public function createNewsletter($list_id, $subject, $body, $body_alt, $from_email, $from_name, $reply_to_email, $language){
|
2021-01-29 10:42:13 +01:00
|
|
|
|
2021-02-24 11:11:25 +01:00
|
|
|
$action = 'create-newsletter';
|
|
|
|
$method = 'POST';
|
|
|
|
|
|
|
|
$data = array(
|
|
|
|
'listIds' => array($list_id),
|
|
|
|
'subject' => $subject,
|
|
|
|
'body' => $body,
|
|
|
|
'altBody' => $body_alt,
|
|
|
|
'fromEmail' => $from_email,
|
|
|
|
'fromName' => $from_name,
|
|
|
|
'replyToEmail' => $reply_to_email,
|
|
|
|
'language' => $language,
|
|
|
|
'visible' => true
|
|
|
|
);
|
|
|
|
|
|
|
|
$response = $this->executeCall($action, $method, $data);
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Dodamo prejemnika
|
|
|
|
|
|
|
|
"accept": true,
|
|
|
|
"confirmed": true,
|
|
|
|
"customAttributes": [{
|
|
|
|
"name": "firstname",
|
|
|
|
"value": "John"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "lastname",
|
|
|
|
"value": "Smith"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"email": "String content",
|
|
|
|
"enabled": true,
|
|
|
|
"html": true,
|
|
|
|
"listIds": [2147483647],
|
|
|
|
"name": "String content",
|
|
|
|
"surname": "String content",
|
|
|
|
"gender": "null | male | female | other",
|
|
|
|
"gdprCanSend": true,
|
|
|
|
"gdprCanTrack": true
|
|
|
|
*/
|
|
|
|
public function addRecipient($email, $list_id, $custom_attributes=array()){
|
|
|
|
|
|
|
|
$action = 'create-recipient';
|
|
|
|
$method = 'POST';
|
|
|
|
|
|
|
|
$data = array(
|
|
|
|
'email' => $email,
|
|
|
|
'listIds' => array($list_id),
|
|
|
|
'accept' => true,
|
|
|
|
'confirmed' => true,
|
|
|
|
'enabled' => true,
|
|
|
|
'gdprCanSend' => true,
|
|
|
|
'gdprCanTrack' => true
|
|
|
|
);
|
|
|
|
|
|
|
|
$response = $this->executeCall($action, $method, $data);
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Pošljemo emaile
|
|
|
|
|
|
|
|
"newsletterId":2147483647,
|
|
|
|
"sendDate":2147483647
|
|
|
|
*/
|
|
|
|
public function sendEmails($newsletter_id){
|
|
|
|
|
|
|
|
$action = 'send-newsletter';
|
|
|
|
$method = 'GET';
|
|
|
|
|
|
|
|
$data = array(
|
|
|
|
'newsletterId' => $newsletter_id,
|
|
|
|
'sendDate' => time()+30
|
|
|
|
);
|
|
|
|
|
|
|
|
$response = $this->executeCall($action, $method, $data);
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Pobrisemo prejemnika
|
|
|
|
public function deleteRecipient($recipient_id){
|
|
|
|
|
|
|
|
$action = 'delete-recipient';
|
|
|
|
$method = 'GET';
|
|
|
|
|
|
|
|
$data = array(
|
|
|
|
'recipientId' => $recipient_id
|
|
|
|
);
|
|
|
|
|
|
|
|
$response = $this->executeCall($action, $method, $data);
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
2021-01-29 10:42:13 +01:00
|
|
|
}
|