using GrpcShared.DTO; using GrpcShared.DTO.TopItem; using GrpcShared.DTO.Track; using GrpcShared.Interfaces; using Microsoft.Net.Http.Headers; using Newtonsoft.Json; using SpotifyService.HttpUtils; namespace SpotifyService.Services { public class StatsService : IStatsService { private readonly IHttpClientFactory _httpClientFactory; public StatsService(IHttpClientFactory httpClientFactory) { _httpClientFactory = httpClientFactory; } public async Task GetCurrentlyPlayingTrack(TokenMessage token) { var client = _httpClientFactory.CreateClient("HttpClient"); string url = "me/player/currently-playing"; return await HttpUtils.GetData(client, url, token.Token!); } public async Task GetTopItems(TopItemRequest request) { //https://api.spotify.com/v1/me/top/albums?limit=10&offset=5 var client = _httpClientFactory.CreateClient("HttpClient"); //URL PARAMS string url = "me/top/"; url += !request.IsTracks ? "artists" : "tracks"; url += request.Limit == null ? "" : $"?limit={request.Limit}"; if (request.Limit == null && request.Offset != null) url += $"?offset={request.Offset}"; else url += request.Offset == null ? "" : $"&offset={request.Offset}"; return await HttpUtils.GetData(client, url, request.Token!); } } }