Closed RickTimmer closed 3 years ago
After reading through the code for a bit I noticed that the methods seem to not differ much. It seems like a lot of the duplicate code can be avoided by something like this:
readonly string baseURL = "https://new.scoresaber.com/api"; private async Task<T> GetEndpoint<T>(string endpoint) { HttpResponseMessage response = await client.GetAsync($"{baseURL}{endpoint}"); if (!response.IsSuccessStatusCode) { return null; } return JsonConvert.DeserializeObject<T>(await response.Content.ReadAsStringAsync()); }
I think this should work for all current endpoints apart from GetAvatar. But that seems to not really be an endpoint.
Bare in mind that I am not a c# developer so the syntax might not be completely correct.
PR -> https://github.com/Daanniello/ScoreSaberLib/pull/2
Noiceee done!
After reading through the code for a bit I noticed that the methods seem to not differ much. It seems like a lot of the duplicate code can be avoided by something like this:
I think this should work for all current endpoints apart from GetAvatar. But that seems to not really be an endpoint.
Bare in mind that I am not a c# developer so the syntax might not be completely correct.