Esempio n. 1
0
        public async Task <SearchResult> SearchAsync(string query, ThingType?type = null, bool exact = false)
        {
            string uri = $"{EndpointsV2.SEARCH_URI}?query={query}";

            if (type.HasValue)
            {
                uri += $"&type={type}";
            }
            if (exact)
            {
                uri += "&exact=1";
            }

            HttpResponseMessage resp = await xmlRestClient.GetAsync(uri);

            if (!resp.IsSuccessStatusCode)
            {
                return(new SearchResult {
                    StatusCode = (int)resp.StatusCode
                });
            }

            _ItemsResult result = await resp.Content.DeserializeXml <_ItemsResult>();

            return(result.ConvertToSearchResult());
        }
 public static HotItemResult ConvertToHotItemResult(this _ItemsResult items)
 {
     return(new HotItemResult
     {
         StatusCode = (int)HttpStatusCode.OK,
         Items = items.Items?.Select(i => new Item
         {
             Id = i.Id,
             Name = i.Name?.Name ?? "",
             YearPublished = i.YearPublished?.YearPublished ?? 0,
             Rank = i.Rank,
             Thumbnail = i.Thumbnail.Url
         }).ToList()
     });
 }
 public static SearchResult ConvertToSearchResult(this _ItemsResult items)
 {
     return(new SearchResult
     {
         StatusCode = (int)HttpStatusCode.OK,
         TotalItems = items.TotalItems,
         Items = items.Items?.Select(i => new Item
         {
             Id = i.Id,
             Name = i.Name?.Name ?? "",
             Type = (ThingType)Enum.Parse(typeof(ThingType), i.Type),
             YearPublished = i.YearPublished?.YearPublished ?? 0
         }).ToList()
     });
 }
Esempio n. 4
0
        public async Task <HotItemResult> GetHotItemsAsync(HotItemType type)
        {
            string uri = $"{EndpointsV2.HOT_ITEMS_URI}?type={type}";

            HttpResponseMessage resp = await xmlRestClient.GetAsync(uri);

            if (!resp.IsSuccessStatusCode)
            {
                return(new HotItemResult {
                    StatusCode = (int)resp.StatusCode
                });
            }

            _ItemsResult result = await resp.Content.DeserializeXml <_ItemsResult>();

            return(result.ConvertToHotItemResult());
        }