Getting started
Getting started with our JavaScript SDK to build your own User Interface
Add the following script to your site:
var ob = new OBManager('https://api.openbooking.ch', '<insert token here>');
var query = {
"types": ["apartment"],
"language" : "de",
"currency" : "CHF",
//"checkin" : "",
//"checkout" : "",
//"rooms" : [
// { "adults": 2, "children": 0, "childrens_age": [] }
//]
};
var options = {
tracktag: "test"
, pageSize: 15
}
var items = ob.getItems(query, options)
Get items returns a Items-Instance, this instance allows you to easily get successive pages by calling
nextPage
on it. You can call reset this way the next call to nextPage
will return the first page again.items.nextPage().then(function(page) {
console.log(page);
}).catch(function(err) {
console.log(err);
});
You can also get a specific page directly based on its (zero based) index.
items.page(5).then(function(page) {
console.log(page);
}).catch(function(err) {
console.log(err);
});
This also sets the internal state to page 5, this means that the next call to nextPage will return page 6.
If you call
nextPage
multiple times or use page with an index you will eventually reach the last page. The last page may have less elements then the specified pageSize
. Requesting a page past the last page will return an empty array.[{
city: "Sureggio (Lugano)",
city_normalized: "Sureggio (Lugano)",
externals: [],
features: [],
hookData: {
"classification": {
"statusCode":408,
"executed":"2016-10-14T10:11:54.434Z"
},
"resort": {
"statusCode":200,
"data":{
"resortKey":2632,
"regionId":"012"
}
,"executed":"2016-10-14T10:11:49.480Z"
}
},
id: "577d16f1074db10b006968d7",
images: [{
"season":"",
"url":"http://www.reka.ch/FewoImageList/sureggio_asb_01_.JPG-940x622-79330.jpg"
},{
"season":"",
"url":"http://www.reka.ch/FewoImageList/sureggio_feriensiedlung_asb_06_.jpg-940x622-79330.jpg"
},{
"season":"",
"url":"http://www.reka.ch/FewoImageList/sureggio_feriensiedlung_aan_01_.jpg-940x622-79330.jpg"
},{
"season":"",
"url":"http://www.reka.ch/FewoImageList/sureggio_aso_01_.jpg-940x622-79330.jpg"
},{
"season":"",
"url":"http://www.reka.ch/FewoImageList/sureggio_feriensiedlung_aso_22_.jpg-940x622-79330.jpg"
},{
"season":"",
"url":"http://www.reka.ch/FewoImageList/sureggio_feriensiedlung_aso_600_.JPG-940x622-79330.jpg"
},{
"season":"summer",
"url":"http://www.reka.ch/FewoImageList/sureggio_feriensiedlung_aso_05_.jpg-940x622-79330.jpg"
},{
"season":"winter",
"url":"http://www.reka.ch/FewoImageList/sureggio_feriensiedlung_aso_01_.tif-940x622-79330.jpg"
}],
imagesServices: [],
name: {"de":"Feriensiedlung Sureggio, Sureggio "},
name_add: {"de":"Typ K, 3-Zi.-Wohnung/5 Pers., 55m², Parterre"},
position: {"lat":46.0535013359,"lng":8.9730388081},
provider_name: "reka",
quality: "3",
ranks: [],
superior: false,
type: "apartment",
visible: true
},
{
city: "Moléson (ob Greyerz)",
city_normalized: "Moléson (ob Greyerz)",
externals: [],
features: [],
hookData: {
"classification": {
"statusCode":408,
"executed":"2016-10-14T10:11:54.756Z"
},
"resort": {
"statusCode":200,
"data": {
"resortKey":795,
"regionId":"013"
},
"executed":"2016-10-14T10:11:49.802Z"
}
},
id: "577d16f1a20ea20c009fbbd3",
images: [{
"season":"",
"url":"http://www.reka.ch/FewoImageList/moleson_andromede_awi_200_.jpg-940x622-101335.jpg"
},{
"season":"",
"url":"http://www.reka.ch/FewoImageList/moleson_andromede_iwz_01_.jpg-940x622-101335.jpg"
},{
"season":"",
"url":"http://www.reka.ch/FewoImageList/moleson_andromede_iwz_02_.jpg-940x622-101335.jpg"
},{
"season":"",
"url":"http://www.reka.ch/FewoImageList/moleson_andromede_iku_02_.jpg-940x622-101335.jpg"
},{
"season":"",
"url":"http://www.reka.ch/FewoImageList/moleson_andromede_ibd_03_.jpg-940x622-101335.jpg"
},{
"season":"",
"url":"http://www.reka.ch/FewoImageList/moleson_andromede_ibd_04_.jpg-940x622-101335.jpg"
},{
"season":"summer",
"url":"http://www.reka.ch/FewoImageList/moleson_andromede_aso_03_.jpg-940x622-101335.jpg"
},{
"season":"winter",
"url":"http://www.reka.ch/FewoImageList/moleson_andromede_awi_01_.tif-940x622-101335.jpg"
}],
imagesServices: [],
name: {"de":"Andromède"},
name_add: {"de":"Typ B, 2-Zi.-Wohnung/4 Pers., 53m², 1. Stock"},
position: {"lat":46.5627267438,"lng":7.0354476192},
provider_name: "reka",
quality: "3",
ranks: [],
superior: false,
type: "apartment",
visible: true
}, ...]
pageCount
returns the number of pages. This is useful if you want to show a pager below your results.items.pageCount().then(function(count) {
console.log(count);
}).catch(function(err) {
console.log(err);
});
Last modified 3yr ago