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"));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the list of suggested tags based on a given URL. The list comprises two hashes. One is called "popular"
        /// and consists of tags that are based on pinboard-wide data. The other is called "recommended" and is culled
        /// from the user's tags.
        /// </summary>
        /// <param name="url">The URL to get suggested tags for.</param>
        /// <returns>A PinboardSuggestedTags objects with the two hashes.</returns>
        public Task<PinboardSuggestedTags> GetSuggestedTags(string url)
        {
            PinboardSuggestedTags Suggestions = new PinboardSuggestedTags(url);

            //
            // The URL is a required parameter so let's just go ahead and validate it locally.
            //
            if (String.IsNullOrEmpty(url))
            {
                return Task.FromResult<PinboardSuggestedTags>(Suggestions);
            }

            RequestObject.SetRequest("posts/suggest");
            RequestObject.AddParameter("url", url);
            return RequestObject.SendRequestAsync().ContinueWith((task) =>
            {
                string content = task.Result;
                object[] ObjectArray = (object[])JsonSerializer.DeserializeObject(content);

                foreach (Dictionary<string, Object> hash in ObjectArray)
                {
                    foreach (KeyValuePair<string, Object> kvp in hash)
                    {
                        List<string> TagList = new List<string>();

                        object[] Tags = (object[])kvp.Value;
                        foreach (string tag in Tags)
                        {
                            TagList.Add(tag);
                        }

                        if (kvp.Key == "popular")
                        {
                            Suggestions.popular = TagList.ToArray();
                        }
                        else
                        {
                            System.Diagnostics.Debug.Assert(kvp.Key == "recommended");
                            Suggestions.recommended = TagList.ToArray();
                        }
                    }
                }

                return Suggestions;
            });
        }