Пример #1
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;
		}
Пример #2
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;
		}
Пример #3
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;
		}
Пример #4
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;
		}
Пример #5
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;
		}
Пример #6
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;
		}
Пример #7
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;
		}
Пример #8
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;
		}