Created
May 10, 2018 00:25
-
-
Save fluxdigital/6c94f8b551e3857904a028789838313e to your computer and use it in GitHub Desktop.
An Example Crypto API Service to use as an external Datasource
This file contains 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 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