Skip to content

Commit

Permalink
Move functions to internal module for sharing with others
Browse files Browse the repository at this point in the history
  • Loading branch information
erewok committed Mar 9, 2017
1 parent e6f7aea commit 9a07a66
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
14 changes: 14 additions & 0 deletions src/Servant/PY/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module Servant.PY.Internal
, buildHeaderDict
, functionArguments
, formatBuilder
, remainingReqCall
-- re-exports
, (:<|>)(..)
, (:>)
Expand Down Expand Up @@ -354,3 +355,16 @@ getMethod (UnTypedPythonRequest req) = decodeUtf8 $ req ^. reqMethod
hasBody :: PythonRequest -> Bool
hasBody (TypedPythonRequest req) = isJust (req ^. reqBody)
hasBody (UnTypedPythonRequest req) = isJust (req ^. reqBody)

remainingReqCall :: PyRequestArgs -> Int -> Text
remainingReqCall reqArgs width
| null argsAsList = ")"
| length argsAsList == 1 = ",\n" <> offset <> head argsAsList <> ")\n"
| otherwise = ",\n" <> offset <> T.intercalate (",\n" <> offset) argsAsList <> ")\n"
where argsAsList = requestArgsToList reqArgs
offset = mconcat $ replicate width " "

requestArgsToList :: PyRequestArgs -> [Text]
requestArgsToList reqArgs = map snd . filter fst $ zip bools strings
where bools = [hasHeaders reqArgs, hasParams reqArgs, hasData reqArgs]
strings = ["headers=headers", "params=params", "json=data"]
15 changes: 0 additions & 15 deletions src/Servant/PY/Requests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,6 @@ generatePyRequestWith opts req = "\n" <>
DangerMode -> "JSON response from the endpoint"
RawResponse -> "response (requests.Response) from issuing the request"


remainingReqCall :: PyRequestArgs -> Int -> Text
remainingReqCall reqArgs width
| null argsAsList = ")"
| length argsAsList == 1 = ",\n" <> offset <> head argsAsList <> ")\n"
| otherwise = ",\n" <> offset <> T.intercalate (",\n" <> offset) argsAsList <> ")\n"
where argsAsList = requestArgsToList reqArgs
offset = mconcat $ replicate width " "

requestArgsToList :: PyRequestArgs -> [Text]
requestArgsToList reqArgs = map snd . filter fst $ zip bools strings
where bools = [hasHeaders reqArgs, hasParams reqArgs, hasData reqArgs]
strings = ["headers=headers", "params=params", "json=data"]


functionReturn :: ReturnStyle -> (Proxy Indent -> T.Text) -> T.Text
functionReturn DangerMode pyindenter = indent' <> "resp.raise_for_status()\n"
<> indent' <> "return resp.json()"
Expand Down

0 comments on commit 9a07a66

Please sign in to comment.