start of HN integration
This commit is contained in:
parent
087a8e3e98
commit
b79d9bf2ec
11 changed files with 144 additions and 1 deletions
|
@ -52,6 +52,7 @@ namespace BirdsiteLive.Twitter
|
||||||
var client = await _twitterAuthenticationInitializer.MakeHttpClient();
|
var client = await _twitterAuthenticationInitializer.MakeHttpClient();
|
||||||
|
|
||||||
|
|
||||||
|
// https://platform.twitter.com/embed/Tweet.html?id=1633788842770825216
|
||||||
string reqURL =
|
string reqURL =
|
||||||
"https://api.twitter.com/graphql/XjlydVWHFIDaAUny86oh2g/TweetDetail?variables=%7B%22focalTweetId%22%3A%22"
|
"https://api.twitter.com/graphql/XjlydVWHFIDaAUny86oh2g/TweetDetail?variables=%7B%22focalTweetId%22%3A%22"
|
||||||
+ statusId +
|
+ statusId +
|
||||||
|
|
|
@ -51,6 +51,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BirdsiteLive.Twitter.Tests"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BirdsiteLive.Wikidata", "BirdsiteLive.Wikidata\BirdsiteLive.Wikidata.csproj", "{EAB43087-359C-46BD-8796-5F7D9B473B39}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BirdsiteLive.Wikidata", "BirdsiteLive.Wikidata\BirdsiteLive.Wikidata.csproj", "{EAB43087-359C-46BD-8796-5F7D9B473B39}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SocialNetworks", "SocialNetworks", "{7ACCADEA-4B64-4ACB-A21D-0627674BBA9D}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dotMakeup.HackerNews", "dotMakeup.HackerNews\dotMakeup.HackerNews.csproj", "{060DE3F7-DB7E-45FD-B233-104C3C464F57}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dotMakeup.HackerNews.Tests", "Tests\dotMakeup.HackerNews.Tests\dotMakeup.HackerNews.Tests.csproj", "{6D650384-7BDD-4628-A46C-2FE4A688DBA4}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
@ -137,13 +143,20 @@ Global
|
||||||
{EAB43087-359C-46BD-8796-5F7D9B473B39}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{EAB43087-359C-46BD-8796-5F7D9B473B39}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{EAB43087-359C-46BD-8796-5F7D9B473B39}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{EAB43087-359C-46BD-8796-5F7D9B473B39}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{EAB43087-359C-46BD-8796-5F7D9B473B39}.Release|Any CPU.Build.0 = Release|Any CPU
|
{EAB43087-359C-46BD-8796-5F7D9B473B39}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{060DE3F7-DB7E-45FD-B233-104C3C464F57}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{060DE3F7-DB7E-45FD-B233-104C3C464F57}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{060DE3F7-DB7E-45FD-B233-104C3C464F57}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{060DE3F7-DB7E-45FD-B233-104C3C464F57}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{6D650384-7BDD-4628-A46C-2FE4A688DBA4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{6D650384-7BDD-4628-A46C-2FE4A688DBA4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{6D650384-7BDD-4628-A46C-2FE4A688DBA4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{6D650384-7BDD-4628-A46C-2FE4A688DBA4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(NestedProjects) = preSolution
|
GlobalSection(NestedProjects) = preSolution
|
||||||
{160AD138-4E29-4706-8546-9826B529E9B2} = {4FEAD6BC-3C8E-451A-8CA1-FF1AF47D26CC}
|
{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}
|
{E64E7501-5DB8-4620-BA35-BA59FD746ABA} = {4FEAD6BC-3C8E-451A-8CA1-FF1AF47D26CC}
|
||||||
{155D46A4-2D05-47F2-8FFC-0B7C412A7652} = {A32D3458-09D0-4E0A-BA4B-8C411B816B94}
|
{155D46A4-2D05-47F2-8FFC-0B7C412A7652} = {A32D3458-09D0-4E0A-BA4B-8C411B816B94}
|
||||||
{D48450EE-D8BD-4228-9864-043AC88F7EE0} = {4FEAD6BC-3C8E-451A-8CA1-FF1AF47D26CC}
|
{D48450EE-D8BD-4228-9864-043AC88F7EE0} = {4FEAD6BC-3C8E-451A-8CA1-FF1AF47D26CC}
|
||||||
|
@ -161,6 +174,9 @@ Global
|
||||||
{C69F7582-6050-44DC-BAAB-7C8F0BDA525C} = {A32D3458-09D0-4E0A-BA4B-8C411B816B94}
|
{C69F7582-6050-44DC-BAAB-7C8F0BDA525C} = {A32D3458-09D0-4E0A-BA4B-8C411B816B94}
|
||||||
{2DFA0BFD-88F5-4434-A6E3-C93B5750E88C} = {A32D3458-09D0-4E0A-BA4B-8C411B816B94}
|
{2DFA0BFD-88F5-4434-A6E3-C93B5750E88C} = {A32D3458-09D0-4E0A-BA4B-8C411B816B94}
|
||||||
{EAB43087-359C-46BD-8796-5F7D9B473B39} = {DA3C160C-4811-4E26-A5AD-42B81FAF2D7C}
|
{EAB43087-359C-46BD-8796-5F7D9B473B39} = {DA3C160C-4811-4E26-A5AD-42B81FAF2D7C}
|
||||||
|
{060DE3F7-DB7E-45FD-B233-104C3C464F57} = {7ACCADEA-4B64-4ACB-A21D-0627674BBA9D}
|
||||||
|
{77C559D1-80A2-4B1C-A566-AE2D156944A4} = {7ACCADEA-4B64-4ACB-A21D-0627674BBA9D}
|
||||||
|
{6D650384-7BDD-4628-A46C-2FE4A688DBA4} = {A32D3458-09D0-4E0A-BA4B-8C411B816B94}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {69E8DCAD-4C37-4010-858F-5F94E6FBABCE}
|
SolutionGuid = {69E8DCAD-4C37-4010-858F-5F94E6FBABCE}
|
||||||
|
|
|
@ -39,6 +39,13 @@ namespace BirdsiteLive.ActivityPub.Tests
|
||||||
Assert.AreEqual(user.Acct, "kobebryant");
|
Assert.AreEqual(user.Acct, "kobebryant");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public async Task UserGrant()
|
||||||
|
{
|
||||||
|
var user = await _tweetService.GetUserAsync("grantimahara");
|
||||||
|
Assert.AreEqual(user.Name, "Grant Imahara");
|
||||||
|
Assert.AreEqual(user.Acct, "grantimahara");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
6
src/Tests/dotMakeup.HackerNews.Tests/PostsTests.cs
Normal file
6
src/Tests/dotMakeup.HackerNews.Tests/PostsTests.cs
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
namespace dotMakeup.HackerNews.Tests;
|
||||||
|
|
||||||
|
public class PostsTests
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
20
src/Tests/dotMakeup.HackerNews.Tests/UsersTests.cs
Normal file
20
src/Tests/dotMakeup.HackerNews.Tests/UsersTests.cs
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
using dotMakeup.HackerNews;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Moq;
|
||||||
|
|
||||||
|
namespace dotMakeup.HackerNews.Tests;
|
||||||
|
|
||||||
|
[TestClass]
|
||||||
|
public class UsersTests
|
||||||
|
{
|
||||||
|
[TestMethod]
|
||||||
|
public async Task TestMethod1()
|
||||||
|
{
|
||||||
|
var httpFactory = new Mock<IHttpClientFactory>();
|
||||||
|
httpFactory.Setup(_ => _.CreateClient(string.Empty)).Returns(new HttpClient());
|
||||||
|
var userService = new HNUserService(httpFactory.Object);
|
||||||
|
var user = await userService.GetUserAsync("dhouston");
|
||||||
|
|
||||||
|
Assert.AreEqual(user.About, "Founder/CEO of Dropbox (http://www.dropbox.com ; yc summer '07)");
|
||||||
|
}
|
||||||
|
}
|
1
src/Tests/dotMakeup.HackerNews.Tests/Usings.cs
Normal file
1
src/Tests/dotMakeup.HackerNews.Tests/Usings.cs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
global using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
@ -0,0 +1,25 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net7.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
|
||||||
|
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
|
||||||
|
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
|
||||||
|
<PackageReference Include="coverlet.collector" Version="3.1.2" />
|
||||||
|
<PackageReference Include="moq" Version="4.16.1" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Http" Version="5.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\dotMakeup.HackerNews\dotMakeup.HackerNews.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
||||||
|
</Project>
|
6
src/dotMakeup.HackerNews/HNPostService.cs
Normal file
6
src/dotMakeup.HackerNews/HNPostService.cs
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
namespace dotMakeup.HackerNews;
|
||||||
|
|
||||||
|
public class HNPostService
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
39
src/dotMakeup.HackerNews/HNUserService.cs
Normal file
39
src/dotMakeup.HackerNews/HNUserService.cs
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Web;
|
||||||
|
using dotMakeup.HackerNews.Models;
|
||||||
|
|
||||||
|
namespace dotMakeup.HackerNews;
|
||||||
|
|
||||||
|
public class HNUserService
|
||||||
|
{
|
||||||
|
private IHttpClientFactory _httpClientFactory;
|
||||||
|
public HNUserService(IHttpClientFactory httpClientFactory)
|
||||||
|
{
|
||||||
|
_httpClientFactory = httpClientFactory;
|
||||||
|
|
||||||
|
}
|
||||||
|
public async Task<HNUser> GetUserAsync(string username)
|
||||||
|
{
|
||||||
|
string reqURL = "https://hacker-news.firebaseio.com/v0/user/dhouston.json";
|
||||||
|
reqURL = reqURL.Replace("dhouston", username);
|
||||||
|
|
||||||
|
var client = _httpClientFactory.CreateClient();
|
||||||
|
var request = new HttpRequestMessage(new HttpMethod("GET"), reqURL);
|
||||||
|
|
||||||
|
JsonDocument userDoc;
|
||||||
|
var httpResponse = await client.SendAsync(request);
|
||||||
|
httpResponse.EnsureSuccessStatusCode();
|
||||||
|
var c = await httpResponse.Content.ReadAsStringAsync();
|
||||||
|
userDoc = JsonDocument.Parse(c);
|
||||||
|
|
||||||
|
string about =
|
||||||
|
HttpUtility.HtmlDecode(userDoc.RootElement.GetProperty("about").GetString());
|
||||||
|
|
||||||
|
var user = new HNUser()
|
||||||
|
{
|
||||||
|
Id = 0,
|
||||||
|
About = about,
|
||||||
|
};
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
}
|
7
src/dotMakeup.HackerNews/Models/HNUser.cs
Normal file
7
src/dotMakeup.HackerNews/Models/HNUser.cs
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
namespace dotMakeup.HackerNews.Models;
|
||||||
|
|
||||||
|
public class HNUser
|
||||||
|
{
|
||||||
|
public long Id { get; set; }
|
||||||
|
public string About { get; set; }
|
||||||
|
}
|
15
src/dotMakeup.HackerNews/dotMakeup.HackerNews.csproj
Normal file
15
src/dotMakeup.HackerNews/dotMakeup.HackerNews.csproj
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net7.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="Microsoft.Extensions.Http">
|
||||||
|
<HintPath>..\..\..\..\.nuget\packages\microsoft.extensions.http\5.0.0\lib\netstandard2.0\Microsoft.Extensions.Http.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
Loading…
Add table
Reference in a new issue