Example #1
0
        public void CreatePost()
        {
            var client        = new Medium.Client();
            var title         = "Liverpool FC";
            var tags          = new[] { "football", "sport", "liverpool" };
            var canonicalUrl  = "http://jamietalbot.com/posts/liverpool-fc";
            var publishStatus = PublishStatus.Unlisted;
            var license       = License.Cc40By;
            var publishedAt   = new DateTime(2015, 1, 1);

            var author = client.GetCurrentUser(new Token {
                AccessToken = _accessToken
            });

            Assert.NotEqual(null, author);

            var body = new CreatePostRequestBody
            {
                Title           = title,
                ContentFormat   = ContentFormat.Html,
                Content         = "<h1>Liverpool FC</h1><p>You’ll never walk alone.</p>",
                Tags            = tags,
                CanonicalUrl    = canonicalUrl,
                PublishStatus   = publishStatus,
                License         = license,
                PublishedAt     = publishedAt,
                NotifyFollowers = false,
            };

            var post = client.CreatePost(author.Id, body, new Token {
                AccessToken = _accessToken
            });

            Assert.NotEqual(null, post);

            Assert.NotEqual(null, post.Id);
            Assert.Equal(title, post.Title);
            Assert.Equal(author.Id, post.AuthorId);
            Assert.Equal(true, tags.All(t => post.Tags.Contains(t)));
            Assert.Equal(true, post.Tags.All(t => tags.Contains(t)));
            Assert.NotEqual(null, post.Url);
            Assert.Equal(canonicalUrl, post.CanonicalUrl);
            Assert.Equal(publishStatus, post.PublishStatus);
            Assert.NotEqual(null, post.PublishedAt);
            Assert.Equal(publishedAt, post.PublishedAt);
            Assert.Equal(license, post.License);
            Assert.NotEqual(null, post.LicenseUrl);
        }
Example #2
0
        public void CreatePostUnderPublication()
        {
            var client        = new Medium.Client();
            var title         = "Liverpool FC";
            var tags          = new[] { "football", "sport", "liverpool" };
            var canonicalUrl  = "http://jamietalbot.com/posts/liverpool-fc";
            var publishStatus = PublishStatus.Public;
            var license       = License.Cc40By;

            var author = client.GetCurrentUser(GetToken());

            Assert.NotEqual(null, author);

            var body = new CreatePostRequestBody
            {
                Title         = title,
                ContentFormat = ContentFormat.Html,
                Content       = "<h1>Liverpool FC (Under Publication)</h1><p>You’ll never walk alone.</p>",
                Tags          = tags,
                CanonicalUrl  = canonicalUrl,
                PublishStatus = publishStatus,
                License       = license
            };

            var post = client.CreatePostUnderPublication(_testPublicationId, body, GetToken());

            Assert.NotEqual(null, post);

            Assert.NotEqual(null, post.Id);
            Assert.Equal(title, post.Title);
            Assert.Equal(author.Id, post.AuthorId);
            Assert.Equal(true, tags.All(t => post.Tags.Contains(t)));
            Assert.Equal(true, post.Tags.All(t => tags.Contains(t)));
            Assert.NotEqual(null, post.Url);
            Assert.Equal(canonicalUrl, post.CanonicalUrl);
            Assert.Equal(publishStatus, post.PublishStatus);
            Assert.NotEqual(null, post.PublishedAt);
            Assert.Equal(license, post.License);
            Assert.NotEqual(null, post.LicenseUrl);

            Assert.NotEqual(null, post.PublicationId);
            Assert.Equal(_testPublicationId, post.PublicationId);
        }
Example #3
0
        private Post CreatePostInternal(string endpointUrl, CreatePostRequestBody createPostRequestBody, Token token)
        {
            var request = Helper.
                          GetRequestWithToken(
                BaseUrl + endpointUrl,
                System.Net.Http.HttpMethod.Post,
                token).
                          SetRequestJson(new
            {
                title           = createPostRequestBody.Title,
                contentFormat   = createPostRequestBody.ContentFormat.ToString().ToLowerInvariant(),
                content         = createPostRequestBody.Content,
                tags            = createPostRequestBody.Tags,
                canonicalUrl    = createPostRequestBody.CanonicalUrl,
                publishStatus   = createPostRequestBody.PublishStatus.ToString().ToLowerInvariant(),
                license         = createPostRequestBody.License.ToString().CamelCaseToSpinalCase(),
                publishedAt     = createPostRequestBody.PublishedAt,
                notifyFollowers = createPostRequestBody.NotifyFollowers,
            });

            return(request.GetResponseJson <Post>());
        }
Example #4
0
 public Post CreatePostUnderPublication(string publicationId, CreatePostRequestBody createPostRequestBody, Token token)
 {
     return(CreatePostInternal($"/publications/{publicationId}/posts", createPostRequestBody, token));
 }
Example #5
0
 public Post CreatePost(string authorId, CreatePostRequestBody createPostRequestBody, Token token)
 {
     return(CreatePostInternal($"/users/{authorId}/posts", createPostRequestBody, token));
 }