Example #1
0
        public void TestAddInvalidBookmarkNoTitle()
        {
            PinboardBookmark bookmark = new PinboardBookmark(TestBookmarkURL, "");

            bool b = Pinboard.AddBookmark(bookmark, true).Result;
            Assert.IsFalse(b);
        }
Example #2
0
        public void TestAddInvalidBookmarkNoURL()
        {
            PinboardBookmark bookmark = new PinboardBookmark("", "Title");

            bool b = Pinboard.AddBookmark(bookmark, true).Result;
            Assert.IsFalse(b);
        }
        /// <summary>
        /// Adds a bookmark.
        /// </summary>
        /// <param name="Bookmark">A PinboardBookmark to add.</param>
        /// <param name="ReplaceExisting">If true then any existing bookmark for the specified URL will be replaced. If a bookmark already exists for the given URL and this parameter is false then the function will fail.</param>
        /// <returns>true if successful, false otherwise.</returns>
        public Task<bool> AddBookmark(PinboardBookmark Bookmark, bool ReplaceExisting)
        {
            RequestObject.SetRequest("posts/add");

            RequestObject.AddParameter("url", Bookmark.URL);
            RequestObject.AddParameter("description", Bookmark.Title);
            RequestObject.AddParameter("extended", Bookmark.Description);
            RequestObject.AddParameter("tags", Bookmark.TagString);
            RequestObject.AddParameter("dt", ConvertTimestamp(Bookmark.CreationTime));
            RequestObject.AddParameter("replace", BoolToString(ReplaceExisting));
            RequestObject.AddParameter("shared", BoolToString(Bookmark.Shared));
            RequestObject.AddParameter("toread", BoolToString(Bookmark.ToRead));

            return RequestObject.SendRequestAsync().ContinueWith((task) =>
            {
                string content = task.Result;
                Dictionary<string, object> hash = (Dictionary<string, Object>)JsonSerializer.DeserializeObject(content);

                if ((string)hash["result_code"] == SuccessStatusString)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            });
        }
        public PinboardRequestMock()
        {
            ReferenceBookmark = new PinboardBookmark("http://www.test.com/", "This is the title");
            ReferenceBookmark.Description = "This is the description";
            ReferenceBookmark.AddTag("tag1");
            ReferenceBookmark.AddTag("tag2");
            ReferenceBookmark.CreationTime = ReferenceDate;
            ReferenceBookmark.Shared = true;
            ReferenceBookmark.ToRead = false;

            ReferencePostDates = new List<PinboardPostDate>();
            ReferencePostDates.Add(new PinboardPostDate("1977-08-10", 7));
            ReferencePostDates.Add(new PinboardPostDate("1982-02-10", 1));

            ReferenceSuggestedTags = new PinboardSuggestedTags("http://www.sun.com/");
            ReferenceSuggestedTags.popular = new string[] { "hardware" };
            ReferenceSuggestedTags.recommended = new string[] { "sun", "solaris", "Hardware", "java", "Bookmarks_bar", "computer", "Computer_Hardware", "Bookmarks_Menu", "ComputerHardware", "Software" };

            ReferenceTags = new List<PinboardCountedTag>();
            ReferenceTags.Add(new PinboardCountedTag("tag1", 7));
            ReferenceTags.Add(new PinboardCountedTag("tag2", 11));
            ReferenceTags.Add(new PinboardCountedTag("tag7", 41));

            ReferenceNotes = new List<PinboardNote>();
            ReferenceNotes.Add(new PinboardNote("Body 1", "ID#1", "skdfjsldf", "Title 1", 6, "1977-08-10", "1983-02-10"));
            ReferenceNotes.Add(new PinboardNote("Body 2", "ID#2", "skdfjsldf", "Title 2", 6, "1977-08-10", "1983-02-10"));
            ReferenceNotes.Add(new PinboardNote("Body 3", "ID#3", "skdfjsldf", "Title 3", 6, "1977-08-10", "1983-02-10"));
        }
Example #5
0
        public void TestAddDuplicateBookmark()
        {
            PinboardBookmark bookmark = new PinboardBookmark(TestBookmarkURL, "Test Title");

            Pinboard.AddBookmark(bookmark, true);
            bool b = Pinboard.AddBookmark(bookmark, false).Result;
            Assert.IsFalse(b);
        }
        public void TestTagsAreKeptSortedWhenAdding()
        {
            PinboardBookmark bookmark = new PinboardBookmark(TestBookmarkURL, "Title");

            bookmark.AddTag("Tag3");
            bookmark.AddTag("Tag2");
            bookmark.AddTag("Tag1");

            Assert.IsTrue(bookmark.TagString == "Tag1 Tag2 Tag3");
        }
Example #7
0
        public void TestAddValidBookmark()
        {
            PinboardBookmark bookmark = new PinboardBookmark(TestBookmarkURL, "Test Title");
            bookmark.Description = "Test Description";
            bookmark.AddTag("test1");
            bookmark.CreationTime = DateTime.Now;
            bookmark.Shared = true;
            bookmark.ToRead = false;

            bool b = Pinboard.AddBookmark(bookmark, true).Result;
            Assert.IsTrue(b);
        }
Example #8
0
        public void TestDeleteValidBookmark()
        {
            bool b;

            PinboardBookmark bookmark = new PinboardBookmark(TestBookmarkURL, "Title");
            b = Pinboard.AddBookmark(bookmark, true).Result;
            Assert.IsTrue(b);

            b = Pinboard.DeleteBookmark(TestBookmarkURL).Result;
            Assert.IsTrue(b);
        }
        /// <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>
        /// 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;
            });
        }
        /// <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;
            });
        }
        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");
            }
        }