Skip to content

Instantly share code, notes, and snippets.

@reidab
Created July 27, 2016 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reidab/53da78665fa17ea7a696d6c75a54a2d0 to your computer and use it in GitHub Desktop.
Save reidab/53da78665fa17ea7a696d6c75a54a2d0 to your computer and use it in GitHub Desktop.
const api_key = JSON.parse($('#_bootstrap-layout-init').attr('content')).api_config.key,
base_path = '/api/v2/pricing_quotes?_format=for_detailed_booking_info_on_web_p3&currency=USD&locale=en&';
var guests = $('.guest-select').attr('value'),
check_in = moment($('#map-search-checkin').attr('value')).format('YYYY-MM-DD'),
check_out = moment($('#map-search-checkout').attr('value')).format('YYYY-MM-DD');
function refresh_total_prices() {
$('.listings-container .listing').each(function() {
var listing = $(this),
id = listing.find('a.media-cover').attr('target').split('_')[1],
query = [
'listing_id=' + id,
'guests=' + guests,
'check_in=' + check_in,
'check_out=' + check_out,
'key=' + api_key
].join('&');
$.getJSON(base_path + query, function(data) {
console.log(data);
var per_night = listing.find('.price-amount').text();
listing.find('.price-amount').text( per_night + ' / ' + data.pricing_quotes[0].price.total.amount );
});
});
}
refresh_total_prices();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment