static void SearchOmdbByTitleAndYear() { Console.WriteLine("Type in the title and year of the movie."); Console.Write("Title: "); var title = Console.ReadLine(); Console.Write("Year: "); var year = Console.ReadLine(); if (string.IsNullOrEmpty(title)) { Console.WriteLine("Search must have a title."); Console.ReadLine(); return; } Console.Clear(); try { Movie movie = webApiClient.GetAsync <Movie>("https://localhost:5001", $"OMDbMovies/searchTitle/{title}" + (string.IsNullOrEmpty(year) ? "" : $"/{year}")).Result; OutputMovie(movie); } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.ReadLine(); }
private async Task <IEnumerable <StockExchangeData> > GetStockTranListAsync(GetStockReq req, string date) { var url = $"{_baseUrl}/exchangeReport/STOCK_DAY?response=json&date={date}&stockNo={req.StockId}"; var jsonData = await _webApi.GetAsync( url, new Dictionary <string, string>()); var options = new JsonSerializerOptions { ReadCommentHandling = JsonCommentHandling.Skip, AllowTrailingCommas = true, PropertyNamingPolicy = JsonNamingPolicy.CamelCase, }; try { var rawData = JsonSerializer.Deserialize <StockExchangeRawData>(jsonData, options); if (rawData == null) { return(Enumerable.Empty <StockExchangeData>()); } return(rawData.GetStockList(req.StockId)); } catch { //Console.WriteLine($"{jsonData}"); return(Enumerable.Empty <StockExchangeData>()); } }
public static Task <TResult> GetAsync <TResult>(this IWebApiClient webApiClient, Priority priority, string path, int retryCount, Func <int, TimeSpan> sleepDurationProvider, CancellationToken cancellationToken = default(CancellationToken)) { return(PollyDecorator( () => webApiClient.GetAsync <TResult>(priority, path, cancellationToken), retryCount, sleepDurationProvider)); }
public async Task <IEnumerable <Photo> > GetPhotos() { var photoUrl = _configuration.GetSection("PhotoApi"); var httpEndpoint = photoUrl["http"]; var response = await _webApiClient.GetAsync(httpEndpoint); string apiResponse = await response.Content.ReadAsStringAsync(); var photoList = JsonConvert.DeserializeObject <List <Photo> >(apiResponse); return(photoList); }
public async Task <IEnumerable <Album> > GetAlbums() { var albumUrl = _configuration.GetSection("AlbumApi"); var httpEndpoint = albumUrl["http"]; var response = await _webApiClient.GetAsync(httpEndpoint); string apiResponse = await response.Content.ReadAsStringAsync(); var albumList = JsonConvert.DeserializeObject <List <Album> >(apiResponse); return(albumList); }
public async Task <Movie> SearchMovie(string query) { var apiResponce = await _webApiClient.GetAsync <Movie>(_omdbConString, query, _apiKey); if (apiResponce.Response == "False") { throw new Exception(apiResponce.Error); } else { return(apiResponce); } }
public async Task <WeatherResponse> SearchWeather(string location) { //TODO Catch and Log Exception //TODO Monitor and Log Performance //TODO: Read the URL and Headers values from config Uri uri = new Uri($"http://samples.openweathermap.org/data/2.5/weather?q={ location }&appid=b6907d289e10d714a6e88b30761fae22"); //TODO: check the url is valid var response = await _webApiClient.GetAsync(uri); if (response.StatusCode == HttpStatusCode.OK) { var result = await response.Content.ReadAsAsync <WeatherResponse>(); return(result); } return(null); }
public async Task <IEnumerable <Restaurant> > SearchRestaurants(string postCode) { //TODO Catch and Log Exception //TODO Monitor and Log Performance //TODO: Read the URL and Headers values from web config Uri uri = new Uri($"https://public.je-apis.com/restaurants?q={ postCode }"); //TODO: check the url is valid var response = await _webApiClient.GetAsync(uri, GetHeader()); if (response.StatusCode == HttpStatusCode.OK) { var result = await response.Content.ReadAsAsync <RestaurantRoot>(); return(result.Restaurants); } return(null); }
public async IAsyncEnumerable <StockExchangeData> GetStockHistoryListAsync(GetStockReq req) { var startDateStr = req.DateRange.StartDate.ToDateString(); var endDateStr = req.DateRange.EndDate.ToDateString(); var url = $"{_baseUrl}/api/v4/data?dataset=TaiwanStockPrice&data_id={req.StockId}&start_date={startDateStr}&end_date={endDateStr}&token={_token}"; var jsonData = await _webApi.GetAsync( url, new Dictionary <string, string>()); if (jsonData == null) { yield break; } var options = new JsonSerializerOptions { ReadCommentHandling = JsonCommentHandling.Skip, AllowTrailingCommas = true, }; var rawData = JsonSerializer.Deserialize <FinMindResp>(jsonData, options); foreach (var data in rawData.data) { yield return(new StockExchangeData { Date = data.date, StockId = data.stock_id, OpeningPrice = data.open, ClosingPrice = data.close, HighestPrice = data.max, LowestPrice = data.min, Change = data.spread, DollorVolume = data.Trading_money, Transaction = data.Trading_turnover, TradeVolume = data.Trading_Volume }); } }
public Result <UsuarioModel> GetUsuario(int id) { return(AsyncContext.Run(() => _apiClient.GetAsync <Result <UsuarioModel> >( $"{apiRoute}GetUsuario/{id}"))); }
public Result <SessaoModel> Get(int id) { return(AsyncContext.Run(() => _apiClient.GetAsync <Result <SessaoModel> >( $"{apiRoute}GetAgenda/{id}"))); }
public Result <CaixaModel> GetCaixa(int id) { return(AsyncContext.Run(() => _apiClient.GetAsync <Result <CaixaModel> >( $"{apiRoute}GetCaixa/{id}"))); }
public Result <List <TipoPerfilModel> > ListTipoPerfil() { return(AsyncContext.Run(() => _apiClient.GetAsync <Result <List <TipoPerfilModel> > >($"{apiRoute}ListTipoPerfil"))); }