Ejemplo n.º 1
0
        /// <summary>
        /// Gets country, locale, and postcode from UserInfo and returns list of relevant TV services.  Need to do Task.Wait() then check for exceptions before getting result
        /// The function that does this should be async to avoid blocking gui.  Can throw various internet related exceptions.
        /// </summary>
        /// <returns>Task{TVServiceCollection}</returns>
        public async Task<TVServiceCollection> getTVServices() {

            TVServiceCollection tvServices = new TVServiceCollection();
            
            string address = "http://api.rovicorp.com/TVlistings/v9/listings/services/postalcode/" + userInfo.PostCode + "/info?locale=" + userInfo.Locale + "&countrycode=" + userInfo.Country + "&apikey=" + tvListingsApiKey;
            
            HttpClient httpClient = new HttpClient();
            string response = await httpClient.GetStringAsync(address);

            JsonObject json = JsonObject.Parse(response);
            JsonArray jArray = json.GetNamedObject("ServicesResult").GetNamedObject("Services").GetNamedArray("Service");

            for (uint n = 0; n < jArray.Count; n++) {
                string name = jArray.GetObjectAt(n).GetNamedString("Name");
                string id = jArray.GetObjectAt(n).GetNamedString("ServiceId");
                string area = jArray.GetObjectAt(n).GetNamedString("City");
                string provider = jArray.GetObjectAt(n).GetNamedString("MSO");
                string type = jArray.GetObjectAt(n).GetNamedString("Type");
                TVService tvService = new TVService(id, name, area, provider, type);
                tvServices.Add(tvService);
            }
            return tvServices;
        }
 public void Add(TVService toBeAdded)
 {
     tvServices.Add(toBeAdded);
 }