public async Task <IEnumerable <Item> > GetItemsInCategoryAsync(string category) { List <Item> result = null; try { using (var client = new HttpClient()) { var resource = new Uri(this.ItemsResource, $"?category={ WebUtility.UrlEncode(category) }"); var response = await InventoryClient.GetWithTimeoutAsync(resource, client); InventoryClient.ThrowExceptionOnError(response); var content = await response.Content.ReadAsStringAsync(); result = JsonConvert.DeserializeObject <List <Item> >(content); } } catch (TaskCanceledException e) { InventoryClient.ThrowTimeoutException(e); } return(result); }
public async Task <Item> GetItemByIdAsync(Guid id) { Item result = null; try { using (var client = new HttpClient()) { var resource = new Uri(this.ItemsResource, $"{ id }"); var response = await InventoryClient.GetWithTimeoutAsync(resource, client); InventoryClient.ThrowExceptionOnError(response); var content = await response.Content.ReadAsStringAsync(); result = JsonConvert.DeserializeObject <Item>(content); } } catch (TaskCanceledException e) { InventoryClient.ThrowTimeoutException(e); } return(result); }
public async Task <IReadOnlyCollection <string> > GetAllCategoriesAsync() { List <string> result = null; try { using (var client = new HttpClient()) { var response = await InventoryClient.GetWithTimeoutAsync(this.CategoriesResource, client); InventoryClient.ThrowExceptionOnError(response); var content = await response.Content.ReadAsStringAsync(); result = JsonConvert.DeserializeObject <List <string> >(content); } } catch (TaskCanceledException e) { InventoryClient.ThrowTimeoutException(e); } return(result); }