Exemplo n.º 1
0
        public void mSet(object o, String key, Action <object, OKCloudException> handler)
        {
            OKUser u = GetUser();

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

            string objRep = "";

            objRep += JSONObjectExt.encode(o);

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

            reqParams.Add("user_id", u.OKUserID.ToString());
            reqParams.Add("field_key", key);
            reqParams.Add("field_value", objRep);

            OKCloudAsyncRequest req = new OKCloudAsyncRequest("developer_data", "POST", reqParams);

            req.performWithCompletionHandler((string response, OKCloudException e) => {
                handler(o, e);
            });
        }
Exemplo n.º 2
0
        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);
                }
            });
        }
Exemplo n.º 3
0
        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"));
                    }
                }
            });
        }
Exemplo n.º 4
0
        public void mGet(String key, Action<JSONObject, OKCloudException> handler)
        {
            OKUser u = GetUser();
            if (u == null)
                throw new Exception("You need a user to perform cloud get.");

            Dictionary<string, string> reqParams = new Dictionary<string, string>();
            reqParams.Add("user_id", u.OKUserID.ToString());

            string path = string.Format("developer_data/{0}", key);
            OKCloudAsyncRequest req = new OKCloudAsyncRequest(path, "GET", reqParams);
            req.performWithCompletionHandler((string response, OKCloudException e) => {
                JSONObject jsonObj = JSONObjectExt.decode(response);
                handler(jsonObj.GetField(key), e);
            });
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        public void mSet(object o, String key, Action<object, OKCloudException> handler)
        {
            OKUser u = GetUser();
            if (u == null)
                throw new Exception("You need a user to perform cloud set.");

            string objRep = "";
            objRep += JSONObjectExt.encode(o);

            Dictionary<string, string> reqParams = new Dictionary<string, string>();
            reqParams.Add("user_id", u.OKUserID.ToString());
            reqParams.Add("field_key", key);
            reqParams.Add("field_value", objRep);

            OKCloudAsyncRequest req = new OKCloudAsyncRequest("developer_data", "POST", reqParams);
            req.performWithCompletionHandler((string response, OKCloudException e) => {
                handler(o, e);
            });
        }
Exemplo n.º 7
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;
            }
        }
Exemplo n.º 8
0
        public void mGet(String key, Action <JSONObject, OKCloudException> handler)
        {
            OKUser u = GetUser();

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

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

            reqParams.Add("user_id", u.OKUserID.ToString());

            string path             = string.Format("developer_data/{0}", key);
            OKCloudAsyncRequest req = new OKCloudAsyncRequest(path, "GET", reqParams);

            req.performWithCompletionHandler((string response, OKCloudException e) => {
                JSONObject jsonObj = JSONObjectExt.decode(response);
                handler(jsonObj.GetField(key), e);
            });
        }
Exemplo n.º 9
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);
            });
        }
Exemplo n.º 10
0
        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);
                }
            });
        }