Example #1
0
        /// <summary>
        /// Initializes a new instance of <see cref="Pastebin.Pastebin"/> with the specified API key.
        /// </summary>
        /// <param name="apiKey">The API key to make requests with. An API key can be obtained by logging into pastebin.com and going to http://pastebin.com/api </param>
        public Pastebin( string apiKey )
        {
            if( apiKey == null )
                throw new ArgumentNullException( "apiKey" );

            this.agent = new WebAgent( apiKey );
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of <see cref="Pastebin.Pastebin"/> with the specified API key.
        /// </summary>
        /// <param name="apiKey">The API key to make requests with. An API key can be obtained by logging into pastebin.com and going to http://pastebin.com/api </param>
        /// <param name="rateLimitMode">Specifies how rate limiting should be handled See <see cref="RateLimitMode" /> for more details.</param>
        public Pastebin( string apiKey, RateLimitMode rateLimitMode = RateLimitMode.None )
        {
            if( apiKey == null )
                throw new ArgumentNullException( "apiKey" );

            this.agent = new WebAgent( apiKey, rateLimitMode );
        }
Example #3
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 );
 }
Example #4
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 );
        }
Example #5
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 );
 }
Example #6
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 );
 }
Example #7
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));
        }