Beispiel #1
0
        /// <summary>
        /// Get USD currency from estadisticasBcraApi
        /// </summary>
        /// <returns></returns>
        private async Task <EstadisticasBcraModel> GetQuoteFromEstadisticasBcraAsync()
        {
            try
            {
                this.httpClient = new HttpClient();
                EstadisticasBcraResponse estadisticasBcraResponse = new EstadisticasBcraResponse();

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

                this.httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", credentials.Key);

                var response = await this.httpClient.GetAsync(credentials.URLBase);

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

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

            return(null);
        }
Beispiel #2
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);
        }
Beispiel #3
0
        private static CredentialsApi GetApiInstance(string token, string serverUrl)
        {
            var apiInstance = new CredentialsApi(serverUrl);

            apiInstance.Configuration.AccessToken = token;

            return(apiInstance);
        }
Beispiel #4
0
        public static Credential GetCredentials(AuthAPIManager apiManager, string credentialId)
        {
            CredentialsApi credentialsApi = new CredentialsApi(apiManager.Configuration);

            try
            {
                return(credentialsApi.GetCredential(credentialId));
            }
            catch (Exception ex)
            {
                // In case of Unauthorized request
                if (ex.GetType().GetProperty("ErrorCode").GetValue(ex, null).ToString() == "401")
                {
                    // Refresh Token and Call API
                    credentialsApi.Configuration.AccessToken = apiManager.GetToken();
                    return(credentialsApi.GetCredential(credentialId));
                }
                throw ex;
            }
        }
Beispiel #5
0
 public void Init()
 {
     instance = new CredentialsApi();
 }