public string Login(PasteLoginRequest request)
        {
            var queryValues = new QueryValues();

            queryValues.Add("api_user_name", request.Name);
            queryValues.Add("api_user_password", request.Password);

            var webRequest = this.CreateWebRequest(this.LoginUri, queryValues);
            var userKey    = this.ProcessWebRequest(webRequest);

            return(userKey);
        }
        public string GetPasteRaw(PasteGetRawRequest request)
        {
            var queryValues = new QueryValues();

            queryValues.Add("api_option", "show_paste");
            queryValues.Add("api_user_key", request.UserKey);
            queryValues.Add("api_paste_key", request.PasteKey);

            var webRequest = this.CreateWebRequest(this.RawUri, queryValues);
            var raw        = this.ProcessWebRequest(webRequest);

            return(raw);
        }
        public bool DeletePaste(PasteDeleteRequest request)
        {
            var queryValues = new QueryValues();

            queryValues.Add("api_option", "delete");
            queryValues.Add("api_user_key", request.UserKey);
            queryValues.Add("api_paste_key", request.PasteKey);

            var webRequest = this.CreateWebRequest(this.BaseUri, queryValues);
            var result     = this.ProcessWebRequest(webRequest);

            return(result.Equals("Paste Removed", StringComparison.OrdinalIgnoreCase));
        }
        public static QueryValues Parse(string str)
        {
            str = StringUtils.RemovePrefix(str, HttpUtility2.QuerySeparator);
            var splits = str.Split(HttpUtility2.QueryValuesDelimiter);

            var queryValues    = new QueryValues();
            var valueDelimiter = QueryValue.ValueDelimiter;

            foreach (var pair in splits)
            {
                if (string.IsNullOrWhiteSpace(pair) == false)
                {
                    var    delimiterIndex = pair.IndexOf(valueDelimiter);
                    string key            = null;
                    string value          = null;

                    if (delimiterIndex == -1)
                    {
                        key = pair;
                    }
                    else
                    {
                        key = pair.Substring(0, delimiterIndex);
                        var valueStartIndex = delimiterIndex + valueDelimiter.Length;
                        value = pair.Substring(valueStartIndex, pair.Length - valueStartIndex);
                    }

                    queryValues.Add(new QueryValue(key, value));
                }
            }

            return(queryValues);
        }
        public PasteUser GetUser(string userKey)
        {
            var queryValues = new QueryValues();

            queryValues.Add("api_option", "userdetails");
            queryValues.Add("api_user_key", userKey);

            var webRequest = this.CreateWebRequest(this.BaseUri, queryValues);
            var html       = this.ProcessWebRequest(webRequest);
            var document   = new HtmlDocument();

            document.LoadHtml(html);

            var userNode = document.DocumentNode.ChildNodes["user"];
            var user     = new PasteUser(userNode);

            return(user);
        }
        public PasteData[] ListPastes(PasteListRequest request)
        {
            var queryValues = new QueryValues();

            queryValues.Add("api_option", "list");
            queryValues.Add("api_user_key", request.UserKey);
            queryValues.Add("api_results_limit", request.ResultsLimit);

            var webRequest = this.CreateWebRequest(this.BaseUri, queryValues);
            var html       = this.ProcessWebRequest(webRequest);
            var document   = new HtmlDocument();

            document.LoadHtml(html);

            var pasteNodes = document.DocumentNode.ChildNodes.Where(n => n.Name.Equals("paste")).ToArray();
            var pasteArray = pasteNodes.Select(n => new PasteData(n)).ToArray();

            return(pasteArray);
        }
        public string CreatePaste(PasteCreateRequest request)
        {
            var queryValues = new QueryValues();

            queryValues.Add("api_option", "paste");
            queryValues.Add("api_user_key", request.UserKey);
            queryValues.Add("api_paste_private", ((byte)request.Private).ToString());
            queryValues.Add("api_paste_name", HttpUtility.UrlEncode(request.Name));
            queryValues.Add("api_paste_expire_date", request.ExpireDate?.Value);
            queryValues.Add("api_paste_format", request.Format);
            queryValues.Add("api_dev_key", this.APIKey);
            queryValues.Add("api_paste_code", HttpUtility.UrlEncode(request.Code));

            var webRequest = this.CreateWebRequest(this.BaseUri, queryValues);
            var url        = this.ProcessWebRequest(webRequest);

            return(url);
        }
        public WebRequestParameter CreateWebRequest(string uri, QueryValues values)
        {
            var apiKeyName = "api_dev_key";
            var overrides  = new QueryValues(values);

            overrides.RemoveAll(apiKeyName);
            overrides.Add(apiKeyName, this.APIKey);

            var request = new WebRequestParameter();

            request.Method         = "POST";
            request.Uri            = uri;
            request.ContentType    = "application/x-www-form-urlencoded";
            request.WriteParameter = overrides.ToString(false, false);

            return(request);
        }