<commit_before>﻿using Newtonsoft.Json;
using System;
using System.Net.Http;
using System.Threading.Tasks;

namespace Twitch.Rest
{
    internal class RestApiClient : IDisposable
    {
        private HttpClient _http;
        private string _clientid;
        private string _baseurl;

        internal RestApiClient(string clientid, string baseurl)
        {
            _clientid = clientid;
            _baseurl = baseurl;
        }

        internal void EnsureHttpClientCreated()
        {
            if (_http == null)
            {
                var http = new HttpClient();

                http.BaseAddress = new Uri(_baseurl);
                http.DefaultRequestHeaders.Add("Accept", "application/vnd.twitchtv.v2+json");
                http.DefaultRequestHeaders.Add("Client-ID", _clientid);

                _http = http;
            }
        }

        internal async Task SendAsync(string method, string endpoint, object payload)
        {
            EnsureHttpClientCreated();
            var request = new HttpRequestMessage(new HttpMethod(method), endpoint);

            var response = await _http.SendAsync(request);
            if (!response.IsSuccessStatusCode)
                throw new HttpRequestException($"{(int)response.StatusCode}: {response.ReasonPhrase}");
        }

        internal async Task<T> SendAsync<T>(string method, string endpoint, object payload)
        {
            EnsureHttpClientCreated();
            var request = new HttpRequestMessage(new HttpMethod(method), endpoint);

            var response = await _http.SendAsync(request);
            if (!response.IsSuccessStatusCode)
            {
                throw new HttpRequestException($"{(int)response.StatusCode}: {response.ReasonPhrase}");
            }
            else
            {
                string content = await response.Content.ReadAsStringAsync();
                return JsonConvert.DeserializeObject<T>(content);
            }
        }

        internal async Task LoginAsync()
        {
            await Task.Delay(1);
        }

        public void Dispose()
        {
            _http.Dispose();
        }
    }
}<commit_msg>Add payloads to restapiclient requests<commit_after>﻿using Newtonsoft.Json;
using System;
using System.Net.Http;
using System.Threading.Tasks;

namespace Twitch.Rest
{
    internal class RestApiClient : IDisposable
    {
        private HttpClient _http;
        private string _clientid;
        private string _baseurl;

        internal RestApiClient(string clientid, string baseurl)
        {
            _clientid = clientid;
            _baseurl = baseurl;
        }

        internal void EnsureHttpClientCreated()
        {
            if (_http == null)
            {
                var http = new HttpClient();

                http.BaseAddress = new Uri(_baseurl);
                http.DefaultRequestHeaders.Add("Accept", "application/vnd.twitchtv.v2+json");
                http.DefaultRequestHeaders.Add("Client-ID", _clientid);

                _http = http;
            }
        }

        internal async Task SendAsync(string method, string endpoint, object payload = null)
        {
            EnsureHttpClientCreated();
            var request = new HttpRequestMessage(new HttpMethod(method), endpoint);

            if (payload != null)
                request.Content = new StringContent(JsonConvert.SerializeObject(payload));

            var response = await _http.SendAsync(request);
            if (!response.IsSuccessStatusCode)
                throw new HttpRequestException($"{(int)response.StatusCode}: {response.ReasonPhrase}");
        }

        internal async Task<T> SendAsync<T>(string method, string endpoint, object payload = null)
        {
            EnsureHttpClientCreated();
            var request = new HttpRequestMessage(new HttpMethod(method), endpoint);

            if (payload != null)
                request.Content = new StringContent(JsonConvert.SerializeObject(payload));

            var response = await _http.SendAsync(request);
            if (!response.IsSuccessStatusCode)
            {
                throw new HttpRequestException($"{(int)response.StatusCode}: {response.ReasonPhrase}");
            }
            else
            {
                string content = await response.Content.ReadAsStringAsync();
                return JsonConvert.DeserializeObject<T>(content);
            }
        }

        internal async Task LoginAsync(string token)
        {
            await Task.Delay(1);
        }

        public void Dispose()
        {
            _http.Dispose();
        }
    }
}
{'fraction_non_alphanumeric': 0.08833080753409829, 'fraction_numerical': 0.0008659883091578263, 'mean_word_length': 1.8875, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2221264', 'n_tokens_mistral': 1146, 'n_tokens_neox': 1117, 'n_words': 259}