{-# LANGUAGE UnicodeSyntax, Safe #-}
module Network.HTTP.Link.Types where
import Data.Text
import Network.URI
data LinkParam = Rel | Anchor | Rev | Hreflang | Media | Title | Title' | ContentType | Other Text
deriving (Eq, Show)
data GLink uri = Link uri [(LinkParam, Text)]
deriving (Eq, Show)
class IsURI uri where
uriFromText ∷ Text → Either String uri
instance IsURI URI where
uriFromText = maybe (Left "") Right . parseURIReference . unpack
instance IsURI Text where
uriFromText = Right
type Link = GLink URI
href ∷ Link → URI
href (Link h _) = h
linkParams ∷ Link → [(LinkParam, Text)]
linkParams (Link _ ps) = ps
lnk ∷ String → [(LinkParam, Text)] → Maybe Link
lnk u r = parseURI u >>= return . \x → Link x r