topical media & game development
#mobile-application-12-DerbyNames-MonoAndroid-DerbyNames-MonoAndroid-Network.cs / cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Json;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using System.Net;
namespace DerbyNames_MonoAndroid
{
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.