Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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<string> callback) {
- WWW www = new WWW (url);
- yield return www;
- if (!IsResponseValid (www)) {
- yield break;
- }
- callback (www.text);
- }
- public IEnumerator GetWeatherXML(Action<string> callback) {
- return CallAPI (xmlApi, callback);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement