public Task(string uri, string data, Callback.Simple resultProcessor, Type type)
 {
     this.uri             = uri;
     this.data            = data;
     this.resultProcessor = resultProcessor;
     this.type            = type;
     time   = EditorApplication.timeSinceStartup;
     result = "";
     error  = Error.None;
     status = Status.InQueue;
 }
        public static Task UpdateClip(string clipUUID, ClipPatch patch, Callback.Simple callback)
        {
            string uri  = apiUri + "/projects/" + Settings.projectUUID + "/clips/" + clipUUID;
            string data = patch.ToJson();

            return(EnqueueTask(uri, data, Task.Type.Patch, (string content, Error error) =>
            {
                if (error)
                {
                    callback.Method.Invoke(callback.Target, new object[] { null, error });
                }
                else
                {
                    callback.Method.Invoke(callback.Target, new object[] { content, Error.None });
                }
            }));
        }
        /// <summary> Enqueue a web request to the task list. This task will be executed as soon as possible. </summary>
        public static Task EnqueueTask(string uri, string data, Task.Type type, Callback.Simple resultProcessor)
        {
            if (type == Task.Type.Download)
            {
                Debug.LogError("Download tasks start automatically, there is no need to put them in the queue.");
                return(null);
            }

            Task task = new Task(uri, data, resultProcessor, type);

            tasks.Enqueue(task);
            if (!receiveUpdates)
            {
                EditorApplication.update += Update;
                receiveUpdates            = true;
            }
            return(task);
        }
        public static Task CreateClipSync(ClipPatch.Data clipData, bool includePhonemes, Callback.Simple callback)
        {
            string uri  = apiUri + "/projects/" + Settings.projectUUID + "/clips/sync";
            string data = new CreateClipRequest(clipData, "high", false, includePhonemes).Json();

            return(EnqueueTask(uri, data, Task.Type.Post, (string content, Error error) =>
            {
                if (error)
                {
                    callback.Method.Invoke(callback.Target, new object[] { null, error });
                }
                else
                {
                    callback.Invoke(content, Error.None);
                }
            }));
        }
        public static Task DeleteClip(string uuid, Callback.Simple callback)
        {
            string uri = apiUri + "/projects/" + Settings.projectUUID + "/clips/" + uuid;

            return(EnqueueTask(uri, Task.Type.Delete, callback));
        }
 /// <summary> Enqueue a web request to the task list. This task will be executed as soon as possible. </summary>
 public static Task EnqueueTask(string uri, Task.Type type, Callback.Simple resultProcessor)
 {
     return(EnqueueTask(uri, "", type, resultProcessor));
 }