-----------------------------------------------------------------------------
-- |
-- License     :  BSD-3-Clause
-- Maintainer  :  Oleg Grenrus <oleg.grenrus@iki.fi>
--
-- The repo starring API as described on
-- <https://developer.github.com/v3/activity/starring/>.
module GitHub.Endpoints.Activity.Starring (
    stargazersFor,
    stargazersForR,
    reposStarredBy,
    reposStarredByR,
    myStarred,
    myStarredR,
    myStarredAcceptStar,
    myStarredAcceptStarR,
    starRepo,
    starRepoR,
    unstarRepo,
    unstarRepoR,
    module GitHub.Data,
    ) where

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

-- | The list of users that have starred the specified Github repo.
--
-- > userInfoFor' Nothing "mike-burns"
stargazersFor :: Maybe Auth -> Name Owner -> Name Repo -> IO (Either Error (Vector SimpleUser))
stargazersFor :: Maybe Auth
-> Name Owner -> Name Repo -> IO (Either Error (Vector SimpleUser))
stargazersFor auth :: Maybe Auth
auth user :: Name Owner
user repo :: Name Repo
repo =
    Maybe Auth
-> GenRequest 'MtJSON 'RO (Vector SimpleUser)
-> IO (Either Error (Vector SimpleUser))
forall am (mt :: MediaType *) a.
(AuthMethod am, ParseResponse mt a) =>
Maybe am -> GenRequest mt 'RO a -> IO (Either Error a)
executeRequestMaybe Maybe Auth
auth (GenRequest 'MtJSON 'RO (Vector SimpleUser)
 -> IO (Either Error (Vector SimpleUser)))
-> GenRequest 'MtJSON 'RO (Vector SimpleUser)
-> IO (Either Error (Vector SimpleUser))
forall a b. (a -> b) -> a -> b
$ Name Owner
-> Name Repo
-> FetchCount
-> GenRequest 'MtJSON 'RO (Vector SimpleUser)
forall (k :: RW).
Name Owner
-> Name Repo -> FetchCount -> Request k (Vector SimpleUser)
stargazersForR Name Owner
user Name Repo
repo FetchCount
FetchAll

-- | List Stargazers.
-- See <https://developer.github.com/v3/activity/starring/#list-stargazers>
stargazersForR :: Name Owner -> Name Repo -> FetchCount -> Request k (Vector SimpleUser)
stargazersForR :: Name Owner
-> Name Repo -> FetchCount -> Request k (Vector SimpleUser)
stargazersForR user :: Name Owner
user repo :: Name Repo
repo =
    Paths -> QueryString -> FetchCount -> Request k (Vector SimpleUser)
forall a (mt :: RW).
FromJSON a =>
Paths -> QueryString -> FetchCount -> Request mt (Vector a)
pagedQuery ["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, "stargazers"] []

-- | All the public repos starred by the specified user.
--
-- > reposStarredBy Nothing "croaky"
reposStarredBy :: Maybe Auth -> Name Owner -> IO (Either Error (Vector Repo))
reposStarredBy :: Maybe Auth -> Name Owner -> IO (Either Error (Vector Repo))
reposStarredBy auth :: Maybe Auth
auth user :: Name Owner
user =
    Maybe Auth
-> GenRequest 'MtJSON 'RO (Vector Repo)
-> IO (Either Error (Vector Repo))
forall am (mt :: MediaType *) a.
(AuthMethod am, ParseResponse mt a) =>
Maybe am -> GenRequest mt 'RO a -> IO (Either Error a)
executeRequestMaybe Maybe Auth
auth (GenRequest 'MtJSON 'RO (Vector Repo)
 -> IO (Either Error (Vector Repo)))
-> GenRequest 'MtJSON 'RO (Vector Repo)
-> IO (Either Error (Vector Repo))
forall a b. (a -> b) -> a -> b
$ Name Owner -> FetchCount -> GenRequest 'MtJSON 'RO (Vector Repo)
forall (k :: RW).
Name Owner -> FetchCount -> Request k (Vector Repo)
reposStarredByR Name Owner
user FetchCount
FetchAll

-- | List repositories being starred.
-- See <https://developer.github.com/v3/activity/starring/#list-repositories-being-starred>
reposStarredByR :: Name Owner -> FetchCount -> Request k (Vector Repo)
reposStarredByR :: Name Owner -> FetchCount -> Request k (Vector Repo)
reposStarredByR user :: Name Owner
user =
    Paths -> QueryString -> FetchCount -> Request k (Vector Repo)
forall a (mt :: RW).
FromJSON a =>
Paths -> QueryString -> FetchCount -> Request mt (Vector a)
pagedQuery ["users", Name Owner -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Owner
user, "starred"] []

-- | All the repos starred by the authenticated user.
myStarred :: Auth -> IO (Either Error (Vector Repo))
myStarred :: Auth -> IO (Either Error (Vector Repo))
myStarred auth :: Auth
auth =
    Auth
-> GenRequest 'MtJSON 'RA (Vector Repo)
-> IO (Either Error (Vector Repo))
forall am (mt :: MediaType *) a (rw :: RW).
(AuthMethod am, ParseResponse mt a) =>
am -> GenRequest mt rw a -> IO (Either Error a)
executeRequest Auth
auth (GenRequest 'MtJSON 'RA (Vector Repo)
 -> IO (Either Error (Vector Repo)))
-> GenRequest 'MtJSON 'RA (Vector Repo)
-> IO (Either Error (Vector Repo))
forall a b. (a -> b) -> a -> b
$ FetchCount -> GenRequest 'MtJSON 'RA (Vector Repo)
myStarredR FetchCount
FetchAll

-- | All the repos starred by the authenticated user.
-- See <https://developer.github.com/v3/activity/starring/#list-repositories-being-starred>
myStarredR :: FetchCount -> Request 'RA (Vector Repo)
myStarredR :: FetchCount -> GenRequest 'MtJSON 'RA (Vector Repo)
myStarredR = Paths
-> QueryString
-> FetchCount
-> GenRequest 'MtJSON 'RA (Vector Repo)
forall a (mt :: RW).
FromJSON a =>
Paths -> QueryString -> FetchCount -> Request mt (Vector a)
pagedQuery ["user", "starred"] []


-- | All the repos starred by the authenticated user.
myStarredAcceptStar :: Auth -> IO (Either Error (Vector RepoStarred))
myStarredAcceptStar :: Auth -> IO (Either Error (Vector RepoStarred))
myStarredAcceptStar auth :: Auth
auth =
    Auth
-> GenRequest 'MtStar 'RA (Vector RepoStarred)
-> IO (Either Error (Vector RepoStarred))
forall am (mt :: MediaType *) a (rw :: RW).
(AuthMethod am, ParseResponse mt a) =>
am -> GenRequest mt rw a -> IO (Either Error a)
executeRequest Auth
auth (GenRequest 'MtStar 'RA (Vector RepoStarred)
 -> IO (Either Error (Vector RepoStarred)))
-> GenRequest 'MtStar 'RA (Vector RepoStarred)
-> IO (Either Error (Vector RepoStarred))
forall a b. (a -> b) -> a -> b
$ FetchCount -> GenRequest 'MtStar 'RA (Vector RepoStarred)
myStarredAcceptStarR FetchCount
FetchAll

-- | All the repos starred by the authenticated user.
-- See <https://developer.github.com/v3/activity/starring/#alternative-response-with-star-creation-timestamps-1>
myStarredAcceptStarR :: FetchCount -> GenRequest 'MtStar 'RA (Vector RepoStarred)
myStarredAcceptStarR :: FetchCount -> GenRequest 'MtStar 'RA (Vector RepoStarred)
myStarredAcceptStarR = Paths
-> QueryString
-> FetchCount
-> GenRequest 'MtStar 'RA (Vector RepoStarred)
forall (mt :: MediaType *) (rw :: RW) a.
Paths -> QueryString -> FetchCount -> GenRequest mt rw (Vector a)
PagedQuery ["user", "starred"] []

-- | Star a repo by the authenticated user.
starRepo :: Auth -> Name Owner -> Name Repo -> IO (Either Error ())
starRepo :: Auth -> Name Owner -> Name Repo -> IO (Either Error ())
starRepo auth :: Auth
auth user :: Name Owner
user repo :: Name Repo
repo = Auth -> GenRequest 'MtUnit 'RW () -> IO (Either Error ())
forall am (mt :: MediaType *) a (rw :: RW).
(AuthMethod am, ParseResponse mt a) =>
am -> GenRequest mt rw a -> IO (Either Error a)
executeRequest Auth
auth (GenRequest 'MtUnit 'RW () -> IO (Either Error ()))
-> GenRequest 'MtUnit 'RW () -> IO (Either Error ())
forall a b. (a -> b) -> a -> b
$ Name Owner -> Name Repo -> GenRequest 'MtUnit 'RW ()
starRepoR Name Owner
user Name Repo
repo

-- | Star a repo by the authenticated user.
-- See <https://developer.github.com/v3/activity/starring/#star-a-repository>
starRepoR :: Name Owner -> Name Repo -> GenRequest 'MtUnit 'RW ()
starRepoR :: Name Owner -> Name Repo -> GenRequest 'MtUnit 'RW ()
starRepoR user :: Name Owner
user repo :: Name Repo
repo = CommandMethod -> Paths -> ByteString -> GenRequest 'MtUnit 'RW ()
forall (mt :: MediaType *) a.
CommandMethod -> Paths -> ByteString -> GenRequest mt 'RW a
Command CommandMethod
Put Paths
paths ByteString
forall a. Monoid a => a
mempty
  where
    paths :: Paths
paths = ["user", "starred", 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]

-- | Unstar a repo by the authenticated user.
unstarRepo :: Auth -> Name Owner -> Name Repo -> IO (Either Error ())
unstarRepo :: Auth -> Name Owner -> Name Repo -> IO (Either Error ())
unstarRepo auth :: Auth
auth user :: Name Owner
user repo :: Name Repo
repo = Auth -> GenRequest 'MtUnit 'RW () -> IO (Either Error ())
forall am (mt :: MediaType *) a (rw :: RW).
(AuthMethod am, ParseResponse mt a) =>
am -> GenRequest mt rw a -> IO (Either Error a)
executeRequest Auth
auth (GenRequest 'MtUnit 'RW () -> IO (Either Error ()))
-> GenRequest 'MtUnit 'RW () -> IO (Either Error ())
forall a b. (a -> b) -> a -> b
$ Name Owner -> Name Repo -> GenRequest 'MtUnit 'RW ()
unstarRepoR Name Owner
user Name Repo
repo

-- | Unstar a repo by the authenticated user.
-- See <https://developer.github.com/v3/activity/starring/#unstar-a-repository>
unstarRepoR :: Name Owner -> Name Repo -> GenRequest 'MtUnit 'RW ()
unstarRepoR :: Name Owner -> Name Repo -> GenRequest 'MtUnit 'RW ()
unstarRepoR user :: Name Owner
user repo :: Name Repo
repo = CommandMethod -> Paths -> ByteString -> GenRequest 'MtUnit 'RW ()
forall (mt :: MediaType *) a.
CommandMethod -> Paths -> ByteString -> GenRequest mt 'RW a
Command CommandMethod
Delete Paths
paths ByteString
forall a. Monoid a => a
mempty
  where
    paths :: Paths
paths = ["user", "starred", 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]