-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A library for rate limiting activities with a persistent backend. -- -- This packages provides a library for rate limiting activities with a -- persistent backend. @package persistent-ratelimit @version 0.2.0.0 module Database.Persist.RateLimit class RateLimit action entity | action -> entity where deleteFilters _ = [] -- | Number of actions allowed in the defined period. Period is easured in -- seconds. rateLimit :: RateLimit action entity => action -> (Int, Int) -- | Convert a given action and time into an entity. convertAction :: RateLimit action entity => action -> UTCTime -> entity -- | Return the field for the time constructor in the entity. timeConstructor :: RateLimit action entity => action -> EntityField entity UTCTime -- | 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. deleteFilters :: RateLimit action entity => action -> [Filter entity] -- | Filters to specify an action for database queries. rateLimitFilters :: RateLimit action entity => action -> [Filter entity] -- | Returns the number of actions remaining for the current period. numberOfRemainingActions :: (RateLimit action entity, PersistEntityBackend entity ~ YesodPersistBackend site, YesodPersist site, PersistEntity entity, PersistQuery (YesodPersistBackend site)) => action -> HandlerT site IO Int -- | Determines whether an actions can be performed. canPerformAction :: (RateLimit action entity, PersistEntityBackend entity ~ YesodPersistBackend site, YesodPersist site, PersistEntity entity, PersistQuery (YesodPersistBackend site)) => action -> HandlerT site IO Bool -- | Record when an action occurs. recordAction :: (RateLimit action entity, PersistEntityBackend entity ~ YesodPersistBackend site, YesodPersist site, PersistEntity entity, PersistQuery (YesodPersistBackend site)) => action -> HandlerT site IO () -- | Delete the recorded logs of an action. deleteRecordedAction :: (RateLimit action entity, PersistEntityBackend entity ~ YesodPersistBackend site, YesodPersist site, PersistEntity entity, PersistQuery (YesodPersistBackend site)) => action -> HandlerT site IO () -- | 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. cleanOldActions :: (RateLimit action entity, PersistEntityBackend entity ~ YesodPersistBackend site, YesodPersist site, PersistEntity entity, PersistQuery (YesodPersistBackend site)) => action -> HandlerT site IO ()