-----------------------------------------------------------------------------
-- |
-- License     :  BSD-3-Clause
-- Maintainer  :  Oleg Grenrus <oleg.grenrus@iki.fi>
--
-- The organization members API as described on
-- <http://developer.github.com/v3/orgs/members/>.
module GitHub.Endpoints.Organizations.Members (
    membersOfR,
    membersOfWithR,
    isMemberOfR,
    orgInvitationsR,
    module GitHub.Data,
    ) where

import GitHub.Data
import GitHub.Internal.Prelude
import Prelude ()

-- | 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 :: Name Organization -> FetchCount -> Request k (Vector SimpleUser)
membersOfR Name Organization
organization =
    Paths -> QueryString -> FetchCount -> Request k (Vector SimpleUser)
forall a (mt :: RW).
FromJSON a =>
Paths -> QueryString -> FetchCount -> Request mt (Vector a)
pagedQuery [Text
"orgs", Name Organization -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Organization
organization, Text
"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 :: Name Organization
-> OrgMemberFilter
-> OrgMemberRole
-> FetchCount
-> Request k (Vector SimpleUser)
membersOfWithR Name Organization
org OrgMemberFilter
f OrgMemberRole
r =
    Paths -> QueryString -> FetchCount -> Request k (Vector SimpleUser)
forall a (mt :: RW).
FromJSON a =>
Paths -> QueryString -> FetchCount -> Request mt (Vector a)
pagedQuery [Text
"orgs", Name Organization -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Organization
org, Text
"members"] [(ByteString
"filter", ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just ByteString
f'), (ByteString
"role", ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just ByteString
r')]
  where
    f' :: ByteString
f' = case OrgMemberFilter
f of
        OrgMemberFilter
OrgMemberFilter2faDisabled -> ByteString
"2fa_disabled"
        OrgMemberFilter
OrgMemberFilterAll         -> ByteString
"all"
    r' :: ByteString
r' = case OrgMemberRole
r of
        OrgMemberRole
OrgMemberRoleAll    -> ByteString
"all"
        OrgMemberRole
OrgMemberRoleAdmin  -> ByteString
"admin"
        OrgMemberRole
OrgMemberRoleMember -> ByteString
"member"

-- | 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 -> GenRequest 'MtStatus rw Bool
isMemberOfR :: Name User -> Name Organization -> GenRequest 'MtStatus rw Bool
isMemberOfR Name User
user Name Organization
org =
    Paths -> QueryString -> GenRequest 'MtStatus rw Bool
forall (mt :: MediaType *) (rw :: RW) a.
Paths -> QueryString -> GenRequest mt rw a
Query [ Text
"orgs", Name Organization -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Organization
org, Text
"members", Name User -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name User
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 :: Name Organization -> FetchCount -> Request 'RA (Vector Invitation)
orgInvitationsR Name Organization
org = Paths
-> QueryString -> FetchCount -> Request 'RA (Vector Invitation)
forall a (mt :: RW).
FromJSON a =>
Paths -> QueryString -> FetchCount -> Request mt (Vector a)
pagedQuery [Text
"orgs", Name Organization -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Organization
org, Text
"invitations"] []