setHeader() 개인적인 메소드

private setHeader ( string field, string value ) : void
field string
value string
리턴 void
예제 #1
0
        internal static IEnumerator Request(MonoBehaviour caller, EngageRequest request, EngageResponse response)
        {
            string requestJSON = request.ToJSON();
            string url = DDNA.Instance.ResolveEngageURL(requestJSON);

            HttpRequest httpRequest = new HttpRequest(url);
            httpRequest.HTTPMethod = HttpRequest.HTTPMethodType.POST;
            httpRequest.HTTPBody = requestJSON;
            httpRequest.TimeoutSeconds = DDNA.Instance.Settings.HttpRequestEngageTimeoutSeconds;
            httpRequest.setHeader("Content-Type", "application/json");

            System.Action<int, string, string> httpHandler = (statusCode, data, error) => {

                string engagementKey = "DDSDK_ENGAGEMENT_" + request.DecisionPoint + "_" + request.Flavour;
                if (error == null && statusCode >= 200 && statusCode < 300) {
                    try {
                        PlayerPrefs.SetString(engagementKey, data);
                    } catch (Exception exception) {
                        Logger.LogWarning("Unable to cache engagement: "+exception.Message);
                    }
                } else {
                    Logger.LogDebug("Engagement failed with "+statusCode+" "+error);
                    if (PlayerPrefs.HasKey(engagementKey)) {
                        Logger.LogDebug("Using cached response");
                        data = "{\"isCachedResponse\":true," + PlayerPrefs.GetString(engagementKey).Substring(1);
                    } else {
                        data = "{}";
                    }
                }

                response(data, statusCode, error);
            };

            yield return caller.StartCoroutine(Network.SendRequest(httpRequest, httpHandler));
        }
예제 #2
0
파일: DDNA.cs 프로젝트: darkfuse15/InesGame
        private IEnumerator PostEvents(string[] events, Action <bool, int> resultCallback)
        {
            string bulkEvent = "{\"eventList\":[" + String.Join(",", events) + "]}";
            string url;

            if (this.HashSecret != null)
            {
                string md5Hash = GenerateHash(bulkEvent, this.HashSecret);
                url = FormatURI(Settings.COLLECT_HASH_URL_PATTERN, this.CollectURL, this.EnvironmentKey, md5Hash);
            }
            else
            {
                url = FormatURI(Settings.COLLECT_URL_PATTERN, this.CollectURL, this.EnvironmentKey, null);
            }

            int  attempts  = 0;
            bool succeeded = false;
            int  status    = 0;

            Action <int, string, string> completionHandler = (statusCode, data, error) => {
                if (statusCode < 400)
                {
                    succeeded = true;
                }
                else
                {
                    Logger.LogDebug("Problem posting events: " + statusCode + " '" + error + "'");
                }
                status = statusCode;
            };

            HttpRequest request = new HttpRequest(url);

            request.HTTPMethod = HttpRequest.HTTPMethodType.POST;
            request.HTTPBody   = bulkEvent;
            request.setHeader("Content-Type", "application/json");

            while (attempts < Settings.HttpRequestMaxRetries)
            {
                yield return(StartCoroutine(Network.SendRequest(request, completionHandler)));

                if (succeeded)
                {
                    break;
                }

                yield return(new WaitForSeconds(Settings.HttpRequestRetryDelaySeconds));

                attempts += 1;
            }

            resultCallback(succeeded, status);
        }
예제 #3
0
        internal static IEnumerator Request(
            MonoBehaviour caller,
            EngageCache cache,
            EngageRequest request,
            EngageResponse response,
            bool useConfigurationTimeout = false)
        {
            string requestJSON = request.ToJSON();
            string url         = DDNA.Instance.ResolveEngageURL(requestJSON);

            HttpRequest httpRequest = new HttpRequest(url);

            httpRequest.HTTPMethod     = HttpRequest.HTTPMethodType.POST;
            httpRequest.HTTPBody       = requestJSON;
            httpRequest.TimeoutSeconds = useConfigurationTimeout ? DDNA.Instance.Settings.HttpRequestConfigurationTimeoutSeconds : DDNA.Instance.Settings.HttpRequestEngageTimeoutSeconds;
            httpRequest.setHeader("Content-Type", "application/json");

            Action <int, string, string> httpHandler = (statusCode, data, error) => {
                if (error == null && statusCode >= 200 && statusCode < 300)
                {
                    cache.Put(request.DecisionPoint, request.Flavour, data);
                }
                else
                {
                    Logger.LogDebug("Engagement failed with " + statusCode + " " + error);
                    var isClientError = statusCode >= 400 && statusCode < 500;
                    var cached        = cache.Get(request.DecisionPoint, request.Flavour);
                    if (cached != null && !isClientError)
                    {
                        Logger.LogDebug("Using cached response");
                        data = "{\"isCachedResponse\":true," + cached.Substring(1);
                    }
                    else
                    {
                        data = "{}";
                    }
                }

                response(data, statusCode, error);
            };

            yield return(caller.StartCoroutine(Network.SendRequest(httpRequest, httpHandler)));
        }
예제 #4
0
        internal static IEnumerator Request(MonoBehaviour caller, EngageRequest request, EngageResponse response)
        {
            string requestJSON = request.ToJSON();
            string url         = DDNA.Instance.ResolveEngageURL(requestJSON);

            HttpRequest httpRequest = new HttpRequest(url);

            httpRequest.HTTPMethod     = HttpRequest.HTTPMethodType.POST;
            httpRequest.HTTPBody       = requestJSON;
            httpRequest.TimeoutSeconds = DDNA.Instance.Settings.HttpRequestEngageTimeoutSeconds;
            httpRequest.setHeader("Content-Type", "application/json");

            System.Action <int, string, string> httpHandler = (statusCode, data, error) => {
                string engagementKey = "DDSDK_ENGAGEMENT_" + request.DecisionPoint + "_" + request.Flavour;
                if (error == null && statusCode >= 200 && statusCode < 300)
                {
                    try {
                        PlayerPrefs.SetString(engagementKey, data);
                    } catch (Exception exception) {
                        Logger.LogWarning("Unable to cache engagement: " + exception.Message);
                    }
                }
                else
                {
                    Logger.LogDebug("Engagement failed with " + statusCode + " " + error);
                    if (PlayerPrefs.HasKey(engagementKey))
                    {
                        Logger.LogDebug("Using cached response");
                        data = "{\"isCachedResponse\":true," + PlayerPrefs.GetString(engagementKey).Substring(1);
                    }
                    else
                    {
                        data = "{}";
                    }
                }

                response(data, statusCode, error);
            };

            yield return(caller.StartCoroutine(Network.SendRequest(httpRequest, httpHandler)));
        }
예제 #5
0
파일: DDNA.cs 프로젝트: darkfuse15/InesGame
        private IEnumerator EngageRequest(string engagement, Action <string> callback)
        {
            string url;

            if (this.HashSecret != null)
            {
                string md5Hash = GenerateHash(engagement, this.HashSecret);
                url = FormatURI(Settings.ENGAGE_HASH_URL_PATTERN, this.EngageURL, this.EnvironmentKey, md5Hash);
            }
            else
            {
                url = FormatURI(Settings.ENGAGE_URL_PATTERN, this.EngageURL, this.EnvironmentKey, null);
            }

            HttpRequest request = new HttpRequest(url);

            request.HTTPMethod = HttpRequest.HTTPMethodType.POST;
            request.HTTPBody   = engagement;
            request.setHeader("Content-Type", "application/json");

            Action <int, string, string> completionHandler = (status, response, error) =>
            {
                if (status < 400)
                {
                    if (callback != null)
                    {
                        callback(response);
                    }
                }
                else
                {
                    Logger.LogDebug("Error requesting engagement, Engage returned: " + error);
                    if (callback != null)
                    {
                        callback(null);
                    }
                }
            };

            yield return(StartCoroutine(Network.SendRequest(request, completionHandler)));
        }
예제 #6
0
        internal override void ForgetMe()
        {
            if (PlayerPrefs.HasKey(DDNA.PF_KEY_FORGOTTEN))
            {
                Logger.LogDebug("Already forgotten user " + UserID);
                return;
            }

            Logger.LogDebug("Forgetting user " + UserID);
            PlayerPrefs.SetInt(DDNA.PF_KEY_FORGET_ME, 1);

            if (IsUploading)
            {
                return;
            }

            string gameEvent;

            try {
                gameEvent = MiniJSON.Json.Serialize(
                    new GameEvent("ddnaForgetMe")
                    .AddParam("eventTimestamp", GetCurrentTimestamp())
                    .AddParam("eventUUID", Guid.NewGuid().ToString())
                    .AddParam("sessionID", SessionID)
                    .AddParam("userID", UserID)
                    .AddParam("eventParams", new Params()
                              .AddParam("platform", Platform)
                              .AddParam("sdkVersion", Settings.SDK_VERSION))
                    .AddParam("ddnaAdvertisingId", PlayerPrefs.GetString(DDNA.PF_KEY_ADVERTISING_ID))
                    .AsDictionary());
            } catch (Exception e) {
                Logger.LogWarning("Unable to generate JSON for 'ddnaForgetMe' event. " + e.Message);
                return;
            }

            var url = (HashSecret != null)
                ? DDNA.FormatURI(
                Settings.COLLECT_HASH_URL_PATTERN,
                CollectURL,
                EnvironmentKey,
                DDNA.GenerateHash(gameEvent, HashSecret))
                : DDNA.FormatURI(
                Settings.COLLECT_URL_PATTERN,
                CollectURL,
                EnvironmentKey,
                null);

            HttpRequest request = new HttpRequest(url)
            {
                HTTPMethod = HttpRequest.HTTPMethodType.POST,
                HTTPBody   = gameEvent
            };

            request.setHeader("Content-Type", "application/json");

            StartCoroutine(Send(
                               request,
                               () => {
                Logger.LogDebug("Forgot user " + UserID);
                PlayerPrefs.SetInt(DDNA.PF_KEY_FORGOTTEN, 1);
            }));
        }
        internal override void ForgetMe()
        {
            if (PlayerPrefs.HasKey(DDNA.PF_KEY_FORGOTTEN))
            {
                Logger.LogDebug("Already forgotten user " + UserID);
                return;
            }

            Logger.LogDebug("Forgetting user " + UserID);
            PlayerPrefs.SetInt(DDNA.PF_KEY_FORGET_ME, 1);

            if (IsUploading)
            {
                return;
            }

            var advertisingId = PlayerPrefs.GetString(DDNA.PF_KEY_ADVERTISING_ID);
            var dictionary    = new Dictionary <string, object>()
            {
                { "eventName", "ddnaForgetMe" },
                { "eventTimestamp", GetCurrentTimestamp() },
                { "eventUUID", Guid.NewGuid().ToString() },
                { "sessionID", SessionID },
                { "userID", UserID },
                { "eventParams", new Dictionary <string, object>()
                  {
                      { "platform", Platform },
                      { "sdkVersion", Settings.SDK_VERSION },
                      { "ddnaAdvertisingId", advertisingId }
                  } }
            };

            if (string.IsNullOrEmpty(advertisingId))
            {
                (dictionary["eventParams"] as Dictionary <string, object>)
                .Remove("ddnaAdvertisingId");
            }

            string json;

            try {
                json = MiniJSON.Json.Serialize(dictionary);
            } catch (Exception e) {
                Logger.LogWarning("Unable to generate JSON for 'ddnaForgetMe' event. " + e.Message);
                return;
            }

            var url = (HashSecret != null)
                ? DDNA.FormatURI(
                Settings.COLLECT_HASH_URL_PATTERN.Replace("/bulk", ""),
                CollectURL,
                EnvironmentKey,
                DDNA.GenerateHash(json, HashSecret))
                : DDNA.FormatURI(
                Settings.COLLECT_URL_PATTERN.Replace("/bulk", ""),
                CollectURL,
                EnvironmentKey,
                null);

            HttpRequest request = new HttpRequest(url)
            {
                HTTPMethod = HttpRequest.HTTPMethodType.POST,
                HTTPBody   = json
            };

            request.setHeader("Content-Type", "application/json");

            StartCoroutine(Send(
                               request,
                               () => {
                Logger.LogDebug("Forgot user " + UserID);
                PlayerPrefs.SetInt(DDNA.PF_KEY_FORGOTTEN, 1);
            }));
        }