-
Notifications
You must be signed in to change notification settings - Fork 144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Requester and RateLimitRequester refactor #481
base: develop
Are you sure you want to change the base?
Requester and RateLimitRequester refactor #481
Conversation
Intention is to seperate the dependency injection friendly class from the singleton code
Not optimal
Sorry for the late review, haven't found the time yet, planning on doing it over the weekend 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great overall 👍
However I wonder if we couldn't parameterize over the serializer, what do you think?
{ new TimeSpan(1, 0, 0), 10 } | ||
}); | ||
|
||
var staticRateLimitProvider = new RateLimitProvider(new Dictionary<TimeSpan, int>{{new TimeSpan(1, 0, 0), 10}}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you limit the lines to 120 chars?
{ | ||
HttpRequestMessage CreateGetRequest(Region region, string apiEndpoint, List<string> addedArguments, bool useHttps = true); | ||
|
||
HttpRequestMessage CreatePostRequest<T>(Region region, string apiEndpoint, T body, List<string> addedArguments, bool useHttps); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we have useHttps = true
as a default here and below too?
var basicRequester = new Requester(client, requestCreator, deserializer); | ||
var riotRateLimitProvider = new RateLimitProvider(riotSharpOptions.RiotApi.RateLimits); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we remove the double empty lines in this file
} | ||
|
||
public string CreatePostRequest(string relativeUrl, Region region, string body, | ||
public T Post<T>(string relativeUrl, Region region, object body, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why an object body
there? can't we parameterize over it?
{ | ||
public class RequestContentSerializer : IRequestContentSerializer | ||
{ | ||
public HttpContent Serialize(object body) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't we parameterize over body
here too?
if (instance == null || Requesters.RiotApiRequester == null || | ||
apiKey != Requesters.RiotApiRequester.ApiKey || | ||
!rateLimits.Equals(Requesters.RiotApiRequester.RateLimits)) | ||
{ | ||
instance = new RiotApi(apiKey, rateLimits); | ||
} | ||
return instance; | ||
} */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was meant to get a new API if someone changes api key or rate limits in his code, I don't know if we should keep it
|
||
requester = new RateLimitedRequester(basicRequester, rateLimitProvider); | ||
|
||
Requesters.RiotApiRequester = (RateLimitedRequester) requester; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is the cast needed?
return await Task.Factory.StartNew(() => JsonConvert.DeserializeObject<Champion>(json)); | ||
var url = PlatformRootUrl + ChampionsUrl + string.Format(IdUrl, championId); | ||
return await requester.GetAsync<Champion>(url, region); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
empty line
if (instance == null || | ||
Requesters.StaticApiRequester == null || | ||
apiKey != Requesters.StaticApiRequester.ApiKey) | ||
if (instance == null || instanceApiKey != apiKey) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we remove it from RiotApi
we might as well remove it here
apiKey != Requesters.TournamentApiRequester.ApiKey || | ||
!rateLimits.Equals(Requesters.TournamentApiRequester.RateLimits)) | ||
apiKey != instanceApiKey || | ||
!rateLimits.Equals(instanceRateLimits)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
Updated API classes to use new requester interfaces