<commit_before>﻿using System;
using System.Net.Http;
using System.Threading.Tasks;
using Solomobro.Instagram.Extensions;
using Solomobro.Instagram.Interfaces;
using Solomobro.Instagram.Models;


namespace Solomobro.Instagram.Endpoints
{
    internal class ApiClient : IApiClient
    {
        private readonly HttpClient _http = new HttpClient();

        internal ApiClient()
        {
        }

        #region Response

        public async Task<Response> GetResponseAsync(Uri uri)
        {
            using (var httpResp = await _http.GetAsync(uri).ConfigureAwait(false))
            {
                var apiResp = await httpResp.DeserializeAsync<Response>().ConfigureAwait(false);
                apiResp.RateLimit = httpResp.GetRateLimitInfo();
                return apiResp;
            }
        }

        public async Task<Response> PostResponseAsync(Uri uri, HttpContent content)
        {
            using (var httpResp = await _http.PostAsync(uri, content).ConfigureAwait(false))
            {
                var apiResp = await httpResp.DeserializeAsync<Response>().ConfigureAwait(false);
                apiResp.RateLimit = httpResp.GetRateLimitInfo();
                return apiResp;
            }
        }

        public async Task<Response> DeleteResponseAsync(Uri uri)
        {
            using (var httpResp = await _http.DeleteAsync(uri).ConfigureAwait(false))
            {
                var apiResp = await httpResp.DeserializeAsync<Response>().ConfigureAwait(false);
                apiResp.RateLimit = httpResp.GetRateLimitInfo();
                return apiResp;
            }
        }
        #endregion


        #region Response<T>

        public async Task<Response<T>> GetResponseAsync<T>(Uri uri)
        {
            using (var httpResp = await _http.GetAsync(uri).ConfigureAwait(false))
            {
                var apiResp = await httpResp.DeserializeAsync<Response<T>>().ConfigureAwait(false);
                apiResp.RateLimit = httpResp.GetRateLimitInfo();
                return apiResp;
            }
        }

        public async Task<Response<T>> PostResponseAsync<T>(Uri uri, HttpContent content)
        {
            using (var httpResp = await _http.PostAsync(uri, content).ConfigureAwait(false))
            {
                var apiResp = await httpResp.DeserializeAsync<Response<T>>().ConfigureAwait(false);
                apiResp.RateLimit = httpResp.GetRateLimitInfo();
                return apiResp;
            }
        }

        public async Task<Response<T>> DeleteResponseAsync<T>(Uri uri)
        {
            using (var httpResp = await _http.DeleteAsync(uri).ConfigureAwait(false))
            {
                var apiResp = await httpResp.DeserializeAsync<Response<T>>().ConfigureAwait(false);
                apiResp.RateLimit = httpResp.GetRateLimitInfo();
                return apiResp;
            }
        }

        #endregion


        #region CollectionResponse<T>

        public async Task<CollectionResponse<T>> GetCollectionResponseAsync<T>(Uri uri)
        {
            using (var httpResp = await _http.GetAsync(uri).ConfigureAwait(false))
            {
                var apiResp = await httpResp.DeserializeAsync<CollectionResponse<T>>().ConfigureAwait(false);
                apiResp.RateLimit = httpResp.GetRateLimitInfo();
                return apiResp;
            }
        }

        public async Task<CollectionResponse<T>> PostCollectionResponseAsync<T>(Uri uri, HttpContent content)
        {
            using (var httpResp = await _http.PostAsync(uri, content).ConfigureAwait(false))
            {
                var apiResp = await httpResp.DeserializeAsync<CollectionResponse<T>>().ConfigureAwait(false);
                apiResp.RateLimit = httpResp.GetRateLimitInfo();
                return apiResp;
            }
        }

        public async Task<CollectionResponse<T>> DeleteCollectionResponseAsync<T>(Uri uri)
        {
            using (var httpResp = await _http.DeleteAsync(uri).ConfigureAwait(false))
            {
                var apiResp = await httpResp.DeserializeAsync<CollectionResponse<T>>().ConfigureAwait(false);
                apiResp.RateLimit = httpResp.GetRateLimitInfo();
                return apiResp;
            }
        }
        #endregion
    }
}
<commit_msg>ensure only 1 HttpClient class is instantiated in ApiClient<commit_after>﻿using System;
using System.Net.Http;
using System.Threading.Tasks;
using Solomobro.Instagram.Extensions;
using Solomobro.Instagram.Interfaces;
using Solomobro.Instagram.Models;


namespace Solomobro.Instagram.Endpoints
{
    internal class ApiClient : IApiClient
    {
        private static readonly Lazy<HttpClient> LazyHttpClient = new Lazy<HttpClient>(() => new HttpClient());

        internal ApiClient()
        {
        }

        private HttpClient Http => LazyHttpClient.Value;

        #region Response

        public async Task<Response> GetResponseAsync(Uri uri)
        {
            using (var httpResp = await Http.GetAsync(uri).ConfigureAwait(false))
            {
                var apiResp = await httpResp.DeserializeAsync<Response>().ConfigureAwait(false);
                apiResp.RateLimit = httpResp.GetRateLimitInfo();
                return apiResp;
            }
        }

        public async Task<Response> PostResponseAsync(Uri uri, HttpContent content)
        {
            using (var httpResp = await Http.PostAsync(uri, content).ConfigureAwait(false))
            {
                var apiResp = await httpResp.DeserializeAsync<Response>().ConfigureAwait(false);
                apiResp.RateLimit = httpResp.GetRateLimitInfo();
                return apiResp;
            }
        }

        public async Task<Response> DeleteResponseAsync(Uri uri)
        {
            using (var httpResp = await Http.DeleteAsync(uri).ConfigureAwait(false))
            {
                var apiResp = await httpResp.DeserializeAsync<Response>().ConfigureAwait(false);
                apiResp.RateLimit = httpResp.GetRateLimitInfo();
                return apiResp;
            }
        }
        #endregion


        #region Response<T>

        public async Task<Response<T>> GetResponseAsync<T>(Uri uri)
        {
            using (var httpResp = await Http.GetAsync(uri).ConfigureAwait(false))
            {
                var apiResp = await httpResp.DeserializeAsync<Response<T>>().ConfigureAwait(false);
                apiResp.RateLimit = httpResp.GetRateLimitInfo();
                return apiResp;
            }
        }

        public async Task<Response<T>> PostResponseAsync<T>(Uri uri, HttpContent content)
        {
            using (var httpResp = await Http.PostAsync(uri, content).ConfigureAwait(false))
            {
                var apiResp = await httpResp.DeserializeAsync<Response<T>>().ConfigureAwait(false);
                apiResp.RateLimit = httpResp.GetRateLimitInfo();
                return apiResp;
            }
        }

        public async Task<Response<T>> DeleteResponseAsync<T>(Uri uri)
        {
            using (var httpResp = await Http.DeleteAsync(uri).ConfigureAwait(false))
            {
                var apiResp = await httpResp.DeserializeAsync<Response<T>>().ConfigureAwait(false);
                apiResp.RateLimit = httpResp.GetRateLimitInfo();
                return apiResp;
            }
        }

        #endregion


        #region CollectionResponse<T>

        public async Task<CollectionResponse<T>> GetCollectionResponseAsync<T>(Uri uri)
        {
            using (var httpResp = await Http.GetAsync(uri).ConfigureAwait(false))
            {
                var apiResp = await httpResp.DeserializeAsync<CollectionResponse<T>>().ConfigureAwait(false);
                apiResp.RateLimit = httpResp.GetRateLimitInfo();
                return apiResp;
            }
        }

        public async Task<CollectionResponse<T>> PostCollectionResponseAsync<T>(Uri uri, HttpContent content)
        {
            using (var httpResp = await Http.PostAsync(uri, content).ConfigureAwait(false))
            {
                var apiResp = await httpResp.DeserializeAsync<CollectionResponse<T>>().ConfigureAwait(false);
                apiResp.RateLimit = httpResp.GetRateLimitInfo();
                return apiResp;
            }
        }

        public async Task<CollectionResponse<T>> DeleteCollectionResponseAsync<T>(Uri uri)
        {
            using (var httpResp = await Http.DeleteAsync(uri).ConfigureAwait(false))
            {
                var apiResp = await httpResp.DeserializeAsync<CollectionResponse<T>>().ConfigureAwait(false);
                apiResp.RateLimit = httpResp.GetRateLimitInfo();
                return apiResp;
            }
        }
        #endregion
    }
}

{'fraction_non_alphanumeric': 0.09104358711733242, 'fraction_numerical': 0.00011380448389666553, 'mean_word_length': 2.053509381514941, 'pattern_counts': {'":': 0, '<': 81, '<?xml version=': 0, '>': 83, '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': '1879546', 'n_tokens_mistral': 2420, 'n_tokens_neox': 2233, 'n_words': 427}