Commit 07ac9e75 authored by Robert Rudman's avatar Robert Rudman

More organization of stuff

parent f2e03b52
......@@ -8,9 +8,9 @@ using System.Threading.Tasks;
using System.Web;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using StackExchangeChat.Api.Responses;
using StackExchangeApi.Responses;
namespace StackExchangeChat.Api
namespace StackExchangeApi
{
public class ApiClient
{
......
using Newtonsoft.Json;
namespace StackExchangeChat.Api.Responses
namespace StackExchangeApi.Responses
{
public class ApiBaseResponse
{
......
using System.Collections.Generic;
using Newtonsoft.Json;
namespace StackExchangeChat.Api.Responses
namespace StackExchangeApi.Responses
{
public class ApiItemsResponse<TItemType> : ApiBaseResponse
{
......
using System.Collections.Generic;
using Newtonsoft.Json;
namespace StackExchangeChat.Api.Responses
namespace StackExchangeApi.Responses
{
public class BaseQuestion
{
......
namespace StackExchangeChat.Api.Responses
namespace StackExchangeApi.Responses
{
public class TotalResponse : ApiBaseResponse
{
......
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="HtmlAgilityPack" Version="1.8.10" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0-preview3-35497" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.2.0-preview3-35497" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1-beta1" />
<PackageReference Include="System.Reactive" Version="4.1.2" />
</ItemGroup>
</Project>
......@@ -4,9 +4,7 @@ using System.Net;
using System.Net.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using StackExchangeChat.Api;
using StackExchangeChat.Authenticators;
using StackExchangeChat.Console.AppSettings;
using StackExchangeApi;
using StackExchangeChat.Utilities;
namespace StackExchangeChat.Console
......@@ -26,7 +24,7 @@ namespace StackExchangeChat.Console
IConfiguration config = builder.Build();
var credentials = new Credentials();
var credentials = new ChatCredentials();
config.Bind("ChatCredentials", credentials);
serviceCollection.AddScoped<SiteAuthenticator>();
......@@ -35,7 +33,7 @@ namespace StackExchangeChat.Console
serviceCollection.AddTransient(_ => new HttpClient(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate }));
serviceCollection.AddTransient<HttpClientWithHandler>();
serviceCollection.AddSingleton(_ => config);
serviceCollection.AddSingleton(_ => credentials);
serviceCollection.AddSingleton<IChatCredentials>(_ => credentials);
var serviceProvider = serviceCollection.BuildServiceProvider();
......@@ -51,7 +49,7 @@ namespace StackExchangeChat.Console
//// var result = apiThing.TotalQuestionsByTag("design").GetAwaiter().GetResult();
//var chatClient = serviceProvider.GetService<ChatClient>();
var chatClient = serviceProvider.GetService<ChatClient>();
//chatClient.SubscribeToEvents(Site.StackOverflow, 167908)
// .Where(c => c.EventType == EventType.MessagePosted || c.EventType == EventType.MessageEdited)
// .Subscribe(async chatEvent =>
......
......@@ -15,6 +15,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\StackExchangeApi\StackExchangeApi.csproj" />
<ProjectReference Include="..\StackExchangeChat\StackExchangeChat.csproj" />
</ItemGroup>
......
......@@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StackExchangeChat.Console",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StackExchangeChat", "StackExchangeChat\StackExchangeChat.csproj", "{3B555F10-2376-4072-9866-7B8462AB056E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StackExchangeApi", "StackExchangeApi\StackExchangeApi.csproj", "{EADAD8A1-AEBF-49DE-9D99-72EA23984133}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
......@@ -21,6 +23,10 @@ Global
{3B555F10-2376-4072-9866-7B8462AB056E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3B555F10-2376-4072-9866-7B8462AB056E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3B555F10-2376-4072-9866-7B8462AB056E}.Release|Any CPU.Build.0 = Release|Any CPU
{EADAD8A1-AEBF-49DE-9D99-72EA23984133}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EADAD8A1-AEBF-49DE-9D99-72EA23984133}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EADAD8A1-AEBF-49DE-9D99-72EA23984133}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EADAD8A1-AEBF-49DE-9D99-72EA23984133}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......
......@@ -6,7 +6,6 @@ using System.Reactive.Linq;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using StackExchangeChat.Authenticators;
using StackExchangeChat.Sites;
using StackExchangeChat.Utilities;
using WebSocketSharp;
......
namespace StackExchangeChat.Console.AppSettings
namespace StackExchangeChat
{
public class Credentials
public class ChatCredentials : IChatCredentials
{
public string AcctCookie { get; set; }
public string AcctCookieExpiry { get; set; }
......
namespace StackExchangeChat
{
public interface IChatCredentials
{
string AcctCookie { get; set; }
string AcctCookieExpiry { get; set; }
string Email { get; set; }
string Password { get; set; }
}
}
......@@ -6,17 +6,16 @@ using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using HtmlAgilityPack;
using StackExchangeChat.Console.AppSettings;
using StackExchangeChat.Sites;
using StackExchangeChat.Utilities;
namespace StackExchangeChat.Authenticators
namespace StackExchangeChat
{
public class SiteAuthenticator
{
private readonly HttpClientWithHandler _authenticatingHttpClient;
private readonly HttpClientWithHandler _fkeyHttpClient;
private readonly Credentials _credentials;
private readonly IChatCredentials _chatCredentials;
private struct SiteRoomIdPair
{
......@@ -33,14 +32,14 @@ namespace StackExchangeChat.Authenticators
public SiteAuthenticator(
HttpClientWithHandler authenticatingHttpClient,
HttpClientWithHandler fkeyHttpClient,
Credentials credentials)
IChatCredentials chatCredentials)
{
if (ReferenceEquals(authenticatingHttpClient, fkeyHttpClient))
throw new ArgumentException("Must provide two distinct instance of HttpClient for the Authenticating client and the fkey client.");
_authenticatingHttpClient = authenticatingHttpClient;
_fkeyHttpClient = fkeyHttpClient;
_credentials = credentials;
_chatCredentials = chatCredentials;
}
public async Task AuthenticateClient(HttpClientWithHandler httpClient, Site site)
......@@ -99,10 +98,10 @@ namespace StackExchangeChat.Authenticators
async Task<Cookie> GetAccountCookieInternal()
{
if (!string.IsNullOrWhiteSpace(_credentials.AcctCookie))
if (!string.IsNullOrWhiteSpace(_chatCredentials.AcctCookie))
{
var expiry = DateTime.ParseExact(_credentials.AcctCookieExpiry, "yyyy-MM-dd HH:mm:ssZ", CultureInfo.InvariantCulture);
return new Cookie("acct", _credentials.AcctCookie, "/", site.LoginDomain)
var expiry = DateTime.ParseExact(_chatCredentials.AcctCookieExpiry, "yyyy-MM-dd HH:mm:ssZ", CultureInfo.InvariantCulture);
return new Cookie("acct", _chatCredentials.AcctCookie, "/", site.LoginDomain)
{
Expires = expiry
};
......@@ -123,8 +122,8 @@ namespace StackExchangeChat.Authenticators
var loginPayload = new FormUrlEncodedContent(new Dictionary<string, string>
{
{"fkey", fkey},
{"email", _credentials.Email},
{"password", _credentials.Password},
{"email", _chatCredentials.Email},
{"password", _chatCredentials.Password},
});
await _authenticatingHttpClient.PostAsync($"https://{site.LoginDomain}/users/login", loginPayload);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment