Пример #1
0
        /// <summary>
        /// Gets the resturants by delivery area.
        /// </summary>
        /// <param name="outcode">The outcode.</param>
        /// <returns></returns>
        public ResturantResult GetResturantsByDeliveryArea(Outcode outcode)
        {
            outcode.ThrowIfNull(nameof(outcode));
            var getResturantResult = new ResturantResult();

            // Cleaning up this
            var requestUrl = $"{BaseUri}" + RestaurantRoute + "?q=" + outcode.Value;
            using (var client = CreateHttpClient())
            {
                try
                {
                    var response = client.GetAsync(requestUrl).Result;

                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        var responseContent = response.Content.ReadAsStringAsync().Result;
                        getResturantResult = FormatSearchResults(responseContent);
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine($"Exception: {ex.Message}");
                    getResturantResult.Successful = false;
                }

                return getResturantResult;
            }
        }
Пример #2
0
        private static void PrintRestrauntResults(ResturantResult resturantResult)
        {
            foreach (var restaurant in resturantResult.Restaurants)
            {
                System.Console.WriteLine($"Name: {restaurant.Name} - Rating: {restaurant.RatingStars}");
                System.Console.WriteLine("Cuisine Types:");
                foreach (var type in restaurant.CuisineTypes)
                {
                    System.Console.WriteLine($" * {type.Name}");
                }
            }

            System.Console.WriteLine($"Total: {resturantResult.Restaurants.Count}");
        }