<commit_before>﻿// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;

namespace Nether.Integration.Identity
{
    /// <summary>
    /// Client used to allow the Identity feature to integrate with Player Management
    /// in a pluggable manner
    /// </summary>
    public class DefaultIdentityPlayerManagementClient : IIdentityPlayerManagementClient
    {
        private readonly HttpClient _httpClient;
        private readonly ILogger<DefaultIdentityPlayerManagementClient> _logger;

        public DefaultIdentityPlayerManagementClient(
            string baseUri, // e.g. localhost:5000
            ILoggerFactory loggerFactory
            )
        {
            _httpClient = new HttpClient
            {
                BaseAddress = new Uri(baseUri)
            };
            _logger = loggerFactory.CreateLogger<DefaultIdentityPlayerManagementClient>();
        }
        public async Task<string> GetGamertagForUserIdAsync(string userId)
        {
            // TODO security, proper url...;-)
            var response = await _httpClient.GetAsync($"/api/EVIL/HELPER/tagfromid/{userId}");
            if (response.IsSuccessStatusCode)
            {
                var gamertag = await response.Content.ReadAsStringAsync();
                return gamertag;
            }
            _logger.LogError("Failed to look up gamertag for user '{0}', statuscode {1}", userId, response.StatusCode);
            return null; // TODO should we throw here?<commit_msg>Avoid error output for user without gamertag<commit_after>﻿// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;

namespace Nether.Integration.Identity
{
    /// <summary>
    /// Client used to allow the Identity feature to integrate with Player Management
    /// in a pluggable manner
    /// </summary>
    public class DefaultIdentityPlayerManagementClient : IIdentityPlayerManagementClient
    {
        private readonly HttpClient _httpClient;
        private readonly ILogger<DefaultIdentityPlayerManagementClient> _logger;

        public DefaultIdentityPlayerManagementClient(
            string baseUri, // e.g. localhost:5000
            ILoggerFactory loggerFactory
            )
        {
            _httpClient = new HttpClient
            {
                BaseAddress = new Uri(baseUri)
            };
            _logger = loggerFactory.CreateLogger<DefaultIdentityPlayerManagementClient>();
        }
        public async Task<string> GetGamertagForUserIdAsync(string userId)
        {
            // TODO security, proper url...;-)
            var response = await _httpClient.GetAsync($"/api/EVIL/HELPER/tagfromid/{userId}");
            if (response.IsSuccessStatusCode)
            {
                var gamertag = await response.Content.ReadAsStringAsync();
                return gamertag;
            }
            if (response.StatusCode == HttpStatusCode.NotFound)
            {
                return null;
            }
            _logger.LogError("Failed to look up gamertag for user '{0}', statuscode {1}", userId, response.StatusCode);
            return null; // TODO should we throw here?
{'fraction_non_alphanumeric': 0.0802980132450331, 'fraction_numerical': 0.0033112582781456954, 'mean_word_length': 2.3752327746741155, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '20454', 'n_tokens_mistral': 869, 'n_tokens_neox': 869, 'n_words': 258}