<commit_before>﻿using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;

namespace Saxx.LingoHubClient
{
    public partial class LingoHubClient : HttpClient
    {
        public LingoHubClient(string username, string password)
        {
            var encodedCredentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(string.Format("{0}:{1}", username, password)));
            BaseAddress = new Uri("https://api.lingohub.com/v1/");
            DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", encodedCredentials);
        }
    }
}<commit_msg>added wrapper methods for fetching data with LH error extraction<commit_after>﻿using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;

namespace Saxx.LingoHubClient
{
    public partial class LingoHubClient : HttpClient
    {
        public LingoHubClient(string username, string password)
        {
            var encodedCredentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(string.Format("{0}:{1}", username, password)));
            BaseAddress = new Uri("https://api.lingohub.com/v1/");
            DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", encodedCredentials);
        }

        /// <summary>
        /// Fetch the data from the LingoHub API.
        /// </summary>
        /// <param name="url">URL</param>
        /// <returns>HTTP Response</returns>
        private async Task<HttpResponseMessage> Fetch(string url)
        {
            var response = await GetAsync(url);
            if (response.IsSuccessStatusCode)
            {
                return response;
            }

            var error = await response.Content.ReadAsStringAsync();
            throw new Exception(string.Format("An error occured during request (HTTP {0}):\n{1}\n------", response.StatusCode, error));
        }

        /// <summary>
        /// Fetch the data from the LingoHub API as string.
        /// </summary>
        /// <param name="url">URL</param>
        /// <returns>Data as String</returns>
        private async Task<string> FetchAsString(string url)
        {
            return await Fetch(url).Result.Content.ReadAsStringAsync();
        }

        /// <summary>
        /// Fetch the data from the LingoHub API as byte array.
        /// </summary>
        /// <param name="url">URL</param>
        /// <returns>Data as String</returns>
        private async Task<byte[]> FetchAsByteArray(string url)
        {
            return await Fetch(url).Result.Content.ReadAsByteArrayAsync();
        }
    }
}
{'fraction_non_alphanumeric': 0.12062404870624048, 'fraction_numerical': 0.0045662100456621, 'mean_word_length': 2.3835263835263834, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, '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': '1868573', 'n_tokens_mistral': 703, 'n_tokens_neox': 699, 'n_words': 165}