Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static class Api
- {
- private static readonly string _baseUrl = "https://data.nba.net/";
- private static async Task<string> getResponse(string? endpoint)
- {
- using (var client = new HttpClient())
- {
- var return_message = new HttpResponseMessage();
- try
- {
- return_message = await client.GetAsync(_baseUrl + (endpoint ?? "")).ConfigureAwait(false);
- }
- catch (Exception ex)
- {
- throw;
- }
- return await return_message.Content.ReadAsStringAsync();
- }
- }
- public static async Task<IEnumerable<PlayerBioModel>> GetPlayerBio(string playerId)
- {
- var playerBioModel = new List<PlayerBioModel>();
- var response = await getResponse("/json/bios/" + playerId + ".json");
- var playerBioRootDto = JsonSerializer.Deserialize<PlayerBioRootDto>(response);
- playerBioModel.Add(new PlayerBioModel()
- {
- Id = playerBioRootDto?.PlayerBioDto?.id,
- Type = playerBioRootDto?.PlayerBioDto?.type,
- College = playerBioRootDto?.PlayerBioDto?.college,
- DisplayName = playerBioRootDto?.PlayerBioDto?.display_name,
- HighSchool = playerBioRootDto?.PlayerBioDto?.highschool,
- OtherLabel = playerBioRootDto?.PlayerBioDto?.other_label,
- OtherText = playerBioRootDto?.PlayerBioDto?.other_text,
- Professional = playerBioRootDto?.PlayerBioDto?.professional,
- Twitter = playerBioRootDto?.PlayerBioDto?.twitter
- });
- return playerBioModel;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement