Skip to content

Instantly share code, notes, and snippets.

@hbulens
Created January 13, 2018 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hbulens/3ddd4950d5fb16ac330065a80a027b56 to your computer and use it in GitHub Desktop.
Save hbulens/3ddd4950d5fb16ac330065a80a027b56 to your computer and use it in GitHub Desktop.
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