Skip to content

Commit 927d6fd

Browse files
authored
Merge pull request #296 from y-taka-23/star-gist
Add endpoints for (un)starring gists
2 parents a00a78f + ced200d commit 927d6fd

File tree

4 files changed

+60
-2
lines changed

4 files changed

+60
-2
lines changed

samples/Gists/StarGist.hs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{-# LANGUAGE OverloadedStrings #-}
2+
module StarGist where
3+
4+
import qualified GitHub.Data.Name as N
5+
import qualified GitHub.Endpoints.Gists as GH
6+
7+
import qualified Data.Text as T
8+
import qualified Data.Text.IO as T
9+
10+
main :: IO ()
11+
main = do
12+
let gid = "your-gist-id"
13+
result <- GH.starGist (GH.OAuth "your-token") gid
14+
case result of
15+
Left err -> putStrLn $ "Error: " ++ show err
16+
Right () -> T.putStrLn $ T.concat ["Starred: ", N.untagName gid]

samples/Gists/UnstarGist.hs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{-# LANGUAGE OverloadedStrings #-}
2+
module UnstarGist where
3+
4+
import qualified GitHub.Data.Name as N
5+
import qualified GitHub.Endpoints.Gists as GH
6+
7+
import qualified Data.Text as T
8+
import qualified Data.Text.IO as T
9+
10+
main :: IO ()
11+
main = do
12+
let gid = "your-gist-id"
13+
result <- GH.unstarGist (GH.OAuth "your-token") gid
14+
case result of
15+
Left err -> putStrLn $ "Error: " ++ show err
16+
Right () -> T.putStrLn $ T.concat ["Unstarred: ", N.untagName gid]

src/GitHub.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ module GitHub (
5252
-- * Create a gist
5353
-- * Edit a gist
5454
-- * List gist commits
55-
-- * Star a gist
56-
-- * Unstar a gist
5755
-- * Check if a gist is starred
5856
-- * Fork a gist
5957
-- * List gist forks
6058
gistsR,
6159
gistR,
60+
starGistR,
61+
unstarGistR,
6262
deleteGistR,
6363

6464
-- ** Comments

src/GitHub/Endpoints/Gists.hs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ module GitHub.Endpoints.Gists (
1111
gist,
1212
gist',
1313
gistR,
14+
starGist,
15+
starGistR,
16+
unstarGist,
17+
unstarGistR,
1418
deleteGist,
1519
deleteGistR,
1620
module GitHub.Data,
@@ -58,6 +62,28 @@ gistR :: Name Gist -> Request k Gist
5862
gistR gid =
5963
query ["gists", toPathPart gid] []
6064

65+
-- | Star a gist by the authenticated user.
66+
--
67+
-- > starGist ("github-username", "github-password") "225074"
68+
starGist :: Auth -> Name Gist -> IO (Either Error ())
69+
starGist auth gid = executeRequest auth $ starGistR gid
70+
71+
-- | Star a gist by the authenticated user.
72+
-- See <https://developer.github.com/v3/gists/#star-a-gist>
73+
starGistR :: Name Gist -> Request 'RW ()
74+
starGistR gid = command Put' ["gists", toPathPart gid, "star"] mempty
75+
76+
-- | Unstar a gist by the authenticated user.
77+
--
78+
-- > unstarGist ("github-username", "github-password") "225074"
79+
unstarGist :: Auth -> Name Gist -> IO (Either Error ())
80+
unstarGist auth gid = executeRequest auth $ unstarGistR gid
81+
82+
-- | Unstar a gist by the authenticated user.
83+
-- See <https://developer.github.com/v3/gists/#unstar-a-gist>
84+
unstarGistR :: Name Gist -> Request 'RW ()
85+
unstarGistR gid = command Delete ["gists", toPathPart gid, "star"] mempty
86+
6187
-- | Delete a gist by the authenticated user.
6288
--
6389
-- > deleteGist ("github-username", "github-password") "225074"

0 commit comments

Comments
 (0)