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

Commit

Permalink
Merge pull request #27 from KSoft-Si/refit-rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
fooooooooooooooo authored Sep 10, 2021
2 parents 787f489 + 19402b1 commit d9f9452
Show file tree
Hide file tree
Showing 77 changed files with 3,724 additions and 1,295 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -538,4 +538,6 @@ obj/

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

# End of https://www.toptal.com/developers/gitignore/api/visualstudio,csharp,dotnetcore,git
# End of https://www.toptal.com/developers/gitignore/api/visualstudio,csharp,dotnetcore,git

KSoftNet.Tests/config.json
143 changes: 119 additions & 24 deletions .idea/.idea.KSoftNet/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions CustomHttpclient/CustomHttpclient.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\KSoftNet\KSoftNet.csproj" />
</ItemGroup>

</Project>
36 changes: 36 additions & 0 deletions CustomHttpclient/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using KSoftNet;

namespace CustomHttpclient {
internal static class Program {
private const string Token = "{token}";

private static void Main() {
new ExampleClass(Token).GetRandomImage("birb").GetAwaiter().GetResult();
}
}

public class ExampleClass {
private readonly KSoftApi _kSoftApi;

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);
}

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

Console.WriteLine(image.Url);
}
}
}
16 changes: 16 additions & 0 deletions DependencyInjection/DependencyInjection.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\KSoftNet\KSoftNet.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.2" />
</ItemGroup>

</Project>
19 changes: 19 additions & 0 deletions DependencyInjection/ExampleClass.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Threading.Tasks;
using KSoftNet;
using KSoftNet.Models.Images;

namespace DependencyInjection {
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;
}
}
}
45 changes: 45 additions & 0 deletions DependencyInjection/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Threading.Tasks;
using KSoftNet;
using Microsoft.Extensions.DependencyInjection;

namespace DependencyInjection {
internal static class Program {

private static void Main() {
var startup = new Startup();
startup.Init();
startup.RunAsync().GetAwaiter().GetResult();
}
}

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>();
}
}

}
12 changes: 12 additions & 0 deletions KSoftNet.Examples/KSoftNet.Examples.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\KSoftNet\KSoftNet.csproj" />
</ItemGroup>

</Project>
Loading

0 comments on commit d9f9452

Please sign in to comment.