/// <summary> /// Retrieves <i>count</i> number of the user's most recent posts filtered by specific tags. /// </summary> /// <param name="count">The number of posts to retrieve.</param> /// <param name="Tags">A list of up to three tags to filter on.</param> /// <returns>A (possibly empty) list of PinboardBookmarks.</returns> public Task<List<PinboardBookmark>> GetRecentBookmarks(uint count, List<string> Tags) { RequestObject.SetRequest("posts/recent"); RequestObject.AddParameter("count", count); if (Tags != null) { RequestObject.AddParameter("tag", FormatTags(Tags)); } return RequestObject.SendRequestAsync().ContinueWith((task) => { List<PinboardBookmark> PostList = new List<PinboardBookmark>(); string content = task.Result; dynamic PostObjects = JsonSerializer.DeserializeObject(content); foreach (Dictionary<string, object> PostObject in PostObjects["posts"]) { PinboardBookmark Bookmark = new PinboardBookmark((string)PostObject["href"], (string)PostObject["description"]); Bookmark.Description = (string)PostObject["extended"]; Bookmark.Shared = StringToBool((string)PostObject["shared"]); Bookmark.ToRead = StringToBool((string)PostObject["toread"]); Bookmark.SetTags((string)PostObject["tags"]); Bookmark.CreationTime = DateTime.Parse((string)PostObject["time"]); PostList.Add(Bookmark); } return PostList; }); }
/// <summary> /// Returns a list of all of the user's bookmarks and notes. /// </summary> /// <returns>A list of PinboardBookmark objects representing the user's posts.</returns> public Task<List<PinboardBookmark>> GetAllBookmarks() { RequestObject.SetRequest("posts/all"); return RequestObject.SendRequestAsync().ContinueWith((task) => { List<PinboardBookmark> List = new List<PinboardBookmark>(); string content = task.Result; dynamic PostObjects = JsonSerializer.DeserializeObject(content); foreach (Dictionary<string, object> PostObject in PostObjects) { PinboardBookmark Bookmark = new PinboardBookmark((string)PostObject["href"], (string)PostObject["description"]); Bookmark.Description = (string)PostObject["extended"]; Bookmark.SetTags((string)PostObject["tags"]); Bookmark.CreationTime = DateTime.Parse((string)PostObject["time"]); List.Add(Bookmark); } return List; }); }
/// <summary> /// Gets the PinboardBookmark object for the specified URL. /// </summary> /// <param name="URL">The URL for which you want the corresponding PinboardBookmark.</param> /// <returns>A PinboardBookmark if the user has a bookmark for the specified URL, null otherwise.</returns> public Task<PinboardBookmark> GetBookmarkByURL(string URL) { RequestObject.SetRequest("posts/get"); RequestObject.AddParameter("url", URL); return RequestObject.SendRequestAsync().ContinueWith((task) => { string content = task.Result; Dictionary<string, object> hash = (Dictionary<string, object>)JsonSerializer.DeserializeObject(content); // // This API returns a list of posts, even though we know in this case there can be at most one result. // Object[] PostsArray = (Object[])hash["posts"]; // // Check if there were actually any results. // if (PostsArray.Length == 0) { return null; } System.Diagnostics.Debug.Assert(PostsArray.Length == 1); Dictionary<string, object> PostObject = PostsArray[0] as Dictionary<string, object>; PinboardBookmark Bookmark = new PinboardBookmark((string)PostObject["href"], (string)PostObject["description"]); Bookmark.Description = (string)PostObject["extended"]; Bookmark.Shared = StringToBool((string)PostObject["shared"]); Bookmark.ToRead = StringToBool((string)PostObject["toread"]); Bookmark.SetTags((string)PostObject["tags"]); Bookmark.CreationTime = DateTime.Parse((string)PostObject["time"]); return Bookmark; }); }
private string AddBookmark() { Dictionary<string, string> hash = new Dictionary<string, string>(); System.Diagnostics.Debug.WriteLine("URL ==> " + URL); // TODO if (String.IsNullOrEmpty(Parameters["url"])) { System.Diagnostics.Debug.WriteLine("No url ..."); // TODO return LoadResourceText("AddNewBookmarkNoURL.txt"); } else if (String.IsNullOrEmpty(Parameters["description"])) { System.Diagnostics.Debug.WriteLine("no title ..."); // TODO return LoadResourceText("AddNewBookmarkNoTitle.txt"); } else if (Bookmarks.ContainsKey(Parameters["url"]) && Parameters["replace"] != "yes") { System.Diagnostics.Debug.WriteLine("bookmark already exists and replace is {0}", Parameters["replace"]); // TODO return LoadResourceText("AddNewBookmarkAlreadyExists.txt"); } else { System.Diagnostics.Debug.WriteLine("bookmark is golden ..."); // TODO // {"href":"http:\/\/news.discovery.com\/tech\/gear-and-gadgets\/how-to-really-drive-across-the-us-hitting-all-major-landmarks-150309.htm", // "description":"Map of US with Major Landmarks (for roadtrip)", // "extended":"", // "meta":"9ac82954f4d5da855d5362f78356f834", // "hash":"c3a970f390fb1a4f2a49ec176a07f0c2", // "time":"2015-03-11T20:01:51Z", // "shared":"yes", // "toread":"no", // "tags":"travel todo"}, PinboardBookmark bookmark = new PinboardBookmark(Parameters["url"], Parameters["description"]); bookmark.Description = Parameters["extended"]; bookmark.CreationTime = DateTime.Parse(Parameters["dt"]); bookmark.SetTags(Parameters["tags"]); bookmark.Shared = PinboardManager.StringToBool(Parameters["shared"]); bookmark.ToRead = PinboardManager.StringToBool(Parameters["toread"]); Bookmarks[Parameters["url"]] = bookmark; return LoadResourceText("AddNewBookmark.txt"); } }