module Network.JSONApi.Link
( Links
, Rel
, Href
, mkLinks
) where
import Data.Aeson (ToJSON, FromJSON)
import Data.Map (Map)
import qualified Data.Map as Map
import Data.Text (Text, pack)
import qualified GHC.Generics as G
import Network.URL (URL, exportURL)
newtype Links = Links (Map Rel Href)
deriving (Show, Eq, Ord, ToJSON, FromJSON, G.Generic)
type Rel = Text
type Href = Text
mkLinks :: [(Rel, URL)] -> Links
mkLinks = Links . Map.fromList . map buildLink
buildLink :: (Rel, URL) -> (Rel, Href)
buildLink (key, url) = (key, pack (exportURL url))