{-# 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 (LinkParam -> LinkParam -> Bool
(LinkParam -> LinkParam -> Bool)
-> (LinkParam -> LinkParam -> Bool) -> Eq LinkParam
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LinkParam -> LinkParam -> Bool
$c/= :: LinkParam -> LinkParam -> Bool
== :: LinkParam -> LinkParam -> Bool
$c== :: LinkParam -> LinkParam -> Bool
Eq, Int -> LinkParam -> ShowS
[LinkParam] -> ShowS
LinkParam -> String
(Int -> LinkParam -> ShowS)
-> (LinkParam -> String)
-> ([LinkParam] -> ShowS)
-> Show LinkParam
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LinkParam] -> ShowS
$cshowList :: [LinkParam] -> ShowS
show :: LinkParam -> String
$cshow :: LinkParam -> String
showsPrec :: Int -> LinkParam -> ShowS
$cshowsPrec :: Int -> LinkParam -> ShowS
Show)
data Link uri = Link uri [(LinkParam, Text)]
deriving (Link uri -> Link uri -> Bool
(Link uri -> Link uri -> Bool)
-> (Link uri -> Link uri -> Bool) -> Eq (Link uri)
forall uri. Eq uri => Link uri -> Link uri -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Link uri -> Link uri -> Bool
$c/= :: forall uri. Eq uri => Link uri -> Link uri -> Bool
== :: Link uri -> Link uri -> Bool
$c== :: forall uri. Eq uri => Link uri -> Link uri -> Bool
Eq, Int -> Link uri -> ShowS
[Link uri] -> ShowS
Link uri -> String
(Int -> Link uri -> ShowS)
-> (Link uri -> String) -> ([Link uri] -> ShowS) -> Show (Link uri)
forall uri. Show uri => Int -> Link uri -> ShowS
forall uri. Show uri => [Link uri] -> ShowS
forall uri. Show uri => Link uri -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Link uri] -> ShowS
$cshowList :: forall uri. Show uri => [Link uri] -> ShowS
show :: Link uri -> String
$cshow :: forall uri. Show uri => Link uri -> String
showsPrec :: Int -> Link uri -> ShowS
$cshowsPrec :: forall uri. Show uri => Int -> Link uri -> ShowS
Show)
class IsURI uri where
uriFromText ∷ Text → Either String uri
uriToText ∷ uri → Text
instance IsURI URI where
uriFromText :: Text -> Either String URI
uriFromText = Either String URI
-> (URI -> Either String URI) -> Maybe URI -> Either String URI
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (String -> Either String URI
forall a b. a -> Either a b
Left String
"") URI -> Either String URI
forall a b. b -> Either a b
Right (Maybe URI -> Either String URI)
-> (Text -> Maybe URI) -> Text -> Either String URI
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Maybe URI
parseURIReference (String -> Maybe URI) -> (Text -> String) -> Text -> Maybe URI
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
unpack
uriToText :: URI -> Text
uriToText = String -> Text
pack (String -> Text) -> (URI -> String) -> URI -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. URI -> String
forall a. Show a => a -> String
show
instance IsURI Text where
uriFromText :: Text -> Either String Text
uriFromText = Text -> Either String Text
forall a b. b -> Either a b
Right
uriToText :: Text -> Text
uriToText = Text -> Text
forall a. a -> a
id
href ∷ (IsURI uri) ⇒ Link uri → uri
href :: Link uri -> uri
href (Link uri
h [(LinkParam, Text)]
_) = uri
h
linkParams ∷ Link uri → [(LinkParam, Text)]
linkParams :: Link uri -> [(LinkParam, Text)]
linkParams (Link uri
_ [(LinkParam, Text)]
ps) = [(LinkParam, Text)]
ps