61 lines
3.0 KiB
PHP
61 lines
3.0 KiB
PHP
<?php
|
|
$ch = curl_init();
|
|
curl_setopt($ch, CURLOPT_URL, 'https://booking-com15.p.rapidapi.com/api/v1/hotels/getHotelDetails?hotel_id=89675&arrival_date=2026-06-01&departure_date=2026-06-02&adults=1&room_qty=1&languagecode=en-us¤cy_code=USD&units=metric&temperature_unit=c');
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array('x-rapidapi-host: booking-com15.p.rapidapi.com', 'x-rapidapi-key: 68aff7697fmsh853b121ba37e29ep15574fjsn1b4cf54ec4bd'));
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
|
|
$r = curl_exec($ch);
|
|
curl_close($ch);
|
|
$d = json_decode($r, true);
|
|
|
|
// Block'tan distinct odalar
|
|
$block = isset($d['data']['block']) ? $d['data']['block'] : array();
|
|
$rooms_data = isset($d['data']['rooms']) ? $d['data']['rooms'] : array();
|
|
|
|
$seen = array();
|
|
echo "=== BLOCK[] - DISTINCT ROOMS ===" . PHP_EOL;
|
|
foreach ($block as $b) {
|
|
$key = isset($b['room_id']) ? $b['room_id'] : (isset($b['roomtype_id']) ? $b['roomtype_id'] : 'unknown');
|
|
if (!isset($seen[$key])) {
|
|
$seen[$key] = 1;
|
|
echo json_encode(array(
|
|
'room_id' => isset($b['room_id']) ? $b['room_id'] : null,
|
|
'roomtype_id' => isset($b['roomtype_id']) ? $b['roomtype_id'] : null,
|
|
'room_name' => isset($b['room_name']) ? $b['room_name'] : null,
|
|
'max_occupancy' => isset($b['max_occupancy']) ? $b['max_occupancy'] : null,
|
|
'nr_adults' => isset($b['nr_adults']) ? $b['nr_adults'] : null,
|
|
'nr_children' => isset($b['nr_children']) ? $b['nr_children'] : null,
|
|
'room_surface_in_m2' => isset($b['room_surface_in_m2']) ? $b['room_surface_in_m2'] : null,
|
|
'number_of_bedrooms' => isset($b['number_of_bedrooms']) ? $b['number_of_bedrooms'] : null,
|
|
'number_of_bathrooms' => isset($b['number_of_bathrooms']) ? $b['number_of_bathrooms'] : null,
|
|
), JSON_PRETTY_PRINT) . PHP_EOL . '---' . PHP_EOL;
|
|
}
|
|
}
|
|
|
|
echo PHP_EOL . "=== ROOMS[] - BED CONFIGS + VIEW ===" . PHP_EOL;
|
|
foreach ($rooms_data as $roomId => $roomVal) {
|
|
$bedConfs = isset($roomVal['bed_configurations']) ? $roomVal['bed_configurations'] : array();
|
|
$highlights = isset($roomVal['highlights']) ? $roomVal['highlights'] : array();
|
|
$views = array();
|
|
foreach ($highlights as $h) {
|
|
if (strpos(strtolower(isset($h['translated_name']) ? $h['translated_name'] : ''), 'view') !== false) {
|
|
$views[] = $h['translated_name'];
|
|
}
|
|
}
|
|
$beds = array();
|
|
foreach ($bedConfs as $conf) {
|
|
foreach (isset($conf['bed_types']) ? $conf['bed_types'] : array() as $bt) {
|
|
$beds[] = array(
|
|
'bed_type_id' => isset($bt['bed_type']) ? $bt['bed_type'] : null,
|
|
'name' => isset($bt['name']) ? $bt['name'] : null,
|
|
'count' => isset($bt['count']) ? $bt['count'] : null,
|
|
);
|
|
}
|
|
}
|
|
echo json_encode(array(
|
|
'room_id' => $roomId,
|
|
'beds' => $beds,
|
|
'views' => $views,
|
|
), JSON_PRETTY_PRINT) . PHP_EOL . '---' . PHP_EOL;
|
|
}
|