-
Notifications
You must be signed in to change notification settings - Fork 195
/
Copy pathMembers.hs
90 lines (81 loc) · 3.2 KB
/
Members.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
-----------------------------------------------------------------------------
-- |
-- License : BSD-3-Clause
-- Maintainer : Oleg Grenrus <[email protected]>
--
-- The organization members API as described on
-- <http://developer.github.com/v3/orgs/members/>.
module GitHub.Endpoints.Organizations.Members (
membersOf,
membersOf',
membersOfR,
membersOfWithR,
isMemberOf,
isMemberOf',
isMemberOfR,
orgInvitationsR,
module GitHub.Data,
) where
import GitHub.Data
import GitHub.Internal.Prelude
import GitHub.Request
import qualified Network.HTTP.Types as W
import Prelude ()
-- | All the users who are members of the specified organization,
-- | with or without authentication.
--
-- > membersOf' (Just $ OAuth "token") "thoughtbot"
membersOf' :: Maybe Auth -> Name Organization -> IO (Either Error (Vector SimpleUser))
membersOf' auth org =
executeRequestMaybe auth $ membersOfR org FetchAll
-- | All the users who are members of the specified organization,
-- | without authentication.
--
-- > membersOf "thoughtbot"
membersOf :: Name Organization -> IO (Either Error (Vector SimpleUser))
membersOf = membersOf' Nothing
-- | All the users who are members of the specified organization.
--
-- See <https://developer.github.com/v3/orgs/members/#members-list>
membersOfR :: Name Organization -> FetchCount -> Request k (Vector SimpleUser)
membersOfR organization =
pagedQuery ["orgs", toPathPart organization, "members"] []
-- | 'membersOfR' with filters.
--
-- See <https://developer.github.com/v3/orgs/members/#members-list>
membersOfWithR :: Name Organization -> OrgMemberFilter -> OrgMemberRole -> FetchCount -> Request k (Vector SimpleUser)
membersOfWithR org f r =
pagedQuery ["orgs", toPathPart org, "members"]
[("filter", [Esc (W.QE f')]), ("role", [Esc (W.QE r')])]
where
f' = case f of
OrgMemberFilter2faDisabled -> "2fa_disabled"
OrgMemberFilterAll -> "all"
r' = case r of
OrgMemberRoleAll -> "all"
OrgMemberRoleAdmin -> "admin"
OrgMemberRoleMember -> "member"
-- | Check if a user is a member of an organization,
-- | with or without authentication.
--
-- > isMemberOf' (Just $ OAuth "token") "phadej" "haskell-infra"
isMemberOf' :: Maybe Auth -> Name User -> Name Organization -> IO (Either Error Bool)
isMemberOf' auth user org =
executeRequestMaybe auth $ isMemberOfR user org
-- | Check if a user is a member of an organization,
-- | without authentication.
--
-- > isMemberOf "phadej" "haskell-infra"
isMemberOf :: Name User -> Name Organization -> IO (Either Error Bool)
isMemberOf = isMemberOf' Nothing
-- | Check if a user is a member of an organization.
--
-- See <https://developer.github.com/v3/orgs/members/#check-membership>
isMemberOfR :: Name User -> Name Organization -> Request k Bool
isMemberOfR user org = StatusQuery statusOnlyOk $
Query [ "orgs", toPathPart org, "members", toPathPart user ] []
-- | List pending organization invitations
--
-- See <https://developer.github.com/v3/orgs/members/#list-pending-organization-invitations>
orgInvitationsR :: Name Organization -> FetchCount -> Request 'RA (Vector Invitation)
orgInvitationsR org = pagedQuery ["orgs", toPathPart org, "invitations"] []