Exemplo n.º 1
0
        public async Task <T> DownloadCurrenciesAsync <T>(BaseMoneyCurrency currentCurrency, CancellationToken cancellationToken)
        {
            using (var client = new HttpClient())
                using (cancellationToken.Register(() => client.CancelPendingRequests()))
                {
                    var response = await client.GetAsync(GetHttpRequestUri(currentCurrency), cancellationToken).ConfigureAwait(false);

                    if (response.Content == null)
                    {
                        throw new ArgumentNullException("Content is missing");
                    }

                    var result = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                    cancellationToken.ThrowIfCancellationRequested();

                    return(JsonConvert.DeserializeObject <T>(result));
                }
        }
Exemplo n.º 2
0
 public Uri GetHttpRequestUri(BaseMoneyCurrency baseCurrency) => new Uri(BaseApiEndpoint + Resources.Token + "/latest/" + supportedBaseCurrencyDictionary[baseCurrency]);