Skip to content

SylveonDeko/MartineApi.Net

Repository files navigation

MartineApi Wrapper

nuget version downloads

https://api.martinebot.com/v1/docs

Overview

MartineAPI is a an API made by the owner of Martine Bot

If you find any errors/issues or want any features added, create an issue

Getting started

Installing the package

Add the NuGet package MartineApiNet to your project:

dotnet add package MartineApiNet

Simple usage

using System;
using System.Threading.Tasks;
using MartineApiNet;

public class ExampleClass
{
  private readonly MartineApi _martineApi;

  public ExampleClass() 
    => _martineApi = new MartineApi();

  public async Task GetRandomMeme() 
  {
    var image = await _martineApi.RedditApi.GetRandomMeme();

    Console.WriteLine(image.Data.PostUrl);
  }
}

Example using custom HttpClient

You can provide your own HttpClient instance, but you have to set the BaseAddress manually

using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using MartineApiNet;

public ExampleClass() 
{
  var httpClient = new HttpClient 
  {
    BaseAddress = new Uri("https://api.martinebot.com/v1")
  };

  _martineApi = new MartineApi(httpClient);
}

Example using dependency injection

Create a ServiceCollection, then add an instance of the MartineApi class to it

using System;
using System.Threading.Tasks;
using MartineApiNet;
using Microsoft.Extensions.DependencyInjection;

public class Startup 
{
  private MartineApi _martineApi;

  private IServiceProvider _serviceProvider;

  public void Init() 
  {
    var services = new ServiceCollection();

    _martineApi = new MartineApi();

    ConfigureServices(services);
    _serviceProvider = services.BuildServiceProvider();
  }

  public async Task RunAsync() 
  {
    var exampleClass = _serviceProvider.GetService<ExampleClass>();

    var image = await exampleClass.GetRandomMeme();

    Console.WriteLine(image.Data.PostUrl);
  }

  private void ConfigureServices(IServiceCollection services) 
  {
    services.AddSingleton(_martineApi);
    services.AddSingleton<ExampleClass>();
  }
}

Using this in a class:

using System.Threading.Tasks;
using MartineApiNet;
using MartineApiNet.Models.Images;

public class ExampleClass 
{
  private readonly MartineApi _martineApi;

  public ExampleClass(MartineApi martineApi) 
    => _martineApi = martineApi;

  public async Task<RedditPost> GetRandomMeme()
    => await _martineApi.GetRandomMeme();
}

About

An unofficial wrapper for the MartineBot api

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages