Ejemplo 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);
            });
        }
Ejemplo 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);
                }
            });
        }
Ejemplo n.º 3
0
        public OKUser getCurrentUser()
        {
            int okID = OKAndroidPlugin.CallStatic<int>("getCurrentUserOKID");

            if(okID == 0)
                return null;
            else {
                OKUser user = new OKUser();
                user.OKUserID = okID;
                user.userNick = OKAndroidPlugin.CallStatic<string>("getCurrentUserNick");
                user.FBUserID = OKAndroidPlugin.CallStatic<long>("getCurrentUserFBID");
                user.twitterUserID = OKAndroidPlugin.CallStatic<long>("getCurrentUserTwitterID");
                return user;
            }
        }
Ejemplo n.º 4
0
        public OKUser GetCurrentUser()
        {
            int okID = OKAndroidPlugin.CallStatic<int>("getCurrentUserOKID");
            OKLog.Info("Current openkit user id: " + okID);

            if(okID == 0)
                return null;
            else {
                OKUser user = new OKUser();
                user.OKUserID = okID;
                user.UserNick = OKAndroidPlugin.CallStatic<string>("getCurrentUserNick");
                user.FBUserID = OKAndroidPlugin.CallStatic<string>("getCurrentUserFBID");
                OKLog.Info("Current user: " + user);
                return user;
            }
        }
Ejemplo 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);
        }
Ejemplo n.º 6
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);
            });
        }
Ejemplo n.º 7
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);
            });
        }
Ejemplo n.º 8
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);
                }
            });
        }
Ejemplo n.º 9
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);
                }
            });
        }
Ejemplo n.º 10
0
 public void GetUsersTopScore(Action <OKScore, OKException> requestHandler)
 {
     this.GetUsersTopScore(OKUser.GetCurrentUser(), requestHandler);
 }