Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions airbnb.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
* - getCalendar() - Get availability for a hosting
* - getEstIncome() - Get estimate income a hosting generates, by month
* - getReviews() - Get reviews for a given user, as host or guest
* - getListingReviews() - Get reviews for a given listing id
*/

var search = require('./api/search'),
getInfo = require('./api/getInfo'),
getCalendar = require('./api/getCalendar'),
getReviews = require('./api/getReviews'),
getEstIncome = require('./api/getEstIncome'),
getListingReviews = require('./api/getListingReviews'),
login = require('./api/login');

var USERNAME = 'username',
Expand All @@ -30,6 +32,7 @@ var AirbnbClient = function(optionalConfigs) {
getCalendar: getCalendar,
getReviews: getReviews,
getEstIncome: getEstIncome,
getListingReviews: getListingReviews,
login: login
};
};
Expand Down
57 changes: 57 additions & 0 deletions api/getListingReviews.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
var request = require('request'),
_ = require('lodash'),
configs = require('../configs/configs'),
serialize = require('../helpers/serialize'),
Promise = require('bluebird');

/**
* Get a list of reviews for a given listing id, as all. Details: http://airbnbapi.org/#get-reviews
* @param {Number, String} listingId
* @param {Object} options - Options to specify _limit, _offset, etc.
* @return {Promise} - contains list of reviews
*
* options = {
* _limit: {Number}, default 50 (max 50)
* _offset: {Number}, default 0
* locale: {String}, default 'en'
* _order: {String}, default 'language'
* role: {String}, default 'all'
* }
*/
function getListingReviews(listingId, options) {
options.listing_id = listingId;
var DEFAULT_LISTING_REVIEWS_PARAMS = _.assign({}, configs.DEFAULT_REQUEST_PARAMS, {
_limit: 50,
_offset: 0,
locale: 'en',
_order: 'language',
role: 'all'
}),
searchOptions = _.assign({}, DEFAULT_LISTING_REVIEWS_PARAMS, options),
requestConfigs = _.assign({}, configs.DEFAULT_REQUEST_CONFIGS, {
url: configs.LISTING_REVIEWS_URL + '?' + serialize(searchOptions)
}),
reviews = [],
$;

return new Promise(function(resolve, reject) {
if (!listingId) {
reject('Invalid listing ID');
}

request(requestConfigs, function(err, res, body) {
body = JSON.parse(body);
if (!err && res.statusCode == 200) {
if (body.error_code){
return reject(body.error_details);
}
resolve(body.reviews);
} else if (err) {
reject(err);
}
});
});

}

module.exports = getListingReviews;
4 changes: 4 additions & 0 deletions configs/configs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ var secrets = require('./_secrets'),
_ = require('lodash');

var AIRBNB_PREFIX = 'https://www.airbnb.com',
AIRBNB_API_PREFIX = 'https://api.airbnb.com',
SEARCH_URL = AIRBNB_PREFIX + '/search/search_results',
AVAILABILITY_URL = AIRBNB_PREFIX + '/api/v2/calendar_months',
HOSTING_INFO_URL = AIRBNB_PREFIX + '/api/v1/listings',
LISTING_REVIEWS_URL = AIRBNB_API_PREFIX + '/v2/reviews',
USER_REVIEWS_URL = AIRBNB_PREFIX + '/users/review_page',
LOGIN_URL = AIRBNB_PREFIX + '/api/v1/authorize',
DEFAULT_REQUEST_CONFIGS = {
Expand All @@ -18,9 +20,11 @@ var AIRBNB_PREFIX = 'https://www.airbnb.com',

module.exports = {
AIRBNB_PREFIX: AIRBNB_PREFIX,
AIRBNB_API_PREFIX: AIRBNB_API_PREFIX,
SEARCH_URL: SEARCH_URL,
AVAILABILITY_URL: AVAILABILITY_URL,
HOSTING_INFO_URL: HOSTING_INFO_URL,
LISTING_REVIEWS_URL: LISTING_REVIEWS_URL,
USER_REVIEWS_URL: USER_REVIEWS_URL,
LOGIN_URL: LOGIN_URL,
DEFAULT_REQUEST_CONFIGS: DEFAULT_REQUEST_CONFIGS,
Expand Down