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

using Newtonsoft.Json;

using B2.Client.Rest.Api;
using B2.Client.Rest.Request;
using B2.Client.Rest.Response;


namespace B2.Client.Rest
{
    /// <summary>
    /// A basic REST client that can make unauthenticated API calls. Typically the only calls it can make are calls to
    /// <see cref="IAuthenticationApi{TReq,TRes}"/>s.
    /// </summary>
    public class UnauthenticatedRestClient
    {
        /// <summary>
        /// The REST endpoint to make calls to.
        /// </summary>
        public Uri Endpoint { get; }

        /// <summary>
        /// The proxy to use (if any).
        /// </summary>
        public IWebProxy WebProxy { get; }

        /// <summary>
        /// Create a new <see cref="UnauthenticatedRestClient"/>.
        /// </summary>
        /// <param name="endpoint">The REST endpoint.</param>
        /// <param name="webProxy">The proxy to use (<code>null</code> to use no proxy).</param>
        public UnauthenticatedRestClient(Uri endpoint, IWebProxy webProxy)
        {
            Endpoint = endpoint.ThrowIfNull(nameof(endpoint));
            WebProxy = webProxy;
        }

        private HttpClient GetHttpClient()
        {
            var useProxy = WebProxy != null;
            var handler = new HttpClientHandler {
                Proxy = WebProxy,
                UseProxy = useProxy
            };
            return new HttpClient(handler) {
                BaseAddress = Endpoint
            };
        }

        private async Task<TRes> HandleResponseAsync<TRes>(HttpResponseMessage apiResponse)
            where TRes : IResponse
        {
            var content = await apiResponse.Content.ReadAsStringAsync();
            //assume success for now (think lucky)

            return JsonConvert.DeserializeObject<TRes>(content);
        }<commit_msg>make web proxy optional in unauthed client<commit_after>﻿using System;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;

using Newtonsoft.Json;

using B2.Client.Rest.Api;
using B2.Client.Rest.Request;
using B2.Client.Rest.Response;


namespace B2.Client.Rest
{
    /// <summary>
    /// A basic REST client that can make unauthenticated API calls. Typically the only calls it can make are calls to
    /// <see cref="IAuthenticationApi{TReq,TRes}"/>s.
    /// </summary>
    public class UnauthenticatedRestClient
    {
        /// <summary>
        /// The REST endpoint to make calls to.
        /// </summary>
        public Uri Endpoint { get; }

        /// <summary>
        /// The proxy to use (if any).
        /// </summary>
        public IWebProxy WebProxy { get; }

        /// <summary>
        /// Create a new <see cref="UnauthenticatedRestClient"/>.
        /// </summary>
        /// <param name="endpoint">The REST endpoint.</param>
        /// <param name="webProxy">The (optional) proxy to use.</param>
        public UnauthenticatedRestClient(Uri endpoint, IWebProxy webProxy = null)
        {
            Endpoint = endpoint.ThrowIfNull(nameof(endpoint));
            WebProxy = webProxy;
        }

        private HttpClient GetHttpClient()
        {
            var useProxy = WebProxy != null;
            var handler = new HttpClientHandler {
                Proxy = WebProxy,
                UseProxy = useProxy
            };
            return new HttpClient(handler) {
                BaseAddress = Endpoint
            };
        }

        private async Task<TRes> HandleResponseAsync<TRes>(HttpResponseMessage apiResponse)
            where TRes : IResponse
        {
            var content = await apiResponse.Content.ReadAsStringAsync();
            //assume success for now (think lucky)

            return JsonConvert.DeserializeObject<TRes>(content);
        }
{'fraction_non_alphanumeric': 0.10789679437060204, 'fraction_numerical': 0.0020849622100599426, 'mean_word_length': 1.9297709923664121, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 39, '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': '255261', 'n_tokens_mistral': 1037, 'n_tokens_neox': 998, 'n_words': 283}