public Cotizacion convert(CotizacionResponse response) { Cotizacion coti = null; try{ coti = new Cotizacion(response.compra, response.venta, Convert.ToDateTime(response.fecha)); } catch (Exception e) { logger.registrarErrorAsync("Problema convirtiendo CotizacionResponse to Cotizacion", e); } return(coti); }
public async Task <ActionResult <Cotizacion> > cotizacion(int id) { CotizacionDisponible cotizacionDisponible = _cotizacionesDisponiblesService.cotizacionDisponible(id); _logger.registrarSolicitudCotizacionAsync(cotizacionDisponible); CotizacionResponse cotizacionResponse = await _cotizacionRequest.solicitarCotizacionAsync(cotizacionDisponible); Cotizacion cotizacion = _responseToCotizacion.convert(cotizacionResponse); _logger.registrarCotizacionConsumidaAsync(cotizacion); return(Ok(cotizacion)); }
public async Task <Cotizacion> solicitarCotizacion(string tipoCotizacion) { Logger.registrarSolicitudCotizacion(tipoCotizacion); CotizacionResponse resultadoCotizacion = await cotizacionRequestService.solicitarCotizacion(tipoCotizacion); Cotizacion coti = responseToCotizacion.convert(resultadoCotizacion); Logger.registrarCotizacionConsumida(coti); return(coti); }
public async Task <CotizacionResponse> solicitarCotizacion(string cotizacion) { string streamTask; CotizacionResponse response = null; try { streamTask = await this.client.GetStringAsync(urlBase + cotizacion); response = JsonConvert.DeserializeObject <CotizacionResponse> (streamTask); } catch (Exception e) { Logger.registrarError("Error consumiendoAPI", e); } return(response); }
public async Task <CotizacionResponse> solicitarCotizacionAsync(CotizacionDisponible cotizacionDisponible) { string streamTask; CotizacionResponse response = null; try { var client = _clientFactory.CreateClient(); streamTask = await client.GetStringAsync(urlBase + cotizacionDisponible.UrlRoute); response = JsonConvert.DeserializeObject <CotizacionResponse> (streamTask); } catch (Exception e) { _logger.registrarErrorAsync("Error consumiendoAPI", e); } return(response); }
public async Task <Cotizacion> Get(Moneda moneda) { const string currencyKey = "d0da54f39a6420a5c247"; using (var client = new HttpClient()) { var url = new Uri($"https://free.currconv.com/api/v7/convert?q={moneda.CodigoISO4217}_ARS&compact=ultra&apiKey={currencyKey}"); var response = await client.GetAsync(url); string json = String.Empty; using (var content = response.Content) { json = await content.ReadAsStringAsync(); } CotizacionResponse conversion = JsonConvert.DeserializeObject(json, moneda.Response.GetType()) as CotizacionResponse; return(new Cotizacion { Moneda = moneda.Nombre.ToLower(), Precio = conversion.Valor }); } }