IEnumerator GetLeaderBoardCoroutine() { using (UnityWebRequest req = UnityWebRequest.Get(String.Format("http://194.32.79.63:8000/api/leaderboard"))) { req.SetRequestHeader("Authorization", PlayerInfoHolder.Token); yield return(req.Send()); while (!req.isDone) { yield return(null); } byte[] result = req.downloadHandler.data; string eventJSON = System.Text.Encoding.Default.GetString(result); Debug.Log(eventJSON); ApiResponse <GetLeaderboardResponse> info = JsonUtility.FromJson <ApiResponse <GetLeaderboardResponse> >(eventJSON); Debug.Log($"Data: {info.data} Result: {info.result} Errors: {info.errors}"); if (info.errors.Length == 0) { GetLeaderboardResponse evn = info.data; PlayerInfoHolder.Position = evn.place; Debug.Log($"Place: {evn.place} PlayersCount: {evn.players.Length}"); } else { Debug.Log($"Errors: {info.errors[0]}"); } } }
public async Task <JsonResult> GetLeaderboard() { try { var id = _securityService.GetUserId(User); var leaderboard = await _leaderboardService.GetLeaderboardByPlayerId(id); var response = new GetLeaderboardResponse { Place = leaderboard.Place, Players = leaderboard.Players.Select(x => new GetLeaderboardResponse.LeaderboardPlayer { Name = x.Name, Place = x.Place, Score = x.Score }).ToArray() }; return(this.JsonApi(response)); } catch (SecurityException exception) { return(this.JsonApi(exception)); } catch (PlayerException exception) { return(this.JsonApi(exception)); } catch (EventException exception) { return(this.JsonApi(exception)); } }