Skip to content

A Dependency Injected HttpClient for the Lemmy API in dotnet

License

Notifications You must be signed in to change notification settings

ydinkov/Lemmy.Net

Repository files navigation

Nuget GitHub Workflow Status (with event)


A (WIP) DI http client for Lemmy in dotnet

Usage

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);
            }
        }
        
    }
}

Supports

  • 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

TODO

  • Better querying
  • Test Coverage
  • Model reuse

About

A Dependency Injected HttpClient for the Lemmy API in dotnet

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages