public PollAndStoreV2(string location, string function, SourceResponse sources) { _function = function; _client = new HttpClient(); _client.DefaultRequestHeaders.Add("x-location", location); _sources = sources; }
private async Task LoadArticles(SourceResponse sourceResponse) { var tasks = new List <Task>(); foreach (var source in sourceResponse.sources) { tasks.Add(source.LoadArticles()); } await Task.WhenAll(tasks); }
/// <summary> /// Gets the sources. /// </summary> /// <returns>The sources.</returns> /// <param name="apikey">Apikey.</param> public async Task <SourceResponse> GetSources(string apikey) { SourceResponse rtn = new SourceResponse(); try { var client = RestService.For <INewsApi>(Constants.UrlNews); rtn = await client.GetSources(apikey); } catch (ApiException ax) { Debug.WriteLine("Api error: " + ax.Message); } catch (Exception ex) { Debug.WriteLine("Generic error: " + ex.Message); } return(rtn); }
async Task LoadData() { ShowEmpty = true; ShowListView = false; IsBusy = true; NewsClient client = new NewsClient(); SourceResponse sources = await client.GetSources(Constants.ApiKey); if (sources != null && sources.Status.ToLower() == "ok") { SourceList = new ObservableCollection <SourceModel>(sources.Sources); if (SourceList.Count > 0) { ShowEmpty = false; ShowListView = true; } OnPropertyChanged(nameof(SourceList)); } IsBusy = false; }
private string Parse(string query, SourceResponse response) { var item = response.Items.FirstOrDefault(); var noResMessage = $"Sorry, I couldn't find any results for '{query}'"; if (item == null) { return(noResMessage); } if (item.Offers == null || !item.Offers.Any()) { return(noResMessage); } var t1Services = new List <string>(); var flatrate = item.Offers.Where(x => x.MonetizationType == MonetizationType.FlatRate) .Select(x => x.Urls?.StandardWeb) .Where(x => x != null); //t1 = flatrate ones most ppl have //could be linqified but whatever for now foreach (var flat in flatrate) { t1Services.AddRange(T1Services.Where(x => flat.Contains(x))); } t1Services = t1Services.Distinct().ToList(); if (t1Services.Any()) { return(GetNiceStringForList($"{item.Title} can be watched for free on ", t1Services)); } //todo: expand this to return info about where else you can find it. //todo: make configurable so you can say if you care about other services return($"{item.Title} is not available on any flat rate streaming services"); }
public async Task <IActionResult> GetAsync(int id, DateTime?realtime_start, DateTime?realtime_end) { SourceResponse result = new SourceResponse(); try { api.Arguments.ApiKey = appSettings.ApiKey; api.Arguments.source_id = id; api.Arguments.realtime_start = realtime_start ?? api.Arguments.realtime_start; api.Arguments.realtime_end = realtime_end ?? api.Arguments.realtime_end; result.container = await api.FetchAsync(); SetApiValues(api, result); } catch (Exception exception) { logger.LogError(exception, "GetSource failed"); return(StatusCode(500)); } return(Ok(result)); }
private string Parse(string query, long userId, SourceResponse response) { if (UserService == null) { throw new InvalidOperationException("Must provide an IUserService"); } var item = response.Items.FirstOrDefault(); var noResMessage = $"Sorry, I couldn't find any results for '{query}'"; if (item == null) { return(noResMessage); } if (item.Offers == null || !item.Offers.Any()) { return(noResMessage); } var services = UserService.GetUserServicePreferences(userId); var avoidedServiceUrls = services .Where(x => x.Preference == -1) .SelectMany(x => x.Service.Urls.Select(y => y.Url.ToLower())) .ToList(); //for now, only use flatrate var flatrate = item.Offers.Where(x => x.MonetizationType == MonetizationType.FlatRate) .Select(x => x.Urls?.StandardWeb) .Where(x => x != null) .Select(x => x.ToLower()) .Where(x => !avoidedServiceUrls.Contains(x)) .ToList() ; var preferredServices = services .Where(x => x.Preference > 0) .ToList(); var serviceList = preferredServices .OrderBy(x => x.Preference) .Where(x => x.Service.Urls.Any(y => flatrate.Contains(y.Url))) .Select(x => x.Service) .ToList(); var serviceNames = serviceList.OrEmptyIfNull().Select(x => x.Name).ToList(); var prefServiceUrls = serviceList.SelectMany(z => z.Urls.Select(y => y.Url)); var remainingServices = flatrate.Where(x => !prefServiceUrls.Contains(x)); var remainingServiceNames = remainingServices .OrEmptyIfNull() .Select(StreamingServiceService.GetServiceByUrl) .SelectMany(x => x.Select(y => y.Name)) .Distinct() .ToList(); serviceNames.AddRange(remainingServiceNames); if (serviceNames.Any()) { return(GetNiceStringForList($"{item.Title} can be watched for free on", serviceNames)); } return($"{item.Title} is not available on any of your flat rate streaming services"); }