Giter VIP home page Giter VIP logo

ksoft.net's Introduction

KSoft.si API Wrapper

nuget version downloads

http://api.ksoft.si

Overview

KSoft.Si API is a professional, fast, reliable and easy to use multi-function service for Discord bot developers or websites. It provides easy, no-nonsense endpoints with an extensive library of images, user data, weather, geo-location and songs. We help you build awesome services and keep Discord community safe and sound.

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

Getting started

Installing the package

Add the NuGet package KSoftNet to your project:

dotnet add package KSoftNet

Simple usage

A minimal example to get a random image by tag

A complete example is available in the examples/SimpleUsage project

using System;
using System.Threading.Tasks;
using KSoftNet;

public class ExampleClass {
  private readonly KSoftApi _kSoftApi;

  public ExampleClass(string token) {
    _kSoftApi = new KSoftApi(token);
  }

  public async Task GetRandomImage(string tag) {
    var image = await _kSoftApi.ImagesApi.GetRandomImage(tag: tag);

    Console.WriteLine(image.Url);
  }
}

Example using custom HttpClient

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

A complete example is available in the examples/CustomHttpclient project

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

public ExampleClass(string token) {
  var httpClient = new HttpClient {
    BaseAddress = new Uri("https://api.ksoft.si"),
    DefaultRequestHeaders = {
      Authorization = new AuthenticationHeaderValue("Bearer", token)
    }
  };

  _kSoftApi = new KSoftApi(httpClient);
}

Example using dependency injection

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

A complete example is available in the examples/DependencyInjection project

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

public class Startup {
  private const string Token = "{token}";
  private KSoftApi _kSoftApi;

  private IServiceProvider _serviceProvider;

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

    _kSoftApi = new KSoftApi(Token);

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

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

    var image = await exampleClass.GetRandomImage("birb");

    Console.WriteLine(image.Url);
  }

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

Using this in a class:

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

public class ExampleClass {
  private readonly KSoftApi _kSoftApi;

  public ExampleClass(KSoftApi kSoftApi) {
    _kSoftApi = kSoftApi;
  }

  public async Task<Image> GetRandomImage(string tag) {
    var image = await _kSoftApi.ImagesApi.GetRandomImage(tag: tag);

    return image;
  }
}

ksoft.net's People

Contributors

fooooooooooooooo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ksoft.net's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.