Example #1
0
        /// <summary>
        ///     Creates a new paste under the current user asynchronously.
        /// </summary>
        /// <param name="title">The title of the paste as it will appear on the page.</param>
        /// <param name="languageId">
        ///     The the language ID of the paste's content. A full list of language IDs can be found at
        ///     https://pastebin.com/api#5
        /// </param>
        /// <param name="code">The contents of the paste.</param>
        /// <param name="exposure">The visibility of the paste (private, public, or unlisted).</param>
        /// <param name="expiration">The duration of time the paste will be available before expiring.</param>
        /// <returns>The newly created <see cref="Paste" />.</returns>
        /// <exception cref="System.Net.WebException">Thrown when the underlying HTTP client encounters an error.</exception>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="code" /> is null.</exception>
        /// <exception cref="PastebinException">Thrown when a bad API request is made.</exception>
        public async Task <Paste> CreatePasteAsync(
            string title,
            string languageId,
            string code,
            PasteExposure?exposure     = null,
            PasteExpiration expiration = PasteExpiration.Never)
        {
            var parameters = PastebinClient.CreatePasteImpl(
                title,
                languageId,
                code,
                exposure ?? this.DefaultExposure,
                expiration);

            await this._agent.PostAsync(PastebinClient.PasteOption, parameters);

            return((await this.GetPastesAsync(1).ConfigureAwait(false)).Single());
        }
Example #2
0
        /// <summary>
        ///     Creates a new anonymous paste asynchronously. Private pastes are not allowed when pasting anonymously.
        /// </summary>
        /// <param name="title">The title of the paste as it will appear on the page.</param>
        /// <param name="languageId">
        ///     The the language ID of the paste's content. A full list of language IDs can be found at
        ///     https://pastebin.com/api#5
        /// </param>
        /// <param name="code">The contents of the paste.</param>
        /// <param name="exposure">The visibility of the paste (private, public, or unlisted).</param>
        /// <param name="expiration">The duration of time the paste will be available before expiring.</param>
        /// <returns>The URL for the newly created paste.</returns>
        /// <exception cref="System.Net.WebException">Thrown when the underlying HTTP client encounters an error.</exception>
        /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="code" /> is null.</exception>
        /// <exception cref="PastebinException">Thrown when a bad API request is made.</exception>
        public async Task <string> CreatePasteAsync(
            string title,
            string languageId,
            string code,
            PasteExposure exposure     = PasteExposure.Public,
            PasteExpiration expiration = PasteExpiration.Never
            )
        {
            var parameters = PastebinClient.CreatePasteImpl(
                title,
                languageId,
                code,
                exposure,
                expiration
                );

            return(await this._agent.PostAsync(PastebinClient.PasteOption, parameters).ConfigureAwait(false));
        }