示例#1
0
文件: Client.cs 项目: navkar/FeedView
        /// <summary>
        /// Searches any and all businesses matching the data in the specified search parameter object.
        /// </summary>
        /// <param name="search">Container object for all search parameters.</param>
        /// <param name="ct">Cancellation token instance. Use CancellationToken.None if not needed.</param>
        /// <param name="connectionRetrySettings">The settings to define whether a connection should be retried.</param>
        /// <returns>SearchResponse with businesses matching the specified parameters.</returns>
        public async Task <SearchResponse> SearchBusinessesAllAsync(
            SearchRequest search,
            CancellationToken ct = default(CancellationToken),
            ConnectionRetrySettings connectionRetrySettings = null)
        {
            if (search == null)
            {
                throw new ArgumentNullException(nameof(search));
            }

            this.ValidateCoordinates(search.Latitude, search.Longitude);
            this.ApplyAuthenticationHeaders(ct);

            var querystring = search.GetChangedProperties().ToQueryString();
            var response    = await this.GetAsync <SearchResponse>(API_VERSION + "/businesses/search" + querystring, ct, connectionRetrySettings);

            // Set distances baased on lat/lon
            if (response?.Businesses != null && !double.IsNaN(search.Latitude) && !double.IsNaN(search.Longitude))
            {
                foreach (var business in response.Businesses)
                {
                    business.SetDistanceAway(search.Latitude, search.Longitude);
                }
            }

            return(response);
        }
示例#2
0
        public void TestGetModelChanges()
        {
            var m = new SearchRequest();

            m.Term  = "Hello world";
            m.Price = "$";
            var dic = m.GetChangedProperties();

            Assert.AreEqual(dic.Count, 2);
            Assert.IsTrue(dic.ContainsKey("term"));
            Assert.IsTrue(dic.ContainsKey("price"));
        }
示例#3
0
        private async Task <T> SearchBusinesses <T>(string url, SearchRequest search, CancellationToken ct = default(CancellationToken)) where T : BusinessResponseBase
        {
            this.ValidateCoordinates(search.Latitude, search.Longitude);
            this.ApplyAuthenticationHeaders(ct);

            var querystring = search.GetChangedProperties().ToQueryString();
            var response    = await this.GetAsync <T>(url + querystring, ct);

            // Set distances baased on lat/lon
            if (response?.Businesses != null && !double.IsNaN(search.Latitude) && !double.IsNaN(search.Longitude))
            {
                foreach (var business in response.Businesses)
                {
                    business.SetDistanceAway(search.Latitude, search.Longitude);
                }
            }

            return(response);
        }