private static async Task ProcessVaccin() { var config = ConfigurationManager.AppSettings; var uri = config["VaccinUri"]; var parameters = config["VaccinParameters"]; var searchArea = _searchArea ?? config["VaccinSearchArea"]; var vaccinBlackListLocations = config["VaccinBlackListLocations"] .Split(";") .Select(b => Int32.Parse(b)).ToList(); var searchUrl = $"{uri}/vaccination-covid-19/{searchArea}?{parameters}"; var locationsCodes = await SearchLocationsInArea(searchUrl); foreach (var locationCode in locationsCodes) { var url = $"{uri}/search_results/{locationCode}.json?{parameters}"; var res = await HttpClientJsonExtensions.GetFromJsonAsync <VaccinResponse>(_client, url); if (res != null) { if (ResponseIsValid(res, vaccinBlackListLocations)) { Console.WriteLine($"{res.search_result.city} => YES !"); _notifier.Notify(Status.Sucess, res.search_result.city, $"{uri}{res.search_result.url}"); } else if (res.search_result != null) { Console.WriteLine($"{res.search_result.city} => none :("); } } else { Console.WriteLine($"{locationCode} => none :("); } } }
private static async Task ProcessCandilib() { var config = ConfigurationManager.AppSettings; var uri = config["CandilibUri"]; _client.DefaultRequestHeaders.Add("X-USER-ID", config["UserId"]); _client.DefaultRequestHeaders.Add("X-CLIENT-ID", config["ClientId"]); _client.DefaultRequestHeaders.Add("X-REQUEST-ID", config["RequestId"]); _client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", config["AuthorizationBearer"]); foreach (var dep in new string[] { "78", "92", "95", "77", "93", "38", "91", "94", "69", "76", "45" }) { var res = await HttpClientJsonExtensions.GetFromJsonAsync <List <City> >(_client, $"{uri}?departement={dep}"); if (res.Count > 0 && res.Any(r => r.count > 0)) { _notifier.Notify(Status.Sucess, dep, dep); } else { Console.WriteLine($"{dep} => none :("); } } }
public async Task <bool> CreateOrUpdateModel() { await HttpClientJsonExtensions.PostJsonAsync(Http, $"{AppState.UpdateURL}", EditObject); AppState.UpdateModel(); if (EditObject.Id == 0) { EditObject = new TeamViewModel(); } return(true); }
public async Task <bool> DeleteClick(long id) { var deleteObject = new ViewModel() { Id = id }; await HttpClientJsonExtensions.PostJsonAsync(Http, $"{AppState.DeleteURL}", deleteObject); await SetData(); return(true); }
public async Task GetUrlsByIds_MediaWithIntegerIds_ReturnsValidMap() { IMediaTypeService mediaTypeService = Services.GetRequiredService <IMediaTypeService>(); IMediaService mediaService = Services.GetRequiredService <IMediaService>(); var mediaItems = new List <Media>(); using (ScopeProvider.CreateScope(autoComplete: true)) { IMediaType mediaType = mediaTypeService.Get("image"); mediaTypeService.Save(mediaType); mediaItems.Add(MediaBuilder.CreateMediaImage(mediaType, -1)); mediaItems.Add(MediaBuilder.CreateMediaImage(mediaType, -1)); foreach (Media media in mediaItems) { mediaService.Save(media); } } var queryParameters = new Dictionary <string, object> { ["type"] = Constants.UdiEntityType.Media }; var url = LinkGenerator.GetUmbracoControllerUrl("GetUrlsByIds", typeof(EntityController), queryParameters); var payload = new { ids = new[] { mediaItems[0].Id, mediaItems[1].Id, } }; HttpResponseMessage response = await HttpClientJsonExtensions.PostAsJsonAsync(Client, url, payload); // skip pointless un-parseable cruft. (await response.Content.ReadAsStreamAsync()).Seek(AngularJsonMediaTypeFormatter.XsrfPrefix.Length, SeekOrigin.Begin); IDictionary <int, string> results = await response.Content.ReadFromJsonAsync <IDictionary <int, string> >(); Assert.Multiple(() => { Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); Assert.IsTrue(results ![payload.ids[0]].StartsWith("/media")); Assert.IsTrue(results ![payload.ids[1]].StartsWith("/media"));
protected async Task HandleInvalidSubmit() { try { var response = await HttpClientJsonExtensions.PostJsonAsync <ResponseObject <FormModel> >(Http, "api/Form", Model); if (response?.Data != null) { Model = response.Data; StateHasChanged(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public async Task <FinanceNews[]> GetFinanceNewsAsync() { var requestUri = new Uri("https://yahoo-finance15.p.rapidapi.com/api/yahoo/ne/news"); var client = new HttpClient(); // IMPORTANT! Go here first to get your own x-rapidapi-key: https://rapidapi.com/apidatacenter-api-data/api/yahoo-finance15 client.DefaultRequestHeaders.Add("x-rapidapi-key", "PUT YOUR API KEY HERE"); client.DefaultRequestHeaders.Add("x-rapidapi-host", "yahoo-finance15.p.rapidapi.com"); CancellationTokenSource source = new CancellationTokenSource(); CancellationToken token = source.Token; var response = await HttpClientJsonExtensions.GetFromJsonAsync <FinanceNews[]>(client, requestUri, token); return(response); }