Пример #1
0
        // 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;
            }
        }
Пример #2
0
        // 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;
            }
        }