-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSendloopAPI3.php
More file actions
89 lines (67 loc) · 1.9 KB
/
SendloopAPI3.php
File metadata and controls
89 lines (67 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php namespace Sendloop;
/*
* Sendloop API Wrapper
* @copyright Octeth, Inc. d/b/a Sendloop
* @author Sendloop
* @version 3.0.0
* @license GNU GPL v3
*/
class SendloopAPI3 {
private $APIKey = '';
private $APICommand = '';
private $Subdomain = '';
private $ResponseFormat = '';
private $APIBaseURL = 'sendloop.com';
public $Result = '';
public function __construct($APIKey,$Subdomain,$ResponseFormat='json') {
$this->SetResponseFormat($ResponseFormat);
if (empty($APIKey)) {
echo 'APIKey is empty';
return false;
}
$this->APIKey = $APIKey;
if (empty($Subdomain)) {
echo 'Subdomain is empty';
return false;
}
$this->Subdomain = $Subdomain;
}
public function SetResponseFormat($ResponseFormat='json') {
$this->ResponseFormat = 'php';
if ($ResponseFormat == 'xml') {
$this->ResponseFormat = 'xml';
} else if ($ResponseFormat == 'json') {
$this->ResponseFormat = 'json';
}
}
private function MakeURL($APICommand) {
$APIURL = 'http://'.$this->Subdomain.'.'.$this->APIBaseURL.'/api/v3/'.$APICommand.'/'.$this->ResponseFormat;
return $APIURL;
}
public function run($APICommand,$Parameters) {
$cURL = curl_init();
$APIURL = $this->MakeURL($APICommand);
$ParametersArray = array('APIKey='.$this->APIKey);
foreach ($Parameters as $Key => $Value) {
if (is_array($Value)) {
foreach ($Value as $V_Key => $V_Value) {
$ParametersArray[] = $Key."[".$V_Key."]=".$V_Value;
}
} else {
$ParametersArray[] = "$Key=$Value";
}
}
$ParametersString = implode('&',$ParametersArray);
curl_setopt($cURL,CURLOPT_URL,$APIURL);
curl_setopt($cURL,CURLOPT_POST,1);
curl_setopt($cURL,CURLOPT_RETURNTRANSFER,1);
curl_setopt($cURL,CURLOPT_POSTFIELDS,$ParametersString);
$Result = curl_exec($cURL);
if ($this->ResponseFormat=='php') {
$Result = unserialize($Result);
}
curl_close($cURL);
$this->Result = $Result;
return true;
}
}