Exemple #1
0
        /// <summary>
        /// To be used only for string type responses, like JSON.
        /// The string response is cached by default.
        /// </summary>
        /// <param name="operation">API operation to execute</param>
        /// <returns>A promise with a string response</returns>
        public IPromise <string> ExecuteOperation(OAOperation operation)
        {
            var promise = new Promise <string>();

            if (operation.ignoreCache == false)
            {
                string data;
                if (operation.GetFromCache(out data))
                {
                    Debug.Log("From cahce");
                    promise.Resolve(data);
                    return(promise);
                }
            }


            ApiAsset.ExecuteOperation(operation)
            .Then(res =>
            {
                if (res.Error == null)
                {
                    operation.Cache = res.Text;
                }
                promise.Resolve(res.Text);
            })
            .Catch(err => promise.Reject(err));

            return(promise);
        }
Exemple #2
0
        /// <summary>
        /// Use this method for JSON data response only.
        /// The string response is cached by default.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="operation">API operation to execute</param>
        /// <returns>A promise with automatically parsed data from JSON</returns>
        public IPromise <T> ExecuteOperation <T>(OAOperation operation)
        {
            var promise = new Promise <T>();

            ExecuteOperation(operation)
            .Then(res => promise.Resolve(JsonConvert.DeserializeObject <T>(res)))
            .Catch(err => promise.Reject(err));

            return(promise);
        }
Exemple #3
0
 /// <summary>
 /// Use this for not JSON responses like binary textures or asset bundles
 /// </summary>
 /// <param name="operation">API operation to execute</param>
 /// <returns>A promise with complete response wrapper containing UnityWebRequest with all data</returns>
 public IPromise <ResponseHelper> ExecuteOperationRaw(OAOperation operation)
 {
     return(ApiAsset.ExecuteOperation(operation));
 }