Created
January 12, 2015 06:43
-
-
Save odedw/a76279b54b9f762eafb5 to your computer and use it in GitHub Desktop.
Fetch a random user from randomuser.me
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RandomUserFetcher | |
{ | |
public async Task<RandomUser> Fetch() | |
{ | |
using (var webClient = new WebClient()) | |
{ | |
var result = await webClient.DownloadStringTaskAsync("http://api.randomuser.me"); | |
dynamic obj = JsonConvert.DeserializeObject(result); | |
var userStr = obj.results[0].user.ToString(); | |
var user = JsonConvert.DeserializeObject<RandomUser>(userStr); | |
return user; | |
} | |
} | |
} | |
public struct Name | |
{ | |
public string Title { get; set; } | |
public string First { get; set; } | |
public string Last { get; set; } | |
} | |
public struct Location | |
{ | |
public string Street { get; set; } | |
public string City { get; set; } | |
public string State { get; set; } | |
public string Zip { get; set; } | |
} | |
public struct Picture | |
{ | |
public string Large { get; set; } | |
public string Medium { get; set; } | |
public string Thumbnail { get; set; } | |
} | |
public class RandomUser | |
{ | |
public string Gender { get; set; } | |
public Name Name { get; set; } | |
public Location Location { get; set; } | |
public string Email { get; set; } | |
public string Username { get; set; } | |
public string Password { get; set; } | |
public string Salt { get; set; } | |
public string Md5 { get; set; } | |
public string Sha1 { get; set; } | |
public string Sha256 { get; set; } | |
public string Registered { get; set; } | |
public string Dob { get; set; } | |
public string Phone { get; set; } | |
public string Cell { get; set; } | |
public string Ssn { get; set; } | |
public Picture Picture { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment