internal static Paste Create(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 = 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), "api_paste_format=" + language, "api_paste_private=" + (int)visibility, "api_paste_expire_date=" + expiration); 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); }
/// <summary> /// Updates user preferences information properties /// </summary> public void RequestPreferences() { var result = Utills.PostRequest(Utills.URL_API, "api_dev_key=" + Pastebin.DevKey, "api_user_key=" + userKey, "api_option=" + "userdetails"); if (result.Contains(Utills.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>http://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"; }