Blazor & WASM in combination to get statistics from Spotify API for performing the song analysis. With separate microservices for auth, Spotify, user data tracking, and application, connected through gRPC with Polly.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

StatsService.cs 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using GrpcShared.DTO;
  2. using GrpcShared.DTO.TopItem;
  3. using GrpcShared.DTO.Track;
  4. using GrpcShared.Interfaces;
  5. using Microsoft.Net.Http.Headers;
  6. using Newtonsoft.Json;
  7. using SpotifyService.HttpUtils;
  8. namespace SpotifyService.Services
  9. {
  10. public class StatsService : IStatsService
  11. {
  12. private readonly IHttpClientFactory _httpClientFactory;
  13. public StatsService(IHttpClientFactory httpClientFactory)
  14. {
  15. _httpClientFactory = httpClientFactory;
  16. }
  17. public async Task<CurrentTrackResponse> GetCurrentlyPlayingTrack(TokenMessage token)
  18. {
  19. var client = _httpClientFactory.CreateClient("HttpClient");
  20. string url = "me/player/currently-playing";
  21. var response = await HttpUtils<CurrentTrackResponse>.GetData(client, url, token.Token!);
  22. return response;
  23. }
  24. public async Task<TopItemResponse> GetTopItems(TopItemRequest request)
  25. {
  26. //https://api.spotify.com/v1/me/top/albums?limit=10&offset=5
  27. var client = _httpClientFactory.CreateClient("HttpClient");
  28. //URL PARAMS
  29. string url = "me/top/";
  30. url += !request.IsTracks ? "artists" : "tracks";
  31. url += request.Limit == null ? "" : $"?limit={request.Limit}";
  32. if (request.Limit == null && request.Offset != null) url += $"?offset={request.Offset}";
  33. else url += request.Offset == null ? "" : $"&offset={request.Offset}";
  34. return await HttpUtils<TopItemResponse>.GetData(client, url, request.Token!);
  35. }
  36. }
  37. }