private IEnumerator SendApiCor <T>(string path, RequestType requestType, SendApiSuccessHandler <T> successCallback, SendApiFailedHandler failedCallback, SendApiFailedByNetWorkHandler networkErrorCallback, string data, string token, Tuple <string, string>[] customHeader) { using (var request = GetUnityWebRequest(path, requestType, data, token, customHeader)) { if (request == null) { yield break; } yield return(request.SendWebRequest()); if (request.isHttpError) { failedCallback?.Invoke(); yield break; } if (request.isNetworkError) { networkErrorCallback?.Invoke(); yield break; } var response = JsonUtility.FromJson <T>(request.downloadHandler.text); successCallback?.Invoke(response); } }
/// <typeparam name="T">Type of response</typeparam> public void SendGetApi <T>(string path, SendApiSuccessHandler <T> successCallback, SendApiFailedHandler failedCallback, SendApiFailedByNetWorkHandler networkErrorCallback, string token = null, params Tuple <string, string>[] customHeader) { StartCoroutine(SendApiCor(path, RequestType.GET, successCallback, failedCallback, networkErrorCallback, null, token, customHeader)); }
/// <typeparam name="T">Type of response</typeparam> public void SendPostApi <T>(string path, SendApiSuccessHandler <T> successCallback, SendApiFailedHandler failedCallback, SendApiFailedByNetWorkHandler networkErrorCallback, object data = null, string token = null, params Tuple <string, string>[] customHeader) { string requestBodyString = JsonUtility.ToJson(data); SendPostApi(path, successCallback, failedCallback, networkErrorCallback, requestBodyString, token, customHeader); }
/// <summary> /// Used this method when response data is not used /// </summary> public void SendPostApi(string path, SendApiSuccessHandler successCallback, SendApiFailedHandler failedCallback, SendApiFailedByNetWorkHandler networkErrorCallback, object data = null, string token = null, params Tuple <string, string>[] customHeader) { string requestBody = JsonUtility.ToJson(data); StartCoroutine(SendApiCor(path, RequestType.POST, successCallback, failedCallback, networkErrorCallback, requestBody, token, customHeader)); }