Beispiel #1
0
        /// <summary>
        ///     Initializes a new instance of <see cref="PastebinClient" /> with the specified API key.
        /// </summary>
        /// <param name="apiKey">
        ///     The API key to make requests with. An API key can be obtained by logging into https://pastebin.com
        ///     and going to https://pastebin.com/api
        /// </param>
        /// <param name="rateLimitMode">
        ///     Specifies how rate limiting should be handled See <see cref="RateLimitMode" /> for more
        ///     details.
        /// </param>
        public PastebinClient(string apiKey, RateLimitMode rateLimitMode = RateLimitMode.None)
        {
            if (apiKey == null)
            {
                throw new ArgumentNullException(nameof(apiKey));
            }

            this._agent = new HttpWebAgent(apiKey, rateLimitMode);
        }
Beispiel #2
0
        public async Task <string> CreateAndExecuteAsync(
            string url,
            string method,
            Dictionary <string, object> parameters)
        {
            var request = await this.CreateRequestAsync(url, method, parameters).ConfigureAwait(false);

            return(await HttpWebAgent.ExecuteRequestAsync(request).ConfigureAwait(false));
        }
Beispiel #3
0
 internal User(HttpWebAgent agent, XContainer user)
 {
     this._agent            = agent;
     this.Username          = user.Element("user_name").Value;
     this.DefaultFormat     = user.Element("user_format_short").Value;
     this.DefaultExpiration = user.Element("user_expiration").Value;
     this.AvatarUrl         = user.Element("user_avatar_url").Value;
     this.Website           = user.Element("user_website").Value;
     this.Email             = user.Element("user_email").Value;
     this.Location          = user.Element("user_location").Value;
     this.DefaultExposure   = (PasteExposure)Int32.Parse(user.Element("user_private").Value);
     this.AccountType       = (AccountType)Int32.Parse(user.Element("user_account_type").Value);
 }
Beispiel #4
0
 internal Paste(HttpWebAgent agent, XContainer paste)
 {
     this._agent           = agent;
     this.Id               = paste.Element("paste_key").Value;
     this.Timestamp        = Int64.Parse(paste.Element("paste_date").Value);
     this.Title            = paste.Element("paste_title").Value;
     this.Size             = Int64.Parse(paste.Element("paste_size").Value);
     this._expireTimestamp = Int64.Parse(paste.Element("paste_expire_date").Value);
     this.Exposure         = (PasteExposure)Int32.Parse(paste.Element("paste_private").Value);
     this.LanguageName     = paste.Element("paste_format_long")?.Value;
     this.LanguageId       = paste.Element("paste_format_short")?.Value;
     this.Url              = paste.Element("paste_url").Value;
     this.Views            = Int64.Parse(paste.Element("paste_hits").Value);
 }
Beispiel #5
0
        public static async Task <string> ExecuteRequestAsync(WebRequest request)
        {
            var response = await request.GetResponseAsync().ConfigureAwait(false);

            string text;

            // ReSharper disable once AssignNullToNotNullAttribute
            using (var stream = response.GetResponseStream())
                using (var reader = new StreamReader(stream, Encoding.UTF8))
                {
                    text = await reader.ReadToEndAsync().ConfigureAwait(false);
                }

            HttpWebAgent.HandleResponseString(text);
            return(text);
        }
Beispiel #6
0
        public async Task <WebRequest> CreateRequestAsync(
            string endPoint,
            string method,
            Dictionary <string, object> parameters)
        {
            await this.EnforceRateLimitAsync().ConfigureAwait(false);

            var request = this.CreateRequestImpl(endPoint, method, parameters, out var query);

            if (method != "POST")
            {
                return(request);
            }

            await HttpWebAgent.WritePostDataAsync(request, query).ConfigureAwait(false);

            return(request);
        }