Exemplo n.º 1
0
        internal static Paste FromXML(XElement xpaste)
        {
            /* Example paste xml
             * <paste>
             *      <paste_key>0b42rwhf</paste_key>
             *      <paste_date>1297953260</paste_date>
             *      <paste_title>javascript test</paste_title>
             *      <paste_size>15</paste_size>
             *      <paste_expire_date>1297956860</paste_expire_date>
             *      <paste_private>0</paste_private>
             *      <paste_format_long>JavaScript</paste_format_long>
             *      <paste_format_short>javascript</paste_format_short>
             *      <paste_url>https://pastebin.com/0b42rwhf</paste_url>
             *      <paste_hits>15</paste_hits>
             * </paste>
             */
            var paste = new Paste();

            paste.Key        = xpaste.Element("paste_key").Value;
            paste.CreateDate = GetDate((long)xpaste.Element("paste_date"));
            paste.Title      = xpaste.Element("paste_title").Value;
            paste.Size       = (int)xpaste.Element("paste_size");
            var exdate = (long)xpaste.Element("paste_expire_date");

            paste.ExpireDate = exdate != 0 ? GetDate(exdate) : paste.CreateDate;
            paste.Expiration = Expiration.FromTimeSpan(paste.ExpireDate - paste.CreateDate);
            paste.Visibility = (Visibility)(int)xpaste.Element("paste_private");
            paste.Language   = Language.Parse(xpaste.Element("paste_format_short").Value);
            paste.Url        = xpaste.Element("paste_url").Value;
            paste.Hits       = (int)xpaste.Element("paste_hits");
            return(paste);
        }
Exemplo n.º 2
0
 static Expiration()
 {
     Never      = new Expiration("N", TimeSpan.Zero);
     TenMinutes = new Expiration("10M", TimeSpan.FromMinutes(10));
     OneHour    = new Expiration("1H", TimeSpan.FromHours(1));
     OneDay     = new Expiration("1D", TimeSpan.FromDays(1));
     OneWeek    = new Expiration("1W", TimeSpan.FromDays(7));
     TwoWeeks   = new Expiration("2W", TimeSpan.FromDays(14));
     OneMonth   = new Expiration("1M", TimeSpan.FromDays(30));
     Default    = Never;
     All        = getExpirations();
 }
Exemplo n.º 3
0
 static Expiration()
 {
     Never = new Expiration("N", TimeSpan.Zero);
     TenMinutes = new Expiration("10M", TimeSpan.FromMinutes(10));
     OneHour = new Expiration("1H", TimeSpan.FromHours(1));
     OneDay = new Expiration("1D", TimeSpan.FromDays(1));
     OneWeek = new Expiration("1W", TimeSpan.FromDays(7));
     TwoWeeks = new Expiration("2W", TimeSpan.FromDays(14));
     OneMonth = new Expiration("1M", TimeSpan.FromDays(30));
     Default = Never;
     All = getExpirations();
 }
Exemplo n.º 4
0
 public static bool TryParse(string s, out Expiration result)
 {
     result = Default;
     if (s == null)
         return false;
     foreach (Expiration expiration in All)
     {
         if (s.ToUpper() == expiration.value)
         {
             result = expiration;
             return true;
         }
     }
     return false;
 }
Exemplo n.º 5
0
 public static bool TryParse(string s, out Expiration result)
 {
     result = Default;
     if (s == null)
     {
         return(false);
     }
     foreach (Expiration expiration in All)
     {
         if (s.ToUpper() == expiration.value)
         {
             result = expiration;
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 6
0
        /// <summary>
        /// Updates user preferences information properties
        /// </summary>
        public async Task RequestPreferencesAsync()
        {
            var result = await PostRequestAsync(URL_API,
                                                "api_dev_key=" + Pastebin.DevKey,
                                                "api_user_key=" + userKey,
                                                "api_option=" + "userdetails");

            if (result.Contains(ERROR))
            {
                throw new PastebinException(result);
            }

            /* Example user xml
             * <user>
             *   <user_name>wiz_kitty</user_name>
             *   <user_format_short>text</user_format_short>
             *   <user_expiration>N</user_expiration>
             *   <user_avatar_url>https://pastebin.com/cache/a/1.jpg</user_avatar_url>
             *   <user_private>1</user_private> (0 Public, 1 Unlisted, 2 Private)
             *   <user_website>http://myawesomesite.com</user_website>
             *   <user_email>[email protected]</user_email>
             *   <user_location>New York</user_location>
             *   <user_account_type>1</user_account_type> (0 normal, 1 PRO)
             * </user>*/
            XElement xuser = XElement.Parse(result);

            Name               = xuser.Element("user_name").Value;
            PreferedLanguage   = Language.Parse(xuser.Element("user_format_short").Value);
            PreferedExpiration = Expiration.Parse(xuser.Element("user_expiration").Value);
            PreferedVisibility = (Visibility)(int)xuser.Element("user_private");
            AvatarURL          = xuser.Element("user_avatar_url").Value;
            Website            = xuser.Element("user_website").Value;
            Email              = xuser.Element("user_email").Value;
            Location           = xuser.Element("user_location").Value;
            IsPro              = xuser.Element("user_account_type").Value == "1";
        }
Exemplo n.º 7
0
 /// <summary>
 /// Creates a new paste anonymously and uploads it to pastebin
 /// </summary>
 /// <returns>Paste object containing the Url given from Pastebin</returns>
 public static async Task <Paste> CreateAsync(string text, string title = null, Language language = null, Visibility visibility = Visibility.Public, Expiration expiration = null)
 {
     return(await CreateAsync("", text, title, language, visibility, expiration));
 }
Exemplo n.º 8
0
        internal static async Task <Paste> CreateAsync(string userKey, string text, string title = null, Language language = null, Visibility visibility = Visibility.Public, Expiration expiration = null)
        {
            title      = title ?? "Untitled";
            language   = language ?? Language.Default;
            expiration = expiration ?? Expiration.Default;

            var result = await PostRequestAsync(URL_API,
                                                //required parameters
                                                "api_dev_key=" + Pastebin.DevKey,
                                                "api_option=" + "paste",
                                                "api_paste_code=" + Uri.EscapeDataString(text),
                                                //optional parameters
                                                "api_user_key=" + userKey,
                                                "api_paste_name=" + Uri.EscapeDataString(title),
                                                "api_paste_format=" + language,
                                                "api_paste_private=" + (int)visibility,
                                                "api_paste_expire_date=" + expiration);

            if (result.Contains(ERROR))
            {
                throw new PastebinException(result);
            }

            var paste = new Paste();

            paste.Key        = result.Replace(URL, string.Empty);
            paste.CreateDate = DateTime.Now;
            paste.Title      = title;
            paste.Size       = Encoding.UTF8.GetByteCount(text);
            paste.ExpireDate = paste.CreateDate + expiration.Time;
            paste.Expiration = expiration;
            paste.Visibility = visibility;
            paste.Language   = language;
            paste.Hits       = 0;
            paste.Url        = result;
            paste.Text       = text;

            return(paste);
        }
Exemplo n.º 9
0
 /// <summary>
 /// Creates a new paste anonymously and uploads it to pastebin
 /// </summary>
 /// <returns>Paste object containing the Url given from Pastebin</returns>
 public static Paste Create(string text, string title = null, Language language = null, Visibility visibility = Visibility.Public, Expiration expiration = null)
 {
     return(Create("", text, title, language, visibility, expiration));
 }
Exemplo n.º 10
0
 /// <summary>
 /// Creates a new paste from this user and uploads it to pastebin.
 /// To create anonymous paste use Paste.Create() or User.Guest.CreatePaste()
 /// </summary>
 /// <param name="language">If left out then user's PreferedLanguage will be used</param>
 /// <param name="visibility">If left out then user's PreferedVisibility will be used</param>
 /// <param name="expiration">If left out then user's PreferedExpiration will be used</param>
 /// <returns>Paste object containing the Url given from Pastebin</returns>
 public Paste CreatePaste(string text, string title = null, Language language = null, Visibility? visibility = null, Expiration expiration = null)
 {
     return Paste.Create(userKey, text, title, language ?? PreferedLanguage, visibility ?? PreferedVisibility, expiration ?? PreferedExpiration);
 }
Exemplo n.º 11
0
 /// <summary>
 /// Creates a new paste from this user and uploads it to pastebin.
 /// To create anonymous paste use Paste.Create() or User.Guest.CreatePaste()
 /// </summary>
 /// <param name="language">If left out then user's PreferedLanguage will be used</param>
 /// <param name="visibility">If left out then user's PreferedVisibility will be used</param>
 /// <param name="expiration">If left out then user's PreferedExpiration will be used</param>
 /// <returns>Paste object containing the Url given from Pastebin</returns>
 public async Task <Paste> CreatePasteAsync(string text, string title = null, Language language = null, Visibility?visibility = null, Expiration expiration = null)
 {
     return(await Paste.CreateAsync(userKey, text, title, language ?? PreferedLanguage, visibility ?? PreferedVisibility, expiration ?? PreferedExpiration));
 }
Exemplo n.º 12
0
 /// <summary>
 /// Creates a new paste from this user and uploads it to pastebin.
 /// To create anonymous paste use Paste.Create() or User.Guest.CreatePaste()
 /// </summary>
 /// <param name="language">If left out then user's PreferedLanguage will be used</param>
 /// <param name="visibility">If left out then user's PreferedVisibility will be used</param>
 /// <param name="expiration">If left out then user's PreferedExpiration will be used</param>
 /// <returns>Paste object containing the Url given from Pastebin</returns>
 public Paste CreatePaste(string text, string title = null, Language language = null, Visibility?visibility = null, Expiration expiration = null)
 {
     return(Paste.Create(userKey, text, title, language ?? PreferedLanguage, visibility ?? PreferedVisibility, expiration ?? PreferedExpiration));
 }
Exemplo n.º 13
0
 /// <summary>
 /// Creates a new paste anonymously and uploads it to pastebin
 /// </summary>
 /// <returns>Paste object containing the Url given from Pastebin</returns>
 public static Paste Create(string text, string title = null, Language language = null, Visibility visibility = Visibility.Public, Expiration expiration = null)
 {
     return Create("", text, title, language, visibility, expiration);
 }
Exemplo n.º 14
0
        internal static Paste Create(string userKey, string text, string title = null, Language language = null, Visibility visibility = Visibility.Public, Expiration expiration = null)
        {
            var result = Utills.PostRequest(Utills.URL_API,
                                            //required parameters
                                            "api_dev_key=" + Pastebin.DevKey,
                                            "api_option=" + "paste",
                                            "api_paste_code=" + Uri.EscapeDataString(text),
                                            //optional parameters
                                            "api_user_key=" + userKey,
                                            "api_paste_name=" + Uri.EscapeDataString(title ?? "Untitled"),
                                            "api_paste_format=" + (language ?? Language.Default),
                                            "api_paste_private=" + (int)visibility,
                                            "api_paste_expire_date=" + (expiration ?? Expiration.Default));

            if (result.Contains(Utills.ERROR))
                throw new PastebinException(result);

            var paste = new Paste();
            paste.Key = result.Replace(Utills.URL, string.Empty);
            paste.CreateDate = DateTime.Now;
            paste.Title = title;
            paste.Size = Encoding.UTF8.GetByteCount(text);
            paste.ExpireDate = paste.CreateDate + expiration.Time;
            paste.Expiration = expiration;
            paste.Visibility = visibility;
            paste.Language = language;
            paste.Hits = 0;
            paste.Url = result;
            paste.Text = text;

            return paste;
        }