Skip to content
This repository was archived by the owner on Jul 29, 2022. It is now read-only.

Commit 19402b1

Browse files
docs: update readme
1 parent 7d412a6 commit 19402b1

File tree

3 files changed

+87
-54
lines changed

3 files changed

+87
-54
lines changed

.idea/.idea.KSoftNet/.idea/workspace.xml

Lines changed: 2 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 84 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
# KSoft.si API Wrapper
22

3+
[![nuget version][0]][1]
4+
[![downloads][2]][1]
5+
36
> http://api.ksoft.si
47
58
## Overview
69

7-
[KSoft.Si API](http://api.ksoft.si) is a service that provides Discord bot developers or others the ease in getting content from the internet. We provide easy to use interface and take hard tasks away from developers.
10+
[KSoft.Si API](http://api.ksoft.si) is a professional, fast, reliable and easy to use multi-function service for Discord
11+
bot developers or websites. It provides easy, no-nonsense endpoints with an extensive library of images, user data,
12+
weather, geo-location and songs. We help you build awesome services and keep Discord community safe and sound.
813

9-
### If you find any errors/issues or want any features added, create an issue and I will fix it ASAP
14+
### If you find any errors/issues or want any features added, [create an issue](https://github.com/KSoft-Si/KSoft.Net/issues/new/choose)
1015

1116
## Getting started
1217

@@ -18,86 +23,123 @@ Add the NuGet package `KSoftNet` to your project:
1823
dotnet add package KSoftNet
1924
```
2025

21-
### Simple Example usage
26+
### Simple usage
27+
28+
A minimal example to get a random image by tag
2229

23-
You can use the wrapper with the images API for example like so:
24-
Create an instance of the KSoftAPI class:
30+
A complete example is available in the `examples/SimpleUsage` project
2531

2632
```cs
33+
using System;
34+
using System.Threading.Tasks;
2735
using KSoftNet;
2836

2937
public class ExampleClass {
30-
private string _token = "token";
38+
private readonly KSoftApi _kSoftApi;
3139

32-
private KSoftAPI _kSoftAPI;
40+
public ExampleClass(string token) {
41+
_kSoftApi = new KSoftApi(token);
42+
}
3343

34-
public void Setup() {
35-
_kSoftAPI = new KSoftAPI(_token);
36-
}
44+
public async Task GetRandomImage(string tag) {
45+
var image = await _kSoftApi.ImagesApi.GetRandomImage(tag: tag);
46+
47+
Console.WriteLine(image.Url);
48+
}
3749
}
3850
```
3951

40-
An example implementation of the RandomImage method:
52+
### Example using custom HttpClient
53+
54+
You can provide your own HttpClient instance, but you have to set the Authorization header and the BaseAddress manually
55+
56+
A complete example is available in the `examples/CustomHttpclient` project
4157

4258
```cs
43-
public void ExampleMethod(string tag) {
44-
KSoftImage image = _kSoftAPI.imagesAPI.RandomImage(tag: tag);
59+
using System;
60+
using System.Net.Http;
61+
using System.Net.Http.Headers;
62+
using System.Threading.Tasks;
63+
using KSoftNet;
64+
65+
public ExampleClass(string token) {
66+
var httpClient = new HttpClient {
67+
BaseAddress = new Uri("https://api.ksoft.si"),
68+
DefaultRequestHeaders = {
69+
Authorization = new AuthenticationHeaderValue("Bearer", token)
70+
}
71+
};
72+
73+
_kSoftApi = new KSoftApi(httpClient);
4574
}
4675
```
4776

4877
### Example using dependency injection
4978

50-
Create an instance of the KSoftAPI class, then create a ServiceCollection, add KSoftAPI to it, and then build the service provider:
79+
Create a ServiceCollection, then add an instance of the KSoftApi class to it
80+
81+
A complete example is available in the `examples/DependencyInjection` project
5182

5283
```cs
53-
using Microsoft.Extensions.DependencyInjection;
84+
using System;
85+
using System.Threading.Tasks;
5486
using KSoftNet;
87+
using Microsoft.Extensions.DependencyInjection;
5588

56-
public class Program {
89+
public class Startup {
90+
private const string Token = "{token}";
91+
private KSoftApi _kSoftApi;
5792

58-
static void Main(string[] args) {
59-
new Startup().Init();
60-
}
61-
}
93+
private IServiceProvider _serviceProvider;
6294

63-
public class Startup {
95+
public void Init() {
96+
var services = new ServiceCollection();
6497

65-
private KSoftAPI _kSoftAPI;
98+
_kSoftApi = new KSoftApi(Token);
6699

67-
private string _token = "token123";
100+
ConfigureServices(services);
101+
_serviceProvider = services.BuildServiceProvider();
102+
}
68103

69-
public void Init() {
70-
ServiceCollection services = new ServiceCollection();
104+
public async Task RunAsync() {
105+
var exampleClass = _serviceProvider.GetService<ExampleClass>();
71106

72-
kSoftAPI = new KSoftAPI(_token);
107+
var image = await exampleClass.GetRandomImage("birb");
73108

74-
ConfigureServices(services);
75-
ServiceProvider provider = services.BuildServiceProvider();
76-
}
109+
Console.WriteLine(image.Url);
110+
}
77111

78-
private void ConfigureServices(IServiceCollection services) {
79-
services.AddSingleton(kSoftAPI);
80-
}
112+
private void ConfigureServices(IServiceCollection services) {
113+
services.AddSingleton(_kSoftApi);
114+
services.AddSingleton<ExampleClass>();
115+
}
81116
}
82117
```
83118

84119
Using this in a class:
85120

86121
```cs
122+
using System.Threading.Tasks;
87123
using KSoftNet;
124+
using KSoftNet.Models.Images;
88125

89-
public class ExampleClass {
90-
91-
private KSoftAPI _kSoftAPI;
126+
public class ExampleClass {
127+
private readonly KSoftApi _kSoftApi;
92128

93-
public ExampleClass(KSoftAPI kSoftAPI) {
94-
_kSoftAPI = kSoftAPI;
95-
}
129+
public ExampleClass(KSoftApi kSoftApi) {
130+
_kSoftApi = kSoftApi;
131+
}
96132

97-
public void GetRandomImage(string tag) {
98-
KSoftImage image = _kSoftAPI.imagesAPI.RandomImage(tag: tag);
133+
public async Task<Image> GetRandomImage(string tag) {
134+
var image = await _kSoftApi.ImagesApi.GetRandomImage(tag: tag);
99135

100-
Console.WriteLine(image.Url);
101-
}
136+
return image;
137+
}
102138
}
103139
```
140+
141+
[0]: https://img.shields.io/nuget/v/KSoftNet?style=flat-square
142+
143+
[1]: https://www.nuget.org/packages/KSoftNet
144+
145+
[2]: https://img.shields.io/nuget/dt/KSoftNet?style=flat-square

SimpleUsage/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ public async Task GetRandomImage(string tag) {
2323

2424
Console.WriteLine(image.Url);
2525
}
26-
}
26+
}
2727
}

0 commit comments

Comments
 (0)