Skip to content

Instantly share code, notes, and snippets.

@jeffpatton1971
Created June 26, 2014 22:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffpatton1971/2de37a567ee22811b4b0 to your computer and use it in GitHub Desktop.
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.
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