private void LoggedIn(ZumoRequest request, Action <IRestResponse <AuthenticatedUser> > callback = null)
        {
            string message = request.Request.downloadHandler.text;
            IRestResponse <AuthenticatedUser> response = request.ParseJson <AuthenticatedUser>();

            if (!response.IsError)
            {
                User = response.Data;
                if (callback != null)
                {
                    callback(response);
                }
            }
            else
            {
                Debug.LogWarning("Login error message:" + message);
            }
            request.Dispose();
        }
        public IEnumerator Logout(Action <IRestResponse <string> > callback = null)
        {
            if (User == null)
            {
                Debug.LogWarning("Error, requires user login.");
                yield break;
            }
            string url     = string.Format("{0}/.auth/logout", Url);
            var    request = new ZumoRequest(url, Method.POST, false, User);

            yield return(request.Request.Send());

            if (callback == null)
            {
                yield break;
            }
            HttpStatusCode        statusCode = (HttpStatusCode)Enum.Parse(typeof(HttpStatusCode), request.Request.responseCode.ToString());
            RestResponse <string> response   = new RestResponse <string>(statusCode, request.Request.url, request.Request.downloadHandler.text);

            if (!statusCode.Equals(HttpStatusCode.OK))
            {
                Debug.LogWarning("Error, logout request failed.");
                yield break;
            }
            // Detect result of logout webpage (using title tag to verify sign out success) with callback response
            var match = Regex.Match(request.Request.downloadHandler.text, @"<title>(.+)<\/title>", RegexOptions.IgnoreCase);

            if (match.Groups.Count == 2 && !string.IsNullOrEmpty(match.Groups[1].Value))
            {
                string title = match.Groups[1].Value;
                Assert.IsTrue(string.Equals(title, "You have been signed out"));
                response = new RestResponse <string>(statusCode, request.Request.url, title);
            }
            callback(response);
            User = null;
            request.Dispose();
        }