Skip to content

Instantly share code, notes, and snippets.

@HilalSener
Last active September 30, 2018 19:55
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save HilalSener/06f858271a13dc42b7130bd9ab3d63b5 to your computer and use it in GitHub Desktop.
public async Task<CurrencyModel> GetCurrencyAsync()
{
var url = "https://lookup.binlist.net/45717360";
var client = new HttpClient();
if (!CrossConnectivity.Current.IsConnected && !Barrel.Current.IsExpired(key: url))
return Barrel.Current.Get<CurrencyModel>(key: url);
CurrencyModel result = null;
var response = await client.GetAsync(url);
if (response.IsSuccessStatusCode)
{
result = JsonConvert.DeserializeObject<CurrencyModel>(response.Content.ReadAsStringAsync().Result);
Barrel.Current.Add(key: url, data: result, expireIn: TimeSpan.FromDays(1));
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment