@@ -20,7 +20,6 @@ module Servant.Foreign
20 ( HasForeign(..)
20 ( HasForeign(..)
21 , Segment(..)
21 , Segment(..)
22 , SegmentType(..)
22 , SegmentType(..)
24 , FunctionName
23 , FunctionName
25 , QueryArg(..)
24 , QueryArg(..)
26 , HeaderArg(..)
25 , HeaderArg(..)
@@ -47,15 +46,14 @@ module Servant.Foreign
47 , module Servant.API
46 , module Servant.API
50−import Control.Lens (makeLenses, (%~), (&), (.~),
49+import Control.Lens (makeLenses, (%~), (&), (.~), (<>~))
52−import Data.Monoid ((<>))
50+import Data.Monoid ((<>))
54−import Data.Proxy
51+import Data.Proxy
55−import GHC.Exts (Constraint)
53+import GHC.Exts (Constraint)
56−import GHC.TypeLits
54+import GHC.TypeLits
58−import Prelude hiding (concat)
55+import Prelude hiding (concat)
60-- | Function name builder that simply concat each part together
58-- | Function name builder that simply concat each part together
61concatCase :: FunctionName -> Text
59concatCase :: FunctionName -> Text
@@ -76,7 +74,7 @@ camelCase (p:ps) = concat $ p : camelCase' ps
77type Arg = Text
75type Arg = Text
79−data Segment = Segment { _segment :: SegmentType, _matrix :: [MatrixArg] }
77+newtype Segment = Segment { _segment :: SegmentType }
80 deriving (Eq, Show)
78 deriving (Eq, Show)
82data SegmentType = Static Text -- ^ a static path segment. like "/foo"
80data SegmentType = Static Text -- ^ a static path segment. like "/foo"
@@ -105,8 +103,6 @@ data HeaderArg = HeaderArg
105 } deriving (Eq, Show)
103 } deriving (Eq, Show)
108−type MatrixArg = QueryArg
110data Url = Url
106data Url = Url
111 { _path :: Path
107 { _path :: Path
112 , _queryStr :: [QueryArg]
108 , _queryStr :: [QueryArg]
@@ -132,12 +128,12 @@ makeLenses ''Url
132makeLenses ''Req
128makeLenses ''Req
134isCapture :: Segment -> Bool
130isCapture :: Segment -> Bool
135−isCapture (Segment (Cap _) _) = True
131+isCapture (Segment (Cap _)) = True
136−isCapture _ = False
132+isCapture _ = False
138captureArg :: Segment -> Arg
134captureArg :: Segment -> Arg
139−captureArg (Segment (Cap s) _) = s
135+captureArg (Segment (Cap s)) = s
140−captureArg _ = error "captureArg called on non capture"
136+captureArg _ = error "captureArg called on non capture"
142defReq :: Req
138defReq :: Req
143defReq = Req defUrl "GET" [] False []
139defReq = Req defUrl "GET" [] False []
@@ -169,7 +165,7 @@ instance (KnownSymbol sym, HasForeign sublayout)
170 foreignFor Proxy req =
166 foreignFor Proxy req =
171 foreignFor (Proxy :: Proxy sublayout) $
167 foreignFor (Proxy :: Proxy sublayout) $
172− req & reqUrl.path <>~ [Segment (Cap str) []]
168+ req & reqUrl.path <>~ [Segment (Cap str)]
173 & funcName %~ (++ ["by", str])
169 & funcName %~ (++ ["by", str])
175 where str = pack . symbolVal $ (Proxy :: Proxy sym)
171 where str = pack . symbolVal $ (Proxy :: Proxy sym)
@@ -242,37 +238,6 @@ instance (KnownSymbol sym, HasForeign sublayout)
243 where str = pack . symbolVal $ (Proxy :: Proxy sym)
239 where str = pack . symbolVal $ (Proxy :: Proxy sym)
245−instance (KnownSymbol sym, HasForeign sublayout)
246− => HasForeign (MatrixParam sym a :> sublayout) where
247− type Foreign (MatrixParam sym a :> sublayout) = Foreign sublayout
249− foreignFor Proxy req =
250− foreignFor (Proxy :: Proxy sublayout) $
251− req & reqUrl.path._last.matrix <>~ [QueryArg strArg Normal]
253− where str = pack . symbolVal $ (Proxy :: Proxy sym)
254− strArg = str <> "Value"
256−instance (KnownSymbol sym, HasForeign sublayout)
257− => HasForeign (MatrixParams sym a :> sublayout) where
258− type Foreign (MatrixParams sym a :> sublayout) = Foreign sublayout
260− foreignFor Proxy req =
261− foreignFor (Proxy :: Proxy sublayout) $
262− req & reqUrl.path._last.matrix <>~ [QueryArg str List]
264− where str = pack . symbolVal $ (Proxy :: Proxy sym)
266−instance (KnownSymbol sym, HasForeign sublayout)
267− => HasForeign (MatrixFlag sym :> sublayout) where
268− type Foreign (MatrixFlag sym :> sublayout) = Foreign sublayout
270− foreignFor Proxy req =
271− foreignFor (Proxy :: Proxy sublayout) $
272− req & reqUrl.path._last.matrix <>~ [QueryArg str Flag]
274− where str = pack . symbolVal $ (Proxy :: Proxy sym)
276instance HasForeign Raw where
241instance HasForeign Raw where
277 type Foreign Raw = Method -> Req
242 type Foreign Raw = Method -> Req
@@ -293,7 +258,7 @@ instance (KnownSymbol path, HasForeign sublayout)
294 foreignFor Proxy req =
259 foreignFor Proxy req =
295 foreignFor (Proxy :: Proxy sublayout) $
260 foreignFor (Proxy :: Proxy sublayout) $
296− req & reqUrl.path <>~ [Segment (Static str) []]
261+ req & reqUrl.path <>~ [Segment (Static str)]
297 & funcName %~ (++ [str])
262 & funcName %~ (++ [str])
299 where str = Data.Text.map (\c -> if c == '.' then '_' else c) . pack . symbolVal $ (Proxy :: Proxy path)
264 where str = Data.Text.map (\c -> if c == '.' then '_' else c) . pack . symbolVal $ (Proxy :: Proxy path)