Created
December 3, 2024 14:29
-
-
Save MartinZikmund/fba90d13461260d27980e860a656365e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 BlueskyService : IBlueskyService | |
{ | |
private readonly ICredentialsService _credentialsService; | |
private ATProtocol _client; | |
private Session? _session; | |
public BlueskyService(ICredentialsService credentialsService) | |
{ | |
_client = new ATProtocolBuilder().EnableAutoRenewSession(true).Build(); | |
_credentialsService = credentialsService; | |
} | |
public bool IsLoggedIn => _client.Session != null; | |
public async Task<bool> InitializeAsync() | |
{ | |
var credentials = _credentialsService.RetrieveCredentials(); | |
if (credentials.handle is not null && credentials.appPassword is not null) | |
{ | |
_session = await _client.AuthenticateWithPasswordAsync(credentials.handle, credentials.appPassword); | |
return _session is not null; | |
} | |
return false; | |
} | |
public async Task<bool> LoginAsync(string handle, string appPassword) | |
{ | |
_session = await _client.AuthenticateWithPasswordAsync(handle, appPassword); | |
if (_session is not null) | |
{ | |
_credentialsService.SaveCredentials(handle, appPassword); | |
} | |
return _session is not null; | |
} | |
public async Task<Result<GetTimelineOutput?>> GetTimelineAsync() => await _client.GetTimelineAsync(); | |
public async Task PostAsync(string message) | |
{ | |
await _client.CreatePostAsync(message); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment