module Network.OpenID.Association.Map (
AssociationMap(..)
, emptyAssociationMap
) where
import Network.OpenID.Association.Manager
import Network.OpenID.Types
import Data.Time
import qualified Data.Map as Map
newtype AssociationMap = AM (Map.Map String (UTCTime,Association))
deriving (Show,Read)
instance AssociationManager AssociationMap where
findAssociation (AM m) p = snd `fmap` Map.lookup (showProvider p) m
addAssociation (AM m) now p a = AM (Map.insert (showProvider p) (ex,a) m)
where ex = addUTCTime (toEnum (assocExpiresIn a)) now
expire (AM m) now = AM (Map.filter ((now >) . fst) m)
exportAssociations (AM m) = map f (Map.toList m)
where f (p,(t,a)) = (p,t,a)
emptyAssociationMap :: AssociationMap
emptyAssociationMap = AM Map.empty