-
Notifications
You must be signed in to change notification settings - Fork 19
/
GitHubUsers.hs
55 lines (40 loc) · 1.63 KB
/
GitHubUsers.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
module GitHubUsers where
import Control.Monad (liftM)
import Numeric (readInt)
import GitHubGeneral
import JsonParsing
-- List users following another user
getFollowing :: UserName -> IO [String]
getFollowing u = u `getLogins` "following"
-- List followers of a user
getFollowers :: UserName -> IO [String]
getFollowers u = u `getLogins` "followers"
getNbFollowers :: UserName -> IO Int
getNbFollowers u = u `getNb` "followers"
getNbFollowing :: UserName -> IO Int
getNbFollowing u = u `getNb` "following"
-- TODO : do we really need helpers ?
getLogins :: UserName -> String -> IO [String]
getLogins user relation = liftM (getStrVal "login")
(request4User user relation)
getNb :: UserName -> String -> IO Int
getNb user relation = liftM (rInt . head . (getStrVal relation))
(request4User user "")
where rInt a = read (a)::Int
{--------------------}
{-- REQUIRING AUTH --}
{--------------------}
-- Check if you are following a user
amIFollowing :: AuthTuple -> UserName -> IO Bool
amIFollowing auth u = liftM (hasfound . fst) (getStatus4Req auth [] ("user/following/" ++ u))
where hasfound nb
| nb == 204 = True
| otherwise = False
getKeys :: AuthTuple -> IO [GitHubKey]
getKeys auth = liftM jsonToKeys
(request "user/keys" [auth])
getKeyByID :: AuthTuple -> Int -> IO GitHubKey
getKeyByID auth id = liftM (head . jsonToKeys) (request ("user/keys/" ++ (show id)) [auth] )
getEmails :: AuthTuple -> IO [String]
getEmails auth = liftM (getStrVal "")
(request "user/emails" [auth])