This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Token | |
{ | |
public string access_token { get; set; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TwitterOptions | |
{ | |
[Required] | |
public string ConsumerKey { get; set; } = ""; | |
[Required] | |
public string ConsumerSecret { get; set; } = ""; | |
public string Username { get; set; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project Sdk="Microsoft.NET.Sdk.Razor"> | |
<PropertyGroup> | |
<TargetFramework>netcoreapp2.1</TargetFramework> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.3" /> | |
<PackageReference Include="Microsoft.AspNetCore.Mvc.ViewFeatures" Version="2.1.3" /> | |
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.1.1" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RetrieveTweetsViewComponent : ViewComponent | |
{ | |
protected TwitterOptions TwitterOptions { get; private set; } | |
public RetrieveTweetsViewComponent(IOptions<TwitterOptions> options = null) | |
{ | |
if (options != null) | |
TwitterOptions = options.Value; | |
else | |
TwitterOptions = new TwitterOptions(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.Extensions.Configuration; | |
using Microsoft.Extensions.DependencyInjection.Extensions; | |
using TwitterViewComponent; | |
namespace Microsoft.Extensions.DependencyInjection | |
{ | |
public static class ServiceCollectionExtensions | |
{ | |
public static IServiceCollection AddTwitter(this IServiceCollection services, IConfiguration configuration = null) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@page | |
@model IndexModel | |
@{ | |
ViewData["Title"] = "Home page"; | |
} | |
@await Component.InvokeAsync("RetrieveTweets", new { }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"TwitterOptions": { | |
"Username": "jgaylord", | |
"ConsumerKey": "YOUR_KEY", | |
"ConsumerSecret": "YOUR_SECRET" | |
}, | |
"Logging": { | |
"LogLevel": { | |
"Default": "Warning" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@model List<TwitterViewComponent.Tweet> | |
<h3>Recent Tweets</h3> | |
<ul> | |
@foreach (var tweet in Model) | |
{ | |
<li> | |
@tweet.Message<br/> | |
<a href="http://twitter.com/@tweet.Username/statuses/@tweet.Id">@(tweet.Timestamp)</a> | |
</li> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@model List<TwitterViewComponent.Tweet> | |
<h3>Recent Tweets</h3> | |
<ul> | |
@foreach (var tweet in Model) | |
{ | |
<li> | |
@tweet.Message<br/> | |
<a href="http://twitter.com/@tweet.Username/statuses/@tweet.Id">@(tweet.Timestamp)</a> | |
</li> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class DateTimeExtensions | |
{ | |
public static string ToFriendlyDate(this DateTime date) | |
{ | |
// Calculate the elapsed time | |
TimeSpan s = DateTime.UtcNow.Subtract(date); | |
// Get total number of days elapsed. | |
int dayDiff = (int)s.TotalDays; |