using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class NetworkService { private const string xmlApi = "http://api.openweathermap.org/data/2.5/weather?id=701824&mode=xml&APPID=ed7e09a620553dba6828003117f600ab"; private bool IsResponseValid(WWW www) { if (www.error != null) { Debug.Log ("bad connection"); return false; } else if (string.IsNullOrEmpty (www.text)) { Debug.Log ("bad data"); return false; } else { return true; } } private IEnumerator CallAPI(string url, Action callback) { WWW www = new WWW (url); yield return www; if (!IsResponseValid (www)) { yield break; } callback (www.text); } public IEnumerator GetWeatherXML(Action callback) { return CallAPI (xmlApi, callback); } }