Skip to content

An HTTP(S) client that supports rate limiting so that a polite integration with a third-party data provider can be implemented.

License

Notifications You must be signed in to change notification settings

hannesbarbez/BarbezDotEu.Provider

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BarbezDotEu.Provider

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.

Contents

IPoliteProvider type

Namespace

BarbezDotEu.Provider.Interfaces

Summary

Defines an HTTP(S) client that supports rate limiting so that a polite integration with a third-party data provider can be implemented.

IsPolite() method

Summary

Returns true if querying using this IPoliteProvider will respects the limit set forth by the third-party resource.

Parameters

This method has no parameters.

Remarks

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.

SetMultiplier() method

Summary

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.

Parameters

This method has no parameters.

Remarks

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.

IPoliteResponse`1 type

Namespace

BarbezDotEu.Provider.Interfaces

Summary

Defines a IPoliteResponse`1 to a HttpRequestMessage requested by an IPoliteProvider.

Content property

Summary

Gets the actual content of a successful response to a HttpRequestMessage.

HasFailed property

Summary

Gets a value indicating whether the HttpResponseMessage indicates a fault.

HttpResponseMessage property

Summary

Gets the HttpRequestMessage that indicates a fault that has occurred.

SetContent(content) method

Summary

Sets the the actual response content.

Parameters
Name Type Description
content `0 The response content to set.

PoliteProvider type

Namespace

BarbezDotEu.Provider

Summary

Implements an HTTP(S) client that supports rate limiting so that a polite integration with a third-party data provider can be implemented.

#ctor(logger,httpClientFactory) constructor

Summary

Constructs a new PoliteProvider.

Parameters
Name Type Description
logger Microsoft.Extensions.Logging.ILogger A ILogger to use for logging.
httpClientFactory System.Net.Http.IHttpClientFactory The IHttpClientFactory to use.

Logger property

Summary

Gets or sets the ILogger.

RequiredSecondsInBetweenCalls property

Summary

Gets the number of seconds required to lapse before a next call to the data provider is considered polite.

GetPoliteResponse``1(response) method

Summary

Converts a HttpResponseMessage into a PoliteReponse`1.

Returns

The HttpResponseMessage as PoliteReponse`1.

Parameters
Name Type Description
response System.Net.Http.HttpResponseMessage The response to convert.
Generic Types
Name Description
T The view model to deserialize a successful response into.

IsPolite() method

Summary

Inherit from parent.

Parameters

This method has no parameters.

Request``1(request,retryOnError,waitingMinutesBeforeRetry) method

Summary

Sends a HttpRequestMessage to the third-party provider, expecting a certain response.

Returns

The expected response content type, as well as other metadata, in case of an exception.

Parameters
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.
Generic Types
Name Description
T The expected response content type.

SetMultiplier() method

Summary

Inherit from parent.

Parameters

This method has no parameters.

SetRateLimitPerDay(callsPerDay) method

Summary

Sets the number of calls per day as allowed to the provider, i.e. third-party resource.

Parameters
Name Type Description
callsPerDay System.Int64 The max. number of allowed calls per day.
Remarks

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.

SetRateLimitPerHour(callsPerHour) method

Summary

Sets the number of calls per hour as allowed to the provider, i.e. third-party resource.

Parameters
Name Type Description
callsPerHour System.Int64 The max. number of allowed calls per hour.
Remarks

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.

SetRateLimitPerMinute(callsPerMinute) method

Summary

Sets the number of calls per minute as allowed to the provider, i.e. third-party resource.

Parameters
Name Type Description
callsPerMinute System.Int64 The max. number of allowed calls per minute.
Remarks

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.

UpdateTimeOfLastCall(lastQueryTime) method

Summary

Updates the date and time of when the last call to the provider, i.e. third-party resource, was made.

Parameters
Name Type Description
lastQueryTime System.DateTime
Remarks

It is important to keep updating this number in order to continuously receive a correct answer from the IsPolite method.

PoliteReponse`1 type

Namespace

BarbezDotEu.Provider

Summary

Inherit from parent.

#ctor(httpResponseMessage) constructor

Summary

Constructs a new PoliteReponse`1 from a given HttpResponseMessage.

Parameters
Name Type Description
httpResponseMessage System.Net.Http.HttpResponseMessage The HttpResponseMessage to construct this IPoliteResponse`1 from.

Content property

Summary

Inherit from parent.

HasFailed property

Summary

Inherit from parent.

HttpResponseMessage property

Summary

Inherit from parent.

SetContent() method

Summary

Inherit from parent.

Parameters

This method has no parameters.

PostClientAuthorizeResponse type

Namespace

BarbezDotEu.Provider.DTO

Summary

Implements a client authorization response DTO in accordance to the interface as defined and shared by Vimeo, Twitter, and others.

AccessToken property

Summary

Gets or sets the access token.

Scope property

Summary

Gets or sets the authorization scope.

TokenType property

Summary

Gets or sets the token type.

About

An HTTP(S) client that supports rate limiting so that a polite integration with a third-party data provider can be implemented.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages