module Rest.Dictionary.Combinators
(
someI
, stringI
, xmlTextI
, fileI
, readI
, xmlI
, rawXmlI
, jsonI
, someO
, stringO
, fileO
, xmlO
, rawXmlO
, jsonO
, multipartO
, someE
, jsonE
, xmlE
, xmlJsonI
, xmlJsonO
, xmlJsonE
, xmlJson
, mkHeader
, addHeader
, mkPar
, addPar
) where
import Prelude hiding (id, (.))
import Control.Category
import Data.Aeson
import Data.ByteString.Lazy (ByteString)
import Data.JSON.Schema
import Data.Text.Lazy (Text)
import Data.Typeable
import Network.Multipart (BodyPart)
import Text.XML.HXT.Arrow.Pickle
import qualified Data.Label.Total as L
import Rest.Dictionary.Types
import Rest.Info
import Rest.Types.Error
mkHeader :: Header h -> Dict x p i o e -> Dict h p i o e
mkHeader = L.set headers
addHeader :: Header h -> Dict h' p i o e -> Dict (h, h') p i o e
addHeader = L.modify headers . TwoHeaders
mkPar :: Param p -> Dict h x i o e -> Dict h p i o e
mkPar = L.set params
addPar :: Param p -> Dict h p' i o e -> Dict h (p, p') i o e
addPar = L.modify params . TwoParams
someI :: Dict h p () o e -> Dict h p i o e
someI = L.set inputs (Dicts [])
stringI :: Dict h p i o e -> Dict h p String o e
stringI = L.set inputs (Dicts [StringI])
xmlTextI :: Dict h p i o e -> Dict h p Text o e
xmlTextI = L.set inputs (Dicts [XmlTextI])
fileI :: Dict h p i o e -> Dict h p ByteString o e
fileI = L.set inputs (Dicts [FileI])
readI :: (Info i, Read i, Show i) => Dict h p i o e -> Dict h p i o e
readI = L.modify (dicts . inputs) (ReadI:)
xmlI :: (Typeable i, XmlPickler i) => Dict h p i o e -> Dict h p i o e
xmlI = L.modify (dicts . inputs) (XmlI:)
rawXmlI :: Dict h p i o e -> Dict h p ByteString o e
rawXmlI = L.set inputs (Dicts [RawXmlI])
jsonI :: (Typeable i, FromJSON i, JSONSchema i) => Dict h p i o e -> Dict h p i o e
jsonI = L.modify (dicts . inputs) (JsonI:)
someO :: Dict h p i () e -> Dict h p i o e
someO = L.set outputs (Dicts [])
stringO :: Dict h p i () e -> Dict h p i String e
stringO = L.set outputs (Dicts [StringO])
fileO :: Dict h p i o e -> Dict h p i (ByteString, String) e
fileO = L.set outputs (Dicts [FileO])
xmlO :: (Typeable o, XmlPickler o) => Dict h p i o e -> Dict h p i o e
xmlO = L.modify (dicts . outputs) (XmlO:)
rawXmlO :: Dict h p i () e -> Dict h p i ByteString e
rawXmlO = L.set outputs (Dicts [RawXmlO])
jsonO :: (Typeable o, ToJSON o, JSONSchema o) => Dict h p i o e -> Dict h p i o e
jsonO = L.modify (dicts . outputs) (JsonO:)
multipartO :: Dict h p i () e -> Dict h p i [BodyPart] e
multipartO = L.set outputs (Dicts [MultipartO])
someE :: (Typeable e, ToJSON e, JSONSchema e) => Dict h p i o () -> Dict h p i o e
someE = L.set errors (Dicts [])
jsonE :: (ToResponseCode e, Typeable e, ToJSON e, JSONSchema e) => Dict h p i o e -> Dict h p i o e
jsonE = L.modify (dicts . errors) (JsonE:)
xmlE :: (ToResponseCode e, Typeable e, XmlPickler e) => Dict h p i o e -> Dict h p i o e
xmlE = L.modify (dicts . errors) (XmlE:)
xmlJsonI :: (Typeable i, FromJSON i, JSONSchema i, XmlPickler i) => Dict h p () o e -> Dict h p i o e
xmlJsonI = xmlI . jsonI . someI
xmlJsonO :: (Typeable o, ToJSON o, JSONSchema o, XmlPickler o) => Dict h p i () e -> Dict h p i o e
xmlJsonO = xmlO . jsonO . someO
xmlJsonE :: (ToResponseCode e, Typeable e, ToJSON e, JSONSchema e, XmlPickler e) => Dict h p i o () -> Dict h p i o e
xmlJsonE = xmlE . jsonE . someE
xmlJson :: (Typeable i, FromJSON i, JSONSchema i, XmlPickler i
,Typeable o, ToJSON o, JSONSchema o, XmlPickler o)
=> Dict h p () () e -> Dict h p i o e
xmlJson = xmlJsonI . xmlJsonO