-----------------------------------------------------------------------------
-- |
-- License     :  BSD-3-Clause
-- Maintainer  :  Todd Mohney <toddmohney@gmail.com>
--
-- The public keys API, as described at
-- <https://developer.github.com/v3/users/keys/>
module GitHub.Endpoints.Users.PublicSSHKeys (
    -- * Querying public SSH keys
    publicSSHKeysR,
    publicSSHKeysForR,
    publicSSHKeyR,

    -- ** Create
    createUserPublicSSHKeyR,

    -- ** Delete
    deleteUserPublicSSHKeyR,
) where

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

-- | Querying public SSH keys.
-- See <https://developer.github.com/v3/users/keys/#list-public-keys-for-a-user>
publicSSHKeysForR :: Name Owner -> FetchCount -> Request 'RO (Vector PublicSSHKeyBasic)
publicSSHKeysForR :: Name Owner -> FetchCount -> Request 'RO (Vector PublicSSHKeyBasic)
publicSSHKeysForR Name Owner
user =
    Paths
-> QueryString
-> FetchCount
-> Request 'RO (Vector PublicSSHKeyBasic)
forall a (mt :: RW).
FromJSON a =>
Paths -> QueryString -> FetchCount -> Request mt (Vector a)
pagedQuery [Text
"users", Name Owner -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Owner
user, Text
"keys"] []

-- | Querying the authenticated users' public SSH keys
-- See <https://developer.github.com/v3/users/keys/#list-your-public-keys>
publicSSHKeysR :: Request 'RA (Vector PublicSSHKey)
publicSSHKeysR :: Request 'RA (Vector PublicSSHKey)
publicSSHKeysR =
    Paths -> QueryString -> Request 'RA (Vector PublicSSHKey)
forall (mt :: RW) a. Paths -> QueryString -> Request mt a
query [Text
"user", Text
"keys"] []

-- | Querying a public SSH key.
-- See <https://developer.github.com/v3/users/keys/#get-a-single-public-key>
publicSSHKeyR :: Id PublicSSHKey -> Request 'RA PublicSSHKey
publicSSHKeyR :: Id PublicSSHKey -> Request 'RA PublicSSHKey
publicSSHKeyR Id PublicSSHKey
keyId =
    Paths -> QueryString -> Request 'RA PublicSSHKey
forall (mt :: RW) a. Paths -> QueryString -> Request mt a
query [Text
"user", Text
"keys", Id PublicSSHKey -> Text
forall a. IsPathPart a => a -> Text
toPathPart Id PublicSSHKey
keyId] []

-- | Create a public SSH key.
-- See <https://developer.github.com/v3/users/keys/#create-a-public-key>.
createUserPublicSSHKeyR :: NewPublicSSHKey -> Request 'RW PublicSSHKey
createUserPublicSSHKeyR :: NewPublicSSHKey -> Request 'RW PublicSSHKey
createUserPublicSSHKeyR NewPublicSSHKey
key =
    CommandMethod -> Paths -> ByteString -> Request 'RW PublicSSHKey
forall a. CommandMethod -> Paths -> ByteString -> Request 'RW a
command CommandMethod
Post [Text
"user", Text
"keys"] (NewPublicSSHKey -> ByteString
forall a. ToJSON a => a -> ByteString
encode NewPublicSSHKey
key)

-- | Delete a public SSH key.
-- See <https://developer.github.com/v3/users/keys/#delete-a-public-key>
deleteUserPublicSSHKeyR :: Id PublicSSHKey -> GenRequest 'MtUnit 'RW ()
deleteUserPublicSSHKeyR :: Id PublicSSHKey -> GenRequest 'MtUnit 'RW ()
deleteUserPublicSSHKeyR Id PublicSSHKey
keyId =
    CommandMethod -> Paths -> ByteString -> GenRequest 'MtUnit 'RW ()
forall (mt :: MediaType (*)) a.
CommandMethod -> Paths -> ByteString -> GenRequest mt 'RW a
Command CommandMethod
Delete [Text
"user", Text
"keys", Id PublicSSHKey -> Text
forall a. IsPathPart a => a -> Text
toPathPart Id PublicSSHKey
keyId] ByteString
forall a. Monoid a => a
mempty