예제 #1
0
        public void SubmitScore(Action <OKScore, OKException> callback)
        {
            OKUser u = GetUser();

            if (u == null)
            {
                throw new Exception("You need a user to submit a score");
            }

            Dictionary <string, object> score = new Dictionary <string, object>();

            score.Add("leaderboard_id", LeaderboardID);
            score.Add("value", scoreValue);
            score.Add("display_string", displayString);
            score.Add("metadata", metadata);
            score.Add("user_id", u.OKUserID.ToString());

            Dictionary <string, object> reqParams = new Dictionary <string, object>();

            reqParams.Add("score", score);

            OKUploadBuffer buff = null;

            if (MetadataBuffer != null)
            {
                buff = new OKUploadBuffer()
                {
                    Bytes     = MetadataBuffer,
                    ParamName = "score[meta_doc]",
                    FileName  = "upload"
                };
            }

            Action <JSONObject, OKCloudException> handler = (responseObj, e) => {
                if (e == null)
                {
                    OKScore retScore = new OKScore(responseObj);
                    callback(retScore, null);
                }
                else
                {
                    callback(null, e);
                }
            };

            OKCloudAsyncRequest.Post("/scores", reqParams, buff, handler);
        }
예제 #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;
            }
        }
예제 #3
0
        public void mSet(object o, String key, Action <OKCloudException> handler)
        {
            OKUser u = GetUser();

            if (u == null)
            {
                throw new Exception("You need a user to perform cloud set.");
            }

            Dictionary <string, object> reqParams = new Dictionary <string, object>();

            reqParams.Add("user_id", u.OKUserID.ToString());
            reqParams.Add("field_key", key);
            reqParams.Add("field_value", o);
            OKCloudAsyncRequest.Post("/developer_data", reqParams, (JSONObject responseObj, OKCloudException e) => {
                if (e != null)
                {
                    OKLog.Error("Async post failed with error " + e);
                }
                handler(e);
            });
        }