-
Notifications
You must be signed in to change notification settings - Fork 0
/
APIsDavid.php
76 lines (60 loc) · 1.69 KB
/
APIsDavid.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
$url ="http://partners.api.skyscanner.net/apiservices/pricing/v1.0";
$data = array( 'apiKey' => 'ah229592831881725379481999349293',
'country' => 'ES',
'currency' => 'EUR',
'locale' => 'es-ES',
'originplace' => 'BCN-sky',
'destinationplace' => 'PARI-sky',
'outbounddate' => '2016-02-21',
);
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data),
),
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
$location = $http_response_header[4] . '?apiKey=ah229592831881725379481999349293';
$location = str_replace("Location: ", "", $location);
//var_dump($location);
$json = file_get_contents($location);
$obj = json_decode($json);
// VARIABLES
$price_list = array();
//var_dump($obj);
$currency = $obj->Query->Currency;
$Iti = $obj->Itineraries;
foreach ($Iti as $priOpt) {
foreach ($priOpt as $o) {
foreach ($o as $a) {
$id = $a->Agents[0];
$price = $a->Price;
$price_list[$id] = $price . ' ' .$currency;
}
}
}
$price_list = array_filter($price_list); // delete null values (trash)
foreach ($obj->Agents as $agent ) {
//var_dump($agent->Id);
$idAgent = $agent->Id;
$nameAgent = $agent->Name;
if (array_key_exists($idAgent, $price_list)) {
$price_list[$nameAgent] = $price_list[$idAgent];
unset($price_list[$idAgent]);
}
}
echo "<pre>" . print_r($price_list,true) . "</pre>";
?>
<!DOCTYPE html>
<html>
<head>
<title>Proves APIs</title>
</head>
<body>
<div id="1">
</div>
</body>
</html>