public async Task <int> GetPictureCallageCount() { ApiResult <int> result = new ApiResult <int>(); string url = $"{Constants.RANDOM_PICTURE_COLLAGE_COUNT_URL}"; int count; try { if (_cache.TryGetCache <int>(url, out count)) { result.Results = count; _logger.LogInformation($"'{count}' for '{url}' was received from cache"); } else { result = await _restClient.GetAsync <int>($"{Constants.RANDOM_PICTURE_COLLAGE_COUNT_URL}"); _cache.SetCache <int>(url, result.Results, 10000); _logger.LogInformation($"'{result}' for '{url}' is now cached for 10000s"); } } catch (Exception ex) { _logger.LogError($"!!! ERROR !!! {ex.ToString()}"); } return(result.Results); }
public async Task <IActionResult> Info([FromQuery] string advertiserIds) { var url = "https://ad.toutiao.com/open_api/2/advertiser/info/" + "?advertiser_ids=[" + advertiserIds + "]"; var response = await _restClient.GetAsync <DynamicResponse>(url, _cache.Get <string>(ToutiaoCacheKey.AccessToken)); response.EnsureSuccess(); return(Ok(response)); }
public async Task <IActionResult> Select([FromQuery] string advertiserId, [FromQuery] int page = 1, [FromQuery] int pageSize = 10) { var url = "https://ad.toutiao.com/open_api/2/tools/adv_convert/select/" + "?advertiser_id=" + advertiserId + "&page=" + page + "&page_size=" + pageSize; var response = await _restClient.GetAsync <DynamicResponse>(url, _cache.Get <string>(ToutiaoCacheKey.AccessToken)); response.EnsureSuccess(); return(Ok(response)); }
private async Task <ApiResult <T> > GetAndCacheDataAync <T>(string url, int cacheDuration) { _logger.LogInformation($"Caching data for {url}"); ApiResult <T> cacheEntry = await _restClient.GetAsync <T>(url); return(Cache.SetCache(url, cacheEntry, cacheDuration)); }
public async Task <IActionResult> Select([FromQuery] string advertiserId) { var url = "https://ad.toutiao.com/open_api/2/creative/select/" + "?advertiser_id=" + advertiserId + "&fields=[\"id\",\"ad_id\",\"advertiser_id\",\"title\",\"image_info\",\"image_mode\",\"status\",\"opt_status\"]"; var response = await _restClient.GetAsync <DynamicResponse>(url, _cache.Get <string>(ToutiaoCacheKey.AccessToken)); response.EnsureSuccess(); return(Ok(response)); }
public async Task <ApiResult <List <Breed> > > GetAllBreeds() { var temp = await _restClient.GetAsync <List <Breed> >("api/dogs/"); Breeds = temp.Results; await GetBreedImagesAsync(); return(temp); }
public async Task GetAsync_forwards_to_IHttpRestClient(IHttpRestClient client, string path, Request request, IQueryString queryString, Response _) { _ = await client.GetAsync <Request, Response>(path, request, queryString); Mock.Get(client).Verify(p => p.SendAsync <Request, Response>(HttpMethod.Get, path, request, queryString)); }
public async Task GetAsync_forwards_to_IHttpRestClient(IHttpRestClient client, string path, IQueryString queryString) { await client.GetAsync(path, queryString); Mock.Get(client).Verify(p => p.SendAsync(HttpMethod.Get, path, queryString)); }