-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathProgram.cs
35 lines (32 loc) · 1.13 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
public class Program
{
private const string URL = "https://testdrive.donordrive.com/api/";
private static string urlParameters = "participants?version=1.5&orderBy=sumDonations%20DESC&limit=10";
static void Main(string[] args)
=> new Program().MainAsync().GetAwaiter().GetResult();
private async Task MainAsync()
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(URL);
HttpResponseMessage response = await client.GetAsync(urlParameters);
if (response.IsSuccessStatusCode)
{
dynamic participants = response.Content.ReadAsAsync<IEnumerable<dynamic>>().Result;
foreach (dynamic participant in participants)
{
Console.WriteLine("{0}", participant);
}
}
else
{
Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
}
}
}
}