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

Commit 7d412a6

Browse files
docs: added example projects
1 parent eb4ad4c commit 7d412a6

13 files changed

Lines changed: 332 additions & 76 deletions

File tree

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

Lines changed: 96 additions & 65 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net5.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<ProjectReference Include="..\KSoftNet\KSoftNet.csproj" />
10+
</ItemGroup>
11+
12+
</Project>

CustomHttpclient/Program.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using System.Net.Http;
3+
using System.Net.Http.Headers;
4+
using System.Threading.Tasks;
5+
using KSoftNet;
6+
7+
namespace CustomHttpclient {
8+
internal static class Program {
9+
private const string Token = "{token}";
10+
11+
private static void Main() {
12+
new ExampleClass(Token).GetRandomImage("birb").GetAwaiter().GetResult();
13+
}
14+
}
15+
16+
public class ExampleClass {
17+
private readonly KSoftApi _kSoftApi;
18+
19+
public ExampleClass(string token) {
20+
var httpClient = new HttpClient {
21+
BaseAddress = new Uri("https://api.ksoft.si"),
22+
DefaultRequestHeaders = {
23+
Authorization = new AuthenticationHeaderValue("Bearer", token)
24+
}
25+
};
26+
27+
_kSoftApi = new KSoftApi(httpClient);
28+
}
29+
30+
public async Task GetRandomImage(string tag) {
31+
var image = await _kSoftApi.ImagesApi.GetRandomImage(tag: tag);
32+
33+
Console.WriteLine(image.Url);
34+
}
35+
}
36+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net5.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<ProjectReference Include="..\KSoftNet\KSoftNet.csproj" />
10+
</ItemGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.2" />
14+
</ItemGroup>
15+
16+
</Project>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.Threading.Tasks;
2+
using KSoftNet;
3+
using KSoftNet.Models.Images;
4+
5+
namespace DependencyInjection {
6+
public class ExampleClass {
7+
private readonly KSoftApi _kSoftApi;
8+
9+
public ExampleClass(KSoftApi kSoftApi) {
10+
_kSoftApi = kSoftApi;
11+
}
12+
13+
public async Task<Image> GetRandomImage(string tag) {
14+
var image = await _kSoftApi.ImagesApi.GetRandomImage(tag: tag);
15+
16+
return image;
17+
}
18+
}
19+
}

DependencyInjection/Program.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using KSoftNet;
4+
using Microsoft.Extensions.DependencyInjection;
5+
6+
namespace DependencyInjection {
7+
internal static class Program {
8+
9+
private static void Main() {
10+
var startup = new Startup();
11+
startup.Init();
12+
startup.RunAsync().GetAwaiter().GetResult();
13+
}
14+
}
15+
16+
public class Startup {
17+
private const string Token = "{token}";
18+
private KSoftApi _kSoftApi;
19+
20+
private IServiceProvider _serviceProvider;
21+
22+
public void Init() {
23+
var services = new ServiceCollection();
24+
25+
_kSoftApi = new KSoftApi(Token);
26+
27+
ConfigureServices(services);
28+
_serviceProvider = services.BuildServiceProvider();
29+
}
30+
31+
public async Task RunAsync() {
32+
var exampleClass = _serviceProvider.GetService<ExampleClass>();
33+
34+
var image = await exampleClass.GetRandomImage("birb");
35+
36+
Console.WriteLine(image.Url);
37+
}
38+
39+
private void ConfigureServices(IServiceCollection services) {
40+
services.AddSingleton(_kSoftApi);
41+
services.AddSingleton<ExampleClass>();
42+
}
43+
}
44+
45+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net5.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<ProjectReference Include="..\KSoftNet\KSoftNet.csproj" />
10+
</ItemGroup>
11+
12+
</Project>

KSoftNet.Examples/Program.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
3+
namespace KSoftNet.Examples {
4+
internal static class Program {
5+
private static string _token = "";
6+
7+
private static void Main(string[] args) {
8+
9+
}
10+
}
11+
12+
public class Startup {
13+
private KSoftApi _kSoftApi;
14+
15+
private string _token = "token123";
16+
17+
public void Init() {
18+
ServiceCollection services = new ServiceCollection();
19+
20+
kSoftAPI = new KSoftAPI(_token);
21+
22+
ConfigureServices(services);
23+
ServiceProvider provider = services.BuildServiceProvider();
24+
}
25+
26+
private void ConfigureServices(IServiceCollection services) {
27+
services.AddSingleton(kSoftAPI);
28+
}
29+
}
30+
}

KSoftNet.Tests/KSoftAPIUnitTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ private static void LogObject(object obj) {
363363
}
364364
}
365365

366-
public static class CumExtensions {
366+
public static class StringExtensions {
367367
public static string ToJson(this object obj) {
368368
return JsonConvert.SerializeObject(obj);
369369
}

0 commit comments

Comments
 (0)