A non-exhaustive, yet useful HTTP(S) JSON client that supports rate limiting, enabling you to implement a polite integration with a third-party data provider.
- IPoliteProvider
- IPoliteResponse`1
- PoliteProvider
- #ctor(logger,httpClientFactory)
- Logger
- RequiredSecondsInBetweenCalls
- GetPoliteResponse``1(response)
- IsPolite()
- Request``1(request,retryOnError,waitingMinutesBeforeRetry)
- SetMultiplier()
- SetRateLimitPerDay(callsPerDay)
- SetRateLimitPerHour(callsPerHour)
- SetRateLimitPerMinute(callsPerMinute)
- UpdateTimeOfLastCall(lastQueryTime)
- PoliteReponse`1
- PostClientAuthorizeResponse
BarbezDotEu.Provider.Interfaces
Defines an HTTP(S) client that supports rate limiting so that a polite integration with a third-party data provider can be implemented.
Returns true if querying using this IPoliteProvider will respects the limit set forth by the third-party resource.
This method has no parameters.
Any other methods of this IPoliteProvider should be called only after this method was called and returned true first, ensuring this application will not be blacklisted or will start receiving errors.
Sets a multiplier intended for cases where multiple calls to the third-party resource have to be performed in rapid succession (a batch). In such cases, the multiplier should be set to the number of calls that were performed in batch. The multiplier is reset to 1 after the next call to IsPolite returns true.
This method has no parameters.
E.g. if ordinary 1 call per minute can be made, but 2 are made in batch, set the multiplier to 2. This way, the next batch will only be allowed to run in 2 minutes' time, thus still respecting the average rate limit of 1 call per minute.
BarbezDotEu.Provider.Interfaces
Defines a IPoliteResponse`1 to a HttpRequestMessage requested by an IPoliteProvider.
Gets the actual content of a successful response to a HttpRequestMessage.
Gets a value indicating whether the HttpResponseMessage indicates a fault.
Gets the HttpRequestMessage that indicates a fault that has occurred.
Sets the the actual response content.
Name | Type | Description |
---|---|---|
content | `0 | The response content to set. |
BarbezDotEu.Provider
Implements an HTTP(S) client that supports rate limiting so that a polite integration with a third-party data provider can be implemented.
Constructs a new PoliteProvider.
Name | Type | Description |
---|---|---|
logger | Microsoft.Extensions.Logging.ILogger | A ILogger to use for logging. |
httpClientFactory | System.Net.Http.IHttpClientFactory | The IHttpClientFactory to use. |
Gets or sets the ILogger.
Gets the number of seconds required to lapse before a next call to the data provider is considered polite.
Converts a HttpResponseMessage into a PoliteReponse`1.
The HttpResponseMessage as PoliteReponse`1.
Name | Type | Description |
---|---|---|
response | System.Net.Http.HttpResponseMessage | The response to convert. |
Name | Description |
---|---|
T | The view model to deserialize a successful response into. |
Inherit from parent.
This method has no parameters.
Sends a HttpRequestMessage to the third-party provider, expecting a certain response.
The expected response content type, as well as other metadata, in case of an exception.
Name | Type | Description |
---|---|---|
request | System.Net.Http.HttpRequestMessage | The HttpRequestMessage to send to the third-party provider. |
retryOnError | System.Boolean | |
waitingMinutesBeforeRetry | System.Double | The number of minutes to wait before automatically retrying re-sending the request, if the intention is to retry again upon error. |
Name | Description |
---|---|
T | The expected response content type. |
Inherit from parent.
This method has no parameters.
Sets the number of calls per day as allowed to the provider, i.e. third-party resource.
Name | Type | Description |
---|---|---|
callsPerDay | System.Int64 | The max. number of allowed calls per day. |
The parameter string is expected to hold numeric values only. SetRateLimitPerDay, SetRateLimitPerHour, and SetRateLimitPerMinute are mutually exclusive, hence the last called method determines the rate limiter.
Sets the number of calls per hour as allowed to the provider, i.e. third-party resource.
Name | Type | Description |
---|---|---|
callsPerHour | System.Int64 | The max. number of allowed calls per hour. |
The parameter string is expected to hold numeric values only. SetRateLimitPerDay, SetRateLimitPerHour, and SetRateLimitPerMinute are mutually exclusive, hence the last called method determines the rate limiter.
Sets the number of calls per minute as allowed to the provider, i.e. third-party resource.
Name | Type | Description |
---|---|---|
callsPerMinute | System.Int64 | The max. number of allowed calls per minute. |
The parameter string is expected to hold numeric values only. SetRateLimitPerDay, SetRateLimitPerHour, and SetRateLimitPerMinute are mutually exclusive, hence the last called method determines the rate limiter.
Updates the date and time of when the last call to the provider, i.e. third-party resource, was made.
Name | Type | Description |
---|---|---|
lastQueryTime | System.DateTime |
It is important to keep updating this number in order to continuously receive a correct answer from the IsPolite method.
BarbezDotEu.Provider
Inherit from parent.
Constructs a new PoliteReponse`1 from a given HttpResponseMessage.
Name | Type | Description |
---|---|---|
httpResponseMessage | System.Net.Http.HttpResponseMessage | The HttpResponseMessage to construct this IPoliteResponse`1 from. |
Inherit from parent.
Inherit from parent.
Inherit from parent.
Inherit from parent.
This method has no parameters.
BarbezDotEu.Provider.DTO
Implements a client authorization response DTO in accordance to the interface as defined and shared by Vimeo, Twitter, and others.
Gets or sets the access token.
Gets or sets the authorization scope.
Gets or sets the token type.