private IEnumerable <RestResponse> Raw(Task <HttpResponseMessage> func, RestSettings restSettings)
        {
            Contract.EnsureWebhookIsNotBroken(_webhook.Status);

            var currentAttempts = 0U;
            // Used to prevent calls if something went wrong
            var forceStop    = false;
            var lastResponse = default(RestResponse);

            do
            {
                if (lastResponse.IsValid())
                {
                    _webhook.ActionManager.FollowRateLimit(lastResponse.RateLimit).ConfigureAwait(false).GetAwaiter().GetResult();
                }

                using var response = func.ConfigureAwait(false).GetAwaiter().GetResult();
                var rateLimitInfo = RateLimitInfo.Get(response.Headers);
                using var responseStream = response.Content.ReadAsStreamAsync().ConfigureAwait(false).GetAwaiter().GetResult();
                lastResponse             = new RestResponse(response.StatusCode, rateLimitInfo, responseStream, currentAttempts);

                // Processing the necessary status codes
                ProcessStatusCode(response.StatusCode, ref forceStop);

                yield return(lastResponse);
            } while (!forceStop && !lastResponse.IsSuccessful && (restSettings.Attempts == 0 || ++currentAttempts <= restSettings.Attempts));
        }
 public override IEnumerable <RestResponse> DELETE(string url, RestSettings restSettings)
 {
     Contract.AssertArgumentNotTrue(string.IsNullOrEmpty(url), nameof(url));
     return(Raw(_httpClient.DeleteAsync(url), restSettings));
 }
        public override IEnumerable <RestResponse> PATCH(string url, SerializationContext data, RestSettings restSettings)
        {
            Contract.AssertArgumentNotTrue(string.IsNullOrEmpty(url), nameof(url));
            Contract.AssertRequiredSerizationType(data, SerializationType.APPLICATION_JSON);

            using HttpRequestMessage requestMessage = new HttpRequestMessage(PATCHMethod, url);
            PrepareContent(requestMessage, data);
            return(Raw(_httpClient.SendAsync(requestMessage), restSettings));
        }
        public override IEnumerable <RestResponse> POST(string url, SerializationContext data, RestSettings restSettings)
        {
            Contract.AssertArgumentNotTrue(string.IsNullOrEmpty(url), nameof(url));

            using HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, url);
            PrepareContent(requestMessage, data);
            return(Raw(_httpClient.SendAsync(requestMessage), restSettings));
        }