Ejemplo n.º 1
0
        public async Task <IDataTransferCollection <ItemPrice> > GetItemPricesByIds(IReadOnlyCollection <int> itemIds)
        {
            if (itemIds == null)
            {
                throw new ArgumentNullException(nameof(itemIds));
            }

            if (itemIds.Count == 0)
            {
                throw new ArgumentException("Item IDs cannot be an empty collection.", nameof(itemIds));
            }

            var request = new ItemPricesByIdsRequest(itemIds);

            using var response = await _http.SendAsync(request).ConfigureAwait(false);

            response.EnsureSuccessStatusCode();
            var json = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

            var context = response.Headers.GetCollectionContext();
            var list    = new List <ItemPrice>(context.ResultCount);

            JsonConvert.PopulateObject(json, list, Json.DefaultJsonSerializerSettings);
            return(new DataTransferCollection <ItemPrice>(list, context));
        }
Ejemplo n.º 2
0
        private async Task <List <string> > GetJsonItemPricesById(IReadOnlyCollection <int> itemIds, bool indented)
        {
            var request = new ItemPricesByIdsRequest(itemIds);

            using var response = await _http.SendAsync(request);

            using var responseReader = new StreamReader(await response.Content.ReadAsStreamAsync());
            using var jsonReader     = new JsonTextReader(responseReader);
            response.EnsureSuccessStatusCode();

            // API returns a JSON array but we want a List of JSON objects instead
            var array = await JToken.ReadFromAsync(jsonReader);

            return(array.Children <JObject>().Select(item => item.ToString(indented ? Formatting.Indented : Formatting.None)).ToList());
        }