fixer-0.0.0.0: A Haskell client for http://fixer.io/

Safe HaskellNone
LanguageHaskell2010

Fixer.Cache

Description

Caches for the raw API

Synopsis

Documentation

data FixerCache Source #

A complete cache for the raw API.

This includes a cache for the rates we get, as well as a cache for the rates we do not get.

insertRates Source #

Arguments

:: Day

The current date

-> Day

The requested date

-> Rates 
-> FixerCache 
-> FixerCache 

Insert a given raw response in a FixerCache

data FixerCacheResult Source #

The result of looking up rates in a FixerCache

Constructors

NotInCache 
CacheDateNotInPast

Because we requested a date in the future

WillNeverExist

Because it was on a weekend or holiday

InCache Rates 

lookupRates Source #

Arguments

:: Day

The current date

-> Day

The requested date

-> Currency 
-> Symbols 
-> FixerCache 
-> FixerCacheResult 

Look up rates in cache

newtype RateCache Source #

A cache for currency rates

This cache uses EUR as the base currency, but will still cache rates appropriately if rates with a different base currency are cached.

Constructors

RateCache 

emptyRateCache :: RateCache Source #

The empty Cache

insertRatesInCache :: Rates -> RateCache -> RateCache Source #

Insert a result into the cache.

This is probably the function you want to use, it does all the smartness.

lookupRatesInCache :: Day -> Currency -> Symbols -> RateCache -> Maybe Rates Source #

Look up multiple rates in a cache.

This function uses smartLookupRateInCache for each requested symbol.

smartInsertInCache :: Day -> Currency -> Currency -> Rate -> RateCache -> RateCache Source #

Insert a rate in a cache, but don't insert it if the from and to currencies are the same.

smartLookupRateInCache :: Day -> Currency -> Currency -> RateCache -> Maybe Rate Source #

Look up a rate in a cache.

This function will try to be smart about what it can find, but will give up after one redirection.

defaultBaseCurrency :: Currency Source #

The default base currency. Currently this is EUR

allSymbolsExcept :: Currency -> Symbols Source #

The symbols to get by default, given a base currency.

convertToBaseWithRate :: Currency -> Rate -> Rates -> Rates Source #

Convert a set of rates to another base currency with the given rate of the new base currency with respect to the old base currency. In the map, we have the info that for 1 base currency, you get s of the currency in the key.

If we now say that for 1 of the old base currency, you can get r of the new base currency

This rate means for one of the new base currency, you can get s / r of the currency in the key.

rawInsertInCache :: Day -> Currency -> Currency -> Rate -> RateCache -> RateCache Source #

Insert a rate into the cache as-is.

You probably want to be using insertRatesInCache or smartInsertInCache instead.

rawLookupInCache :: Day -> Currency -> Currency -> RateCache -> Maybe Rate Source #

Lookup a rate in the cache as-is.

You probably want to be using smartLookupRateInCache instead.