|
1 | | -{-# LANGUAGE CPP #-} |
2 | | -{-# LANGUAGE FlexibleContexts #-} |
3 | | -{-# LANGUAGE FlexibleInstances #-} |
4 | | -{-# LANGUAGE GADTs #-} |
5 | | -{-# LANGUAGE KindSignatures #-} |
6 | | -{-# LANGUAGE MultiParamTypeClasses #-} |
| 1 | +{-# LANGUAGE CPP #-} |
| 2 | +{-# LANGUAGE FlexibleContexts #-} |
| 3 | +{-# LANGUAGE FlexibleInstances #-} |
| 4 | +{-# LANGUAGE FunctionalDependencies #-} |
| 5 | +{-# LANGUAGE GADTs #-} |
| 6 | +{-# LANGUAGE KindSignatures #-} |
| 7 | +{-# LANGUAGE ScopedTypeVariables #-} |
| 8 | +{-# LANGUAGE UndecidableInstances #-} |
7 | 9 | ----------------------------------------------------------------------------- |
8 | 10 | -- | |
9 | 11 | -- License : BSD-3-Clause |
|
29 | 31 | -- > githubRequest :: GH.Request 'False a -> GithubMonad a |
30 | 32 | -- > githubRequest = singleton |
31 | 33 | module GitHub.Request ( |
| 34 | + -- * A convinient execution of requests |
| 35 | + github, |
| 36 | + github', |
| 37 | + GitHubRW, |
| 38 | + GitHubRO, |
32 | 39 | -- * Types |
33 | 40 | Request, |
34 | 41 | GenRequest (..), |
@@ -107,6 +114,63 @@ import GitHub.Data.Request |
107 | 114 |
|
108 | 115 | import Paths_github (version) |
109 | 116 |
|
| 117 | +------------------------------------------------------------------------------- |
| 118 | +-- Convinience |
| 119 | +------------------------------------------------------------------------------- |
| 120 | + |
| 121 | +-- | A convinience function to turn functions returning @'Request' rw x@, |
| 122 | +-- into functions returning @IO (Either 'Error' x)@. |
| 123 | +-- |
| 124 | +-- >>> :t \auth -> github auth userInfoForR |
| 125 | +-- \auth -> github auth userInfoForR |
| 126 | +-- :: AuthMethod am => am -> Name User -> IO (Either Error User) |
| 127 | +-- |
| 128 | +-- >>> :t github pullRequestsForR |
| 129 | +-- \auth -> github auth pullRequestsForR |
| 130 | +-- :: AuthMethod am => |
| 131 | +-- am |
| 132 | +-- -> Name Owner |
| 133 | +-- -> Name Repo |
| 134 | +-- -> PullRequestMod |
| 135 | +-- -> FetchCount |
| 136 | +-- -> IO (Either Error (Data.Vector.Vector SimplePullRequest)) |
| 137 | +-- |
| 138 | +github :: (AuthMethod am, GitHubRW req res) => am -> req -> res |
| 139 | +github = githubImpl |
| 140 | + |
| 141 | +-- | Like 'github'' but for 'RO' i.e. read-only requests. |
| 142 | +-- Note that GitHub has low request limit for non-authenticated requests. |
| 143 | +-- |
| 144 | +-- >>> :t github' userInfoForR |
| 145 | +-- github' userInfoForR :: Name User -> IO (Either Error User) |
| 146 | +-- |
| 147 | +github' :: GitHubRO req res => req -> res |
| 148 | +github' = githubImpl' |
| 149 | + |
| 150 | +-- | A type-class implementing 'github'. |
| 151 | +class GitHubRW req res | req -> res where |
| 152 | + githubImpl :: AuthMethod am => am -> req -> res |
| 153 | + |
| 154 | +-- | A type-class implementing 'github''. |
| 155 | +class GitHubRO req res | req -> res where |
| 156 | + githubImpl' :: req -> res |
| 157 | + |
| 158 | +instance (ParseResponse mt req, res ~ Either Error req) => GitHubRW (GenRequest mt rw req) (IO res) where |
| 159 | + githubImpl = executeRequest |
| 160 | + |
| 161 | +instance (ParseResponse mt req, res ~ Either Error req, rw ~ 'RO) => GitHubRO (GenRequest mt rw req) (IO res) where |
| 162 | + githubImpl' = executeRequest' |
| 163 | + |
| 164 | +instance GitHubRW req res => GitHubRW (a -> req) (a -> res) where |
| 165 | + githubImpl am req x = githubImpl am (req x) |
| 166 | + |
| 167 | +instance GitHubRO req res => GitHubRO (a -> req) (a -> res) where |
| 168 | + githubImpl' req x = githubImpl' (req x) |
| 169 | + |
| 170 | +------------------------------------------------------------------------------- |
| 171 | +-- Execution |
| 172 | +------------------------------------------------------------------------------- |
| 173 | + |
110 | 174 | #ifdef MIN_VERSION_http_client_tls |
111 | 175 | withOpenSSL :: IO a -> IO a |
112 | 176 | withOpenSSL = id |
|
0 commit comments