<commit_before>﻿using System.IO;
using System.Net;
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

namespace PowerBIDotNet
{

    public class Communication : ICommunication
    {
        static JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() };
        const string baseUrl = "https://api.powerbi.com/v1.0/myorg/";


        public T Get<T>(Token token, string action)
        {
            var request = CreateRequest(token, action, "GET");
            return Get<T>(request);
        }

        public void Put<TInput>(
            Token token,
            string action,
            TInput message)
        {
            var json = JsonConvert.SerializeObject(message, jsonSerializerSettings);

            var request = CreateRequest(token, action, "PUT");
            Post(request, json);
        }

        public void Post<TInput>(
            Token token,
            string action,
            TInput message)
        {
            var json = JsonConvert.SerializeObject(message, jsonSerializerSettings);
            var request = CreateRequest(token, action, "POST");
            Post(request, json);
        }


        public TOutput Post<TOutput, TInput>(
            Token token,
            string action, 
            TInput message)
        {
            var json = JsonConvert.SerializeObject(message, jsonSerializerSettings);
            var request = CreateRequest(token, action, "POST");

            return Post<TOutput>(request, json);
        }

        HttpWebRequest CreateRequest(Token token, string action, string method)
        {
            var url = $"{baseUrl}{action}";
            var request = System.Net.WebRequest.Create(url) as HttpWebRequest;
            request.KeepAlive = true;
            request.Method = method;
            request.ContentLength = 0;
            request.ContentType = "application/json";
            request.Headers.Add("Authorization", $"Bearer {token.Value}");

            return request;
        }


        T Get<T>(HttpWebRequest request)
        {
            var json = string.Empty;
            using (var response = request.GetResponse() as HttpWebResponse)
            {
                using (var reader = new StreamReader(response.GetResponseStream()))
                {
                    json = reader.ReadToEnd();
                }
            }

            return JsonConvert.DeserializeObject<T>(json, jsonSerializerSettings);
        }

        void Post(HttpWebRequest request, string json)
        {
            var bytes = Encoding.UTF8.GetBytes(json);
            request.ContentLength = bytes.Length;
            using (var writer = request.GetRequestStream())
            {
                writer.Write(bytes, 0, bytes.Length);
            }
        }

        T Post<T>(HttpWebRequest request, string json)
        {
            Post(request, json);
            return Get<T>(request);
        }
    }
}
<commit_msg>Cleanup<commit_after>﻿using System.IO;
using System.Net;
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

namespace PowerBIDotNet
{

    public class Communication : ICommunication
    {
        static JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() };
        const string baseUrl = "https://api.powerbi.com/v1.0/myorg/";


        public T Get<T>(Token token, string action)
        {
            var request = CreateRequest(token, action, "GET");
            return Get<T>(request);
        }

        public void Put<TInput>(
            Token token,
            string action,
            TInput message)
        {
            var json = JsonConvert.SerializeObject(message, jsonSerializerSettings);

            var request = CreateRequest(token, action, "PUT");
            Post(request, json);
        }

        public void Post<TInput>(
            Token token,
            string action,
            TInput message)
        {
            var json = JsonConvert.SerializeObject(message, jsonSerializerSettings);
            var request = CreateRequest(token, action, "POST");
            Post(request, json);
        }


        public TOutput Post<TOutput, TInput>(
            Token token,
            string action, 
            TInput message)
        {
            var json = JsonConvert.SerializeObject(message, jsonSerializerSettings);
            var request = CreateRequest(token, action, "POST");

            return Post<TOutput>(request, json);
        }

        HttpWebRequest CreateRequest(Token token, string action, string method)
        {
            var url = $"{baseUrl}{action}";
            var request = WebRequest.Create(url) as HttpWebRequest;
            request.KeepAlive = true;
            request.Method = method;
            request.ContentLength = 0;
            request.ContentType = "application/json";
            request.Headers.Add("Authorization", $"Bearer {token.Value}");

            return request;
        }


        T Get<T>(HttpWebRequest request)
        {
            var json = string.Empty;
            using (var response = request.GetResponse() as HttpWebResponse)
            {
                using (var reader = new StreamReader(response.GetResponseStream()))
                {
                    json = reader.ReadToEnd();
                }
            }

            return JsonConvert.DeserializeObject<T>(json, jsonSerializerSettings);
        }

        void Post(HttpWebRequest request, string json)
        {
            var bytes = Encoding.UTF8.GetBytes(json);
            request.ContentLength = bytes.Length;
            using (var writer = request.GetRequestStream())
            {
                writer.Write(bytes, 0, bytes.Length);
            }
        }

        T Post<T>(HttpWebRequest request, string json)
        {
            Post(request, json);
            return Get<T>(request);
        }
    }
}

{'fraction_non_alphanumeric': 0.09158538601421723, 'fraction_numerical': 0.0016531658125309968, 'mean_word_length': 1.8205128205128205, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 2, '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': '5308482', 'n_tokens_mistral': 1510, 'n_tokens_neox': 1465, 'n_words': 358}