-----------------------------------------------------------------------------
-- |
-- License     :  BSD-3-Clause
-- Maintainer  :  Oleg Grenrus <oleg.grenrus@iki.fi>
--
-- The repo invitations API as described on
-- <https://developer.github.com/v3/repos/invitations/>.
module GitHub.Endpoints.Repos.Invitations (
    listInvitationsOnR,
    listInvitationsForR,
    acceptInvitationFromR
    ) where

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

-- | List open invitations of a repository
-- See <https://developer.github.com/v3/repos/invitations/#list-invitations-for-a-repository>
listInvitationsOnR :: Name Owner -> Name Repo -> FetchCount -> GenRequest 'MtJSON k (Vector RepoInvitation)
listInvitationsOnR :: Name Owner
-> Name Repo
-> FetchCount
-> GenRequest 'MtJSON k (Vector RepoInvitation)
listInvitationsOnR Name Owner
user Name Repo
repo =
    Paths
-> QueryString
-> FetchCount
-> GenRequest 'MtJSON k (Vector RepoInvitation)
forall a (t :: * -> *) b (mt :: MediaType *) (rw :: RW).
(a ~ t b, Foldable t, Semigroup a) =>
Paths -> QueryString -> FetchCount -> GenRequest mt rw a
PagedQuery [Text
"repos", Name Owner -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Owner
user, Name Repo -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Repo
repo, Text
"invitations"] []

-- | List a user's repository invitations
-- See <https://developer.github.com/v3/repos/invitations/#list-a-users-repository-invitations>
listInvitationsForR :: FetchCount -> Request k (Vector RepoInvitation)
listInvitationsForR :: FetchCount -> Request k (Vector RepoInvitation)
listInvitationsForR =
    Paths
-> QueryString -> FetchCount -> Request k (Vector RepoInvitation)
forall a (mt :: RW).
FromJSON a =>
Paths -> QueryString -> FetchCount -> Request mt (Vector a)
pagedQuery [Text
"user", Text
"repository_invitations"] []


-- | Accept a repository invitation
-- See <https://developer.github.com/v3/repos/invitations/#accept-a-repository-invitation>
acceptInvitationFromR :: Id RepoInvitation -> GenRequest 'MtUnit 'RW ()
acceptInvitationFromR :: Id RepoInvitation -> GenRequest 'MtUnit 'RW ()
acceptInvitationFromR Id RepoInvitation
invId =
    CommandMethod -> Paths -> ByteString -> GenRequest 'MtUnit 'RW ()
forall (mt :: MediaType *) a.
CommandMethod -> Paths -> ByteString -> GenRequest mt 'RW a
Command CommandMethod
Patch [Text
"user", Text
"repository_invitations", Id RepoInvitation -> Text
forall a. IsPathPart a => a -> Text
toPathPart Id RepoInvitation
invId] ByteString
forall a. Monoid a => a
mempty