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();
        }
Beispiel #3
0
 public ZumoRequest(string url, Method httpMethod = Method.GET, bool excludeSystemProperties = true, AuthenticatedUser user = null) : base(url, httpMethod)
 {
     this.excludeSystemProperties = excludeSystemProperties;
     this.AddHeader("ZUMO-API-VERSION", "2.0.0");
     this.AddHeader("Accept", "application/json");
     this.AddHeader("Content-Type", "application/json; charset=utf-8");
     // User Authentictated request
     if (user != null && !string.IsNullOrEmpty(user.authenticationToken))
     {
         this.AddHeader("X-ZUMO-AUTH", user.authenticationToken);
     }
 }