using System; using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; using NostaleAuth.Extensions; using NostaleAuth.Models; namespace NostaleAuth.Api { public class AuthorizedGameforgeApi { private List _accounts; public AuthorizedGameforgeApi(string authToken, Guid installationId) { AuthToken = authToken; InstallationId = installationId; } public Guid InstallationId { get; set; } public string AuthToken { get; } public async Task> GetAccounts(bool cache = true) { if (cache && _accounts != null) { return _accounts; } var request = new GameforgeRequest(HttpMethod.Get, "/user/accounts", InstallationId, AuthToken); Dictionary response = await request.Send(); if (response == null) { return new List(); } _accounts = new List(response.Values); return _accounts; } public async Task GetSessionToken(GameforgeAccount gameforgeAccount, bool raw = false) { var request = new GameforgeRequest(HttpMethod.Post, "/auth/thin/codes", InstallationId, AuthToken); var sessionRequest = new SessionRequest { PlatformGameAccountId = gameforgeAccount.Id }; Dictionary response = await request.Send(sessionRequest); if (response == null) { return string.Empty; } string data = (response.GetValueOrDefault("code") ?? string.Empty); return raw ? data : data.ToHex(); } } }