Run
dotnet add package Lemmy.Net.Client
Add this to you Startup
var services = new ServiceCollection();
services.AddLemmyClient(
new Uri("<LEMMY INSTANCE URL>"),
"<USERNAME>",
"<PASSWORD>",
//Optionally, add a pair of methods to read and write tokens.
//This avoid having to reauthenticate on every request
//WARNING: The file IO below is for demo purposes only!
//please use something other than files to save your tokens!
async username => File.Exists($"{username}.txt") ? File.ReadAllText($"{username}.txt") : "",
(username, jwtToken) => File.WriteAllText($"{username}.txt", jwtToken)
);
var provider = services.BuildServiceProvider();
Then start the service
var lemmyService = provider.GetRequiredService<ILemmyService>();
or use it in your DI consumers
using Microsoft.AspNetCore.Mvc;
using YourNamespace.Services;
namespace YourNamespace.Controllers
{
public class YourController : Controller
{
private readonly ILemmyService _lemmyService;
public YourController(ILemmyService lemmyService)
{
_lemmyService = lemmyService;
}
// Your action methods go here
public void DoAThing(){
//Prints the names of all the communities on the instance
foreach(var c in _lemmyService.Community.List().Communities)
{
Console.WriteLine(c.Community.Name);
}
}
}
}
- CRUD for Communities
- CRUD for Posts (and voting)
- CRUD for Comments (and voting)
- CRUD for Private messages (and reporting)
- Site actions
- Reporting and Resolving
- Modding and Admin actions
- Captachs, registrations, password resets and email validation
- Replies, Mentions and Notifications
- Exponential retry policy
- Better querying
- Test Coverage
- Model reuse