Safe Haskell | None |
---|---|
Language | Haskell2010 |
The transparently caching client
- autoRunFixerClient :: FClient a -> IO (Either ServantError a)
- defaultConfig :: Config
- runFixerClient :: FEnv -> ClientEnv -> FClient a -> IO (Either ServantError a)
- data FClient a
- getLatest :: Maybe Currency -> Maybe Symbols -> FClient RatesResult
- getAtDate :: Day -> Maybe Currency -> Maybe Symbols -> FClient RatesResult
- data RatesResult
- withFileCache :: FilePath -> FClient a -> FClient a
- readCacheFromFileIfExists :: FilePath -> FClient ()
- flushCacheToFile :: FilePath -> FClient ()
Documentation
autoRunFixerClient :: FClient a -> IO (Either ServantError a) Source #
Run a FClient
action and figure out the ClientEnv
and FixerCache
arguments automatically.
This is probably the function you want to use
defaultConfig :: Config Source #
A default configuration for the client: One second of delay between calls
runFixerClient :: FEnv -> ClientEnv -> FClient a -> IO (Either ServantError a) Source #
Run a FClient
action with full control over the inputs.
A client function
getLatest :: Maybe Currency -> Maybe Symbols -> FClient RatesResult Source #
Get the latest rates.
Note that this function fetches the latest rates, but that does not mean
that the latest symbols appeared on the current date. However, there is no
way to predict what date the last rates appeared on, so we still look in the
cache at the current date. For maximum cache hits, use getAtDate
and only
look at the past beyond the last three days.
getAtDate :: Day -> Maybe Currency -> Maybe Symbols -> FClient RatesResult Source #
Get the rates at a specific date.
data RatesResult Source #
The result of calling the API the local cache
DateNotInPast | because you tried to call the API for a future date |
RateDoesNotExist | because the date is on a weekend, for example |
RatesFound Rates |
withFileCache :: FilePath -> FClient a -> FClient a Source #
Declare that we want to use the given file as a persistent cache.
Note that FClient
will still use a per-run cache if this function is not used.
This function only makes sure that the cache is persistent accross runs.
withFileCache path func = do readCacheFromFileIfExists path r <- func flushCacheToFile path pure r
readCacheFromFileIfExists :: FilePath -> FClient () Source #
Read a persistent cache from the given file if that file exists.
flushCacheToFile :: FilePath -> FClient () Source #
Flush the currently gathered cache to the given file.