topical media & game development

talk show tell print

#mobile-application-12-DerbyNames-MonoTouch-DerbyNames-MonoTouch-Network.cs / cs



  using System;
  using System.Json;
  using System.Collections.Generic;
  using System.Net;
  
  namespace DerbyNames_MonoTouch
  {
          public static class Network
          {
                  public static List<DerbyName> GetRoster(string leagueName)
                  {                
                          List<DerbyName> tmpRtn = new List<DerbyName>();
                          String requestURL = "http://derbynames.gravityworksdesign.com/DerbyNamesService.svc/DerbyNames?$filter=League%20eq%20'" + leagueName + "'";
                          
                          HttpWebResponse response = GetServiceResponse(requestURL);
                          JsonObject fullJsonObject = (JsonObject)JsonObject.Load(response.GetResponseStream());
                          var rosterData = fullJsonObject["d"];
                          
                          foreach (JsonObject singleEntry in rosterData) {
                                  tmpRtn.Add(new DerbyName(singleEntry["DerbyNameId"],singleEntry["Name"],singleEntry["Number"],singleEntry["League"]));                                        
                          }
                          
                          // return
                          return tmpRtn;
                  }
                  
                  public static List<League> GetLeaugeData()
                  {                
                          List<League> tmpRtn = new List<League>();
                          string requestURL = "http://derbynames.gravityworksdesign.com/DerbyNamesService.svc/Leagues";
                          
                          HttpWebResponse response = GetServiceResponse(requestURL);
                          JsonObject fullJsonObject = (JsonObject)JsonObject.Load(response.GetResponseStream());
                          var leagueData = fullJsonObject["d"];
                          
                          foreach (JsonObject singleEntry in leagueData) {
                                  tmpRtn.Add(new League(singleEntry["LeagueId"],singleEntry["LeagueName"]));                                        
                          }
                          
                          // return
                          return tmpRtn;
                  }
                  
                  private static HttpWebResponse GetServiceResponse (string url)
                  {
                          HttpWebResponse tmpRtn;
                          var request = (HttpWebRequest) WebRequest.Create (url);
                          
                          tmpRtn = (HttpWebResponse) request.GetResponse ();
                          
                          // return
                          return tmpRtn;
                  }
          }
  }
  
  


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.