Ejemplo n.º 1
0
        public async Task <List <KeyValuePair <InternalDebtModel, ExternalDebtModel> > > GetDebtModels()
        {
            string url = "https://www.transparency.treasury.gov/services/api/fiscal_service/v1/accounting/od/debt_to_penny?sort=-data_date&format=json";

            using (HttpResponseMessage response = await _client.Client.GetAsync(url))
            {
                if (response.IsSuccessStatusCode)
                {
                    string modelsString = await response.Content.ReadAsStringAsync();

                    DebtAPIArray models = JsonConvert.DeserializeObject <DebtAPIArray>(modelsString);
                    var          output = new List <KeyValuePair <InternalDebtModel, ExternalDebtModel> >();
                    foreach (DebtAPIModel model in models.data)
                    {
                        output.Add(_converter.ConvertModelFromAPI(model));
                    }
                    return(output);
                }
                else
                {
                    throw new Exception(response.ReasonPhrase);
                }
            }
        }