示例#1
0
        public async void TestGetCategoryInfoList()
        {
            var leClient = new LEClient();

            var states = await leClient.GetStatesList();

            var tn = states.First(si => si.Name == "Tennessee");

            var cities = await leClient.GetCityList(tn);

            Assert.IsNotNull(cities);
            Assert.That(cities.Count(), Is.GreaterThan(0));

            var nashville = cities.FirstOrDefault(city => city.Name == "Nashville");
            Assert.That(nashville, Is.Not.Null);

            var filterOptions = new FilterOptions(FilterOptions.TOP_10);

            var categories = await leClient.GetCategoryInfoListFor(nashville, filterOptions);

            Assert.IsNotNull(categories);
            Assert.That(categories.Count(), Is.GreaterThan(0));
            var first = categories.First();

            Assert.NotNull(first.Id);
            Assert.NotNull(first.Name);
            Assert.NotNull(first.RestaurantCount);
        }
示例#2
0
		public async Task<List<RestaurantInfo>> GetRestaurantListNearBy(FilterOptions filterOptions, double? lat = null, double? lon = null, string orCityId = null, int givenSize = 25, int skipping = 0)
		{
			var parameters = new Object[]{givenSize, skipping, lat, lon, orCityId, filterOptions };
            var cacheKey = Newtonsoft.Json.JsonConvert.SerializeObject(parameters);

			if (this._inMemoryCache.Contains(cacheKey)) {
				return await Task.FromResult<List<RestaurantInfo>> ((List<RestaurantInfo>)this._inMemoryCache[cacheKey]);
			} else {
				var result = await this._dataAccess.GetRestaurantListNearBy (filterOptions, lat, lon, orCityId, givenSize, skipping);

				this._inMemoryCache[cacheKey] = result;

				return result;
			}
		}
示例#3
0
        public async Task<IEnumerable<RestaurantCategoryInfo>> GetCategoryInfoListFor(CityInfo city, FilterOptions filterOptions)
        {
            var cacheKey = (city.ToString() + "GetCategoryInfoListFor");
            if (this._inMemoryCache.Contains(cacheKey))
            {
                return await Task.FromResult<IEnumerable<RestaurantCategoryInfo>>(
                    (IEnumerable<RestaurantCategoryInfo>)this._inMemoryCache[cacheKey]
                );
            }
            else
            {
                var result = await this._dataAccess.GetCategoryInfoListFor(city, filterOptions);

                this._inMemoryCache[cacheKey] = result;

                return result;
            }
        }
示例#4
0
        public static FilterOptions NewWith(params FilterOption[] otherFilterOptions)
        {
            var options = new FilterOptions();

            return options.Add(otherFilterOptions);
        }
示例#5
0
        public async Task<IEnumerable<RestaurantAmenityInfo>> GetAmenityInfoListFor(CityInfo city, FilterOptions filterOptions)
        {
            var command = new LECommand("GetAmmendityListCount");

            command.AddParam("format", "json");
            command.AddParam("cityid", city.Id);

            if (filterOptions != null)
            {
                foreach (var filterOption in filterOptions.AllOptions)
                {
                    command.AddParam(filterOption.Name, filterOption.Value);
                }
            }

            JObject json = await this.DoGet(command);

            JArray amenityInfos = (JArray)json["AmendityFilterCount"];

            return amenityInfos.Select<JToken, RestaurantAmenityInfo>(jsonToken =>
            {
                return new RestaurantAmenityInfo()
                {
                    Id = (string)jsonToken["AmendityID"],
                    Name = (string)jsonToken["AmendityName"],
                    RestaurantCount = (int)jsonToken["AmendityCount"]
                };
            });
        }
示例#6
0
        /// <summary>
        /// Return a list of restaurants "near by" in a city or geo location with the given
        /// size and skipping the given number of restaurants before returning any restaurants.
        /// Note:  If lat/lon is given then city is ignored and vice versa.
        /// </summary>
        /// <param name="givenSize">The size of the restaurant list expected</param>
        /// <param name="skipping">The restaurants to skip before adding restaurant to list</param>
        /// <param name="lat">Near by latitude</param>
        /// <param name="lon">Near by longitude</param>
        /// <param name="orCity">Near by city</param>
        /// <returns>Restaurant list</returns>
        public async Task<List<RestaurantInfo>> GetRestaurantListNearBy(
            FilterOptions filterOptions,
            double? lat = null, double? lon = null, 
            string orCityId = null, int givenSize = 25, int skipping = 0)
        {
            System.Diagnostics.Debug.Assert((lat.HasValue && lon.HasValue) || !String.IsNullOrEmpty(orCityId));

            var command = new LECommand("GetRestaurantListNearBy");

            command.AddParam("format", "json");

            if(String.IsNullOrEmpty(orCityId) == false)
                command.AddParam("cityid", orCityId);

            // this returns the 
            command.AddParam("ginfo", "acdhprstm");
            if (lat.HasValue)
                command.AddParam("lat", Convert.ToString(lat.Value));
            if (lon.HasValue)
                command.AddParam("lon", Convert.ToString(lon.Value));

            command.AddParam("top",Convert.ToString(givenSize));

            command.AddParam("skip",Convert.ToString(skipping));

            if (filterOptions != null)
            {
                foreach (var filterOption in filterOptions.AllOptions)
                {
                    command.AddParam(filterOption.Name, filterOption.Value);
                }
            }

            JObject json = await this.DoGet(command);

            if(json == null)
                return new List<RestaurantInfo>();

            var cnt = (int)json["Count"];

            if (cnt > 0)
            {
                JArray restaurantArray = (JArray)json["Restaurants"];

                return restaurantArray.Select<JToken, RestaurantInfo>(jObj => {

                    RestaurantInfo restaurant = new RestaurantInfo();

                    restaurant.LocId = Convert.ToString((int)jObj["AddyID"]);
                    restaurant.Id = Convert.ToString((int)jObj["RestID"]);
                    restaurant.Name = (string)jObj["RestName"];

                    restaurant.StreetAddress = (string)jObj["Address1"];
                    if ((string)jObj["Address2"] != null)
                    {
                        restaurant.StreetAddress += (Environment.NewLine + (string)jObj["Address2"]);
                    }

                    restaurant.CityStateZip = String.Format("{0}, {1} {2}",
                        (string)jObj["City"], (string)jObj["State"], (string)jObj["Zip"]
                    );

                    restaurant.PhoneNumber = (string)jObj["Phone"];

                    restaurant.PriceRange = string.Empty;
                    int avgCost = (int)jObj["AvgCost"];
                    for (int i = 0; i <= avgCost; i++)
                    {
                        restaurant.PriceRange += '$';//star - '\u2605';
                    }

                    //CatInfoList
                    var catList = (JArray)jObj["CatInfoList"];

                    restaurant.CategoryList = 
                        catList.Select<JToken, RestaurantInfo.CategoryInfo>(jCat => {
                            return new RestaurantInfo.CategoryInfo()
                            {
                                Id = (string)jCat["CatID"],
                                Name = (string)jCat["CatName"],
                                IsBestOf = jCat["IsBestOf"] == null ? false : ((bool)jCat["IsBestOf"])
                            };
                        });

                    // Features/Amenities
                    var featuresList = (JArray)jObj["AmendInfoList"];

                    restaurant.AmenityList =
                        featuresList.Select<JToken, RestaurantInfo.AmenityInfo>(jAmen =>
                        {
                            return new RestaurantInfo.AmenityInfo()
                            {
                                Id = (string)jAmen["AmendityID"],
                                Name = (string)jAmen["AmendityName"],
                                LocId = (string)jAmen["AddyID"]
                            };
                        });

                    //MediaInfoList
                    var mediaInfoList = (JArray)jObj["MediaInfoList"];
                    var mediaInfo = mediaInfoList.FirstOrDefault<JToken>();
                    if (mediaInfo != null)
                    {
                        //http://cdn.localeats.com/media/images/23132-1.jpg?dummy=dummy40
                        restaurant.ImageUri = 
                            String.Format(@"http://cdn.localeats.com/media/images/{0}?dummy=dummy40",
                                          (string)mediaInfo["MediaFileName"]);
                    }

                    if (jObj["DistanceAway"] != null)
                        restaurant.SpatialOffset = (decimal)jObj["DistanceAway"];

                    // Awards
                    if (jObj["AwardInfoList"] != null)
                    {
                        var jAwardList = (JArray)jObj["AwardInfoList"];

                        var awardList = new List<RestaurantInfo.AwardInfo>();

                        foreach (var awardObj in jAwardList)
                        {
                            var awardName = (string)awardObj["AwardName"];

                            // as switch later .. maybe
                            if (((int)awardObj["AwardID"]) == ((int)Award.EditorsPick))
                            { 
                                restaurant.IsEditorsPick = true;

                                // LE now refers to Top 100 as editors pick
                                awardName = "Editors Pick";
                            }
                            
                            awardList.Add(new RestaurantInfo.AwardInfo()
                            {
                                Id = (string)awardObj["AwardID"],
                                Name = awardName
                            });
                        }

                        restaurant.AwardList = awardList;
                    }

                    // Neighborhoods
                    if (jObj["HoodInfoList"] != null)
                    {
                        var jHoodList = (JArray)jObj["HoodInfoList"];

                        restaurant.NeighborhoodList =
                            jHoodList.Select<JToken, RestaurantInfo.NeighborhoodInfo>(jHood =>
                            {
                                return new RestaurantInfo.NeighborhoodInfo() {
                                    Id = (string)jHood["HoodID"],
                                    Name = (string)jHood["HoodName"]
                                };
                            });
                    }

                    // Deals
                    if (jObj["DealInfoList"] != null)
                    {
                        var jDealList = (JArray)jObj["DealInfoList"];

                        restaurant.DealList =
                            jDealList.Select<JToken, RestaurantInfo.DealInfo>(jDeal =>
                             {
                                 return new RestaurantInfo.DealInfo()
                                 {
                                     Id = (string)jDeal["Id"],
                                     Description = (string)jDeal["Description"],
                                     StartDate = (DateTime)jDeal["StartDate"],
                                     Title = (string)jDeal["Title"]
                                 };
                             });
                    }

                    return restaurant;
                }).ToList<RestaurantInfo>();
            }
            else
            {
                return new List<RestaurantInfo>();
            }
        }
示例#7
0
 /// <summary>
 /// Return the list of amenities in a city along with the count of restaurants in those amenities.
 /// Use the filter options to filter restaurants that are in those amenities.
 /// </summary>
 /// <param name="city">The city to get categories for.</param>
 /// <param name="filterOptions">Restaurant filter options</param>
 /// <returns>Amenity list</returns>
 public async Task<IEnumerable<RestaurantAmenityInfo>> GetAmenityInfoListFor(CityInfo city, FilterOptions filterOptions)
 {
     return await this._leRepository.GetAmenityInfoListFor(city, filterOptions).ConfigureAwait(_configAwait);
 }
示例#8
0
 /// <summary>
 /// Return the list of neighborhoods in a city along with the count of restaurants in those neighborhoods.
 /// Use the filter options to filter restaurants that are in those neighborhoods.
 /// </summary>
 /// <param name="city">The city to get categories for.</param>
 /// <param name="filterOptions">Restaurant filter options</param>
 /// <returns>Neighborhood list</returns>
 public async Task<IEnumerable<NeighborhoodInfo>> GetNeighborhoodInfoListFor(CityInfo city, FilterOptions filterOptions)
 {
     return await this._leRepository.GetNeighborhoodInfoListFor(city, filterOptions).ConfigureAwait(_configAwait);
 }
示例#9
0
 /// <summary>
 /// Return a list of restaurants "near by" in a city or geo location with the given
 /// size and skipping the given number of restaurants before returning any restaurants.
 /// Note:  If lat/lon is given then city is ignored and vice versa.
 /// </summary>
 /// <param name="givenSize">The size of the restaurant list expected</param>
 /// <param name="skipping">The restaurants to skip before adding restaurant to list</param>
 /// <param name="lat">Near by latitude</param>
 /// <param name="lon">Near by longitude</param>
 /// <param name="orCity">Near by city</param>
 /// <returns>Restaurant list</returns>
 public async Task<List<RestaurantInfo>> GetRestaurantListNearBy(FilterOptions filterOptions, double? lat = null, double? lon = null, 
                                                                 CityInfo orCity = null, int givenSize = 25, int skipping = 0)
 {
     var orCityId = orCity == null ? null : orCity.Id;
     return await this._leRepository.GetRestaurantListNearBy(filterOptions, lat, lon, orCityId, givenSize, skipping);
 }