-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add FacetBuilder * Add tests * Add mention resolver * Update project parameters * Update auth handling * Rename LICENSE to LICENSE.md
- Loading branch information
Showing
18 changed files
with
513 additions
and
122 deletions.
There are no files selected for viewing
File renamed without changes.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<Project> | ||
|
||
<PropertyGroup> | ||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild> | ||
|
||
<PackageReadmeFile>README.md</PackageReadmeFile> | ||
<PackageLicenseFile>LICENSE.md</PackageLicenseFile> | ||
<PackageIcon>x.png</PackageIcon> | ||
|
||
<Authors>Andrew Gubskiy</Authors> | ||
<Copyright>Andrew Gubskiy © 2024</Copyright> | ||
<Company>Ukrainian .NET Developer Community</Company> | ||
|
||
<Version>1.1.0</Version> | ||
<AssemblyVersion>1.1.0</AssemblyVersion> | ||
<FileVersion>1.1.0</FileVersion> | ||
<PackageVersion>1.1.0</PackageVersion> | ||
|
||
<RepositoryType>git</RepositoryType> | ||
<RepositoryUrl>https://github.com/ernado-x/X.Bluesky.git</RepositoryUrl> | ||
<PackageProjectUrl>https://andrew.gubskiy.com/open-source</PackageProjectUrl> | ||
</PropertyGroup> | ||
|
||
</Project> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System.Text; | ||
using Newtonsoft.Json; | ||
using X.Bluesky.Models; | ||
|
||
namespace X.Bluesky; | ||
|
||
public interface IAuthorizationClient | ||
{ | ||
Task<Session> GetSession(); | ||
} | ||
|
||
public class AuthorizationClient : IAuthorizationClient | ||
{ | ||
private readonly IHttpClientFactory _httpClientFactory; | ||
private readonly string _identifier; | ||
private readonly string _password; | ||
|
||
public AuthorizationClient(string identifier, string password) | ||
: this(new BlueskyHttpClientFactory(), identifier, password) | ||
{ | ||
} | ||
|
||
public AuthorizationClient(IHttpClientFactory httpClientFactory, string identifier, string password) | ||
{ | ||
_httpClientFactory = httpClientFactory; | ||
_identifier = identifier; | ||
_password = password; | ||
} | ||
|
||
/// <summary> | ||
/// Authorize in Bluesky | ||
/// </summary> | ||
/// <returns> | ||
/// Instance of authorized session | ||
/// </returns> | ||
public async Task<Session> GetSession() | ||
{ | ||
var requestData = new | ||
{ | ||
identifier = _identifier, | ||
password = _password | ||
}; | ||
|
||
var json = JsonConvert.SerializeObject(requestData); | ||
|
||
var content = new StringContent(json, Encoding.UTF8, "application/json"); | ||
|
||
var httpClient = _httpClientFactory.CreateClient(); | ||
|
||
var uri = "https://bsky.social/xrpc/com.atproto.server.createSession"; | ||
var response = await httpClient.PostAsync(uri, content); | ||
|
||
response.EnsureSuccessStatusCode(); | ||
|
||
var jsonResponse = await response.Content.ReadAsStringAsync(); | ||
|
||
return JsonConvert.DeserializeObject<Session>(jsonResponse)!; | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.Net; | ||
|
||
namespace X.Bluesky; | ||
|
||
public class BlueskyHttpClientFactory : IHttpClientFactory | ||
{ | ||
private readonly HttpClient _client; | ||
|
||
public BlueskyHttpClientFactory() | ||
{ | ||
var handler = new HttpClientHandler | ||
{ | ||
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate | ||
}; | ||
|
||
_client = new HttpClient(handler); | ||
} | ||
|
||
public HttpClient CreateClient(string name) | ||
{ | ||
return _client; | ||
} | ||
} |
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
Oops, something went wrong.