on master help sign in
github-app/src/GitHub/App/Request.hs
40 lines 1.2 kB history raw
1{- This Source Code Form is subject to the terms of the Mozilla Public
2 - License, v. 2.0. If a copy of the MPL was not distributed with this
3 - file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 -}
6{-# LANGUAGE CPP #-}
8module GitHub.App.Request
9 ( executeAppRequest
10 , executeAppRequestWithMgr
11 ) where
13import Data.Aeson (FromJSON)
14import GitHub.Data (Error (..))
15import GitHub.Data.Request (Request)
16import GitHub.Request (executeRequestWithMgr)
17import Network.HTTP.Client (Manager)
18import Network.HTTP.Client.TLS (newTlsManager)
20import GitHub.App.Auth (InstallationAuth, obtainAccessToken)
23executeAppRequest :: FromJSON a => InstallationAuth -> Request k a -> IO (Either Error a)
24executeAppRequest instAuth req = do
25 manager <- newTlsManager
26 x <- executeAppRequestWithMgr manager instAuth req
27#if !MIN_VERSION_http_client(0, 4, 18)
28 closeManager manager
29#endif
30 pure x
32executeAppRequestWithMgr
33 :: FromJSON a
34 => Manager
35 -> InstallationAuth
36 -> Request k a
37 -> IO (Either Error a)
38executeAppRequestWithMgr mgr instAuth req = obtainAccessToken mgr instAuth >>= \case
39 Right auth -> executeRequestWithMgr mgr auth req
40 Left err -> pure $ Left err