persistent-ratelimit-0.1.0.1: A library for rate limiting activities with a persistent backend.

Safe HaskellNone
LanguageHaskell2010

Database.Persist.RateLimit

Synopsis

Documentation

class RateLimit action entity | action -> entity where Source

Methods

rateLimit :: action -> (Int, Int) Source

Number of actions allowed in the defined period. Period is easured in seconds.

convertAction :: action -> UTCTime -> entity Source

Convert a given action and time into an entity.

timeConstructor :: action -> EntityField entity UTCTime Source

Return the field for the time constructor in the entity.

deleteFilters :: action -> [Filter entity] Source

Filter to delete the records of a specific action. The default is `[]`. You probably only need this if multiple rate limiters use the same database entity.

rateLimitFilters :: action -> [Filter entity] Source

Filters to specify an action for database queries.

numberOfRemainingActions :: (RateLimit action entity, PersistEntityBackend entity ~ YesodPersistBackend site, YesodPersist site, PersistEntity entity, PersistQuery (YesodPersistBackend site)) => action -> HandlerT site IO Int Source

Returns the number of actions remaining for the current period.

canPerformAction :: (RateLimit action entity, PersistEntityBackend entity ~ YesodPersistBackend site, YesodPersist site, PersistEntity entity, PersistQuery (YesodPersistBackend site)) => action -> HandlerT site IO Bool Source

Determines whether an actions can be performed.

recordAction :: (RateLimit action entity, PersistEntityBackend entity ~ YesodPersistBackend site, YesodPersist site, PersistEntity entity, PersistQuery (YesodPersistBackend site)) => action -> HandlerT site IO () Source

Record when an action occurs.

deleteRecordedAction :: (RateLimit action entity, PersistEntityBackend entity ~ YesodPersistBackend site, YesodPersist site, PersistEntity entity, PersistQuery (YesodPersistBackend site)) => action -> HandlerT site IO () Source

Delete the recorded logs of an action.

cleanOldActions :: (RateLimit action entity, PersistEntityBackend entity ~ YesodPersistBackend site, YesodPersist site, PersistEntity entity, PersistQuery (YesodPersistBackend site)) => action -> HandlerT site IO () Source

Periodically call this function to delete old actions that are past the rate limit period. A nonsensical action can be used as only the rate limit period will be used.