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

Commit d9f9452

Browse files
Merge pull request #27 from KSoft-Si/refit-rewrite
2 parents 787f489 + 19402b1 commit d9f9452

77 files changed

Lines changed: 3724 additions & 1295 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,4 +538,6 @@ obj/
538538

539539
# Ionide (cross platform F# VS Code tools) working folder
540540

541-
# End of https://www.toptal.com/developers/gitignore/api/visualstudio,csharp,dotnetcore,git
541+
# End of https://www.toptal.com/developers/gitignore/api/visualstudio,csharp,dotnetcore,git
542+
543+
KSoftNet.Tests/config.json

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

Lines changed: 119 additions & 24 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>

0 commit comments

Comments
 (0)