Exemplo n.º 1
0
        public IEnumerator postJSONRequest(string url, string authentification, IGoedleWebRequest gwr, IGoedleUploadHandler guh, bool staging)
        {
            if (staging)
            {
                Debug.Log("Staging is on you would request from this url:\n" + url + "\n The data would look like this:\n" + guh.getDataString());
            }
            else
            {
                gwr.unityWebRequest = new UnityWebRequest();
                using (gwr.unityWebRequest)
                {
                    gwr.method        = "POST";
                    gwr.url           = url;
                    gwr.uploadHandler = guh.uploadHandler;
                    gwr.SetRequestHeader("Content-Type", "application/json");
                    if (!string.IsNullOrEmpty(authentification))
                    {
                        gwr.SetRequestHeader("Authorization", authentification);
                    }
                    gwr.chunkedTransfer = false;
                    yield return(gwr.SendWebRequest());

                    if (gwr.isNetworkError || gwr.isHttpError)
                    {
                        Debug.Log("{\"error\": {  \"isHttpError\": \"" + gwr.isHttpError + "\",  \"isNetworkError\": \"" + gwr.isNetworkError + "\" } }");
                    }
                    yield break;
                }
            }
        }
Exemplo n.º 2
0
        /*
         * Returns an JSONNode object this can be accessed via:
         * CoroutineWithData cd = new CoroutineWithData(this, LoadSomeStuff( ) );
         * yield return cd.coroutine;
         * Debug.Log("result is " + cd.result);  //  'JSONNode'
         * CoroutineWithData is in GoedleUtils
         */
        public IEnumerator getJSONResponse(string url, GoedleAnalytics ga, IGoedleWebRequest gwr, IGoedleDownloadBuffer gdb, bool staging)
        {
            if (staging)
            {
                Debug.Log("Staging is on your get request would look like this:\n" + url);
            }
            else
            {
                gwr.unityWebRequest = new UnityWebRequest();
                using (gwr.unityWebRequest)
                {
                    gwr.method          = "GET";
                    gwr.url             = url;
                    gwr.downloadHandler = gdb.downloadHandlerBuffer;
                    yield return(gwr.SendWebRequest());

                    JSONNode strategy_json = null;
                    if (gwr.isNetworkError || gwr.isHttpError)
                    {
                        Debug.Log("{\"error\": {  \"isHttpError\": \"" + gwr.isHttpError + "\",  \"isNetworkError\": \"" + gwr.isNetworkError + "\" } }");
                        strategy_json = null;
                    }
                    else
                    {
                        // Show results as text
                        try
                        {
                            Debug.Log("The following strategy was received: " + gdb.text);
                            strategy_json = JSON.Parse(gdb.text);
                        }
                        catch (Exception e)
                        {
                            Debug.Log("{\"error\": \" " + e.Message + " \"}");
                            strategy_json = null;
                        }
                        // Or retrieve results as binary data
                        //byte[] results = client.downloadHandler.data;
                    }
                    ga.strategy = strategy_json;
                    yield break;
                }
            }
        }
Exemplo n.º 3
0
        public IEnumerator getRequest(string url, IGoedleWebRequest gwr, bool staging)
        {
            if (staging)
            {
                Debug.Log("Staging is on your get request would look like this:\n" + url);
            }
            else
            {
                gwr.unityWebRequest = new UnityWebRequest();
                using (gwr.unityWebRequest)
                {
                    gwr.method = "GET";
                    gwr.url    = url;
                    yield return(gwr.SendWebRequest());

                    if (gwr.isNetworkError || gwr.isHttpError)
                    {
                        Debug.Log("{\"error\": {  \"isHttpError\": \"" + gwr.isHttpError + "\",  \"isNetworkError\": \"" + gwr.isNetworkError + "\" } }");
                    }
                    yield break;
                }
            }
        }