Skip to content

Commit a6b3f05

Browse files
Added news from Discover.NET to the ticker
Co-authored-by: Dave Glick <[email protected]>
1 parent ee33086 commit a6b3f05

File tree

3 files changed

+65
-5
lines changed

3 files changed

+65
-5
lines changed

Fritz.StreamTools/Controllers/GitHubController.cs

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
using LazyCache;
99
using Microsoft.Extensions.Logging;
1010
using Fritz.StreamTools.Services;
11+
using System.Collections.Generic;
12+
using System.Net.Http;
13+
using Newtonsoft.Json;
14+
using System.IO;
1115

1216
namespace Fritz.StreamTools.Controllers
1317
{
@@ -18,13 +22,15 @@ public GitHubController(
1822
GitHubRepository repository,
1923
GithubyMcGithubFaceClient client,
2024
ILogger<GitHubController> logger,
21-
IOptions<GitHubConfiguration> githubConfiguration)
25+
IOptions<GitHubConfiguration> githubConfiguration,
26+
IHttpClientFactory httpClientFactory)
2227
{
2328
this.Cache = cache;
2429
this.Logger = logger;
2530
this.Client = client;
2631
_gitHubRepository = repository;
2732
_gitHubConfiguration = githubConfiguration.Value;
33+
_httpClient = httpClientFactory.CreateClient("DiscoverDotNet");
2834
}
2935

3036
public IAppCache Cache { get; }
@@ -35,6 +41,10 @@ public GitHubController(
3541

3642
private readonly GitHubConfiguration _gitHubConfiguration;
3743

44+
private readonly HttpClient _httpClient;
45+
46+
private static JsonSerializer _serializer = new JsonSerializer();
47+
3848
public async Task<IActionResult> ContributorsInformation(string repo, string userName, int count)
3949
{
4050
var outModel = await _gitHubRepository.GetRecentContributors(_gitHubConfiguration.RepositoryCsv);
@@ -49,14 +59,35 @@ public async Task<IActionResult> ContributorsInformation(string repo, string use
4959
});
5060
}
5161

52-
62+
var newsPosts = await GetNewsFromDiscoverDotNet();
63+
var outViewModel = new TickerViewModel()
64+
{
65+
GitHubInformation = outModel.ToArray(),
66+
News = newsPosts
67+
};
5368

5469
ViewBag.Configuration = _gitHubConfiguration;
5570

56-
return View($"contributor_{_gitHubConfiguration.DisplayMode}", outModel.ToArray());
71+
return View($"contributor_{_gitHubConfiguration.DisplayMode}", outViewModel);
5772

5873
}
5974

75+
private async Task<(string source, string color, IEnumerable<BlogPostModel> blogPosts)> GetNewsFromDiscoverDotNet()
76+
{
77+
IList<BlogPostModel> posts;
78+
using(Stream response = await _httpClient.GetStreamAsync("https://discoverdot.net/data/news.json"))
79+
{
80+
using(StreamReader reader = new StreamReader(response))
81+
{
82+
using(JsonTextReader json = new JsonTextReader(reader))
83+
{
84+
posts = _serializer.Deserialize<IList<BlogPostModel>>(json);
85+
}
86+
}
87+
}
88+
return ("Discover .NET", "#551A8B", posts.Take(5).ToArray());
89+
}
90+
6091
public IActionResult Configuration()
6192
{
6293
return View(_gitHubConfiguration);
@@ -145,4 +176,21 @@ public async Task<IActionResult> VerifyRepository(string repositoryName, string
145176
return Json(true);
146177
}
147178
}
179+
180+
public class TickerViewModel {
181+
182+
public IEnumerable<GitHubInformation> GitHubInformation { get; set; }
183+
184+
public (string source, string color, IEnumerable<BlogPostModel> blogPosts) News { get; set; }
185+
186+
}
187+
188+
public class BlogPostModel
189+
{
190+
public string Title { get; set; }
191+
public string FeedTitle { get; set; }
192+
public string Link { get; set; }
193+
public DateTime Published { get; set; }
194+
}
195+
148196
}

Fritz.StreamTools/StartupServices/ConfigureServices.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ private static void RegisterGitHubServices(IServiceCollection services, IConfigu
6868
c.DefaultRequestHeaders.Add("Accept", "applications/json");
6969
});
7070

71+
services.AddHttpClient("DiscoverDotNet");
72+
7173
services.AddHttpClient("ShoutoutCommand", c =>
7274
{
7375
c.BaseAddress = new Uri("https://api.twitch.tv/kraken/channels/");

Fritz.StreamTools/Views/GitHub/Contributor_h-scroll.cshtml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@model IEnumerable<GitHubInformation>
1+
@model Fritz.StreamTools.Controllers.TickerViewModel
22
@{
33
Layout = null;
44
var Config = ViewBag.Configuration as GitHubConfiguration;
@@ -41,7 +41,7 @@
4141
4242
<p id="marquee">
4343
44-
@foreach (var repo in Model)
44+
@foreach (var repo in Model.GitHubInformation)
4545
{
4646
4747
<span id="[email protected]">
@@ -83,6 +83,16 @@
8383
8484
</span>
8585
86+
<span id="news">
87+
88+
<b style="color: @Model.News.color!important">Latest news from @Model.News.source</b>
89+
90+
@foreach(var article in Model.News.blogPosts) {
91+
<span style="margin-right: 3px; text-decoration: underline;">@article.Title</span>
92+
}
93+
94+
</span>
95+
8696
}
8797
8898
</p>

0 commit comments

Comments
 (0)