Beispiel #1
0
        public static async Task <RecentVotes> GetRecentVotesAsync(int id)
        {
            try {
                using (var httpClient = new HttpClient()) {
                    string url = String.Format("https://www.govtrack.us/api/v2/vote_voter?person={0}&limit=50&sort=-created&format=xml", id);

                    var response = await httpClient.GetAsync(url);

                    var stream = await response.Content.ReadAsStreamAsync();

                    var votes       = LoadVotes(stream);
                    var recentVotes = new RecentVotes {
                        Id = id, Votes = votes
                    };

                    return(recentVotes);
                }
            } catch (Exception) {
                var recentVotes = new RecentVotes {
                    Id = id, Votes = new List <Vote> {
                        new Vote {
                            Question = "Could not connect to the internet"
                        }
                    }
                };
                return(recentVotes);
            }
        }
        public static async Task<RecentVotes> GetRecentVotesAsync (int id)
        {
            try {
                using (var httpClient = new HttpClient ()) {
                 
                    string url= String.Format("https://www.govtrack.us/api/v2/vote_voter?person={0}&limit=50&sort=-created&format=xml", id);

                    var response = await httpClient.GetAsync (url);
                    var stream = await response.Content.ReadAsStreamAsync ();
                    var votes = LoadVotes (stream);
                    var recentVotes = new RecentVotes { Id = id, Votes = votes };

                    return recentVotes;
                }
            } catch (Exception) {
                var recentVotes = new RecentVotes {Id = id, Votes = new List<Vote> {
                        new Vote { Question = "Could not connect to the internet" }
                    }
                };
                return recentVotes;
            }
        }