public IPromise <EventLeaderboardData> GetRankAndNeighbours(string eventID) { var promise = new Promise <EventLeaderboardData>(); Action <ConnectionHandler.RequestResult, string> HandleRankAndNeighboursResponse = (ConnectionHandler.RequestResult result, string response) => { logger.Log(Tag, "HandleGetRankAndNeighboursResponse (result=" + result + ")\nresponse=" + response); if (result != ConnectionHandler.RequestResult.Ok) { modelSyncService.HandleErrorResponse(result, response); promise.Reject(new Exception(response)); return; } EventLeaderboardData leaderboardData = new EventLeaderboardData(); JsonData responseJsonObject = (JsonData)JsonMapper.ToObject(response); leaderboardData.leaderboardData = JsonMapper.ToObject <List <LeaderboardPlayerData> >(responseJsonObject["neighborsLeaderboard"].ToJson()); leaderboardData.rank = (int)responseJsonObject["rank"]; promise.Resolve(leaderboardData); }; _coroutineFactory.StartCoroutine(() => connectionHandler.SendRequest(ConnectionHandler.RequestType.GetRankAndNeighboursRequest, HandleRankAndNeighboursResponse, eventID, null)); return(promise); }
public IPromise <EventLeaderboardData> GetTopLeaderboard(string eventID) { var promise = new Promise <EventLeaderboardData>(); Action <ConnectionHandler.RequestResult, string> HandleGetTopLeaderboardResponse = (ConnectionHandler.RequestResult result, string response) => { logger.Log(Tag, "HandleGetTopLeaderboardResponse (result=" + result + ")\nresponse=" + response); if (result != ConnectionHandler.RequestResult.Ok) { promise.Resolve(new EventLeaderboardData()); return; } EventLeaderboardData topData = new EventLeaderboardData(); // Parse out the leaderboard data from the response JsonData responseJsonObject = (JsonData)JsonMapper.ToObject(response); topData.leaderboardData = JsonMapper.ToObject <List <LeaderboardPlayerData> >(responseJsonObject["topLeaderboard"].ToJson()); int tryFindPlayerInLeaderboard = topData.leaderboardData.FirstIndex(l => l.playerId.ToString() == playerInfoService.PlayerId); if (tryFindPlayerInLeaderboard != -1) { topData.rank = topData.leaderboardData[tryFindPlayerInLeaderboard].rank; } promise.Resolve(topData); }; _coroutineFactory.StartCoroutine(() => connectionHandler.SendRequest(ConnectionHandler.RequestType.GetTopLeaderboardRequest, HandleGetTopLeaderboardResponse, eventID, null)); return(promise); }