forked from BenFradet/RiotSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jan Ouborny
authored
May 31, 2017
1 parent
d67b8cc
commit 1aad4d5
Showing
6 changed files
with
100 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace RiotSharp.AspNetCore | ||
{ | ||
public class ApiKey | ||
{ | ||
public string Key { get; set; } | ||
public int RateLimitPer10S { get; set; } | ||
public int RateLimitPer10M { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using RiotSharp.Http; | ||
using RiotSharp.Interfaces; | ||
using System; | ||
|
||
namespace RiotSharp.AspNetCore | ||
{ | ||
public static class IServiceCollectionExtension | ||
{ | ||
/// <summary> | ||
/// Adds and configures RiotSharp's services | ||
/// </summary> | ||
/// <param name="serviceCollection"></param> | ||
/// <param name="options"></param> | ||
/// <returns></returns> | ||
public static IServiceCollection AddRiotSharp(this IServiceCollection serviceCollection, Action<RiotSharpOptions> options) | ||
{ | ||
var riotSharpOptions = new RiotSharpOptions(); | ||
options(riotSharpOptions); | ||
|
||
if (riotSharpOptions.TournamentApiKey.Key == null && riotSharpOptions.ApiKey.Key == null) | ||
throw new ArgumentNullException("No api key provided.", innerException: null); | ||
|
||
if (riotSharpOptions.ApiKey.Key != null) | ||
{ | ||
var rateLimitedRequester = new RateLimitedRequester(riotSharpOptions.ApiKey.Key, | ||
riotSharpOptions.ApiKey.RateLimitPer10S, riotSharpOptions.ApiKey.RateLimitPer10M); | ||
serviceCollection.AddSingleton<ITournamentRiotApi>(serviceProvider => | ||
new TournamentRiotApi(rateLimitedRequester)); | ||
serviceCollection.AddSingleton<IRiotApi>(serviceProvider => new RiotApi(rateLimitedRequester)); | ||
|
||
var requester = new Requester(riotSharpOptions.ApiKey.Key); | ||
serviceCollection.AddSingleton<ICache, Cache>(); | ||
serviceCollection.AddSingleton<IStaticRiotApi>(serviceProvider => | ||
new StaticRiotApi(requester, serviceProvider.GetRequiredService<ICache>())); | ||
} | ||
|
||
if (riotSharpOptions.TournamentApiKey.Key != null) | ||
{ | ||
var rateLimitedRequester = new RateLimitedRequester(riotSharpOptions.TournamentApiKey.Key, | ||
riotSharpOptions.TournamentApiKey.RateLimitPer10S, riotSharpOptions.TournamentApiKey.RateLimitPer10M); | ||
serviceCollection.AddSingleton<ITournamentRiotApi>(serviceProvider => | ||
new TournamentRiotApi(rateLimitedRequester)); | ||
} | ||
|
||
return serviceCollection; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp1.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="1.1.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\RiotSharp\RiotSharp.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace RiotSharp.AspNetCore | ||
{ | ||
public class RiotSharpOptions | ||
{ | ||
public RiotSharpOptions() | ||
{ | ||
ApiKey = new ApiKey(); | ||
ApiKey.RateLimitPer10S = 10; | ||
ApiKey.RateLimitPer10M = 500; | ||
TournamentApiKey = new ApiKey(); | ||
TournamentApiKey.RateLimitPer10S = 10; | ||
TournamentApiKey.RateLimitPer10M = 500; | ||
} | ||
|
||
public ApiKey ApiKey { get; set; } | ||
public ApiKey TournamentApiKey { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters