Skip to content

Commit 116f6bf

Browse files
schoettlTristanCacqueray
authored andcommitted
Refactor and documentation
1 parent c638ade commit 116f6bf

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

matrix-client/src/Network/Matrix/Client.hs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,15 @@ mkRequest ClientSession {..} = mkRequest' baseUrl token
226226
doRequest :: FromJSON a => ClientSession -> HTTP.Request -> MatrixIO a
227227
doRequest ClientSession {..} = doRequest' manager
228228

229+
-- | Same as 'doRequest' but expect an empty JSON response @{}@
230+
-- which is converted to an empty Haskell tuple @()@.
229231
doRequestExpectEmptyResponse :: ClientSession -> String -> HTTP.Request -> MatrixIO ()
230-
doRequestExpectEmptyResponse sess apiName request = fmap (ensureEmptyObject apiName) <$> doRequest sess request
232+
doRequestExpectEmptyResponse sess apiName request = fmap ensureEmptyObject <$> doRequest sess request
233+
where
234+
ensureEmptyObject :: Value -> ()
235+
ensureEmptyObject value = case value of
236+
Object xs | xs == mempty -> ()
237+
_ -> error $ "Unknown " <> apiName <> " response: " <> show value
231238

232239
-- | 'getTokenOwner' gets information about the owner of a given access token.
233240
getTokenOwner :: ClientSession -> MatrixIO UserID
@@ -1323,9 +1330,3 @@ tshow = T.pack . show
13231330

13241331
escapeUriComponent :: T.Text -> T.Text
13251332
escapeUriComponent = T.pack . URI.escapeURIString URI.isUnreserved . T.unpack
1326-
1327-
1328-
ensureEmptyObject :: String -> Value -> ()
1329-
ensureEmptyObject apiName value = case value of
1330-
Object xs | xs == mempty -> ()
1331-
_ -> error $ "Unknown " <> apiName <> " response: " <> show value

0 commit comments

Comments
 (0)