Esempio n. 1
0
        public static void Add(WebCall webCall)
        {
            Debug.Log("Call failed. Queue requested: " + webCall.URL + "\n" +
                      (string.IsNullOrEmpty(webCall.PostJSON) ? string.Empty : webCall.PostJSON));

            Instance.mNeedSave = true;
            Instance.mQueue.Add(webCall);
        }
Esempio n. 2
0
        public static void ExecuteWebCall(WebCall webCall)
        {
            if (mRoutineObject == null)
            {
                CreateRoutineObject();
            }

            webCall.ExecuteCall(mRoutineObject);
        }
Esempio n. 3
0
        /// <summary> Change user email, then automatically execute GetMe(). </summary>
        public static void ChangeUserEmail(string newMail)
        {
            Dictionary <string, object> postData = new Dictionary <string, object>()
            {
                { "email", newMail }
            };

            WebCall call = new WebCall(BaseURL + API.MeChange, CreateBaseHeaders(), postData, (x) => DataManager.Me.FetchData(true), true);

            ExecuteWebCall(call);
        }
Esempio n. 4
0
        public static void SendFeedback(string feedback)
        {
            Dictionary <string, object> postData = new Dictionary <string, object>()
            {
                { "body", feedback }
            };

            WebCall call = new WebCall(BaseURL + API.SendFeedback, CreateBaseHeaders(), postData, null);

            ExecuteWebCall(call);
        }
Esempio n. 5
0
        public static void LogIn(string personalID)
        {
            Dictionary <string, object> postData = new Dictionary <string, object>()
            {
                { "personal_identity_number", personalID },
                { "password", "secret" }
            };

            WebCall call = new WebCall(BaseURL + API.Login, null, postData, HandleLogIn);

            ExecuteWebCall(call);
        }
Esempio n. 6
0
        public static void SendChatMessage(int chatID, string body)
        {
            string url = BaseURL + API.SendChatmessage.Replace("{id}", chatID.ToString());

            Dictionary <string, object> postData = new Dictionary <string, object>()
            {
                { "body", body }
            };

            WebCall call = new WebCall(url, CreateBaseHeaders(), postData, HandleSendChatMessage);

            ExecuteWebCall(call);
        }
Esempio n. 7
0
 private void OnFetchFail(WebCall webCall)
 {
     if (webCall.StatusCode == 408)
     {
         // Timeout, try again
         PopupManager.DisplayPopup(TextManager.Get(mTimeoutBody), TextManager.Get(mTimeoutButton), DataManager.FetchInitialData);
     }
     else
     {
         // Other error
         string errorBody = TextManager.Get(mErrorBody) + " " + webCall.StatusCode + ": " + webCall.Error;
         PopupManager.DisplayPopup(errorBody, TextManager.Get(mErrorButton), DataManager.FetchInitialData);
     }
 }
Esempio n. 8
0
        private void UpdateQueue()
        {
            if (!Backend.IsLoggedIn || DataManager.Me.Data == null)
            {
                return;
            }

            if (mCurrentlyRetrying == null && mQueue.Count == 0)
            {
                return;                 // Nothing in the queue
            }
            if (mCurrentlyRetrying == null)
            {
                // Not currently retrying any call, pick one and execute it
                int currentUser = DataManager.Me.Data[0].ID;

                for (int i = 0; i < mQueue.Count; i++)
                {
                    // Only allow posting calls which belong to this user
                    if (mQueue[i].UserID == currentUser)
                    {
                        mCurrentlyRetrying = mQueue[i];
                        break;
                    }
                }

                // Retry the call
                mCurrentlyRetrying.MarkAsQueued();
                Backend.RefreshHeaderToken(mCurrentlyRetrying.Headers);
                Backend.ExecuteWebCall(mCurrentlyRetrying);

                // If the call fails, 10 seconds need to pass before trying again
                mNextTryTime = Time.time + 10f;
            }
            else if (mCurrentlyRetrying.IsDone)
            {
                if (mCurrentlyRetrying.IsSuccess)
                {
                    // The retried webcall succeeded, remove it from the queue
                    mQueue.Remove(mCurrentlyRetrying);
                    mCurrentlyRetrying = null;
                    mNeedSave          = true;
                }
                else if (Time.time > mNextTryTime)
                {
                    // The retried webcall failed, wait until minimum time has passed and try again
                    mCurrentlyRetrying = null;
                }
            }
        }
Esempio n. 9
0
        private void OnReceiveImage(WebCall webCall)
        {
            Texture2D texture = PhotoConverter.ConvertToSquare(webCall.ResponseImage, 128);

            texture.name = "User" + ID + "Picture";

            Image      = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
            Image.name = texture.name;

            if (OnGetImage != null)
            {
                OnGetImage();
            }
        }
Esempio n. 10
0
        /// <summary> Change user profile picture, then automatically execute GetMe(). </summary>
        public static void ChangeUserPicture(Texture2D picture)
        {
            WebCall call = new WebCall(BaseURL + API.MeChange, CreateBaseHeaders(), null, (x) => DataManager.Me.FetchData(true), true);

            if (picture != null)
            {
                call.SetImage(picture);
            }
            else
            {
                call.PostDictionary["image_uuid"] = "remove";
            }

            ExecuteWebCall(call);
        }
Esempio n. 11
0
        public static void SubmitAssignment(int id, string text, Texture2D picture)
        {
            Dictionary <string, object> postData = new Dictionary <string, object>();

            if (!string.IsNullOrEmpty(text))
            {
                postData["answer"] = text;
            }

            string  url  = BaseURL + API.AssignmentDone.Replace("{id}", id.ToString());
            WebCall call = new WebCall(url, CreateBaseHeaders(), postData, HandleSubmitAssignment);

            if (picture != null)
            {
                call.SetImage(picture);
            }

            ExecuteWebCall(call);
        }
Esempio n. 12
0
        private static void ChangeUserConfigFlag(string flag, bool value, bool updateMe)
        {
            Dictionary <string, object> postData = new Dictionary <string, object>();

            postData["key"]   = flag;
            postData["value"] = value ? "1" : "0";

            WebCall call = new WebCall(
                BaseURL + API.MeConfigChange,
                CreateBaseHeaders(),
                postData,
                (x) =>
            {
                if (updateMe)
                {
                    DataManager.Me.FetchData(true);
                }
            },
                true);

            ExecuteWebCall(call);
        }
Esempio n. 13
0
        public static void RefreshLogIn()
        {
            WebCall call = new WebCall(BaseURL + API.RefreshToken, CreateBaseHeaders(), HandleRefreshLogIn);

            ExecuteWebCall(call);
        }
Esempio n. 14
0
 private void OnSetPushTokenFailed(WebCall error)
 {
     SetDebugText("Failed setting token\n" + error);
 }
Esempio n. 15
0
        public static void GetFAQs()
        {
            WebCall call = new WebCall(BaseURL + API.FAQ, CreateBaseHeaders(), HandleGetFAQs);

            ExecuteWebCall(call);
        }
Esempio n. 16
0
        public static void GetPlan()
        {
            WebCall call = new WebCall(BaseURL + API.Goals, CreateBaseHeaders(), HandleGetGoals);

            ExecuteWebCall(call);
        }
Esempio n. 17
0
        public static void GetEvaluations()
        {
            WebCall call = new WebCall(BaseURL + API.Evaluations, CreateBaseHeaders(), HandleGetEvaluations);

            ExecuteWebCall(call);
        }
Esempio n. 18
0
        public static void CallURL(string url, Action <WebCall> onDone)
        {
            WebCall call = new WebCall(url, onDone);

            ExecuteWebCall(call);
        }
Esempio n. 19
0
        public static void GetAssignments()
        {
            WebCall call = new WebCall(BaseURL + API.Assignment, CreateBaseHeaders(), HandleGetAssignments);

            ExecuteWebCall(call);
        }