Skip to content

Instantly share code, notes, and snippets.

@fluxdigital
Created May 10, 2018 00:25
Show Gist options
  • Save fluxdigital/6c94f8b551e3857904a028789838313e to your computer and use it in GitHub Desktop.
Save fluxdigital/6c94f8b551e3857904a028789838313e to your computer and use it in GitHub Desktop.
An Example Crypto API Service to use as an external Datasource
namespace FluxDigital.Sitecore.Extensions.Services
{
public class CryptoService
{
public List<CryptoCoin> CointList()
{
List<CryptoCoin> coinList = new List<CryptoCoin>();
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create("https://www.cryptocompare.com/api/data/coinlist/");
httpWebRequest.ContentType = "application/json";
httpWebRequest.Method = "GET";
using (HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse())
using (Stream stream = httpWebResponse.GetResponseStream())
using (StreamReader reader = new StreamReader(stream))
{
var result = reader.ReadToEnd();
var cryptoResponse = JsonConvert.DeserializeObject<RootCryptoResponse>(result);
if (cryptoResponse != null)
{
coinList = cryptoResponse.Coins.Values.ToList<CryptoCoin>();
}
}
return coinList;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment