Utilize new api

This commit is contained in:
Daniel_I_Am 2020-09-05 01:38:09 +02:00
parent 71b05a2bbd
commit c0f8a49d92
No known key found for this signature in database
GPG Key ID: 80C428FCC9743E84

View File

@ -6,11 +6,13 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Net.Http; using System.Net.Http;
using System.Net.Http.Headers;
using System.Text; using System.Text;
using ChaosBot.Discord.PreConditions; using ChaosBot.Discord.PreConditions;
using ChaosBot.Lodestone; using ChaosBot.Lodestone;
using ChaosBot.Models; using ChaosBot.Models;
using ChaosBot.Repositories; using ChaosBot.Repositories;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace ChaosBot.Discord.Modules.Admin namespace ChaosBot.Discord.Modules.Admin
@ -107,14 +109,18 @@ namespace ChaosBot.Discord.Modules.Admin
{ {
using HttpClient client = new HttpClient(); using HttpClient client = new HttpClient();
IConfigurationSection configurationSection =
Program.AppSettingsHandler.GetSection("Lodestone:ChaosBotApi");
string endpoint = configurationSection.GetValue<string>("Url");
string apiToken = configurationSection.GetValue<string>("ApiToken");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiToken);
HttpResponseMessage result = HttpResponseMessage result =
await client.GetAsync( await client.GetAsync(endpoint);
ConfigurationRepository.GetValue<string>("Lodestone:RankCheck:Url", discordGuildId));
result.EnsureSuccessStatusCode(); result.EnsureSuccessStatusCode();
response = await result.Content.ReadAsStringAsync(); response = await result.Content.ReadAsStringAsync();
// return new List<LodestoneRankedUser>();
return JsonConvert.DeserializeObject<LodestoneRankApi>(response).Data; return JsonConvert.DeserializeObject<LodestoneRankApi>(response).Data;
} }
catch (Exception ex) catch (Exception ex)