Created
January 13, 2018 18:29
-
-
Save hbulens/3ddd4950d5fb16ac330065a80a027b56 to your computer and use it in GitHub Desktop.
This file contains 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 IEnumerable GetWordPressPosts() | |
{ | |
using(WebClient webClient = new WebClient()) | |
{ | |
string blogUrl = @ "https://public-api.wordpress.com/rest/v1.1/sites/hendrikbulens.wordpress.com/posts/"; | |
string response = webClient.DownloadString(blogUrl); | |
WordPressBlog blogPosts = JsonConvert.DeserializeObject(response); | |
IEnumerable posts = blogPosts.posts.OrderByDescending(x => x.date).Take(3).Select(x => new BlogPost() { | |
Title = x.title, | |
Message = x.excerpt.CharacterLimit(150), | |
PublishedOn = x.date, | |
Comments = x.discussion.comment_count, | |
Link = x.URL | |
}); | |
return posts; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment