this.getDataForPlaces = function(addresses){
var locationDescs = [];
_.each(addresses, function(address){
var promise = $.when(getLocationDesc(address)).done(function(data){
locationDescs.push(data);
});
})
return locationDescs;
};
var getLocationDesc = function(address){
var parameters = [];
var message = {
'action' : 'http://api.yelp.com/v2/search',
'method' : 'GET',
'parameters' : parameters
};
OAuth.setTimestampAndNonce(message);
OAuth.SignatureMethod.sign(message, accessor);
var parameterMap = OAuth.getParameterMap(message.parameters);
$.ajax({
'url' : message.action,
'cache': true,
'method':message.method,
'data' : parameterMap,
'dataType' : 'jsonp',
'jsonp' : 'callback',
'success':function(data){
console.log(data);
return data;
}
});
};
this.getDataForPlaces = function(addresses){
return Promise.all(Array.prototype.map.call(addresses, function(address) {
return getLocationDesc(address);
}));
};
function getLocationDesc(address) {
return new Promise(function(resolve, reject) {
var parameters = [];
var message = {
'action' : 'http://api.yelp.com/v2/search',
'method' : 'GET',
'parameters' : parameters
};
OAuth.setTimestampAndNonce(message);
OAuth.SignatureMethod.sign(message, accessor);
var parameterMap = OAuth.getParameterMap(message.parameters);
$.ajax({
url : message.action,
cache : true,
method : message.method,
data : parameterMap,
dataType : 'jsonp',
jsonp : 'callback',
success : resolve,
error : reject
});
});
};