Exemplo n.º 1
0
        public async Task <List <string> > GetAllJsonFloors(int continentId, bool indented)
        {
            var request = new FloorsRequest(continentId);

            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(obj => obj.ToString(indented ? Formatting.Indented : Formatting.None)).ToList());
        }
Exemplo n.º 2
0
        public async Task <IDataTransferCollection <Floor> > GetFloors(int continentId)
        {
            var request = new FloorsRequest(continentId);

            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 <Floor>(context.ResultCount);

            JsonConvert.PopulateObject(json, list, Json.DefaultJsonSerializerSettings);
            return(new DataTransferCollection <Floor>(list, context));
        }