Esempio n. 1
0
        public static void Get(
            string method,
            Dictionary <string, string> parameters,
            Action <Core.Response> callback,
            bool requireVerified       = true,
            Core.ResponseFormat format = Core.ResponseFormat.Json)
        {
            var error = Prepare(ref parameters, requireVerified, format);

            if (error != null)
            {
                callback(new Core.Response(error));
            }
            else
            {
                var url = GetRequestURL(method, parameters);
                Manager.Instance.StartCoroutine(Manager.Instance.GetRequest(url, format, callback));
            }
        }
Esempio n. 2
0
        public IEnumerator GetRequest(string url, Core.ResponseFormat format, Action <Core.Response> callback)
        {
            if (Settings.GameId == 0 || Settings.PrivateKey == null)
            {
                callback(new Core.Response("Bad Credentials"));
                yield break;
            }

            float timeout = Time.time + Settings.Timeout;
            var   www     = new WWW(url);

            while (!www.isDone)
            {
                if (Time.time > timeout)
                {
                    callback(new Core.Response("Timeout for " + url));
                    yield break;
                }
                yield return(new WaitForEndOfFrame());
            }
            callback(new Core.Response(www, format));
        }
Esempio n. 3
0
        public IEnumerator PostRequest(string url, Dictionary <string, string> payload, Core.ResponseFormat format,
                                       Action <Core.Response> callback)
        {
            if (Settings.GameId == 0 || Settings.PrivateKey == null)
            {
                callback(new Core.Response("Bad Credentials"));
                yield break;
            }

            var form = new WWWForm();

            foreach (KeyValuePair <string, string> field in payload)
            {
                form.AddField(field.Key, field.Value);
            }

            float timeout = Time.time + Settings.Timeout;

            var www = new WWW(url, form);

            while (!www.isDone)
            {
                if (Time.time > timeout)
                {
                    callback(new Core.Response("Timeout for " + url));
                    yield break;
                }
                yield return(new WaitForEndOfFrame());
            }

            callback(new Core.Response(www, format));
        }
Esempio n. 4
0
        static string Prepare(ref Dictionary <string, string> parameters, bool requireVerified, Core.ResponseFormat format)
        {
            if (parameters == null)
            {
                parameters = new Dictionary <string, string>();
            }

            if (requireVerified)
            {
                if (Manager.Instance.CurrentUser == null || !Manager.Instance.CurrentUser.IsAuthenticated)
                {
                    return("Missing Authenticated User.");
                }
                parameters.Add("username", Manager.Instance.CurrentUser.Name.ToLower());
                parameters.Add("user_token", Manager.Instance.CurrentUser.Token.ToLower());
            }

            parameters.Add("format", format.ToString().ToLower());

            return(null);
        }