Skip to content

Commit fe4956f

Browse files
committed
add starring interface
Since these are new functions, I made them all take a Maybe GithubAuth. Only implemented the parts I need, which does not include the api to star and unstar a repository, or check if a single repository is starred by the authed user.
1 parent 3d023d9 commit fe4956f

3 files changed

Lines changed: 55 additions & 0 deletions

File tree

‎Github/Repos/Starring.hs‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
-- | The repo starring API as described on
2+
-- <http://developer.github.com/v3/repos/starring/>.
3+
module Github.Repos.Starring (
4+
stargazersFor
5+
,reposStarredBy
6+
,myStarred
7+
,module Github.Data
8+
) where
9+
10+
import Github.Data
11+
import Github.Data.Definitions
12+
import Github.Private
13+
14+
-- | The list of users that have starred the specified Github repo.
15+
--
16+
-- > userInfoFor' Nothing "mike-burns"
17+
stargazersFor :: Maybe GithubAuth -> String -> String -> IO (Either Error [GithubOwner])
18+
stargazersFor auth userName repoName =
19+
githubGet' auth ["repos", userName, repoName, "stargazers"]
20+
21+
-- | All the public repos starred by the specified user.
22+
--
23+
-- > reposStarredBy Nothing "croaky"
24+
reposStarredBy :: Maybe GithubAuth -> String -> IO (Either Error [Repo])
25+
reposStarredBy auth userName = githubGet' auth ["users", userName, "starred"]
26+
27+
-- | All the repos starred by the authenticated user.
28+
myStarred :: GithubAuth -> IO (Either Error [Repo])
29+
myStarred auth = githubGet' (Just auth) ["user", "starred"]

‎github.cabal‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ Extra-source-files: README.md
9696
,samples/Repos/ShowRepo.hs
9797
,samples/Repos/Watching/ListWatched.hs
9898
,samples/Repos/Watching/ListWatchers.hs
99+
,samples/Repos/Starring/ListStarred.hs
99100
,samples/Users/Followers/ListFollowers.hs
100101
,samples/Users/Followers/ListFollowing.hs
101102
,samples/Users/ShowUser.hs
@@ -134,6 +135,7 @@ Library
134135
Github.Repos.Commits,
135136
Github.Repos.Forks,
136137
Github.Repos.Watching,
138+
Github.Repos.Starring,
137139
Github.Users,
138140
Github.Users.Followers
139141

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module ListStarred where
2+
3+
import qualified Github.Repos.Starring as Github
4+
import Data.List (intercalate)
5+
import Data.Maybe (fromMaybe)
6+
7+
main = do
8+
possibleRepos <- Github.reposStarredBy Nothing "mike-burns"
9+
putStrLn $ either (("Error: "++) . show)
10+
(intercalate "\n\n" . map formatRepo)
11+
possibleRepos
12+
13+
formatRepo repo =
14+
(Github.repoName repo) ++ "\t" ++
15+
(fromMaybe "" $ Github.repoDescription repo) ++ "\n" ++
16+
(Github.repoHtmlUrl repo) ++ "\n" ++
17+
(Github.repoCloneUrl repo) ++ "\t" ++
18+
(formatDate $ Github.repoUpdatedAt repo) ++ "\n" ++
19+
formatLanguage (Github.repoLanguage repo)
20+
21+
formatDate = show . Github.fromGithubDate
22+
23+
formatLanguage (Just language) = "language: " ++ language ++ "\t"
24+
formatLanguage Nothing = ""

0 commit comments

Comments
 (0)