Esempio n. 1
0
		/// <summary>
		/// Asynchronously edits an existing post.
		/// </summary>
		/// <remarks>
		/// See: http://www.tumblr.com/docs/en/api/v2#editing
		/// </remarks>
		/// <param name="blogName">
		/// The name of the blog where the post to edit is (must be one of the current user's blogs).
		/// </param>
		/// <param name="postId">
		/// The identifier of the post to edit.
		/// </param>
		/// <param name="postData">
		/// The data that represents the updated information for the post. See <see cref="PostData"/> for how
		/// to create various post types.
		/// </param>
		/// <param name="cancellationToken">
		/// A <see cref="CancellationToken"/> that can be used to cancel the operation.
		/// </param>
		/// <returns>
		/// A <see cref="Task{T}"/> that can be used to track the operation. If the task succeeds, the <see cref="Task{T}.Result"/> will
		/// carry a <see cref="PostCreationInfo"/> instance. Otherwise <see cref="Task.Exception"/> will carry a <see cref="TumblrException"/>
		/// representing the error occurred during the call.
		/// </returns>
		/// <exception cref="ObjectDisposedException">
		/// The object has been disposed.
		/// </exception>
		/// <exception cref="ArgumentNullException">
		/// <list type="bullet">
		/// <item>
		///		<description>
		///			<paramref name="blogName"/> is <b>null</b>.
		///		</description>
		///	</item>
		///	<item>
		///		<description>
		///			<paramref name="postData"/> is <b>null</b>.
		///		</description>
		///	</item>
		/// </list>
		/// </exception>
		/// <exception cref="ArgumentException">
		/// <list type="bullet">
		/// <item>
		///		<description>
		///			<paramref name="blogName"/> is empty.
		///		</description>
		///	</item>
		///	<item>
		///		<description>
		///			<paramref name="postId"/> is less than 0.
		///		</description>
		///	</item>
		/// </list>
		/// </exception>
		/// <exception cref="InvalidOperationException">
		/// This <see cref="TumblrClient"/> instance does not have an OAuth token specified.
		/// </exception>
		public Task<PostCreationInfo> EditPostAsync(string blogName, long postId, PostData postData, CancellationToken cancellationToken)
		{
			if (disposed)
				throw new ObjectDisposedException("TumblrClient");

			if (blogName == null)
				throw new ArgumentNullException("blogName");

			if (blogName.Length == 0)
				throw new ArgumentException("Blog name cannot be empty.", "blogName");

			if (postId < 0)
				throw new ArgumentOutOfRangeException("postId", "Post ID must be greater or equal to zero.");

			if (postData == null)
				throw new ArgumentNullException("postData");

			if (OAuthToken == null)
				throw new InvalidOperationException("EditPostAsync method requires an OAuth token to be specified.");

			var parameters = postData.ToMethodParameterSet();
			parameters.Add("id", postId);

			return CallApiMethodAsync<PostCreationInfo>(
				new BlogMethod(blogName, "post/edit", OAuthToken, HttpMethod.Post, parameters),
				CancellationToken.None);
		}
Esempio n. 2
0
		/// <summary>
		/// Asynchronously creates a new post.
		/// </summary>
		/// <remarks>
		/// See: http://www.tumblr.com/docs/en/api/v2#posting
		/// </remarks>
		/// <param name="blogName">
		/// The name of the blog where to post to (must be one of the current user's blogs).
		/// </param>
		/// <param name="postData">
		/// The data that represents the type of post to create. See <see cref="PostData"/> for how
		/// to create various post types.
		/// </param>
		/// <param name="cancellationToken">
		/// A <see cref="CancellationToken"/> that can be used to cancel the operation.
		/// </param>
		/// <returns>
		/// A <see cref="Task{T}"/> that can be used to track the operation. If the task succeeds, the <see cref="Task{T}.Result"/> will
		/// carry a <see cref="PostCreationInfo"/> instance. Otherwise <see cref="Task.Exception"/> will carry a <see cref="TumblrException"/>
		/// representing the error occurred during the call.
		/// </returns>
		/// <exception cref="ObjectDisposedException">
		/// The object has been disposed.
		/// </exception>
		/// <exception cref="ArgumentNullException">
		/// <list type="bullet">
		/// <item>
		///		<description>
		///			<paramref name="blogName"/> is <b>null</b>.
		///		</description>
		///	</item>
		///	<item>
		///		<description>
		///			<paramref name="postData"/> is <b>null</b>.
		///		</description>
		///	</item>
		/// </list>
		/// </exception>
		/// <exception cref="ArgumentException">
		/// <paramref name="blogName"/> is empty.
		/// </exception>
		/// <exception cref="InvalidOperationException">
		/// This <see cref="TumblrClient"/> instance does not have an OAuth token specified.
		/// </exception>
		public Task<PostCreationInfo> CreatePostAsync(string blogName, PostData postData, CancellationToken cancellationToken)
		{
			if (disposed)
				throw new ObjectDisposedException("TumblrClient");

			if (blogName == null)
				throw new ArgumentNullException("blogName");

			if (blogName.Length == 0)
				throw new ArgumentException("Blog name cannot be empty.", "blogName");

			if (postData == null)
				throw new ArgumentNullException("postData");

			if (OAuthToken == null)
				throw new InvalidOperationException("CreatePostAsync method requires an OAuth token to be specified.");

			return CallApiMethodAsync<PostCreationInfo>(
				new BlogMethod(blogName, "post", OAuthToken, HttpMethod.Post, postData.ToMethodParameterSet()),
				cancellationToken);
		}