using System; using System.Collections.Generic; using System.Text; using System.Linq; using Nuane.Posterous; namespace Sample { class Program { /// <summary> /// Display a list of all posts from a specified site. /// </summary> public static void Sample1() { // Initialize an anonymous posterous session using the specified site PosterousSession posterous = new PosterousSession("pokorny.posterous.com"); // Retrieve all posts (this can take some time) PosterousPostCollection posts = posterous.GetPosts(0, 0, int.MaxValue); // Display ID, short URL, date and title of each post foreach (PosterousPost post in posts) { Console.WriteLine("{0} | {1} | {2:yyyy-MM-dd} | {3}", post.Id, post.ShortUri, post.Date, post.Title); } } /// <summary> /// Publishes a new post with a photo gallery to your primary site. /// </summary> public static void Sample2() { // Initialize an authenticated posterous session PosterousSession session = new PosterousSession("example@nuane.com", "password"); // Test that it works fine (this is optional) session.Ping(); // Construct a new post and attach two photos PosterousNewPost newPost = new PosterousNewPost(); newPost.Title = "New post!"; newPost.Body = "This is the body of the new post."; newPost.Tags = "posterous, api, photo"; newPost.Files.Add("photo1.jpg"); newPost.Files.Add("photo2.png"); // Publish the post to the primary site (blog) PosterousPostInfo postInfo = session.PublishPost(0, newPost); // Display some information about the new post Console.WriteLine("Published as {0}", postInfo.ShortUri); } /// <summary> /// Displays a list of your sites (blogs). /// </summary> public static void Sample3() { // Initialize an authenticated posterous session PosterousSession posterous = new PosterousSession("example@nuane.com", "password"); // Retrieve list of sites for the account PosterousSiteCollection sites = posterous.GetSites(); // Display information about each of each sites foreach (PosterousSite site in sites) { Console.WriteLine("{0} | {1} ({2} posts) | {3}", site.Id, site.Name, site.PostsCount, site.Uri); } } /// <summary> /// Changes the title of latest post at the specified site and adds a photo. /// </summary> public static void Sample4() { // Initialize an authenticated posterous session PosterousSession posterous = new PosterousSession("example@nuane.com", "password"); // Retrieve list of sites for the account PosterousSiteCollection sites = posterous.GetSites(); // Get the "lukas.pokorny.eu" site info PosterousSite mySite = sites.First(site => site.Hostname == "lukas.pokorny.eu"); // Get the latest post at my site PosterousPost latestPost = mySite.GetPosts(0, 1)[0]; // Change the latest post's title latestPost.Title += " [Update: New photo arrived]"; latestPost.Update(); // Attach a new photo the latest post latestPost.AddMedia(new PosterousFile(@"new-photo.jpg")); } /// <summary> /// Dummy entrypoint. /// </summary> public static void Main() { Console.WriteLine("See the source code for samples."); } } }