예제 #1
0
        public IEnumerator AddItemRoutine(string item)
        {
            string uuid = System.Guid.NewGuid().ToString();
            string body = JsonBody.TodoistTask(item, projectId);

            UnityWebRequest request = Postman.CreatePostRequest(Endpoints.instance.TODOIST_TASKS(), body);

            request.SetRequestHeader("Authorization", "Bearer " + apiKey);
            request.SetRequestHeader("X-Request-Id", uuid);
            yield return(request.SendWebRequest());

            bool ok = request.error == null ? true : false;

            if (!ok)
            {
                WidgetLogger.instance.Log("<b>" + listType.ToString() + " List</b>: Could not add item (" + item + "): " + request.downloadHandler.text);
                itemsNotUploaded.Add(item);

                // Todoist is flaky, and to avoid messing up category order, try again immediately
                if (request.responseCode == 500)
                {
                    yield return(AddItemRoutine(item));
                }
            }
            else if (itemsNotUploaded.Contains(item))
            {
                itemsNotUploaded.Remove(item);
            }

            addDialog.SetStatusText(string.Format("'{0}' uploaded!", item));
        }
        private IEnumerator RemoveRoutine()
        {
            ConfirmDialog dialog = FindObjectOfType <ConfirmDialog>();

            dialog.ApplyColours();
            dialog.Show();
            dialog.SetInfoMessage("Remove '<b>" + nameText.text + "</b>'?");
            dialog.SetNone();

            while (dialog.IsNone())
            {
                yield return(null);
            }

            if (dialog.IsNo() || dialog.IsCancel())
            {
                dialog.Hide();
                yield break;
            }

            if (dialog.IsYes())
            {
                dialog.Hide();

                string          url     = string.Format("{0}/{1}/close", Endpoints.instance.TODOIST_TASKS(), taskId);
                UnityWebRequest request = Postman.CreatePostRequest(url, new JSONObject());
                request.SetRequestHeader("Authorization", "Bearer " + apiKey);
                yield return(request.SendWebRequest());

                Destroy(this.gameObject);
            }
        }
예제 #3
0
        private IEnumerator ClearRecipeRoutine()
        {
            JSONObject      body    = JsonBody.AddToPlanner(" ", day.ToString());
            UnityWebRequest request = Postman.CreatePostRequest(Endpoints.instance.PLANNER(), body);

            yield return(request.SendWebRequest());

            JSONNode response = JSON.Parse(request.downloadHandler.text);

            if (request.error == null)
            {
                recipe.text = "";
            }
            else
            {
                WidgetLogger.instance.Log("Could not clear recipe: " + response["message"]);
            }
        }
예제 #4
0
        private IEnumerator UploadNewRecipeRoutine()
        {
            NewIngredientEntry[] newIngredients = FindObjectsOfType <NewIngredientEntry>();

            JSONArray ingredientsArray = new JSONArray();

            foreach (NewIngredientEntry newIngredient in newIngredients)
            {
                JSONObject ingredientJson = JsonBody.RecipeIngredient(newIngredient.GetIngredientName(), newIngredient.GetAmount(), newIngredient.GetWeight(), newIngredient.GetCategory());
                ingredientsArray.Add(ingredientJson);
            }

            JSONObject body = JsonBody.AddRecipe(recipeName.text, ingredientsArray);

            UnityWebRequest request = Postman.CreatePostRequest(Endpoints.instance.RECIPES(), body);

            yield return(request.SendWebRequest());

            status.text = request.responseCode.Equals(200) ? recipeName.text + " added!" : "Error: " + request.error;
        }