コード例 #1
0
    /**
     * Get answers for a quizz and a question.
     */
    public override Answers GetAnswersForQuestion(object quizzId, object questionId)
    {
        // If Api was set as FullyNested or PartiallyNested or that link don't contain {quizzId} and {questionId}, this method should not be called at all but should be overriden in the class that inherits from Api Manager
        if (apiDataModelEndpointType == ApiDataModelEndpointType.FullyNested ||
            apiDataModelEndpointType == ApiDataModelEndpointType.PartiallyNested ||
            !DoUrlsHaveQuizzIdAndQuestionIdInThem())
        {
            Debug.Log(
                $"[WARNING]: Your api seems to be Fully or Partially nested because you set it like this or you didn't define {{quizzId}} and {{questionId}} in api urls\n" +
                $"In this case the code could not work and you should override GetAnswersForQuestion method should be overriden in the class that inherits from ApiManager. There, you should implement how questions are retrieved and return them. Look at documentation for examples"
                );
        }

        // Replace {quizzId} and {questionid} in the link
        apiAnswersUrl = _originalApiAnswersUrl.Replace("{quizzId}", quizzId.ToString()).Replace("{questionId}", questionId.ToString());

        string json_answers = NetworkRequestManager.HttpGetRequest(apiAnswersUrl);

        CheckIfNullAndLog(json_answers, $"[WARNING]: Response for {GetActualMethodName()} is null");


        Answers answersData = child.SerializeAnswers(json_answers);

        answersData.MapAPIValuesToAbstractClass(); // Maps the values from ApiModel to Answers. The mapping is defined in api model class that inherits from Answers


        CheckIfNullAndLog(answersData, $"[WARNING]: answersData is null");


        return(answersData);
    }
コード例 #2
0
    public override Answers GetAnswersForQuestion(object quizzId, object questionId)
    {
        string json_quizzes_with_questions_with_answers = NetworkRequestManager.HttpGetRequest(apiAnswersUrl);

        CheckIfNullAndLog(json_quizzes_with_questions_with_answers, $"[WARNING]: Response for {GetActualMethodName()} is null");

        DardiNestedApiModel.QuizzesInAPI quizzesData = JsonUtility.FromJson <DardiNestedApiModel.QuizzesInAPI>(json_quizzes_with_questions_with_answers);

        Answers answers = new Answers();

        foreach (QuizzInAPI quizzData in quizzesData.quizzes)
        {
            if (quizzData.id.ToString() == quizzId.ToString())
            {
                foreach (QuestionInAPI questionData in quizzData.questions)
                {
                    if (questionData.id.ToString() == questionId.ToString())
                    {
                        foreach (DardiNestedApiModel.AnswerInAPI answerData in questionData.answers)
                        {
                            answerData.MapAPIValuesToAbstractClass();
                            answers.AddAnswer(answerData);
                        }

                        return(answers);
                    }
                }
            }
        }

        return(null);
    }
コード例 #3
0
    public override Answers GetAnswersForQuestion(object quizzId, object questionId)
    {
        // Replace {quizzId} and {questionid} in the link
        base.apiAnswersUrl = base._originalApiAnswersUrl.Replace("{quizzId}", quizzId.ToString()).Replace("{questionId}", questionId.ToString());

        string json_questions_with_answers = NetworkRequestManager.HttpGetRequest(apiAnswersUrl);

        CheckIfNullAndLog(json_questions_with_answers, $"[WARNING]: Response for {GetActualMethodName()} is null");


        KwizApiModel.QuestionsInAPI questionsData = JsonUtility.FromJson <KwizApiModel.QuestionsInAPI>(json_questions_with_answers);

        Answers answers = new Answers();

        // Let's begin to search the questionId we need in this case
        foreach (QuestionInAPI questionData in questionsData.data)
        {
            Debug.Log(questionId);
            if (questionId.ToString() == questionData.id.ToString())
            {
                // Now that we found the question with the questionId we need, let's get all answers
                foreach (AnswerInAPI answerData in questionData.answers)
                {
                    answerData.MapAPIValuesToAbstractClass();
                    answers.AddAnswer(answerData);
                }

                return(answers);
            }
        }

        return(null);
    }
コード例 #4
0
    /**
     * Method that register a user to the api.
     * Some api needs a user to be logged to be able to make requests in the api (have a look on LoginToGetApiToken for login)
     * Registration is sometimes needed because user has no login yet.
     * Even if some apis may return the api token after registration request, the common idea of "getting token" is not in registration but in login.
     * So here the app only returns true or false depending on the http request response (error or request not in 2xx response code).
     * The user should then be redirected to login where there should be a token response.
     */
    public virtual bool RegisterUserToGetApiToken(Dictionary <string, string> keyValuePairs)
    {
        string json_register = NetworkRequestManager.HttpPostRequest(apiRegisteringUrl, keyValuePairs);

        CheckIfNullAndLog(json_register, $"json_register is null");

        return(json_register != null && NetworkRequestManager.lastHttpWebRequestErrorMessage == null);
    }
コード例 #5
0
    /**
     * Get quizzes
     */
    public override Quizzes GetQuizzes()
    {
        string json_quizzes = NetworkRequestManager.HttpGetRequest(apiQuizzesUrl);

        CheckIfNullAndLog(json_quizzes, $"[WARNING]: Response for {GetActualMethodName()} is null");

        Quizzes quizzesData = child.SerializeQuizzes(json_quizzes);

        quizzesData.MapAPIValuesToAbstractClass(); // Maps the values from ApiModel to Quizzes. The mapping is defined in api model class that inherits from Quizzes

        CheckIfNullAndLog(quizzesData, $"[WARNING]: quizzesData is null");


        return(quizzesData);
    }
コード例 #6
0
    /**
     * Method that connects/logins to the api using POST request with what is sent in keyValuePairs.
     * If modification or some other special things/logic has to be implemented, override this method in the class that inherits from ApiManager
     *
     * Works with what LoginManager send as parameters. It returns an api token that must be defined in api model if used
     */
    public virtual ApiToken LoginToGetApiToken(Dictionary <string, string> keyValuePairsToSend)
    {
        string json_login = NetworkRequestManager.HttpPostRequest(apiLoginUrl, keyValuePairsToSend);

        CheckIfNullAndLog(json_login, $"[WARNING]: Response for {GetActualMethodName()} is null");


        ApiToken tokenData = child.SerializeApiToken(json_login); // Class that inherits from ApiManager has to override SerializeApiToken if token is used

        tokenData.MapAPIValuesToAbstractClass();                  // Maps the values from ApiModel to Answers. The mapping is defined in api model class that inherits from Answers


        CheckIfNullAndLog(tokenData, $"tokenData is null");


        return(tokenData);
    }
コード例 #7
0
 public void GetDrivingRouteResult(View view)
 {
     RemovePolylines();
     NetworkRequestManager.GetDrivingRoutePlanningResult(latLng1, latLng2,
                                                         new OnNetworkListenerClass(
                                                             delegate(string result)
     {
         // Request Success
         GenerateRoute(result);
     },
                                                             delegate(string errorMsg)
     {
         // Request Fail
         Message msg   = Message.Obtain();
         Bundle bundle = new Bundle();
         bundle.PutString("errorMsg", errorMsg);
         msg.What = 1;
         msg.Data = bundle;
         mHandler.SendMessage(msg);
     }
                                                             ));
 }