retrieving user

This commit is contained in:
Nicolas Constant 2020-03-22 01:29:51 -04:00
parent aa6e1fb254
commit 32337058c5
No known key found for this signature in database
GPG key ID: 1E9F677FB01A5688
11 changed files with 77 additions and 34 deletions

View file

@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
</Project>

View file

@ -0,0 +1,10 @@
namespace BirdsiteLive.Common.Settings
{
public class TwitterSettings
{
public string ConsumerKey { get; set; }
public string ConsumerSecret { get; set; }
public string AccessToken { get; set; }
public string AccessTokenSecret { get; set; }
}
}

View file

@ -8,4 +8,8 @@
<PackageReference Include="TweetinviAPI" Version="4.0.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BirdsiteLive.Common\BirdsiteLive.Common.csproj" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,11 @@
namespace BirdsiteLive.Twitter.Models
{
public class TwitterUser
{
public string Name { get; set; }
public string Description { get; set; }
public string Url { get; set; }
public string ProfileImageUrl { get; set; }
public string ProfileBackgroundImageUrl { get; set; }
}
}

View file

@ -1,20 +0,0 @@
namespace BirdsiteLive.Twitter.Settings
{
public class TwitterSettings
{
#region Ctor
public TwitterSettings(string apiKey, string consumerKey, string consumerSecret, string accessToken, string accessTokenSecret)
{
ConsumerKey = consumerKey;
ConsumerSecret = consumerSecret;
AccessToken = accessToken;
AccessTokenSecret = accessTokenSecret;
}
#endregion
public string ConsumerKey { get; set; }
public string ConsumerSecret { get; set; }
public string AccessToken { get; set; }
public string AccessTokenSecret { get; set; }
}
}

View file

@ -1,11 +1,14 @@
using System;
using BirdsiteLive.Twitter.Settings;
using System.Threading.Tasks;
using BirdsiteLive.Common.Settings;
using BirdsiteLive.Twitter.Models;
using Tweetinvi;
namespace BirdsiteLive.Twitter
{
public interface ITwitterService
{
TwitterUser GetUser(string username);
}
public class TwitterService : ITwitterService
@ -19,9 +22,19 @@ namespace BirdsiteLive.Twitter
}
#endregion
public void GetUser(string username)
public TwitterUser GetUser(string username)
{
Auth.SetUserCredentials(_settings.ConsumerKey, _settings.ConsumerSecret, _settings.AccessToken, _settings.AccessTokenSecret);
var user = User.GetUserFromScreenName(username);
return new TwitterUser
{
Name = user.Name,
Description = user.Description,
Url = user.Url,
ProfileImageUrl = user.ProfileImageUrl,
ProfileBackgroundImageUrl = user.ProfileBackgroundImageUrl
};
}
}
}

View file

@ -5,11 +5,13 @@ VisualStudioVersion = 16.0.29911.84
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BirdsiteLive", "BirdsiteLive\BirdsiteLive.csproj", "{4059D92B-A86B-4765-A905-EFC2D7259C34}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BirdsiteLive.Cryptography", "BirdsiteLive.Cryptography\BirdsiteLive.Cryptography.csproj", "{160AD138-4E29-4706-8546-9826B529E9B2}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BirdsiteLive.Cryptography", "BirdsiteLive.Cryptography\BirdsiteLive.Cryptography.csproj", "{160AD138-4E29-4706-8546-9826B529E9B2}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Domain", "Domain", "{4FEAD6BC-3C8E-451A-8CA1-FF1AF47D26CC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BirdsiteLive.Twitter", "BirdsiteLive.Twitter\BirdsiteLive.Twitter.csproj", "{77C559D1-80A2-4B1C-A566-AE2D156944A4}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BirdsiteLive.Twitter", "BirdsiteLive.Twitter\BirdsiteLive.Twitter.csproj", "{77C559D1-80A2-4B1C-A566-AE2D156944A4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BirdsiteLive.Common", "BirdsiteLive.Common\BirdsiteLive.Common.csproj", "{E64E7501-5DB8-4620-BA35-BA59FD746ABA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -29,6 +31,10 @@ Global
{77C559D1-80A2-4B1C-A566-AE2D156944A4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{77C559D1-80A2-4B1C-A566-AE2D156944A4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{77C559D1-80A2-4B1C-A566-AE2D156944A4}.Release|Any CPU.Build.0 = Release|Any CPU
{E64E7501-5DB8-4620-BA35-BA59FD746ABA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E64E7501-5DB8-4620-BA35-BA59FD746ABA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E64E7501-5DB8-4620-BA35-BA59FD746ABA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E64E7501-5DB8-4620-BA35-BA59FD746ABA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -36,6 +42,7 @@ Global
GlobalSection(NestedProjects) = preSolution
{160AD138-4E29-4706-8546-9826B529E9B2} = {4FEAD6BC-3C8E-451A-8CA1-FF1AF47D26CC}
{77C559D1-80A2-4B1C-A566-AE2D156944A4} = {4FEAD6BC-3C8E-451A-8CA1-FF1AF47D26CC}
{E64E7501-5DB8-4620-BA35-BA59FD746ABA} = {4FEAD6BC-3C8E-451A-8CA1-FF1AF47D26CC}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {69E8DCAD-4C37-4010-858F-5F94E6FBABCE}

View file

@ -13,6 +13,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BirdsiteLive.Common\BirdsiteLive.Common.csproj" />
<ProjectReference Include="..\BirdsiteLive.Cryptography\BirdsiteLive.Cryptography.csproj" />
<ProjectReference Include="..\BirdsiteLive.Twitter\BirdsiteLive.Twitter.csproj" />
</ItemGroup>

View file

@ -3,22 +3,34 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using BirdsiteLive.Twitter;
using Microsoft.AspNetCore.Mvc;
namespace BirdsiteLive.Controllers
{
public class UserController : Controller
{
private readonly ITwitterService _twitterService;
#region Ctor
public UserController(ITwitterService twitterService)
{
_twitterService = twitterService;
}
#endregion
[Route("/@{id}")]
[Route("/user/{id}")]
public IActionResult Index(string id)
{
var user = _twitterService.GetUser(id);
var r = Request.Headers["Accept"].First();
if(r.Contains("application/activity+json"))
if (r.Contains("application/activity+json"))
return Json(new { test = "test" });
return View();
return View(user);
}
}
}

View file

@ -2,8 +2,8 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BirdsiteLive.Common.Settings;
using BirdsiteLive.Models;
using BirdsiteLive.Twitter.Settings;
using Lamar;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
@ -43,12 +43,7 @@ namespace BirdsiteLive
public void ConfigureContainer(ServiceRegistry services)
{
var twitterSettings = Configuration.GetSection("Twitter").Get<TwitterSettings>();
services.For<TwitterSettings>().Use<TwitterSettings>()
.Ctor<string>("accessToken").Is(twitterSettings.AccessToken)
.Ctor<string>("accessTokenSecret").Is(twitterSettings.AccessTokenSecret)
.Ctor<string>("consumerKey").Is(twitterSettings.ConsumerKey)
.Ctor<string>("consumerSecret").Is(twitterSettings.ConsumerSecret);
services.For<TwitterSettings>().Use(x => twitterSettings);
services.Scan(_ =>
{

View file

@ -5,3 +5,6 @@
<h1>User</h1>
@ViewData.Model.Name
@ViewData.Model.Description