Skip to content
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

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from

Conversation

frederickrogan
Copy link
Contributor

Updated API classes to use new requester interfaces

@JanOuborny JanOuborny mentioned this pull request Oct 4, 2017
@JanOuborny JanOuborny requested review from JanOuborny and BenFradet and removed request for JanOuborny October 5, 2017 17:23
@BenFradet
Copy link
Owner

Sorry for the late review, haven't found the time yet, planning on doing it over the weekend 👍

Copy link
Owner

@BenFradet BenFradet left a 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}});
Copy link
Owner

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);
Copy link
Owner

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


Copy link
Owner

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,
Copy link
Owner

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)
Copy link
Owner

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;
} */
Copy link
Owner

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;
Copy link
Owner

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

Copy link
Owner

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)
Copy link
Owner

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))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants