-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMetricWiseAPI.php
More file actions
81 lines (70 loc) · 1.37 KB
/
MetricWiseAPI.php
File metadata and controls
81 lines (70 loc) · 1.37 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
<?php
/**
* @copyright 2012-2025 MetricWise, Inc.
* @license https://opensource.org/licenses/MIT
*/
class MetricWiseAPI
{
/**
* @var string
*/
private $accessKey;
/**
* @var string
*/
private $error;
/**
* @var string
*/
private $hostname;
/**
* @var string
*/
private $username;
/**
* @param string $accessKey
*/
public function setAccessKey($accessKey) {
$this->accessKey = $accessKey;
}
/**
* @param string $hostname
*/
public function setHostname($hostname) {
$this->hostname = $hostname;
}
/**
* @param string $username
*/
public function setUsername($username) {
$this->username = $username;
}
/**
* @return string
*/
public function getError() {
return $this->error;
}
/**
* @param array $lead
*/
public function submitLead($lead) {
$curl = curl_init("$this->hostname/mwapi/lead");
curl_setopt($curl, CURLOPT_HTTPHEADER, array("x-api-key: $this->username:$this->accessKey"));
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($lead));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($curl);
$this->error = curl_error($curl);
$errno = curl_errno($curl);
$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
if ($errno) {
return false;
}
if (202 != $httpcode) {
$this->error = json_decode($result)->message;
return false;
}
return true;
}
}