コード例 #1
0
        public static void GetConversionDetails(MonoBehaviour couroutineStarter, string wallCode, string userId, Action <AdGateConversionResponse> onOfferWallLoadSuccess = null, Action <string, int> onOfferWallLoadFailed = null, List <string> subIds = null)
        {
            string url = AdGateConfig.current.GetConversionListUrlWithParams(wallCode, userId, subIds);

            if (AdGateConfig.current.debugMode && subIds != null)
            {
                string allsubids = "";
                for (int i = 0; i < subIds.Count; i++)
                {
                    allsubids += subIds[i] + ",";
                }
                AdGateManager.DebugMessage(string.Format("Getting conversion details for wallCode: {0} + userId: {1} and subIds: {2}", wallCode, userId, allsubids));
            }
            Action <AdGateDefaultResponse> onComplete = (onComplete) =>
            {
                if (onComplete.success)
                {
                    AdGateConversionResponse conversionResponse = JsonConvert.DeserializeObject <AdGateConversionResponse>(onComplete.text);
                    conversionResponse.text       = onComplete.text;
                    conversionResponse.status     = onComplete.status;
                    conversionResponse.success    = onComplete.success;
                    conversionResponse.statusCode = onComplete.statusCode;
                    onOfferWallLoadSuccess?.Invoke(conversionResponse);
                }
                else
                {
                    onOfferWallLoadFailed?.Invoke(onComplete.Error, onComplete.statusCode);
                }
            };

            HttpClient.CallAPI(couroutineStarter, url, AdGateHTTPMethod.GET, "", onComplete);
        }
コード例 #2
0
        public static void LoadOfferWall(UniWebView uniWebView, string wallCode, string userId, Action onOfferWallLoadSuccess = null, Action <int> onOfferWallLoadFailed = null, List <string> subIds = null)
        {
            if (AdGateConfig.current.debugMode && subIds != null)
            {
                string allsubids = "";
                for (int i = 0; i < subIds.Count; i++)
                {
                    allsubids += subIds[i] + ",";
                }
                AdGateManager.DebugMessage(string.Format("Loading offerwall for wallcode: {0} + userId: {1} and subIds: {2}", wallCode, userId, allsubids));
            }
            string url = AdGateConfig.current.GetOfferWallUrlWithParams(wallCode, userId, subIds);

            uniWebView.Load(url);
            uniWebView.OnPageFinished += (view, statusCode, url) =>
            {
                AdGateManager.DebugMessage("Finished Loading offerwall");
                onOfferWallLoadSuccess?.Invoke();
                uniWebView.SetOpenLinksInExternalBrowser(true);
                uniWebView.SetBackButtonEnabled(false);
            };

            uniWebView.OnPageErrorReceived += (view, statusCode, url) =>
            {
                AdGateManager.DebugMessage(string.Format("Failed to load offerwall with code {0}", statusCode), true);
                onOfferWallLoadFailed?.Invoke(statusCode);
            };

            uniWebView.OnMessageReceived += (view, message) =>
            {
                if (message.Path.Equals("closeadgate"))
                {
                    AdGateManager.DebugMessage("Closed offerwall");
                    AdGateManager.CloseOfferWall();
                }
            };
            if (AdGateConfig.current.debugMode)
            {
                UniWebViewLogger.Instance.LogLevel = UniWebViewLogger.Level.Verbose;
            }
        }
コード例 #3
0
        public static IEnumerator SendRequest(AdGateServerRequest request, System.Action <AdGateDefaultResponse> OnServerResponse = null)
        {
            //Always wait 1 frame before starting any request to the server to make sure the requesters code has exited the main thread.
            yield return(null);

            //Build the URL that we will hit based on the specified endpoint, query params, etc
            string url = request.url;


#if UNITY_EDITOR
            AdGateManager.DebugMessage("ServerRequest URL: " + url);
#endif

            using (UnityWebRequest webRequest = request.CreateWebRequest())
            {
                webRequest.downloadHandler = new DownloadHandlerBuffer();

                float startTime  = Time.time;
                float maxTimeOut = 5f;

                yield return(webRequest.SendWebRequest());

                while (!webRequest.isDone)
                {
                    yield return(null);

                    if (Time.time - startTime >= maxTimeOut)
                    {
                        AdGateManager.DebugMessage("ERROR: Exceeded maxTimeOut waiting for a response from " + request.httpMethod.ToString() + " " + url);
                        yield break;
                    }
                }

                if (!webRequest.isDone)
                {
                    OnServerResponse?.Invoke(new AdGateDefaultResponse()
                    {
                        statusCode = 408, Error = "{\"error\": \"" + request.url + " Timed out.\"}"
                    });
                    yield break;
                }

                try
                {
#if UNITY_EDITOR
                    AdGateManager.DebugMessage("Server Response: " + request.httpMethod + " " + request.url + " completed in " + (Time.time - startTime).ToString("n4") + " secs.\nResponse: " + webRequest.downloadHandler.text);
#endif
                }
                catch
                {
                    AdGateManager.DebugMessage(request.httpMethod.ToString(), true);
                    AdGateManager.DebugMessage(request.url, true);
                    AdGateManager.DebugMessage(webRequest.downloadHandler.text, true);
                }

                AdGateDefaultResponse response = new AdGateDefaultResponse();
                response.statusCode = (int)webRequest.responseCode;
                if (webRequest.result == UnityWebRequest.Result.ProtocolError || webRequest.result == UnityWebRequest.Result.ConnectionError || !string.IsNullOrEmpty(webRequest.error))
                {
                    switch (webRequest.responseCode)
                    {
                    case 200:
                        response.Error = "";
                        break;

                    case 400:
                        response.Error = "Bad Request -- Your request has an error";
                        break;

                    case 402:
                        response.Error = "Payment Required -- Payment failed. Insufficient funds, etc.";
                        break;

                    case 401:
                        response.Error = "Unauthroized -- Your session_token is invalid";
                        break;

                    case 403:
                        response.Error = "Forbidden -- You do not have access";
                        break;

                    case 404:
                        response.Error = "Not Found";
                        break;

                    case 405:
                        response.Error = "Method Not Allowed";
                        break;

                    case 406:
                        response.Error = "Not Acceptable -- Purchasing is disabled";
                        break;

                    case 409:
                        response.Error = "Conflict -- Your state is most likely not aligned with the servers.";
                        break;

                    case 429:
                        response.Error = "Too Many Requests -- You're being limited for sending too many requests too quickly.";
                        break;

                    case 500:
                        response.Error = "Internal Server Error -- We had a problem with our server. Try again later.";
                        break;

                    case 503:
                        response.Error = "Service Unavailable -- We're either offline for maintenance, or an error that should be solvable by calling again later was triggered.";
                        break;
                    }
#if UNITY_EDITOR
                    AdGateManager.DebugMessage("Response code: " + webRequest.responseCode);
#endif
                    response.Error  += " " + webRequest.downloadHandler.text;
                    response.text    = webRequest.downloadHandler.text;
                    response.success = false;
                    response.text    = webRequest.downloadHandler.text;
                    OnServerResponse?.Invoke(response);
                }
                else
                {
                    response.success = true;
                    response.text    = webRequest.downloadHandler.text;
                    OnServerResponse?.Invoke(response);
                }
            }
        }
コード例 #4
0
 public static void ShowOfferWall(UniWebView uniWebViewComponent, Action <bool> onOfferWallShown = null)
 {
     AdGateManager.DebugMessage("Showing currently loaded offerwall");
     uniWebViewComponent?.Show();
     onOfferWallShown?.Invoke(true);
 }