Example #1
0
        private void OnCurrentPushMessage(string response)
        {
            var jsonResponse = GowMiniJSON.Deserialize(response) as JsonObject;
            var notification = jsonResponse.Get <JsonObject>("currentPushMessage");

            OnCurrentNotificationRecieved(notification);
        }
Example #2
0
        protected static void SendRequest(string point, JsonObject args, System.Action <JsonObject> success, System.Action <string> failed)
        {
            var argsBytes = System.Text.Encoding.UTF8.GetBytes(GoWMiniJSON.Serialize(args));
            var request   = WebRequest.Create(Settings.serverUrl + "/" + point);

            request.Method        = "POST";
            request.ContentType   = "application/json";
            request.ContentLength = argsBytes.Length;
            var dataStream = request.GetRequestStream();

            dataStream.Write(argsBytes, 0, argsBytes.Length);
            dataStream.Close();
            try {
                var response = request.GetResponse();

                webErrorLine = null;

                if (success != null)
                {
                    success((JsonObject)GoWMiniJSON.Deserialize(GetTextResponse(response)));
                }
            } catch (WebException e) {
                var errorResponse = (JsonObject)GoWMiniJSON.Deserialize(GetTextResponse(e.Response));
                webErrorLine = errorResponse["error"].ToString();
                if (failed != null)
                {
                    failed(webErrorLine);
                }
                LogUtils.LogError(webErrorLine);
            }
        }
Example #3
0
        private void DefaultDialogCallback(string response)
        {
            var jsonResponse         = GOWMiniJSON.Deserialize(response) as JsonObject;
            var dialogResponseString = jsonResponse.Get <string>("response");

            if (string.IsNullOrEmpty(dialogResponseString))
            {
                LogUtils.LogError("Incorrect dialog response: " + dialogResponseString);
            }
            try
            {
                var dialogResponse = (DialogButtons)Enum.Parse(typeof(DialogButtons), dialogResponseString);
                if (_currentDialogRequest != null)
                {
                    var callback = dialogResponse == DialogButtons.Ok
                        ? _currentDialogRequest.onOk
                        : _currentDialogRequest.onCancel;
                    if (callback != null)
                    {
                        callback();
                    }
                }
            }
            catch (ArgumentException e)
            {
                Debug.LogError("Parse enum exception: " + e.Message + "\r\n" + e.StackTrace);
            }
            _currentDialogRequest = null;
        }
Example #4
0
        protected static JsonObject DecodeToken(string token)
        {
            var parts   = token.Split('.');
            var header  = parts[0];
            var payload = parts[1];

            byte[] crypto = Base64UrlDecode(parts[2]);

            var headerJson  = System.Text.Encoding.UTF8.GetString(Base64UrlDecode(header));
            var headerData  = (JsonObject)GoWMiniJSON.Deserialize(headerJson);
            var payloadJson = System.Text.Encoding.UTF8.GetString(Base64UrlDecode(payload));
            var payloadData = (JsonObject)GoWMiniJSON.Deserialize(payloadJson);

            return(payloadData);
        }
Example #5
0
        private void OnPushMessages(string response)
        {
            var jsonResponse  = GowMiniJSON.Deserialize(response) as JsonObject;
            var objectsList   = jsonResponse.Get <List <object> >("notifications");
            var notifications = new List <JsonObject>();

            objectsList.ForEach(o =>
            {
                var item = o as JsonObject;
                if (item != null)
                {
                    notifications.Add(item);
                }
            });
            OnNotificationsRecieved(notifications.ToArray());
        }
Example #6
0
        public GowDataStorage()
        {
            var line = PlayerPrefs.GetString(GOW_DATA, null);

            if (string.IsNullOrEmpty(line))
            {
                _gowData = new JsonObject();
            }
            else
            {
                try
                {
                    _gowData = (JsonObject)GoWMiniJSON.Deserialize(line);
                }
                catch (Exception e)
                {
                    LogUtils.LogError(e.Message);
                    LogUtils.LogError(e.StackTrace);
                    _gowData = new JsonObject();
                }
            }
        }
Example #7
0
 private void SaveData()
 {
     PlayerPrefs.SetString(GOW_DATA, GoWMiniJSON.Serialize(_gowData));
     PlayerPrefs.Save();
 }
Example #8
0
        protected void OnCurrentNotificationRecieved(JsonObject notification)
        {
            if (!GowNotification.IsValid(notification))
            {
                LogUtils.LogWarning("Not valid json : " + (notification == null ? "<NULL>" : GOWMiniJSON.Serialize(notification)));
                return;
            }

            if (CurrentNotificationRecieved != null)
            {
                CurrentNotificationRecieved(new GowNotification(notification));
            }
        }
Example #9
0
 protected void OnNotificationsRecieved(JsonObject[] notifications)
 {
     if (NotificationRecieved != null)
     {
         NotificationRecieved(notifications.Select(json => {
             if (!GowNotification.IsValid(json))
             {
                 LogUtils.LogWarning("Not valid json : " + json == null ? "<NULL>" : GOWMiniJSON.Serialize(json));
                 return(null);
             }
             return(new GowNotification(json));
         }).SelectNotNull().ToArray());
     }
 }