예제 #1
0
    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);
        }
    }
예제 #2
0
 /// <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));
 }
예제 #3
0
    /// <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);
    }
예제 #4
0
    /// <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));
    }