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 asyncCallFailed(string errorString) { OKLog.Error("asyncCallFailed: " + errorString); if (functionCallback != null) { functionCallback(false, errorString); } GameObject.Destroy(this.gameObject); }
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); }); }
public RestRequest GetHttpRequest() { RestRequest httpRequest = null; switch (_verb) { case OKRestVerb.Get: httpRequest = BuildGetRequest(_path, _params); break; case OKRestVerb.Post: httpRequest = (_upload == null) ? BuildPostRequest(_path, _params) : BuildMultipartPostRequest(_path, _params, _upload); break; case OKRestVerb.Put: httpRequest = BuildPutRequest(_path, _params); break; default: OKLog.Error("Doing it wrong!"); break; } return(httpRequest); }
public static JSONObject jsonObjectify(object o) { JSONObject j = null; Type ot = o.GetType(); if (ot == typeof(String)) { j = new JSONObject { type = JSONObject.Type.STRING, str = (string)o }; } else if (ot == typeof(ArrayList)) { j = new JSONObject { type = JSONObject.Type.ARRAY }; foreach (object element in (ArrayList)o) { j.Add(jsonObjectify(element)); } } else if (ot.IsGenericType && (ot.GetGenericTypeDefinition() == typeof(List <>))) { j = new JSONObject { type = JSONObject.Type.ARRAY }; // There must be a better way to do this at runtime. Right now we get // the type T in List<T> and cast 'o' to it. Type lt = ot.GetGenericArguments()[0]; if (lt == typeof(string)) { foreach (object element in (List <string>)o) { j.Add(jsonObjectify(element)); } } else { OKLog.Error("Lists of that type are not supported by JSONObjectExt! Fix me."); } } else if (ot == typeof(Dictionary <string, object>)) { j = new JSONObject { type = JSONObject.Type.OBJECT }; foreach (KeyValuePair <string, object> entry in (Dictionary <string, object>)o) { j.AddField(entry.Key, jsonObjectify(entry.Value)); } } else if (ot.IsPrimitive) { if (typeof(bool) == ot) { j = new JSONObject { type = JSONObject.Type.BOOL, b = (bool)o }; } else { double d = Convert.ToDouble(o); j = new JSONObject { type = JSONObject.Type.NUMBER, n = d }; } } return(j); }