Example #1
0
        public IEnumerator Update <T>(T item, Action <IRestResponse <T> > callback = null) where T : new()
        {
            string id = null;
            // Check if item uses the 'IDataModel' Interface to get 'id' property, otherwise try Refelection (using Reflection helper).
            IDataModel model = item as IDataModel;

            if (model != null)
            {
                id = model.GetId();
            }
            else if (ReflectionHelper.HasField(item, "id"))
            {
                var x = ReflectionHelper.GetField(item, "id");
                id = x.GetValue(item) as string;
            }
            else
            {
                Debug.LogError("Unable to get 'id' data model property");
            }
            if (string.IsNullOrEmpty(id))
            {
                Debug.LogError("Error 'id' value is missing");
                yield return(null);
            }
            string      url     = TableUrl(_name, id);
            ZumoRequest request = new ZumoRequest(url, Method.PATCH, true, _client.User);

            request.AddBody(item);
            Debug.Log("Update Request Url: " + url + " patch:" + item);
            yield return(request.Request.Send());

            request.ParseJson <T>(callback);
        }
Example #2
0
        public IEnumerator Read <T>(Action <IRestResponse <T[]> > callback = null) where T : new()
        {
            string      url     = TableUrl(_name);
            ZumoRequest request = new ZumoRequest(url, Method.GET, true, _client.User);

            Debug.Log("Read Request: " + url);
            yield return(request.Request.Send());

            request.ParseJsonArray <T>(callback);
        }
Example #3
0
        public IEnumerator Query <T>(TableQuery query, Action <IRestResponse <T[]> > callback = null) where T : new()
        {
            string      url     = TableQueryUrl(_name, query.ToString());
            ZumoRequest request = new ZumoRequest(url, Method.GET, true, _client.User);

            Debug.Log("Query Request: " + url + " Query:" + query);
            yield return(request.Request.Send());

            request.ParseJsonArray <T>(callback);
        }
Example #4
0
        public IEnumerator Lookup <T>(string id, Action <IRestResponse <T> > callback = null) where T : new()
        {
            string      url     = TableUrl(_name, id);
            ZumoRequest request = new ZumoRequest(url, Method.GET, true, _client.User);

            Debug.Log("Lookup Request Url: " + url);
            yield return(request.Request.Send());

            request.ParseJson <T>(callback);
        }
        /// <summary>
        /// Client-directed single sign on for Google+ (using access token and id token)
        /// </summary>
        public IEnumerator LoginWithGoogle(string accessToken, string idToken, Action <IRestResponse <AuthenticatedUser> > callback = null)
        {
            string url     = AppServiceAuthenticationProviderUrl(AuthenticationProvider.Google);
            var    request = new ZumoRequest(url, Method.POST, false);

            request.AddBodyAccessTokenId(accessToken, idToken);
            yield return(request.Request.Send());

            LoggedIn(request, callback);
        }
Example #6
0
        /// <summary>
        /// Client-directed single sign on for Twitter (using access token and access token secret)
        /// </summary>
        public IEnumerator LoginWithTwitter(string accessToken, string accessTokenSecret, Action <IRestResponse <AuthenticatedUser> > callback = null)
        {
            string url     = AppServiceAuthenticationProviderUrl(AuthenticationProvider.Twitter);
            var    request = new ZumoRequest(url, Method.POST, false);

            request.AddBodyAccessTokenSecret(accessToken, accessTokenSecret);
            yield return(request.Request.SendWebRequest());

            LoggedIn(request, callback);
        }
Example #7
0
        public IEnumerator Insert <T>(T item, Action <IRestResponse <T> > callback = null) where T : new()
        {
            string      url     = TableUrl(_name);
            ZumoRequest request = new ZumoRequest(url, Method.POST, true, _client.User);

            Debug.Log("Insert Request: " + url);
            request.AddBody(item);
            yield return(request.Request.Send());

            request.ParseJson <T>(callback);
        }
Example #8
0
        /// <summary>
        /// Invokes custom API for HTTP Methods: GET, POST, PUT, PATCH, DELETE
        /// </summary>
        public IEnumerator InvokeApi <T>(string apiName, Method httpMethod, Action <IRestResponse <T> > callback = null) where T : new()
        {
            string url = ApiUrl(apiName);

            Debug.Log(httpMethod.ToString() + " custom API Request Url: " + url);
            ZumoRequest request = new ZumoRequest(url, httpMethod, true, User);

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

            request.ParseJson <T>(callback);
        }
        public IEnumerator Query <T>(TableQuery query, Action <IRestResponse <NestedResults <T> > > callback = null) where T : new()
        {
            string q = query.ToString();
            string nestedQueryString = string.Format("{0}{1}$inlinecount=allpages", q, (q.Length > 1) ? "&" : "?");
            string url = TableQueryUrl(_name, nestedQueryString);
            //Debug.Log("Query Request: " + url + " Paginated Query:" + query);
            ZumoRequest request = new ZumoRequest(url, Method.GET, true, _client.User);

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

            request.ParseJsonNestedArray <T, NestedResults <T> >("results", callback);
        }
Example #10
0
        private IEnumerator Login(AuthenticationProvider authenticationProvider,
                                  string accessToken,
                                  Action <IRestResponse <AuthenticatedUser> > callback = null)
        {
            string url     = AppServiceAuthenticationProviderUrl(authenticationProvider);
            var    request = new ZumoRequest(url, Method.POST, false);

            request.AddBodyAccessToken(accessToken);
            yield return(request.Request.SendWebRequest());

            LoggedIn(request, callback);
        }
        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();
        }