Ejemplo n.º 1
0
        public bool authWithCurrentUser(string password, string uri)
        {
            //get auth token with current user
            request = new RequestEngine();

            string email = this.getEmail();
            string body  = "{\"email\":\"" + email + "\",\"password\":\"" + password + "\"}";


            RequestProperties headers = new RequestProperties();

            headers.setMethod("POST");
            headers.setEndpoint("/api/v/1/user/auth");
            headers.setUri(uri);
            headers.setBody(body);

            request.setHeaders(headers);
            Console.WriteLine("In Auth with current user");
            PlatformResponse <string> result = request.executePost();

            if (result.getError())
            {
                Util.logger("CBUserTask", "User call failed: " + result.getData(), true);
                ClearBlade.setInitError(true);
                Console.WriteLine("Some error in result");
                return(false);
            }
            else
            {
                JObject json = JObject.Parse((string)result.getData());
                setAuthToken((string)json["user_token"]);
                return(true);
            }
        }
Ejemplo n.º 2
0
        public bool authWithAnonUser(string uri, int timeout)
        {
            request = new RequestEngine();
            Console.WriteLine("Req URI: " + uri);
            RequestProperties headers = new RequestProperties();

            headers.setMethod("POST");
            headers.setEndpoint("/api/v/1/user/anon");
            headers.setUri(uri);
            headers.setTimeout(timeout);

            request.setHeaders(headers);

            PlatformResponse <string> result = request.execute();

            if (result.getError())
            {
                Util.logger("CBUserTask", "User call failed: " + result.getData(), true);
                ClearBlade.setInitError(true);
                return(false);
            }
            else
            {
                JObject json = JObject.Parse((string)result.getData());
                setAuthToken((string)json["user_token"]);
                return(true);
            }
        }
Ejemplo n.º 3
0
        public bool executeCode(string serviceName, string parameters)
        {
            request = new RequestEngine();
            Console.WriteLine("Service Name: " + serviceName);
            RequestProperties headers = new RequestProperties();

            headers.setMethod("POST");
            string endpoint = "/api/v/1/code/" + Util.getSystemKey() + "/" + this.serviceName + "";

            headers.setEndpoint(endpoint);
            headers.setBody(parameters);

            request.setHeaders(headers);

            PlatformResponse <string> result = request.executePost();

            if (result.getError())
            {
                Util.logger("CBUserTask", "User call failed: " + result.getData(), true);
                return(false);
            }
            else
            {
                Console.WriteLine((string)result.getData());

                return(true);
            }
        }
Ejemplo n.º 4
0
        public bool logout(string uri)
        {
            request = new RequestEngine();
            Console.WriteLine("Req URI: " + uri);
            RequestProperties headers = new RequestProperties();

            headers.setMethod("POST");
            headers.setEndpoint("/api/v/1/user/logout");
            headers.setUri(uri);


            request.setHeaders(headers);

            PlatformResponse <string> result = request.execute();

            if (result.getError())
            {
                Util.logger("CBUserTask", "User call failed: " + result.getData(), true);
                ClearBlade.setInitError(true);
                return(false);
            }
            else
            {
                setAuthToken(null);
                Console.WriteLine("User Logged out");
                return(true);
            }
        }