Created
June 26, 2014 22:14
-
-
Save jeffpatton1971/2de37a567ee22811b4b0 to your computer and use it in GitHub Desktop.
A generic function that I use to work with the Arin Web Service (Whois-RWS). I have created classes out of the resulting xml and included them in the project. That is ultimately what <T> becomes. See section 4.5 (https://www.arin.net/resources/whoisrws/whois_api.html#whoisrws) ARIN's RESTful Resources, for the various resources available.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace ArinPortableAPI | |
{ | |
using System; | |
using System.IO; | |
using System.Net.Http; | |
using System.Threading.Tasks; | |
using System.Xml.Serialization; | |
public class ArinLookup | |
{ | |
public static string ApiUrl = "http://whois.arin.net/rest"; | |
public async Task<T>GetResource<T>(string restUrl) where T : class | |
{ | |
Stream responseStream = null; | |
HttpClient client = new HttpClient(); | |
try | |
{ | |
responseStream = await client.GetStreamAsync(restUrl); | |
} | |
catch (Exception ex) | |
{ | |
throw ex; | |
} | |
XmlSerializer xSerializer = new XmlSerializer(typeof(T)); | |
T arinReturn = xSerializer.Deserialize(responseStream) as T; | |
return arinReturn; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment