Exemple #1
0
        /// <summary>
        /// Get the currency from CambiosTodayApi
        /// </summary>
        /// <param name="currenciesCode"></param>
        /// <returns></returns>
        private async Task <CambioTodayModel> GetQuoteFromCambiosTodayAsync(CurrenciesCodeEnum currenciesCode)
        {
            try
            {
                this.httpClient = new HttpClient();
                CambioTodayModel cambioToday = new CambioTodayModel();

                CredentialsApi credentials = this.credentialsCurrencies.KeyValues[ExchangerEnum.CambioToday];

                string cambiosTodayURL = string.Format(credentials.URLBase, currenciesCode.ToString("g"), CurrenciesCodeEnum.ARS.ToString("g"), credentials.Key);

                var response = await this.httpClient.GetAsync(cambiosTodayURL);

                if (response.IsSuccessStatusCode)
                {
                    var result = await response.Content.ReadAsStringAsync();

                    cambioToday = JsonConvert.DeserializeObject <CambioTodayModel>(result);
                    return(cambioToday);
                }
            }
            catch (Exception)
            {
                throw new Exception("Ha ocurrido un problema, por favor intente más tarde");
            }

            return(null);
        }
Exemple #2
0
        /// <summary>
        /// Get the quote of currency
        /// </summary>
        /// <param name="currencyName"></param>
        /// <param name="currencyCode"></param>
        /// <returns></returns>
        public async Task <NashResponse> GetQuote(CurrenciesNameEnum currencyName, CurrenciesCodeEnum currencyCode)
        {
            NashResponse     nashResponse = new NashResponse();
            CambioTodayModel cambioToday  = new CambioTodayModel();

            if (currencyCode.Equals(CurrenciesCodeEnum.USD))
            {
                var EstadisticasBcraModel = await this.GetQuoteFromEstadisticasBcraAsync();

                nashResponse.Precio = EstadisticasBcraModel.v;
                nashResponse.Moneda = currencyName.ToString("g");
            }
            else
            {
                cambioToday = await this.GetQuoteFromCambiosTodayAsync(currencyCode);

                nashResponse.Moneda = currencyName.ToString("g");
                nashResponse.Precio = cambioToday.Result.Value;
            }

            return(nashResponse);
        }