-
Notifications
You must be signed in to change notification settings - Fork 0
/
mot_history.php
48 lines (40 loc) · 1.25 KB
/
mot_history.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
<?php
class mot_history {
protected $api_key;
public function __construct ($api_key) {
if (isset($api_key)) {
$this->api_key = $api_key;
} else {
echo "Please specify an API key" . PHP_EOL;
die();
}
}
public function getMotHistory($vehicle_registration) {
$curl = curl_init();
curl_setopt_array(
$curl, array(
CURLOPT_URL => "https://beta.check-mot.service.gov.uk/trade/vehicles/mot-tests?registration=$vehicle_registration",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Accept: application/json+v2",
"x-api-key: $this->api_key"
),
)
);
$response = json_decode(curl_exec($curl), true);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err . PHP_EOL;
return false;
} else {
return $response[0]['motTests'];
}
}
}
?>