-----------------------------------------------------------------------------
-- |
-- License     :  BSD-3-Clause
-- Maintainer  :  Oleg Grenrus <oleg.grenrus@iki.fi>
--
-- The orgs API as described on <http://developer.github.com/v3/orgs/>.
module GitHub.Endpoints.Organizations (
    publicOrganizationsFor,
    publicOrganizationsFor',
    publicOrganizationsForR,
    publicOrganization,
    publicOrganization',
    publicOrganizationR,
    organizationsR,
    module GitHub.Data,
    ) where

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

-- | The public organizations for a user, given the user's login, with authorization
--
-- > publicOrganizationsFor' (Just $ BasicAuth "github-username" "github-password") "mike-burns"
publicOrganizationsFor' :: Maybe Auth -> Name User -> IO (Either Error (Vector SimpleOrganization))
publicOrganizationsFor' :: Maybe Auth
-> Name User -> IO (Either Error (Vector SimpleOrganization))
publicOrganizationsFor' auth :: Maybe Auth
auth org :: Name User
org =
    Maybe Auth
-> GenRequest 'MtJSON 'RO (Vector SimpleOrganization)
-> IO (Either Error (Vector SimpleOrganization))
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 SimpleOrganization)
 -> IO (Either Error (Vector SimpleOrganization)))
-> GenRequest 'MtJSON 'RO (Vector SimpleOrganization)
-> IO (Either Error (Vector SimpleOrganization))
forall a b. (a -> b) -> a -> b
$ Name User
-> FetchCount -> GenRequest 'MtJSON 'RO (Vector SimpleOrganization)
forall (k :: RW).
Name User -> FetchCount -> Request k (Vector SimpleOrganization)
publicOrganizationsForR Name User
org FetchCount
FetchAll

-- | List user organizations. The public organizations for a user, given the user's login.
--
-- > publicOrganizationsFor "mike-burns"
publicOrganizationsFor :: Name User -> IO (Either Error (Vector SimpleOrganization))
publicOrganizationsFor :: Name User -> IO (Either Error (Vector SimpleOrganization))
publicOrganizationsFor = Maybe Auth
-> Name User -> IO (Either Error (Vector SimpleOrganization))
publicOrganizationsFor' Maybe Auth
forall a. Maybe a
Nothing

-- | List all user organizations.
-- See <https://developer.github.com/v3/orgs/#list-your-organizations>
organizationsR :: FetchCount -> Request k (Vector SimpleOrganization)
organizationsR :: FetchCount -> Request k (Vector SimpleOrganization)
organizationsR = Paths
-> QueryString
-> FetchCount
-> Request k (Vector SimpleOrganization)
forall a (mt :: RW).
FromJSON a =>
Paths -> QueryString -> FetchCount -> Request mt (Vector a)
pagedQuery ["user", "orgs"] []

-- | List public user organizations.
-- See <https://developer.github.com/v3/orgs/#list-user-organizations>
publicOrganizationsForR :: Name User -> FetchCount -> Request k (Vector SimpleOrganization)
publicOrganizationsForR :: Name User -> FetchCount -> Request k (Vector SimpleOrganization)
publicOrganizationsForR user :: Name User
user = Paths
-> QueryString
-> FetchCount
-> Request k (Vector SimpleOrganization)
forall a (mt :: RW).
FromJSON a =>
Paths -> QueryString -> FetchCount -> Request mt (Vector a)
pagedQuery ["users", Name User -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name User
user, "orgs"] []

-- | Details on a public organization. Takes the organization's login.
--
-- > publicOrganization' (Just $ BasicAuth "github-username" "github-password") "thoughtbot"
publicOrganization' :: Maybe Auth -> Name Organization -> IO (Either Error Organization)
publicOrganization' :: Maybe Auth -> Name Organization -> IO (Either Error Organization)
publicOrganization' auth :: Maybe Auth
auth = Maybe Auth
-> GenRequest 'MtJSON 'RO Organization
-> IO (Either Error Organization)
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 Organization
 -> IO (Either Error Organization))
-> (Name Organization -> GenRequest 'MtJSON 'RO Organization)
-> Name Organization
-> IO (Either Error Organization)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name Organization -> GenRequest 'MtJSON 'RO Organization
forall (k :: RW). Name Organization -> Request k Organization
publicOrganizationR

-- | Query an organization. Details on a public organization. Takes the organization's login.
--
-- > publicOrganization "thoughtbot"
publicOrganization :: Name Organization -> IO (Either Error Organization)
publicOrganization :: Name Organization -> IO (Either Error Organization)
publicOrganization = Maybe Auth -> Name Organization -> IO (Either Error Organization)
publicOrganization' Maybe Auth
forall a. Maybe a
Nothing

-- | Query an organization.
-- See <https://developer.github.com/v3/orgs/#get-an-organization>
publicOrganizationR :: Name Organization -> Request k Organization
publicOrganizationR :: Name Organization -> Request k Organization
publicOrganizationR reqOrganizationName :: Name Organization
reqOrganizationName = Paths -> QueryString -> Request k Organization
forall (mt :: RW) a. Paths -> QueryString -> Request mt a
query ["orgs", Name Organization -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Organization
reqOrganizationName] []