Booking API for goibibo
class Booking_api {
private $app_id;
private $app_key;
function __construct() {
$this->app_id = 'Your APP ID';
$this->app_key = 'APP Key';
}
function SearchFlight($param = false) {
$param['app_id'] = $this->app_id;
$param['app_key'] = $this->app_key;
$param['format'] = 'json';
$param['counter'] = '100';
if(empty($param['source'])){
return $this->error('Please Enter source');
}
if(empty($param['destination'])){
return $this->error('Please Enter destination');
}
if(empty($param['dateofdeparture'])){
return $this->error('Please Enter dateofdeparture');
}
if(empty($param['seatingclass'])){
return $this->error('Please Enter seatingclass');
}
if(empty($param['adults'])){
return $this->error('Please Enter number of adults');
}
if(empty($param['children'])){
$param['children'] = 0;
}
if(empty($param['infants'])){
$param['infants'] = 0;
}
$url = http_build_query($param);
return $this->__apiCall('api/search/?'.$url);
}
function SearchHotel($param = false) {
$param['app_id'] = $this->app_id;
$param['app_key'] = $this->app_key;
if(empty($param['city_id'])){
return $this->error('Please Enter City');
}
$url = http_build_query($param);
return $this->__apiCall('api/voyager/get_hotels_by_cityid/?'.$url);
}
function SearchBus($param = false) {
$param['app_id'] = $this->app_id;
$param['app_key'] = $this->app_key;
$param['format'] = 'json';
if(empty($param['source'])){
return $this->error('Please Enter source');
}
if(empty($param['destination'])){
return $this->error('Please Enter destination');
}
if(empty($param['dateofdeparture'])){
return $this->error('Please Enter dateofdeparture');
}
$url = http_build_query($param);
return $this->__apiCall('api/bus/search/?'.$url);
}
function __apiCall($url, $post_parameters = FALSE) {
$url = 'http://developer.goibibo.com/'.$url;
$curl_session = curl_init();
curl_setopt($curl_session, CURLOPT_URL, $url);
if($post_parameters !== FALSE) {
curl_setopt ($curl_session, CURLOPT_POSTFIELDS, $post_parameters);
}
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, $this->codeigniter_instance->config->item('instagram_ssl_verify'));
$contents = curl_exec ($curl_session);
// Close cURL session
curl_close ($curl_session);
// Return the response
return json_decode($contents);
}
function error($msg) {
return $obj = new stdclass(array('data'=>array('Error'=>$msg)));
}
}
$obj = new Booking_api();
/* $param =array();
$param['source'] = 'IDR';
$param['destination'] = 'DEL';
$param['dateofdeparture'] = '20161231';
$param['seatingclass'] = 'E';
$param['adults'] = '2';
$responce = $obj->SearchFlight($param);
*/
/* $param =array();
$param['city_id'] = '6771549831164675055';
$responce = $obj->SearchHotel($param); */
$param =array();
$param['source'] = 'indore';
$param['destination'] = 'bangalore';
$param['dateofdeparture'] = '20170112';
$responce = $obj->SearchBus($param);
print_r($responce);
private $app_id;
private $app_key;
function __construct() {
$this->app_id = 'Your APP ID';
$this->app_key = 'APP Key';
}
function SearchFlight($param = false) {
$param['app_id'] = $this->app_id;
$param['app_key'] = $this->app_key;
$param['format'] = 'json';
$param['counter'] = '100';
if(empty($param['source'])){
return $this->error('Please Enter source');
}
if(empty($param['destination'])){
return $this->error('Please Enter destination');
}
if(empty($param['dateofdeparture'])){
return $this->error('Please Enter dateofdeparture');
}
if(empty($param['seatingclass'])){
return $this->error('Please Enter seatingclass');
}
if(empty($param['adults'])){
return $this->error('Please Enter number of adults');
}
if(empty($param['children'])){
$param['children'] = 0;
}
if(empty($param['infants'])){
$param['infants'] = 0;
}
$url = http_build_query($param);
return $this->__apiCall('api/search/?'.$url);
}
function SearchHotel($param = false) {
$param['app_id'] = $this->app_id;
$param['app_key'] = $this->app_key;
if(empty($param['city_id'])){
return $this->error('Please Enter City');
}
$url = http_build_query($param);
return $this->__apiCall('api/voyager/get_hotels_by_cityid/?'.$url);
}
function SearchBus($param = false) {
$param['app_id'] = $this->app_id;
$param['app_key'] = $this->app_key;
$param['format'] = 'json';
if(empty($param['source'])){
return $this->error('Please Enter source');
}
if(empty($param['destination'])){
return $this->error('Please Enter destination');
}
if(empty($param['dateofdeparture'])){
return $this->error('Please Enter dateofdeparture');
}
$url = http_build_query($param);
return $this->__apiCall('api/bus/search/?'.$url);
}
function __apiCall($url, $post_parameters = FALSE) {
$url = 'http://developer.goibibo.com/'.$url;
$curl_session = curl_init();
curl_setopt($curl_session, CURLOPT_URL, $url);
if($post_parameters !== FALSE) {
curl_setopt ($curl_session, CURLOPT_POSTFIELDS, $post_parameters);
}
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, $this->codeigniter_instance->config->item('instagram_ssl_verify'));
$contents = curl_exec ($curl_session);
// Close cURL session
curl_close ($curl_session);
// Return the response
return json_decode($contents);
}
function error($msg) {
return $obj = new stdclass(array('data'=>array('Error'=>$msg)));
}
}
$obj = new Booking_api();
/* $param =array();
$param['source'] = 'IDR';
$param['destination'] = 'DEL';
$param['dateofdeparture'] = '20161231';
$param['seatingclass'] = 'E';
$param['adults'] = '2';
$responce = $obj->SearchFlight($param);
*/
/* $param =array();
$param['city_id'] = '6771549831164675055';
$responce = $obj->SearchHotel($param); */
$param =array();
$param['source'] = 'indore';
$param['destination'] = 'bangalore';
$param['dateofdeparture'] = '20170112';
$responce = $obj->SearchBus($param);
print_r($responce);
This comment has been removed by the author.
ReplyDelete