<commit_before>﻿using System.Collections.Generic;
using System.Net;
using AppGet.Http;
using NLog;

namespace AppGet.PackageRepository
{
    public class AppGetServerClient : IPackageRepository
    {
        private readonly IHttpClient _httpClient;
        private readonly Logger _logger;
        private readonly HttpRequestBuilder _requestBuilder;

        private const string API_ROOT = "https://appget.net/api/v1/";

        public AppGetServerClient(IHttpClient httpClient, Logger logger)
        {
            _httpClient = httpClient;
            _logger = logger;

            _requestBuilder = new HttpRequestBuilder(API_ROOT);
        }


        public PackageInfo GetLatest(string name)
        {
            _logger.Info("Getting package " + name);

            var request = _requestBuilder.Build("packages/{package}/latest");
            request.AddSegment("package", name);

            try
            {
                var package = _httpClient.Get<PackageInfo>(request);
                return package.Resource;
            }
            catch (HttpException ex)
            {
                if (ex.Response.StatusCode == HttpStatusCode.NotFound)
                {
                    return null;
                }
                throw;
            }<commit_msg>Use azure hosted server for now<commit_after>﻿using System.Collections.Generic;
using System.Net;
using AppGet.Http;
using NLog;

namespace AppGet.PackageRepository
{
    public class AppGetServerClient : IPackageRepository
    {
        private readonly IHttpClient _httpClient;
        private readonly Logger _logger;
        private readonly HttpRequestBuilder _requestBuilder;

        private const string API_ROOT = "https://appget.azurewebsites.net/v1/";

        public AppGetServerClient(IHttpClient httpClient, Logger logger)
        {
            _httpClient = httpClient;
            _logger = logger;

            _requestBuilder = new HttpRequestBuilder(API_ROOT);
        }


        public PackageInfo GetLatest(string name)
        {
            _logger.Info("Getting package " + name);

            var request = _requestBuilder.Build("packages/{package}/latest");
            request.AddSegment("package", name);

            try
            {
                var package = _httpClient.Get<PackageInfo>(request);
                return package.Resource;
            }
            catch (HttpException ex)
            {
                if (ex.Response.StatusCode == HttpStatusCode.NotFound)
                {
                    return null;
                }
                throw;
            }
{'fraction_non_alphanumeric': 0.07455803228285934, 'fraction_numerical': 0.0007686395080707148, 'mean_word_length': 1.817099567099567, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5707567', 'n_tokens_mistral': 636, 'n_tokens_neox': 607, 'n_words': 145}