Example #1
0
    public IEnumerator GetSingleCase(GameObject loadingGo, string countryName, System.Action <bool, CaseDetails> aCallback)
    {
        string          path            = "https://api.covid19tracking.narrativa.com/api/" + CodeUtils.GetCurrentDate() + "/country/" + countryName;
        UnityWebRequest cardInfoRequest = UnityWebRequest.Get(path);
        var             operation       = cardInfoRequest.SendWebRequest();

        loadingGo.SetActive(true);
        yield return(CodeUtils.ProgressBar(operation));

        if (cardInfoRequest.isNetworkError || cardInfoRequest.isHttpError)
        {
            aCallback(true, new CaseDetails());
            Debug.Log(cardInfoRequest.error);
            yield break;
        }
        loadingGo.SetActive(false);
        JSONNode    cardInfo       = JSON.Parse(cardInfoRequest.downloadHandler.text);
        int         deadTotal      = cardInfo["dates"][CodeUtils.GetCurrentDate()]["countries"][CodeUtils.UppercaseFirst(countryName)]["today_deaths"];
        int         covidTotal     = cardInfo["dates"][CodeUtils.GetCurrentDate()]["countries"][CodeUtils.UppercaseFirst(countryName)]["today_confirmed"];
        int         covidToday     = cardInfo["dates"][CodeUtils.GetCurrentDate()]["countries"][CodeUtils.UppercaseFirst(countryName)]["today_new_confirmed"];
        int         deadToday      = cardInfo["dates"][CodeUtils.GetCurrentDate()]["countries"][CodeUtils.UppercaseFirst(countryName)]["today_new_deaths"];
        int         recoveredToday = cardInfo["dates"][CodeUtils.GetCurrentDate()]["countries"][CodeUtils.UppercaseFirst(countryName)]["today_new_recovered"];
        int         recoveredTotal = cardInfo["dates"][CodeUtils.GetCurrentDate()]["countries"][CodeUtils.UppercaseFirst(countryName)]["today_recovered"];
        CaseDetails caseDetail     = new CaseDetails(covidToday, deadToday, recoveredTotal, recoveredToday, covidTotal, deadTotal, countryName);

        aCallback(false, caseDetail);
    }
Example #2
0
    public IEnumerator GetListCase(GameObject cardsGroup, string countryName, int cardIndexIngroup, System.Action <bool, Case> aCallback)
    {
        string          path            = "https://api.covid19tracking.narrativa.com/api/" + CodeUtils.GetCurrentDate() + "/country/" + countryName;
        UnityWebRequest cardInfoRequest = UnityWebRequest.Get(path);
        var             operation       = cardInfoRequest.SendWebRequest();

        yield return(CodeUtils.ProgressBar(operation));

        // yield return coroutine;
        if (cardInfoRequest.isNetworkError || cardInfoRequest.isHttpError)
        {
            aCallback(false, new Case());
            Debug.Log(cardInfoRequest.error);
            yield break;
        }
        JSONNode cardInfo  = JSON.Parse(cardInfoRequest.downloadHandler.text);
        int      deaths    = cardInfo["dates"][CodeUtils.GetCurrentDate()]["countries"][CodeUtils.UppercaseFirst(countryName)]["today_deaths"];
        int      positives = cardInfo["dates"][CodeUtils.GetCurrentDate()]["countries"][CodeUtils.UppercaseFirst(countryName)]["today_confirmed"];
        Case     newCase   = new Case(positives, deaths, countryName);

        aCallback(true, newCase);
    }
Example #3
0
    public IEnumerator GetInfoByItalyRegion(string region, System.Action <bool, Case> aCallback)
    {
        string          path = "https://api.covid19tracking.narrativa.com/api/" + CodeUtils.GetCurrentDate() + "/country/italy/region/" + region;
        UnityWebRequest regionInfoRequest = UnityWebRequest.Get(path);
        var             operation         = regionInfoRequest.SendWebRequest();

        //wait loading
        yield return(CodeUtils.ProgressBar(operation));

        if (regionInfoRequest.isNetworkError || regionInfoRequest.isHttpError)
        {
            aCallback(false, new CaseDetails());
            Debug.Log(regionInfoRequest.error);
            yield break;
        }
        //Stop loading
        JSONNode regionInfoText = JSON.Parse(regionInfoRequest.downloadHandler.text);
        int      deaths         = regionInfoText["dates"][CodeUtils.GetCurrentDate()]["countries"]["Italy"]["regions"][0]["today_deaths"];
        int      positives      = regionInfoText["dates"][CodeUtils.GetCurrentDate()]["countries"]["Italy"]["regions"][0]["today_confirmed"];
        Case     regionCase     = new Case(positives, deaths, "italy");

        aCallback(true, regionCase);
    }