forked from mailermailer/mailermailer-api-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MAILAPI_Call.php
59 lines (46 loc) · 1.49 KB
/
MAILAPI_Call.php
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
<?php
/**
* Refer to license.php for file headers and license
*/
require_once('xmlrpc/xmlrpc.inc');
require_once('config.php');
require_once('MAILAPI_Error.php');
/**
* Override the default internal encoding declared within xmlrpc.inc
*/
$xmlrpc_internalencoding = "UTF-8";
/**
* Class that performs all the required work to
* connect to the Mail API.
*/
class MAILAPI_Call
{
private $apikey;
public function __construct($apikey)
{
$this->apikey = $apikey;
}
/**
* Connects to the Mail API and calls the desired
* function with the specified parameters
*
* @param method to invoke and parameters for the method
* @return mixed
*/
public function executeMethod($method, $params)
{
$host = getenv("MAILAPI_URL") ? getenv("MAILAPI_URL") : MAILAPI_ENDPOINT;
$params['apikey'] = new xmlrpcval($this->apikey);
$xmlrpcmsg = new xmlrpcmsg($method, array(new xmlrpcval($params, 'struct')));
$xmlrpc_client = new xmlrpc_client($host);
$xmlrpc_client->request_charset_encoding="UTF-8";
$xmlrpc_client->SetUserAgent(MAILAPI_PARTNER . "/PHP/v" . MAILAPI_VERSION);
$response = $xmlrpc_client->send($xmlrpcmsg);
if (!$response->faultCode()) {
return php_xmlrpc_decode($response->value());
} else {
return new MAILAPI_Error($response->faultCode(), $response->faultString());
}
}
}
?>