Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 073e458

Browse files
committed
Authorized GET requests for private gists and issues
1 parent a26e6cc commit 073e458

File tree

3 files changed

+48
-11
lines changed

3 files changed

+48
-11
lines changed

Github/Gists.hs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,26 @@ module Github.Gists (
88
import Github.Data
99
import Github.Private
1010

11+
-- | The list of all public gists created by the user.
12+
--
13+
-- > gists "mike-burns"
14+
gists' :: Maybe BasicAuth -> String -> IO (Either Error [Gist])
15+
gists' auth userName = githubGet' auth ["users", userName, "gists"]
16+
1117
-- | The list of all public gists created by the user.
1218
--
1319
-- > gists "mike-burns"
1420
gists :: String -> IO (Either Error [Gist])
15-
gists userName = githubGet ["users", userName, "gists"]
21+
gists = gists' Nothing
22+
23+
-- | A specific gist, given its id.
24+
--
25+
-- > gist "225074"
26+
gist' :: Maybe BasicAuth -> String -> IO (Either Error Gist)
27+
gist' auth gistId = githubGet' auth ["gists", gistId]
1628

1729
-- | A specific gist, given its id.
1830
--
1931
-- > gist "225074"
2032
gist :: String -> IO (Either Error Gist)
21-
gist gistId = githubGet ["gists", gistId]
33+
gist = gist' Nothing

Github/Issues.hs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
-- | The issues API as described on <http://developer.github.com/v3/issues/>.
22
module Github.Issues (
33
issue
4+
,issue'
45
,issuesForRepo
6+
,issuesForRepo'
57
,IssueLimitation(..)
68
,module Github.Data
79
) where
@@ -30,21 +32,30 @@ data IssueLimitation =
3032
| Descending -- ^ Sort descending. [default]
3133
| Since UTCTime -- ^ Only issues created since the specified date and time.
3234

35+
36+
-- | Details on a specific issue, given the repo owner and name, and the issue
37+
-- number.'
38+
--
39+
-- > issue "thoughtbot" "paperclip" "462"
40+
issue' :: Maybe BasicAuth -> String -> String -> Int -> IO (Either Error Issue)
41+
issue' auth user repoName issueNumber =
42+
githubGet' auth ["repos", user, repoName, "issues", show issueNumber]
43+
3344
-- | Details on a specific issue, given the repo owner and name, and the issue
3445
-- number.
3546
--
3647
-- > issue "thoughtbot" "paperclip" "462"
3748
issue :: String -> String -> Int -> IO (Either Error Issue)
38-
issue user repoName issueNumber =
39-
githubGet ["repos", user, repoName, "issues", show issueNumber]
49+
issue = issue' Nothing
4050

4151
-- | All issues for a repo (given the repo owner and name), with optional
4252
-- restrictions as described in the @IssueLimitation@ data type.
4353
--
4454
-- > issuesForRepo "thoughtbot" "paperclip" [NoMilestone, OnlyClosed, Mentions "jyurek", Ascending]
45-
issuesForRepo :: String -> String -> [IssueLimitation] -> IO (Either Error [Issue])
46-
issuesForRepo user repoName issueLimitations =
47-
githubGetWithQueryString
55+
issuesForRepo' :: Maybe BasicAuth -> String -> String -> [IssueLimitation] -> IO (Either Error [Issue])
56+
issuesForRepo' auth user repoName issueLimitations =
57+
githubGetWithQueryString'
58+
auth
4859
["repos", user, repoName, "issues"]
4960
(queryStringFromLimitations issueLimitations)
5061
where
@@ -64,3 +75,10 @@ issuesForRepo user repoName issueLimitations =
6475
convert Descending = "direction=desc"
6576
convert (Since t) =
6677
"since=" ++ formatTime defaultTimeLocale "%FT%TZ" t
78+
79+
-- | All issues for a repo (given the repo owner and name), with optional
80+
-- restrictions as described in the @IssueLimitation@ data type.
81+
--
82+
-- > issuesForRepo "thoughtbot" "paperclip" [NoMilestone, OnlyClosed, Mentions "jyurek", Ascending]
83+
issuesForRepo :: String -> String -> [IssueLimitation] -> IO (Either Error [Issue])
84+
issuesForRepo = issuesForRepo' Nothing

Github/Private.hs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,25 @@ import Text.URI
1414
import qualified Control.Exception as E
1515
import Data.Maybe (fromMaybe)
1616

17+
1718
githubGet :: (FromJSON b, Show b) => [String] -> IO (Either Error b)
18-
githubGet paths =
19+
githubGet = githubGet' Nothing
20+
21+
githubGet' :: (FromJSON b, Show b) => Maybe BasicAuth -> [String] -> IO (Either Error b)
22+
githubGet' auth paths =
1923
githubAPI (BS.pack "GET")
2024
(buildUrl paths)
21-
Nothing
25+
auth
2226
(Nothing :: Maybe Value)
2327

2428
githubGetWithQueryString :: (FromJSON b, Show b) => [String] -> String -> IO (Either Error b)
25-
githubGetWithQueryString paths queryString =
29+
githubGetWithQueryString = githubGetWithQueryString' Nothing
30+
31+
githubGetWithQueryString' :: (FromJSON b, Show b) => Maybe BasicAuth -> [String] -> String -> IO (Either Error b)
32+
githubGetWithQueryString' auth paths queryString =
2633
githubAPI (BS.pack "GET")
2734
(buildUrl paths ++ "?" ++ queryString)
28-
Nothing
35+
auth
2936
(Nothing :: Maybe Value)
3037

3138
githubPost :: (ToJSON a, Show a, FromJSON b, Show b) => BasicAuth -> [String] -> a -> IO (Either Error b)

0 commit comments

Comments
 (0)