public async Task <List <Pet> > GetAllPets(string family) { BaseRepository br = new BaseRepository(); if (_rootPet == null) { _rootPet = await br.GetAsync <RootPet>(_BASEURL); } List <Pet> lstPetAll = _rootPet.pets as List <Pet>; List <Pet> lstPetFilter = new List <Pet>(); foreach (Pet pet in lstPetAll) { if (pet.family == family) { lstPetFilter.Add(pet); } } return(lstPetFilter); }
public void GetPetRequest(UnityAction callback) { HttpClient client = new HttpClient(); client.Headers.Add("Authorization", "Token " + PlayerPrefs.GetString("token")); // client.Headers.Add("Content-Type", "application/json"); client.Get(new Uri("https://www.pacheti.com/api/games/pet/"), HttpCompletionOption.AllResponseContent, r => { if (!r.IsSuccessStatusCode) { Debug.Log(r.ReadAsString()); } else { petlist = JsonUtility.FromJson <RootPet>(r.ReadAsString()); player.player.petList = petlist.result; Debug.Log(r.ReadAsString()); callback(); } }); }