public static void GetLeaderboards(String leaderboardListTag, Action <List <OKLeaderboard>, OKException> requestHandler) { Dictionary <string, object> requestParams = new Dictionary <string, object>(); requestParams.Add("tag", leaderboardListTag); OKCloudAsyncRequest.Get("/leaderboards", requestParams, (JSONObject responseObj, OKCloudException e) => { if (e != null) { OKLog.Error("Getting leaderboards failed with error: " + e); requestHandler(null, e); } else { Debug.Log("Got leaderboards"); if (responseObj.type == JSONObject.Type.ARRAY) { List <OKLeaderboard> leaderboardList = new List <OKLeaderboard>(responseObj.list.Count); for (int x = 0; x < responseObj.list.Count; x++) { OKLeaderboard leaderboard = new OKLeaderboard(responseObj[x]); leaderboardList.Add(leaderboard); } requestHandler(leaderboardList, null); } else { OKLog.Error("Expected an array of leaderboards but did not get back an Array JSON"); requestHandler(null, new OKException("Expected an array of leaderboards but did not get back an Array JSON")); } } }); }
public void mGet(String key, Action <object, OKCloudException> handler) { OKUser u = GetUser(); if (u == null) { throw new Exception("You need a user to perform cloud get."); } Dictionary <string, object> reqParams = new Dictionary <string, object>(); reqParams.Add("user_id", u.OKUserID.ToString()); string path = string.Format("/developer_data/{0}", key); OKCloudAsyncRequest.Get(path, reqParams, (JSONObject responseObj, OKCloudException e) => { JSONObject j = responseObj.GetField(key); object retObject = JSONObjectExt.DeJSONify(j); if (retObject == null) { handler(null, new OKCloudException("Fail.")); } else { handler(retObject, null); } }); }
// Helper function for getting scores from OpenKit, internal use only private void GetScores(ScoreRequestType rt, Dictionary <string, object> requestParams, Action <List <OKScore>, OKException> requestHandler) { Action <JSONObject, OKCloudException> internalHandler = (responseObj, e) => { if (e == null) { if (responseObj.type == JSONObject.Type.ARRAY) { OKLog.Info("Successfully got " + responseObj.list.Count + " scores"); // OKLog.Info("GetScores Response json: " + responseObj.ToString()); List <OKScore> scoresList = new List <OKScore>(responseObj.list.Count); for (int x = 0; x < responseObj.list.Count; x++) { OKScore score = new OKScore(responseObj[x]); scoresList.Add(score); } requestHandler(scoresList, null); } else { requestHandler(null, new OKException("Expected an array of scores but did not get back an Array JSON")); } } else { requestHandler(null, e); } }; switch (rt) { case ScoreRequestType.Global: OKCloudAsyncRequest.Get("/best_scores", requestParams, internalHandler); break; case ScoreRequestType.Social: OKCloudAsyncRequest.Post("/best_scores/social", requestParams, internalHandler); break; } }
private void GetUsersTopScore(OKUser currentUser, Action <OKScore, OKException> requestHandler) { if (currentUser == null) { requestHandler(null, new OKException("No OKUser logged in, can't get best score")); return; } Dictionary <string, object> requestParams = new Dictionary <string, object>(); requestParams.Add("leaderboard_id", this.LeaderboardID); requestParams.Add("leaderboard_range", "all_time"); requestParams.Add("user_id", currentUser.OKUserID); OKCloudAsyncRequest.Get("/best_scores/user", requestParams, (JSONObject responseObj, OKCloudException e) => { if (e == null) { if (responseObj.type == JSONObject.Type.OBJECT) { OKScore topScore = new OKScore(responseObj); requestHandler(topScore, null); } else if (responseObj.type == JSONObject.Type.NULL) { requestHandler(null, null); } else { requestHandler(null, new OKException("Expected a single score JSON object but got something else")); } } else { requestHandler(null, e); } }); }