UNPKG

nsyelpapi

Version:

Nativescript implementation of the native v2 yelp api

212 lines 8.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var NSYelpApi_common_1 = require("./NSYelpApi.common"); var NSYelpApi = (function (_super) { __extends(NSYelpApi, _super); function NSYelpApi(apiKey) { var _this = _super.call(this) || this; _this._client = new com.yelp.fusion.client.connection.YelpFusionApiFactory().createAPI(apiKey); return _this; } NSYelpApi.prototype.businessSearchWithId = function (id) { var _this = this; return new Promise(function (resolve, reject) { try { var search = _this._client.getBusiness(id); var response = search.execute().body(); var data = _this.parseAndroidBusiness(response); resolve(data); } catch (err) { reject(err); } }); }; NSYelpApi.prototype.searchWithCoordinates = function (coordinates) { var _this = this; return new Promise(function (resolve, reject) { var params = new java.util.HashMap(); params.put("latitude", "" + coordinates.latitude); params.put("longitude", "" + coordinates.longitude); try { var search = _this._client .getBusinessSearch(params) .execute() .body(); var businesses = search.getBusinesses(); var parsedBusinesses = _this.parseAndroidBusinesses(businesses); resolve(parsedBusinesses); } catch (err) { reject(err); } }); }; NSYelpApi.prototype.searchWithLocation = function (location) { var _this = this; return new Promise(function (resolve, reject) { var params = new java.util.HashMap(); params.put("location", location); try { var search = _this._client .getBusinessSearch(params) .execute() .body(); var businesses = search.getBusinesses(); var parsedBusinesses = _this.parseAndroidBusinesses(businesses); resolve(parsedBusinesses); } catch (err) { reject(err); } }); }; NSYelpApi.prototype.searchWithLocationTermLimitOffsetSort = function (location, term, limit, offset, sort) { var _this = this; return new Promise(function (resolve, reject) { var params = new java.util.HashMap(); params.put("location", location); params.put("term", term); params.put("limit", "" + limit); params.put("offset", "" + offset); params.put("sort_by", sort); try { var search = _this._client .getBusinessSearch(params) .execute() .body(); var businesses = search.getBusinesses(); var parsedBusinesses = _this.parseAndroidBusinesses(businesses); resolve(parsedBusinesses); } catch (err) { reject(err); } }); }; NSYelpApi.prototype.businessReviewsWithIdAndLocale = function (id) { var _this = this; return new Promise(function (resolve, reject) { try { var search = _this._client.getBusinessReviews(id, java.util.Locale.getDefault().toString()); var reviews = search .execute() .body(); var parsedReviews = _this.parseAndroidReviews(reviews.getReviews(), reviews.getTotal()); resolve(parsedReviews); } catch (err) { } }); }; NSYelpApi.prototype.searchWithCoordinateLimitOffsetSort = function (coordinates, term, limit, offset, sort) { var _this = this; return new Promise(function (resolve, reject) { var params = new java.util.HashMap(); params.put("latitude", "" + coordinates.latitude); params.put("longitude", "" + coordinates.longitude); params.put("term", term); params.put("limit", "" + limit); params.put("offset", "" + offset); params.put("sort", "" + sort); try { var search = _this._client .getBusinessSearch(params) .execute() .body(); var businesses = search.getBusinesses(); var parsedBusinesses = _this.parseAndroidBusinesses(businesses); console.log(parsedBusinesses); resolve(parsedBusinesses); } catch (err) { reject(err); } }); }; NSYelpApi.prototype.searchWithQuery = function (location, category, deals, limit, offset, radius, sort, searchTerm) { var _this = this; return new Promise(function (resolve, reject) { var params = new java.util.HashMap(); if (typeof location === "string") { params.put("location", location); } if (location.hasOwnProperty("latitude")) { var coordinates = location; params.put("latitude", "" + coordinates.latitude); params.put("longitude", "" + coordinates.longitude); } if (searchTerm) { params.put("term", searchTerm); } if (limit) { params.put("limit", "" + limit); } if (offset) { params.put("offset", "" + offset); } if (sort) { params.put("sort", "" + sort); } if (deals) { params.put("attributes", "deals"); } if (radius) { params.put("radius", "" + radius); } if (category) { var categoryString_1 = ""; category.forEach(function (val) { categoryString_1 += " " + val; }); params.put("categories", categoryString_1.trim()); } try { var search = _this._client .getBusinessSearch(params) .execute() .body(); var businesses = search.getBusinesses(); var parsedBusinesses = _this.parseAndroidBusinesses(businesses); resolve(parsedBusinesses); } catch (err) { reject(err); } }); }; NSYelpApi.prototype.businessSearchWithNumber = function (phone) { var _this = this; return new Promise(function (resolve, reject) { try { var search = _this._client.getPhoneSearch("+1" + phone); var response = search .execute() .body(); var businesses = _this.parseAndroidBusinesses(response.getBusinesses()); resolve(businesses); } catch (err) { reject(err); } }); }; NSYelpApi.prototype.businessReviewsWithId = function (id) { var _this = this; return new Promise(function (resolve, reject) { try { var search = _this._client.getBusinessReviews(id, java.util.Locale.getDefault().toString()); var reviews = search .execute() .body(); var parsedReviews = _this.parseAndroidReviews(reviews.getReviews(), reviews.getTotal()); resolve(parsedReviews); } catch (err) { reject(err); } }); }; return NSYelpApi; }(NSYelpApi_common_1.Common)); exports.NSYelpApi = NSYelpApi; //# sourceMappingURL=NSYelpApi.android.js.map