Exemple #1
0
        public void UploadCompletePost()
        {
            var  medium = new MediumApiClient(WeblogInfo);
            bool result = medium.GetUser();

            Assert.IsTrue(result, medium.ErrorMessage);

            // make sure there is at least one publication available
            var pubs = medium.GetBlogs();

            Assert.IsNotNull(pubs, medium.ErrorMessage);
            Assert.IsTrue(pubs.Count > 0);

            string pubId = pubs.FirstOrDefault().BlogId as string;

            WeblogInfo.BlogId = pubId;

            var post = new Post
            {
                Tags  = new string[] { "Markdown", "Test" },
                Title = "Test Post #" + DataUtils.GenerateUniqueId(),
                Body  = @"<h1>New Post</h1>
<img src=""MarkdownMonster.png"" />
<p>This is a new post and text and image</p>
"
            };


            var mediumPost = medium.PublishCompletePost(post, documentBasePath: FileUtils.GetPhysicalPath(".\\"));

            Assert.IsNotNull(mediumPost.url, medium.ErrorMessage);
            Console.WriteLine(mediumPost.url);
            Console.WriteLine(mediumPost.id);
            ShellUtils.GoUrl(mediumPost.url);
        }
Exemple #2
0
        public void UploadPostToPublication()
        {
            var  medium = new MediumApiClient(WeblogInfo);
            bool result = medium.GetUser();

            Assert.IsTrue(result, medium.ErrorMessage);

            // make sure there is at least one publication available
            var pubs = medium.GetBlogs();

            Assert.IsNotNull(pubs, medium.ErrorMessage);

            string pubId = pubs.FirstOrDefault().BlogId as string;


            var post = new MediumPost()
            {
                tags            = new string[] { "Markdown", "Test" },
                title           = "Test Post #" + DataUtils.GenerateUniqueId(),
                content         = "This is a **test post**.",
                contentFormat   = "markdown",
                publishStatus   = "draft",
                notifyFollowers = false,
                canonicalUrl    = "https://weblog.west-wind.com"
            };

            post = medium.PublishPost(post, pubId);

            Assert.IsNotNull(post.url, medium.ErrorMessage);
            Console.WriteLine(post.url);
            Console.WriteLine(post.id);
            ShellUtils.GoUrl(post.url);
        }
Exemple #3
0
        public void GetBlogs()
        {
            Console.WriteLine("Starting.");

            var  medium = new MediumApiClient(WeblogInfo);
            bool result = medium.GetUser();

            Assert.IsTrue(result, medium.ErrorMessage);

            var pubs = medium.GetBlogs();

            Assert.IsNotNull(pubs, medium.ErrorMessage);
            foreach (var pub in pubs)
            {
                Console.WriteLine(pub.BlogId + " - " + pub.BlogName);
            }
        }
        private void DropDownButton_Click(object sender, RoutedEventArgs e)
        {
            ShowStatus("Getting Blog listing information from service...");
            WindowUtilities.DoEvents();

            var context = Resources["BlogsContextMenu"] as ContextMenu;

            context.Items.Clear();

            IEnumerable <UserBlog> blogs = null;

            try
            {
                if (Model.ActiveWeblogInfo.Type == WeblogTypes.Medium)
                {
                    var client = new MediumApiClient(Model.ActiveWeblogInfo);
                    blogs = client.GetBlogs();
                    if (blogs == null)
                    {
                        ShowStatus("Failed to get blog listing: " + client.ErrorMessage, 6000);
                    }
                }
                else if (Model.ActiveWeblogInfo.Type == WeblogTypes.MetaWeblogApi ||
                         Model.ActiveWeblogInfo.Type == WeblogTypes.Wordpress)
                {
                    var client = new MetaWebLogWordpressApiClient(Model.ActiveWeblogInfo);
                    blogs = client.GetBlogs();
                    if (blogs == null)
                    {
                        ShowStatus("Failed to get blog listing: " + client.ErrorMessage, 6000);
                    }
                }
            }
            catch (Exception ex)
            {
                ShowStatus("Failed to get blogs: " + ex.Message, 6000);
                return;
            }

            ShowStatus("Blogs retrieved...", 2000);

            if (blogs == null)
            {
                return;
            }

            string blogId = Model.ActiveWeblogInfo.BlogId as string;

            if (!string.IsNullOrEmpty(blogId) && !blogs.Any(b => blogId == b.BlogId as string))
            {
                context.Items.Add(new MenuItem {
                    Header = blogId, Tag = blogId
                });
            }

            foreach (var blog in blogs)
            {
                var item = new MenuItem()
                {
                    Header = blog.BlogName,
                    Tag    = blog.BlogId,
                };
                item.Click += (s, ea) =>
                {
                    var mitem = s as MenuItem;
                    if (mitem == null)
                    {
                        return;
                    }

                    Model.ActiveWeblogInfo.BlogId = mitem.Tag as string;
                    context.Items.Clear();
                };
                context.Items.Add(item);
            }
        }