2026-01-28 11:55:25 -06:00

36 lines
1.1 KiB
C#

using CharacterApi.Models;
using System.Net;
using System.Net.Http.Json;
namespace CharacterApi.Services;
public class LocationsClient
{
private readonly HttpClient _http;
private readonly string _internalKey;
public LocationsClient(HttpClient http, IConfiguration cfg)
{
_http = http;
_internalKey = cfg["LocationsApi:InternalKey"] ?? string.Empty;
}
public async Task<(bool Ok, HttpStatusCode Status, string? Body)> UpdatePresenceAsync(
string characterId,
Coord coord,
CancellationToken ct = default)
{
using var request = new HttpRequestMessage(HttpMethod.Post, "api/locations/presence")
{
Content = JsonContent.Create(new { characterId, coord })
};
if (!string.IsNullOrWhiteSpace(_internalKey))
request.Headers.TryAddWithoutValidation("X-Internal-Key", _internalKey);
using var response = await _http.SendAsync(request, ct);
var body = await response.Content.ReadAsStringAsync(ct);
return (response.IsSuccessStatusCode, response.StatusCode, body);
}
}