示例#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);
            }
        }
        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);
            }
        }