public async Task <YoungPerson> SetYoungPersonFreeze(YoungPerson youngPerson, bool isFrozen) { //Set up the request var client = new RestClient(API.BaseURL + "Admin.php"); var request = new RestRequest(Method.PATCH); request.AddHeader("Cache-Control", "no-cache"); request.AddHeader("Authorization", "Bearer " + RawToken); request.AddHeader("Content-Type", "application/x-www-form-urlencoded"); request.AddParameter("id", youngPerson.ID); request.AddParameter("action", isFrozen ? "freeze" : "defrost"); //Get the data async IRestResponse response = await Task.Run(() => { return(client.Execute(request)); }); Response <YoungPerson> data = Response <YoungPerson> .FromJson(response.Content); //Log any errors for (int i = 0; i < data.Errors.Length; i++) { Debug.LogError(data.Errors[i]); } if (data.Result.Length == 1) { string result = JsonConvert.SerializeObject(data.Result[0]); JsonConvert.PopulateObject(result, youngPerson); } return(youngPerson); }
// Commands // ======== public static async Task <YoungPerson> Login(string email, string password, string tempPassword = "") { //Set up the request var client = new RestClient(API.BaseURL + "Login.php"); var request = new RestRequest(Method.POST); request.AddHeader("Cache-Control", "no-cache"); request.AddHeader("Content-Type", "application/x-www-form-urlencoded"); request.AddParameter("email", email); request.AddParameter("password", password); if (tempPassword != "") { request.AddParameter("tempPassword", tempPassword); } //Get the data async IRestResponse response = await Task.Run(() => { return(client.Execute(request)); }); TokenRequest token = TokenRequest.FromJson(response.Content); //Log any errors for (int i = 0; i < token.Errors.Length; i++) { Debug.LogError(token.Errors[i]); } YoungPerson newYoungPerson = new YoungPerson { RawToken = token.Value, Token = Token.FromJWT(token.Value) }; await newYoungPerson.Update(); return(newYoungPerson); }