Beispiel #1
0
    IEnumerator GetPnr(string name, string reference)
    {
        System.DateTime departure = new System.DateTime(2050, 9, 25, 17, 55, 0);
        WWWForm         form      = new WWWForm();

        Debug.Log("dep " + departure.ToString());
        form.AddField("bookingReference", reference);
        form.AddField("bookingLastName", name);
        using (UnityWebRequest www = UnityWebRequest.Post("https://apigw.singaporeair.com/appchallenge/api/pax/pnr", form))
        {
            www.SetRequestHeader("apikey", "aghk73f4x5haxeby7z24d2rc");
            yield return(www.SendWebRequest());

            if (www.isNetworkError || www.isHttpError)
            {
                // text.text = www.error.ToString();
            }
            else
            {
                Pnr pnr = JsonUtility.FromJson <Pnr>(www.downloadHandler.text.ToString());
                departure = Convert.ToDateTime(pnr.responseBody.flights[0].flightSegment[0].estimatedDepartureTime).Add(new System.TimeSpan(0, -30, 0));
                System.DateTime now = new System.DateTime(2018, 9, 25, 17, 59, 45);
                while (System.DateTime.Compare(now, departure) < 0)
                {
                    now = now.AddSeconds(1);
                    yield return(new WaitForSeconds(1));
                }
                gameController.ShowWarning();
            }
        }
    }