Example #1
0
        /// <summary>
        /// Get paste code in raw version
        /// </summary>
        /// <param name="pasteInfo">Paste information. Require field <seealso cref="PasteInfo.Key"/></param>
        public async Task <PasteInfo> GetRawPaste(PasteInfo pasteInfo)
        {
            var url     = new Uri("https://pastebin.com/api/api_raw.php");
            var content = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("api_option", "show_paste"),
                new KeyValuePair <string, string>("api_user_key", UserApiKey),
                new KeyValuePair <string, string>("api_dev_key", DeveloperApiKey),
                new KeyValuePair <string, string>("api_paste_key", pasteInfo.Key)
            });

            var result = WebAgent.Execute(url, content).Result;

            if (result.IsSuccessStatusCode)
            {
                pasteInfo.Code = await result.Content.ReadAsStringAsync().ConfigureAwait(false);

                return(pasteInfo);
            }

            throw new HttpRequestException("Something went wrong");
        }
Example #2
0
        /// <summary>
        /// Return user`s info and settings
        /// </summary>
        public async Task <UserInfo> GetUserInfoAndSettings()
        {
            var url = new Uri("https://pastebin.com/api/api_post.php");

            var content = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("api_option", "userdetails"),
                new KeyValuePair <string, string>("api_user_key", UserApiKey),
                new KeyValuePair <string, string>("api_dev_key", DeveloperApiKey),
            });

            var result = WebAgent.Execute(url, content).Result;

            if (result.IsSuccessStatusCode)
            {
                var xml = await result.Content.ReadAsStringAsync().ConfigureAwait(false);

                return(ParseUserInfo(xml));
            }

            throw new Exception("Something went wrong");
        }
Example #3
0
        /// <summary>
        /// Create new paste as user
        /// </summary>
        /// <param name="pasteInfo">Paste information. Required fields: <seealso cref="PasteInfo.Private"/>, <see cref="PasteInfo.Name"/>,
        /// <seealso cref="PasteInfo.ExpireDate"/>, <seealso cref="PasteInfo.Language"/>, <seealso cref="PasteInfo.Code"/></param>
        /// <returns>Paste information <seealso cref="PasteInfo"/></returns>
        public async Task <PasteInfo> CreateNewPasteAsUserAsync(PasteInfo pasteInfo, string userApiKey)
        {
            var baseAddress = new Uri("https://pastebin.com/api/api_post.php");
            var content     = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("api_option", "paste"),
                new KeyValuePair <string, string>("api_user_key", userApiKey),
                new KeyValuePair <string, string>("api_paste_private", ((int)pasteInfo.Private).ToString()),
                new KeyValuePair <string, string>("api_paste_name", pasteInfo.Name),
                new KeyValuePair <string, string>("api_paste_expire_date", ConvertPasteExpireDateToString(pasteInfo.ExpireDate)),
                new KeyValuePair <string, string>("api_paste_format", Enum.GetName(typeof(PasteLanguage), pasteInfo.Language)),
                new KeyValuePair <string, string>("api_dev_key", DeveloperApiKey),
                new KeyValuePair <string, string>("api_paste_code", pasteInfo.Code)
            });

            var result = WebAgent.Execute(baseAddress, content).Result;

            if (result.IsSuccessStatusCode)
            {
                pasteInfo.Link = await result.Content.ReadAsStringAsync().ConfigureAwait(false);
            }

            return(pasteInfo);
        }
Example #4
0
        /// <summary>
        /// Get list of user`s pastes info
        /// </summary>
        public async Task <List <PasteInfo> > GetUserPastes(int resultsLimit = 50)
        {
            var url     = new Uri("https://pastebin.com/api/api_post.php");
            var content = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("api_option", "list"),
                new KeyValuePair <string, string>("api_user_key", UserApiKey),
                new KeyValuePair <string, string>("api_dev_key", DeveloperApiKey),
                new KeyValuePair <string, string>("api_results_limit", resultsLimit.ToString())
            });

            var result = WebAgent.Execute(url, content).Result;

            if (result.IsSuccessStatusCode)
            {
                var xml = await result.Content.ReadAsStringAsync().ConfigureAwait(false);

                var sb = new StringBuilder();
                sb.Append("<pastes> ").Append(xml).Append(" </pastes>");

                return(ParsePastes(sb.ToString()));
            }
            throw new Exception("Something went wrong");
        }