nsyelpapi
Version:
Nativescript implementation of the native v2 yelp api
172 lines • 7.32 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var NSYelpApi_common_1 = require("./NSYelpApi.common");
var utils_1 = require("tns-core-modules/utils/utils");
var NSYelpApi = (function (_super) {
__extends(NSYelpApi, _super);
function NSYelpApi(apiKey) {
var _this = _super.call(this) || this;
_this.sortMap = {
'best_match': 0,
'distance': 1,
'rating': 2,
'review_count': 3
};
_this._client = new YLPClient({ APIKey: apiKey });
return _this;
}
NSYelpApi.prototype.businessSearchWithNumber = function (phone) {
var _this = this;
return new Promise(function (resolve, reject) {
_this._client.businessWithPhoneNumberCompletionHandler("+1" + phone, function (search, err) {
if (err)
reject(err);
if (search.total > 0) {
var business = search.businesses[0];
resolve(_this.parseBusiness(business));
}
else {
resolve({});
}
});
});
};
NSYelpApi.prototype.businessSearchWithId = function (id) {
var _this = this;
return new Promise(function (resolve, reject) {
_this._client.businessWithIdCompletionHandler(id, function (business, err) {
if (err)
reject(err);
if (business) {
resolve(_this.parseBusiness(business));
}
else {
resolve({});
}
});
});
};
NSYelpApi.prototype.businessReviewsWithId = function (id) {
var _this = this;
return new Promise(function (resolve, reject) {
_this._client.reviewsForBusinessWithIdCompletionHandler(id, function (reviews, err) {
if (err)
reject(err);
if (reviews) {
var parsedReviews = _this.parseReviews(reviews);
resolve(parsedReviews);
}
else {
resolve([]);
}
});
});
};
NSYelpApi.prototype.searchWithCoordinates = function (coordinates) {
var _this = this;
return new Promise(function (resolve, reject) {
var ylpCoordinates = new YLPCoordinate(coordinates);
_this._client.searchWithCoordinateCompletionHandler(ylpCoordinates, function (search, err) {
if (err)
reject(err);
if (search.total > 0) {
var businessesInCoordiantes = utils_1.ios.collections.nsArrayToJSArray(search.businesses);
var parsedBusinesses = businessesInCoordiantes.map(function (business) { return _this.parseBusiness(business); });
resolve(parsedBusinesses);
}
else {
resolve([]);
}
});
});
};
NSYelpApi.prototype.searchWithLocation = function (location) {
var _this = this;
return new Promise(function (resolve, reject) {
_this._client.searchWithLocationCompletionHandler(location, function (search, err) {
if (err)
reject(err);
if (search.total > 0) {
var businessesInCoordiantes = utils_1.ios.collections.nsArrayToJSArray(search.businesses);
var parsedBusinesses = businessesInCoordiantes.map(function (business) { return _this.parseBusiness(business); });
resolve(parsedBusinesses);
}
else {
resolve([]);
}
});
});
};
NSYelpApi.prototype.searchWithLocationTermLimitOffsetSort = function (location, term, limit, offset, sort) {
var _this = this;
return new Promise(function (resolve, reject) {
_this._client.searchWithLocationTermLimitOffsetSortCompletionHandler(location, term, limit, offset, _this.sortMap[sort], function (search, err) {
if (err)
reject(err);
if (search.total > 0) {
var businessesInLocation = utils_1.ios.collections.nsArrayToJSArray(search.businesses);
var parsedBusinesses = businessesInLocation.map(function (business) { return _this.parseBusiness(business); });
resolve(parsedBusinesses);
}
else {
resolve([]);
}
});
});
};
NSYelpApi.prototype.businessReviewsWithIdAndLocale = function (id) {
var _this = this;
return new Promise(function (resolve, reject) {
_this._client.reviewsForBusinessWithIdLocaleCompletionHandler(id, 'en_US', function (reviews, err) {
if (err)
reject(err);
if (reviews) {
var parsedReviews = _this.parseReviews(reviews);
resolve(parsedReviews);
}
else {
resolve([]);
}
});
});
};
NSYelpApi.prototype.searchWithCoordinateLimitOffsetSort = function (coordinates, term, limit, offset, sort) {
var _this = this;
return new Promise(function (resolve, reject) {
var ylpCoordinates = new YLPCoordinate(coordinates);
_this._client.searchWithCoordinateTermLimitOffsetSortCompletionHandler(ylpCoordinates, term, limit, offset, _this.sortMap[sort], function (search, err) {
if (err)
reject(err);
if (search.total > 0) {
var businessesInCoordinates = utils_1.ios.collections.nsArrayToJSArray(search.businesses);
var parsedBusinesses = businessesInCoordinates.map(function (business) { return _this.parseBusiness(business); });
resolve(parsedBusinesses);
}
else {
resolve([]);
}
});
});
};
NSYelpApi.prototype.searchWithQuery = function (location, category, deals, limit, offset, radius, sort, searchTerm) {
var _this = this;
return new Promise(function (resolve, reject) {
var query = _this.formatSearchQuery(location, category, deals, limit, offset, radius, sort, searchTerm);
_this._client.searchWithQueryCompletionHandler(query, function (search, err) {
if (err)
reject(err);
if (search.total > 0) {
var businessesInQuery = utils_1.ios.collections.nsArrayToJSArray(search.businesses);
var parsedBusinesses = businessesInQuery.map(function (business) { return _this.parseBusiness(business); });
resolve(parsedBusinesses);
}
else {
resolve([]);
}
});
});
};
return NSYelpApi;
}(NSYelpApi_common_1.Common));
exports.NSYelpApi = NSYelpApi;
//# sourceMappingURL=NSYelpApi.ios.js.map