public void Fetch(string layout, MagicUIManager.GenericCallback <JSONObject> callback) { if (callback == null) { return; } StartCoroutine(landingPage(layout, (error, json) => { if (!string.IsNullOrEmpty(error)) { callback(error, null); } else { int firstId = (int)json["pageGroups"].list[0]["properties"]["pageIds"].list[0].n; JSONObject parsed = parseToIntermediateFormat(json["pages"], firstId); if (parsed == null) { callback("PREPARSE FAILED", null); } else { callback(null, parsed); } } })); }
public void Setup(MagicUIManager.GenericCallback <bool> callback) { // Nothing to do! if (callback != null) { callback(null, true); } }
protected IEnumerator loadProject(string projectId, string auth, MagicUIManager.GenericCallback <JSONObject> callback) { Hashtable headers = new Hashtable(); headers["Cookie"] = auth; headers["Content-Type"] = "application/json"; JSONObject json = new JSONObject(JSONObject.Type.OBJECT); json.AddField("projectId", projectId); json.AddField("sharedPagesOnly", true); string postText = json.ToString(); byte[] postData = Encoding.UTF8.GetBytes(postText); WWW request = new WWW(_kGetProjectDataURL, postData, headers); DebugManager.Log("Fetch {0}", _kGetProjectDataURL); yield return(request); JSONObject response = null; if (!string.IsNullOrEmpty(request.error)) { Debug.LogWarning(request.error); } else { string unescaped = unescape(request.text); response = new JSONObject(unescaped); if (!response.IsObject) { callback("PROJECT PARSE FAILED", null); } else { callback(null, response); } } }
protected IEnumerator landingPage(string url, MagicUIManager.GenericCallback <JSONObject> callback) { string id = null; string auth = null; string body = null; #if UNIWEB DebugManager.Log("Fetch {0} via UniWeb", url); var request = new HTTP.Request("GET", url); yield return(request.Send()); if (request.exception != null) { callback(request.exception.Message, null); } else { if (request.response.headers.Contains("SET-COOKIE")) { foreach (string cookie in request.response.headers.GetAll("SET-COOKIE")) { if (cookie.StartsWith(".ASPXAUTH")) { auth = cookie.Substring(0, auth.IndexOf(";"));; body = request.response.Text; break; } } if (auth == null) { callback("COOKIE NOT FOUND", null); } } } #else DebugManager.Log("Fetch {0} via WWW", url); WWW request = new WWW(url); yield return(request); if (!string.IsNullOrEmpty(request.error)) { callback(request.error, null); } else { if (request.responseHeaders.ContainsKey("SET-COOKIE")) { auth = request.responseHeaders["SET-COOKIE"]; if (!auth.StartsWith(".ASPXAUTH")) { Debug.Log(request.responseHeaders["SET-COOKIE"]); callback("COOKIE BURIED", null); } else { auth = auth.Substring(0, auth.IndexOf(";")); body = request.text; } } } #endif if (body != null) { int start = body.IndexOf(_kProjectIdMarker); if (start >= 0) { int count = body.IndexOf(',', start + _kProjectIdMarker.Length) - (start + _kProjectIdMarker.Length); if (count >= 0) { id = body.Substring(start + _kProjectIdMarker.Length, count).Trim(); } } } if (id == null) { callback("BODY PARSE FAILED", null); } if (!string.IsNullOrEmpty(id) && !string.IsNullOrEmpty(auth)) { yield return(StartCoroutine(loadProject(id, auth, callback))); } }