Exemple #1
0
        /// <summary>
        /// Creates the <see cref="PostData"/> for a link post.
        /// </summary>
        /// <param name="url">
        /// The url for the link.
        /// </param>
        /// <param name="title">
        /// The display text for the link.
        /// </param>
        /// <param name="description">
        /// The link's description.
        /// </param>
        /// <param name="tags">
        /// The tags to associate with the post.
        /// </param>
        /// <param name="state">
        /// The <see cref="PostCreationState"/> of the post.
        /// </param>
        /// <returns>
        /// A <see cref="PostData"/> instance representing the post.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="url"/> is <b>null</b>.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// <paramref name="url"/> is empty.
        /// </exception>
        public static PostData CreateLink(
            string url,
            string title              = null,
            string description        = null,
            IEnumerable <string> tags = null,
            PostCreationState state   = PostCreationState.Published)
        {
            if (url == null)
            {
                throw new ArgumentNullException("url");
            }

            if (url.Length == 0)
            {
                throw new ArgumentException("Url cannot be empty.", "url");
            }

            var postData = new PostData(state, tags);

            postData.parameters.Add("type", "link");
            postData.parameters.Add("url", url);
            postData.parameters.Add("title", title, null);
            postData.parameters.Add("description", description, null);

            return(postData);
        }
Exemple #2
0
        private PostCreationState getCreationState(string name)
        {
            PostCreationState pcs = PostCreationState.Published;

            switch (name)
            {
            case "Queue":
                pcs = PostCreationState.Queue;
                break;

            case "Submission":
                pcs = PostCreationState.Submission;
                break;

            case "Draft":
                pcs = PostCreationState.Draft;
                break;

            case "Private":
                pcs = PostCreationState.Private;
                break;

            case "Published":
                pcs = PostCreationState.Published;
                break;
            }
            return(pcs);
        }
Exemple #3
0
		internal PostData(PostCreationState state, IEnumerable<string> tags)
		{
			parameters = new MethodParameterSet();

			State = state;
			Tags = (tags != null && tags.FirstOrDefault() != null) ? new List<string>(tags) : new List<string>();
			Format = PostFormat.Html;
		}
Exemple #4
0
        internal PostData(PostCreationState state, IEnumerable <string> tags)
        {
            parameters = new MethodParameterSet();

            State  = state;
            Tags   = (tags != null && tags.FirstOrDefault() != null) ? new List <string>(tags) : new List <string>();
            Format = PostFormat.Html;
        }
Exemple #5
0
        /// <summary>
        /// Creates the <see cref="PostData"/> for a photo post.
        /// </summary>
        /// <param name="photo">
        /// A photo to upload, defined as a <see cref="BinaryFile"/> instance.
        /// </param>
        /// <param name="state">
        /// The <see cref="PostCreationState"/> of this photo post.
        /// </param>
        /// <param name="caption">
        /// The optional string caption for this photo post.
        /// </param>
        /// <param name="tags">
        /// The optional array of string used for tags.
        /// </param>
        /// </param>
        /// <param name="caption">
        /// The caption for the photo post.
        /// </param>
        /// <returns>
        /// A <see cref="PostData"/> instance representing the post.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="photo"/> is <b>null</b>.
        /// </exception>
        public static PostData CreatePhoto(
            BinaryFile photo,
            string caption            = null,
            IEnumerable <string> tags = null,
            PostCreationState state   = PostCreationState.Published)
        {
            if (photo == null)
            {
                throw new ArgumentNullException("photo");
            }

            var photos = new BinaryFile[] { photo };

            return(CreatePhoto(photos, caption, null, tags, PostCreationState.Published));
        }
Exemple #6
0
        /// <summary>
        /// Creates the <see cref="PostData"/> for a text post.
        /// </summary>
        /// <param name="body">
        /// The body of the text post.
        /// </param>
        /// <param name="title">
        /// The title of the text post.
        /// </param>
        /// <param name="tags">
        /// The tags to associate with the post.
        /// </param>
        /// <param name="state">
        /// The <see cref="PostCreationState"/> of the post.
        /// </param>
        /// <returns>
        /// A <see cref="PostData"/> instance representing the post.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="body"/> is <b>null</b>.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// <paramref name="body"/> is empty.
        /// </exception>
        public static PostData CreateText(
            string body  = null,
            string title = null,
            IEnumerable <string> tags = null,
            PostCreationState state   = PostCreationState.Published)
        {
            if (body == null && title == null)
            {
                throw new ArgumentException("Must have at least body or title.");
            }

            var postData = new PostData(state, tags);

            postData.parameters.Add("type", "text");
            postData.parameters.Add("body", body, null);
            postData.parameters.Add("title", title, null);

            return(postData);
        }
Exemple #7
0
        /// <summary>
        /// Creates the <see cref="PostData"/> for a video post.
        /// </summary>
        /// <param name="videoFile">
        /// The video file to upload, defined as a <see cref="BinaryFile"/> instance.
        /// </param>
        /// <param name="caption">
        /// The caption for the video post.
        /// </param>
        /// <param name="tags">
        /// The tags to associate with the post.
        /// </param>
        /// <param name="state">
        /// The <see cref="PostCreationState"/> of the post.
        /// </param>
        /// <returns>
        /// A <see cref="PostData"/> instance representing the post.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="videoFile"/> is <b>null</b>.
        /// </exception>
        public static PostData CreateVideo(
            BinaryFile videoFile,
            string caption            = null,
            IEnumerable <string> tags = null,
            PostCreationState state   = PostCreationState.Published)
        {
            if (videoFile == null)
            {
                throw new ArgumentNullException("videoFile");
            }

            var postData = new PostData(state, tags);

            postData.parameters.Add("type", "video");
            postData.parameters.Add(new BinaryMethodParameter("data", videoFile.Data, videoFile.FileName, videoFile.MimeType));
            postData.parameters.Add("caption", caption, null);

            return(postData);
        }
Exemple #8
0
        /// <summary>
        /// Creates the <see cref="PostData"/> for a photo post.
        /// </summary>
        /// <param name="photos">
        /// A list of photos to upload, defined as <see cref="BinaryFile"/> instances.
        /// </param>
        /// <param name="caption">
        /// The caption for the photo post.
        /// </param>
        /// <param name="clickThroughUrl">
        /// The photo(s) click trough url.
        /// </param>
        /// <param name="tags">
        /// The tags to associate with the post.
        /// </param>
        /// <param name="state">
        /// The <see cref="PostCreationState"/> of the post.
        /// </param>
        /// <returns>
        /// A <see cref="PostData"/> instance representing the post.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="photos"/> is <b>null</b>.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// <paramref name="photos"/> is empty.
        /// </exception>
        public static PostData CreatePhoto(
            IEnumerable <BinaryFile> photos,
            string caption            = null,
            string clickThroughUrl    = null,
            IEnumerable <string> tags = null,
            PostCreationState state   = PostCreationState.Published)
        {
            if (photos == null)
            {
                throw new ArgumentNullException("photos");
            }

            if (photos.FirstOrDefault() == null)
            {
                throw new ArgumentException("There must be at least one photo to post.", "photos");
            }

            var postData = new PostData(state, tags);

            postData.parameters.Add("type", "photo");

            if (photos.Count() == 1)
            {
                var photo = photos.First();
                postData.parameters.Add(new BinaryMethodParameter("data", photo.Data, photo.FileName, photo.MimeType));
            }
            else
            {
                int i = 0;
                foreach (var photo in photos)
                {
                    postData.parameters.Add(new BinaryMethodParameter(String.Format("data[{0}]", i++), photo.Data, photo.FileName, photo.MimeType));
                }
            }

            postData.parameters.Add("caption", caption, null);
            postData.parameters.Add("link", clickThroughUrl, null);

            return(postData);
        }
Exemple #9
0
        /// <summary>
        /// Creates the <see cref="PostData"/> for a video post.
        /// </summary>
        /// <param name="embedCode">
        /// The HTML embed code for the video.
        /// </param>
        /// <param name="caption">
        /// The caption for the video post.
        /// </param>
        /// <param name="tags">
        /// The tags to associate with the post.
        /// </param>
        /// <param name="state">
        /// The <see cref="PostCreationState"/> of the post.
        /// </param>
        /// <returns>
        /// A <see cref="PostData"/> instance representing the post.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="embedCode"/> is <b>null</b>.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// <paramref name="embedCode"/> is empty.
        /// </exception>
        public static PostData CreateVideo(
            string embedCode,
            string caption            = null,
            IEnumerable <string> tags = null,
            PostCreationState state   = PostCreationState.Published)
        {
            if (embedCode == null)
            {
                throw new ArgumentNullException("embedCode");
            }

            if (embedCode.Length == 0)
            {
                throw new ArgumentException("Embed Code cannot be empty.", "embedCode");
            }

            var postData = new PostData(state, tags);

            postData.parameters.Add("type", "video");
            postData.parameters.Add("embed", embedCode);
            postData.parameters.Add("caption", caption, null);

            return(postData);
        }
Exemple #10
0
        /// <summary>
        /// Creates the <see cref="PostData"/> for a chat post.
        /// </summary>
        /// <param name="conversation">
        /// The chat conversation.
        /// </param>
        /// <param name="title">
        /// The title of the chat.
        /// </param>
        /// <param name="tags">
        /// The tags to associate with the post.
        /// </param>
        /// <param name="state">
        /// The <see cref="PostCreationState"/> of the post.
        /// </param>
        /// <returns>
        /// A <see cref="PostData"/> instance representing the post.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="conversation"/> is <b>null</b>.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// <paramref name="conversation"/> is empty.
        /// </exception>
        public static PostData CreateChat(
            string conversation,
            string title = null,
            IEnumerable <string> tags = null,
            PostCreationState state   = PostCreationState.Published)
        {
            if (conversation == null)
            {
                throw new ArgumentNullException("conversation");
            }

            if (conversation.Length == 0)
            {
                throw new ArgumentException("Conversation cannot be empty.", "conversation");
            }

            var postData = new PostData(state, tags);

            postData.parameters.Add("type", "chat");
            postData.parameters.Add("conversation", conversation);
            postData.parameters.Add("title", title, null);

            return(postData);
        }
Exemple #11
0
        /// <summary>
        /// Creates the <see cref="PostData"/> for a quote post.
        /// </summary>
        /// <param name="quote">
        /// The quote.
        /// </param>
        /// <param name="source">
        /// The quote's source.
        /// </param>
        /// <param name="tags">
        /// The tags to associate with the post.
        /// </param>
        /// <param name="state">
        /// The <see cref="PostCreationState"/> of the post.
        /// </param>
        /// <returns>
        /// A <see cref="PostData"/> instance representing the post.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="quote"/> is <b>null</b>.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// <paramref name="quote"/> is empty.
        /// </exception>
        public static PostData CreateQuote(
            string quote,
            string source,
            IEnumerable <string> tags = null,
            PostCreationState state   = PostCreationState.Published)
        {
            if (quote == null)
            {
                throw new ArgumentNullException("quote");
            }

            if (quote.Length == 0)
            {
                throw new ArgumentException("Quote cannot be empty.", "quote");
            }

            var postData = new PostData(state, tags);

            postData.parameters.Add("type", "quote");
            postData.parameters.Add("quote", quote);
            postData.parameters.Add("source", source, null);

            return(postData);
        }
Exemple #12
0
 public async void PostLink(string name, string url, string title, string description, IEnumerable <string> tags, PostCreationState pcs = PostCreationState.Published)
 {
     //await _tumblrClient.CreatePostAsync(name, PostData.CreateLink(url, title, description, tags, pcs));
 }
Exemple #13
0
		/// <summary>
		/// Creates the <see cref="PostData"/> for a photo post.
		/// </summary>
		/// <param name="photos">
		/// A list of photos to upload, defined as <see cref="BinaryFile"/> instances.
		/// </param>
		/// <param name="caption">
		/// The caption for the photo post.
		/// </param>
		/// <param name="clickThroughUrl">
		/// The photo(s) click trough url.
		/// </param>
		/// <param name="tags">
		/// The tags to associate with the post.
		/// </param>
		/// <param name="state">
		/// The <see cref="PostCreationState"/> of the post.
		/// </param>
		/// <returns>
		/// A <see cref="PostData"/> instance representing the post.
		/// </returns>
		/// <exception cref="ArgumentNullException">
		/// <paramref name="photos"/> is <b>null</b>.
		/// </exception>
		/// <exception cref="ArgumentException">
		/// <paramref name="photos"/> is empty.
		/// </exception>
		public static PostData CreatePhoto(IEnumerable<BinaryFile> photos, string caption, string clickThroughUrl, IEnumerable<string> tags, PostCreationState state)
		{
			if (photos == null)
				throw new ArgumentNullException("photos");

			if (photos.FirstOrDefault() == null)
				throw new ArgumentException("There must be at least one photo to post.", "photos");

			var postData = new PostData(state, tags);
			postData.parameters.Add("type", "photo");

			if (photos.Count() == 1)
			{
				var photo = photos.First();
				postData.parameters.Add(new BinaryMethodParameter("data", photo.Data, photo.FileName, photo.MimeType));
			}
			else
			{
				int i = 0;
				foreach (var photo in photos)
					postData.parameters.Add(new BinaryMethodParameter(String.Format("data[{0}]", i++), photo.Data, photo.FileName, photo.MimeType));
			}

			postData.parameters.Add("caption", caption, null);
			postData.parameters.Add("link", clickThroughUrl, null);

			return postData;
		}
Exemple #14
0
		/// <summary>
		/// Creates the <see cref="PostData"/> for a quote post.
		/// </summary>
		/// <param name="quote">
		/// The quote.
		/// </param>
		/// <param name="source">
		/// The quote's source.
		/// </param>
		/// <param name="tags">
		/// The tags to associate with the post.
		/// </param>
		/// <param name="state">
		/// The <see cref="PostCreationState"/> of the post.
		/// </param>
		/// <returns>
		/// A <see cref="PostData"/> instance representing the post.
		/// </returns>
		/// <exception cref="ArgumentNullException">
		/// <paramref name="quote"/> is <b>null</b>.
		/// </exception>
		/// <exception cref="ArgumentException">
		/// <paramref name="quote"/> is empty.
		/// </exception>
		public static PostData CreateQuote(string quote, string source, IEnumerable<string> tags, PostCreationState state)
		{
			if (quote == null)
				throw new ArgumentNullException("quote");

			if (quote.Length == 0)
				throw new ArgumentException("Quote cannot be empty.", "quote");

			var postData = new PostData(state, tags);
			postData.parameters.Add("type", "quote");
			postData.parameters.Add("quote", quote);
			postData.parameters.Add("source", source, null);

			return postData;
		}
Exemple #15
0
		/// <summary>
		/// Creates the <see cref="PostData"/> for a text post.
		/// </summary>
		/// <param name="body">
		/// The body of the text post.
		/// </param>
		/// <param name="title">
		/// The title of the text post.
		/// </param>
		/// <param name="tags">
		/// The tags to associate with the post.
		/// </param>
		/// <param name="state">
		/// The <see cref="PostCreationState"/> of the post.
		/// </param>
		/// <returns>
		/// A <see cref="PostData"/> instance representing the post.
		/// </returns>
		/// <exception cref="ArgumentNullException">
		/// <paramref name="body"/> is <b>null</b>.
		/// </exception>
		/// <exception cref="ArgumentException">
		/// <paramref name="body"/> is empty.
		/// </exception>
		public static PostData CreateText(string body, string title, IEnumerable<string> tags, PostCreationState state)
		{
			if (body == null)
				throw new ArgumentNullException("body");

			if (body.Length == 0)
				throw new ArgumentException("Body cannot be empty.", "body");

			var postData = new PostData(state, tags);
			postData.parameters.Add("type", "text");
			postData.parameters.Add("body", body);
			postData.parameters.Add("title", title, null);

			return postData;
		}
Exemple #16
0
		/// <summary>
		/// Creates the <see cref="PostData"/> for a link post.
		/// </summary>
		/// <param name="url">
		/// The url for the link.
		/// </param>
		/// <param name="title">
		/// The display text for the link.
		/// </param>
		/// <param name="description">
		/// The link's description.
		/// </param>
		/// <param name="tags">
		/// The tags to associate with the post.
		/// </param>
		/// <param name="state">
		/// The <see cref="PostCreationState"/> of the post.
		/// </param>
		/// <returns>
		/// A <see cref="PostData"/> instance representing the post.
		/// </returns>
		/// <exception cref="ArgumentNullException">
		/// <paramref name="url"/> is <b>null</b>.
		/// </exception>
		/// <exception cref="ArgumentException">
		/// <paramref name="url"/> is empty.
		/// </exception>
		public static PostData CreateLink(string url, string title, string description, IEnumerable<string> tags, PostCreationState state)
		{
			if (url == null)
				throw new ArgumentNullException("url");

			if (url.Length == 0)
				throw new ArgumentException("Url cannot be empty.", "url");

			var postData = new PostData(state, tags);
			postData.parameters.Add("type", "link");
			postData.parameters.Add("url", url);
			postData.parameters.Add("title", title, null);
			postData.parameters.Add("description", description, null);

			return postData;
		}
Exemple #17
0
 public async void PostPhoto(string name, string title = null, IEnumerable <string> tags = null, PostCreationState pcs = PostCreationState.Published)
 {
     //BinaryFile bf = new BinaryFile();
     //await _tumblrClient.CreatePostAsync(name, PostData.CreatePhoto(bf, title, tags, pcs));
 }
Exemple #18
0
        /// <summary>
        /// Creates the <see cref="PostData"/> for an answer post.
        /// </summary>
        /// <param name="answer">The body of the answer post.</param>
        /// <param name="tags"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public static PostData CreateAnswer(string answer, IEnumerable <string> tags, PostCreationState state)
        {
            var postData = new PostData(state, tags);

            postData.parameters.Add("type", "answer");
            postData.parameters.Add("answer", answer);

            return(postData);
        }
Exemple #19
0
		/// <summary>
		/// Creates the <see cref="PostData"/> for an audio post.
		/// </summary>
		/// <param name="url">
		/// The url to the audio file to post (the url must not be on Tumblr).
		/// </param>
		/// <param name="caption">
		/// The caption for the audio post.
		/// </param>
		/// <param name="tags">
		/// The tags to associate with the post.
		/// </param>
		/// <param name="state">
		/// The <see cref="PostCreationState"/> of the post.
		/// </param>
		/// <returns>
		/// A <see cref="PostData"/> instance representing the post.
		/// </returns>
		/// <exception cref="ArgumentNullException">
		/// <paramref name="url"/> is <b>null</b>.
		/// </exception>
		/// <exception cref="ArgumentException">
		/// <paramref name="url"/> is empty.
		/// </exception>
		public static PostData CreateAudio(string url, string caption, IEnumerable<string> tags, PostCreationState state)
		{
			if (url == null)
				throw new ArgumentNullException("url");

			if (url.Length == 0)
				throw new ArgumentException("Url cannot be empty.", "url");

			var postData = new PostData(state, tags);
			postData.parameters.Add("type", "audio");
			postData.parameters.Add("url", url);
			postData.parameters.Add("caption", caption, null);

			return postData;
		}
Exemple #20
0
		/// <summary>
		/// Creates the <see cref="PostData"/> for an audio post.
		/// </summary>
		/// <param name="audioFile">
		/// The audio file to upload, defined as a <see cref="BinaryFile"/> instance.
		/// </param>
		/// <param name="caption">
		/// The caption for the audio post.
		/// </param>
		/// <param name="tags">
		/// The tags to associate with the post.
		/// </param>
		/// <param name="state">
		/// The <see cref="PostCreationState"/> of the post.
		/// </param>
		/// <returns>
		/// A <see cref="PostData"/> instance representing the post.
		/// </returns>
		/// <exception cref="ArgumentNullException">
		/// <paramref name="audioFile"/> is <b>null</b>.
		/// </exception>
		public static PostData CreateAudio(BinaryFile audioFile, string caption, IEnumerable<string> tags, PostCreationState state)
		{
			if (audioFile == null)
				throw new ArgumentNullException("audioFile");

			var postData = new PostData(state, tags);
			postData.parameters.Add("type", "audio");
			postData.parameters.Add(new BinaryMethodParameter("data", audioFile.Data, audioFile.FileName, audioFile.MimeType));
			postData.parameters.Add("caption", caption, null);

			return postData;
		}
Exemple #21
0
		/// <summary>
		/// Creates the <see cref="PostData"/> for a chat post.
		/// </summary>
		/// <param name="conversation">
		/// The chat conversation.
		/// </param>
		/// <param name="title">
		/// The title of the chat.
		/// </param>
		/// <param name="tags">
		/// The tags to associate with the post.
		/// </param>
		/// <param name="state">
		/// The <see cref="PostCreationState"/> of the post.
		/// </param>
		/// <returns>
		/// A <see cref="PostData"/> instance representing the post.
		/// </returns>
		/// <exception cref="ArgumentNullException">
		/// <paramref name="conversation"/> is <b>null</b>.
		/// </exception>
		/// <exception cref="ArgumentException">
		/// <paramref name="conversation"/> is empty.
		/// </exception>
		public static PostData CreateChat(string conversation, string title, IEnumerable<string> tags, PostCreationState state)
		{
			if (conversation == null)
				throw new ArgumentNullException("conversation");

			if (conversation.Length == 0)
				throw new ArgumentException("Conversation cannot be empty.", "conversation");

			var postData = new PostData(state, tags);
			postData.parameters.Add("type", "chat");
			postData.parameters.Add("conversation", conversation);
			postData.parameters.Add("title", title, null);

			return postData;
		}
Exemple #22
0
 public async void PostText(string name, string body, string title = null, IEnumerable <string> tags = null, PostCreationState pcs = PostCreationState.Published)
 {
     await _tumblrClient.CreatePostAsync(name, PostData.CreateText(body, title, tags, pcs));
 }
Exemple #23
0
		/// <summary>
		/// Creates the <see cref="PostData"/> for a video post.
		/// </summary>
		/// <param name="embedCode">
		/// The HTML embed code for the video.
		/// </param>
		/// <param name="caption">
		/// The caption for the video post.
		/// </param>
		/// <param name="tags">
		/// The tags to associate with the post.
		/// </param>
		/// <param name="state">
		/// The <see cref="PostCreationState"/> of the post.
		/// </param>
		/// <returns>
		/// A <see cref="PostData"/> instance representing the post.
		/// </returns>
		/// <exception cref="ArgumentNullException">
		/// <paramref name="embedCode"/> is <b>null</b>.
		/// </exception>
		/// <exception cref="ArgumentException">
		/// <paramref name="embedCode"/> is empty.
		/// </exception>
		public static PostData CreateVideo(string embedCode, string caption, IEnumerable<string> tags, PostCreationState state)
		{
			if (embedCode == null)
				throw new ArgumentNullException("embedCode");

			if (embedCode.Length == 0)
				throw new ArgumentException("Embed Code cannot be empty.", "embedCode");

			var postData = new PostData(state, tags);
			postData.parameters.Add("type", "video");
			postData.parameters.Add("embed", embedCode);
			postData.parameters.Add("caption", caption, null);

			return postData;
		}