Esempio 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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
 public static IEnumerable <Paste> PastesFromXML(string xml)
 {
     foreach (var paste in XElement.Parse("<pastes>" + xml + "</pastes>").Descendants("paste"))
     {
         yield return(Paste.FromXML(paste));
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Deletes a paste created by this user
        /// </summary>
        public async Task DeletePasteAsync(Paste paste)
        {
            var result = await PostRequestAsync(URL_API,
                                                "api_dev_key=" + Pastebin.DevKey,
                                                "api_user_key=" + userKey,
                                                "api_paste_key=" + paste.Key,
                                                "api_option=" + "delete");

            if (result.Contains(ERROR))
            {
                throw new PastebinException(result);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Deletes a paste created by this user
        /// </summary>
        public void DeletePaste(Paste paste)
        {
            var result = Utills.PostRequest(Utills.URL_API,
                                            "api_dev_key=" + Pastebin.DevKey,
                                            "api_user_key=" + userKey,
                                            "api_paste_key=" + paste.Key,
                                            "api_option=" + "delete");

            if (result.Contains(Utills.ERROR))
            {
                throw new PastebinException(result);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Deletes a paste created by this user
        /// </summary>
        public void DeletePaste(Paste paste)
        {
            var result = Utills.PostRequest(Utills.URL_API,
                                            "api_dev_key=" + Pastebin.DevKey,
                                            "api_user_key=" + userKey,
                                            "api_paste_key=" + paste.Key,
                                            "api_option=" + "delete");

            if (result.Contains(Utills.ERROR))
                throw new PastebinException(result);
        }
Esempio n. 7
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));
 }
Esempio n. 8
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));
 }
Esempio n. 9
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>http://pastebin.com/0b42rwhf</paste_url>
         <paste_hits>15</paste_hits>
     </paste>
      */
     var paste = new Paste();
     paste.Key = xpaste.Element("paste_key").Value;
     paste.CreateDate = Utills.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 ? Utills.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;
 }
Esempio n. 10
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;
        }