Exemplo n.º 1
0
 internal User(WebAgent agent, XElement user)
 {
     this.agent             = agent;
     this.username          = user.Get("user_name");
     this.defaultFormat     = user.Get("user_format_short");
     this.defaultExpiration = user.Get("user_expiration");
     this.avatarUrl         = user.Get("user_avatar_url");
     this.website           = user.Get("user_website");
     this.email             = user.Get("user_email");
     this.location          = user.Get("user_location");
     this.defaultExposure   = user.Get <PasteExposure, int>("user_private", Int32.Parse);
     this.accountType       = user.Get <AccountType, int>("user_account_type", Int32.Parse);
 }
Exemplo n.º 2
0
 internal User( WebAgent agent, XElement user )
 {
     this.agent = agent;
     this.username = user.Get( "user_name" );
     this.defaultFormat = user.Get( "user_format_short" );
     this.defaultExpiration = user.Get( "user_expiration" );
     this.avatarUrl = user.Get( "user_avatar_url" );
     this.website = user.Get( "user_website" );
     this.email = user.Get( "user_email" );
     this.location = user.Get( "user_location" );
     this.defaultExposure = user.Get<PasteExposure, int>( "user_private", Int32.Parse );
     this.accountType = user.Get<AccountType, int>( "user_account_type", Int32.Parse );
 }
Exemplo n.º 3
0
 internal Paste(WebAgent agent, XElement paste)
 {
     this.agent           = agent;
     this.key             = paste.Get("paste_key");
     this.timestamp       = paste.Get("paste_date", Int32.Parse);
     this.title           = paste.Get("paste_title");
     this.size            = paste.Get("paste_size", Int32.Parse);
     this.expireTimestamp = paste.Get("paste_expire_date", Int32.Parse);
     this.exposure        = paste.Get <PasteExposure, int>("paste_private", Int32.Parse);
     this.formatName      = paste.HasValueFor("paste_format_long") ? paste.Get("paste_format_long") : null;
     this.formatId        = paste.HasValueFor("paste_format_short") ? paste.Get("paste_format_short") : null;
     this.url             = paste.Get("paste_url");
     this.views           = paste.Get("paste_hits", Int32.Parse);
 }
Exemplo n.º 4
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));
        }
Exemplo n.º 5
0
        internal static string CreatePasteImpl( WebAgent agent, bool authenticated, string title, string languageId, string code, PasteExposure exposure, PasteExpiration expiration )
        {
            if( code == null )
                throw new ArgumentNullException( "code" );

            if( title == null )
                title = "Untitled";

            if( languageId == null )
                languageId = "text";

            string expirationString;
            switch( expiration )
            {
                case PasteExpiration.Never:
                    expirationString = "N";
                    break;

                case PasteExpiration.OneDay:
                    expirationString = "1D";
                    break;

                case PasteExpiration.OneHour:
                    expirationString = "1H";
                    break;

                case PasteExpiration.OneMonth:
                    expirationString = "1M";
                    break;

                case PasteExpiration.OneWeek:
                    expirationString = "1W";
                    break;

                case PasteExpiration.TenMinutes:
                    expirationString = "10M";
                    break;

                case PasteExpiration.TwoWeeks:
                    expirationString = "2W";
                    break;

                default:
                    throw new NotImplementedException();
            }

            var parameters = new Dictionary<string, object>
            {
                { "api_paste_code", code },
                { "api_paste_name", title },
                { "api_paste_format", languageId },
                { "api_paste_private", (int)exposure },
                { "api_paste_expire_date", expirationString },
            };

            return agent.Post( PasteOption, parameters );
        }
Exemplo n.º 6
0
 /// <summary>
 /// Creates a new anonymous paste. 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 http://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 string CreatePaste( string title, string languageId, string code, PasteExposure exposure = PasteExposure.Public, PasteExpiration expiration = PasteExpiration.Never )
 {
     return Pastebin.CreatePasteImpl( this.agent, false, title, languageId, code, exposure, expiration );
 }
Exemplo n.º 7
0
 internal Paste( WebAgent agent, XElement paste )
 {
     this.agent = agent;
     this.key = paste.Value( "paste_key" );
     this.timestamp = paste.Value( "paste_date", Int32.Parse );
     this.title = paste.Value( "paste_title" );
     this.size = paste.Value( "paste_size", Int32.Parse );
     this.expireTimestamp = paste.Value( "paste_expire_date", Int32.Parse );
     this.exposure = (PasteExposure)paste.Value( "paste_private", Int32.Parse );
     this.formatName = paste.ValueOrDefault( "paste_format_long" );
     this.formatId = paste.ValueOrDefault( "paste_format_short" );
     this.url = paste.Value( "paste_url" );
     this.views = paste.Value( "paste_hits", Int32.Parse );
 }
Exemplo n.º 8
0
 /// <summary>
 /// Creates a new paste under the current user.
 /// </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 http://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 string CreatePaste(string title, string languageId, string code, PasteExposure exposure = PasteExposure.Public, PasteExpiration expiration = PasteExpiration.Never)
 {
     return(Pastebin.CreatePasteImpl(this.agent, true, title, languageId, code, exposure, expiration));
 }
Exemplo n.º 9
0
        internal static Dictionary <string, object> CreatePasteImpl(
            string title,
            string languageId,
            string code,
            PasteExposure exposure,
            PasteExpiration expiration)
        {
            if (code == null)
            {
                throw new ArgumentNullException(nameof(code));
            }

            if (title == null)
            {
                title = "Untitled";
            }

            if (languageId == null)
            {
                languageId = "text";
            }

            string expirationString;

            switch (expiration)
            {
            case PasteExpiration.Never:
                expirationString = "N";
                break;

            case PasteExpiration.OneDay:
                expirationString = "1D";
                break;

            case PasteExpiration.OneHour:
                expirationString = "1H";
                break;

            case PasteExpiration.OneMonth:
                expirationString = "1M";
                break;

            case PasteExpiration.OneWeek:
                expirationString = "1W";
                break;

            case PasteExpiration.TenMinutes:
                expirationString = "10M";
                break;

            case PasteExpiration.TwoWeeks:
                expirationString = "2W";
                break;

            default: throw new NotSupportedException();
            }

            return(new Dictionary <string, object>
            {
                { "api_paste_code", code },
                { "api_paste_name", title },
                { "api_paste_format", languageId },
                { "api_paste_private", (int)exposure },
                { "api_paste_expire_date", expirationString }
            });
        }
Exemplo n.º 10
0
 internal Paste( WebAgent agent, XElement paste )
 {
     this.agent = agent;
     this.key = paste.Get( "paste_key" );
     this.timestamp = paste.Get( "paste_date", Int32.Parse );
     this.title = paste.Get( "paste_title" );
     this.size = paste.Get( "paste_size", Int32.Parse );
     this.expireTimestamp = paste.Get( "paste_expire_date", Int32.Parse );
     this.exposure = paste.Get<PasteExposure, int>( "paste_private", Int32.Parse );
     this.formatName = paste.HasValueFor( "paste_format_long" ) ? paste.Get( "paste_format_long" ) : null;
     this.formatId = paste.HasValueFor( "paste_format_short" ) ? paste.Get( "paste_format_short" ) : null;
     this.url = paste.Get( "paste_url" );
     this.views = paste.Get( "paste_hits", Int32.Parse );
 }
Exemplo n.º 11
0
        internal static string CreatePasteImpl(WebAgent agent, bool authenticated, string title, string languageId, string code, PasteExposure exposure, PasteExpiration expiration)
        {
            if (code == null)
            {
                throw new ArgumentNullException("code");
            }

            if (title == null)
            {
                title = "Untitled";
            }

            if (languageId == null)
            {
                languageId = "text";
            }

            string expirationString;

            switch (expiration)
            {
            case PasteExpiration.Never:
                expirationString = "N";
                break;

            case PasteExpiration.OneDay:
                expirationString = "1D";
                break;

            case PasteExpiration.OneHour:
                expirationString = "1H";
                break;

            case PasteExpiration.OneMonth:
                expirationString = "1M";
                break;

            case PasteExpiration.OneWeek:
                expirationString = "1W";
                break;

            case PasteExpiration.TenMinutes:
                expirationString = "10M";
                break;

            case PasteExpiration.TwoWeeks:
                expirationString = "2W";
                break;

            default:
                throw new NotImplementedException();
            }

            var parameters = new Dictionary <string, object>
            {
                { "api_paste_code", code },
                { "api_paste_name", title },
                { "api_paste_format", languageId },
                { "api_paste_private", (int)exposure },
                { "api_paste_expire_date", expirationString },
            };

            return(agent.Post(PasteOption, parameters, authenticated));
        }