{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.AppSync.CreateApiKey
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Creates a unique key that you can distribute to clients who are
-- executing your API.
module Amazonka.AppSync.CreateApiKey
  ( -- * Creating a Request
    CreateApiKey (..),
    newCreateApiKey,

    -- * Request Lenses
    createApiKey_expires,
    createApiKey_description,
    createApiKey_apiId,

    -- * Destructuring the Response
    CreateApiKeyResponse (..),
    newCreateApiKeyResponse,

    -- * Response Lenses
    createApiKeyResponse_apiKey,
    createApiKeyResponse_httpStatus,
  )
where

import Amazonka.AppSync.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newCreateApiKey' smart constructor.
data CreateApiKey = CreateApiKey'
  { -- | The time from creation time after which the API key expires. The date is
    -- represented as seconds since the epoch, rounded down to the nearest
    -- hour. The default value for this parameter is 7 days from creation time.
    -- For more information, see .
    CreateApiKey -> Maybe Integer
expires :: Prelude.Maybe Prelude.Integer,
    -- | A description of the purpose of the API key.
    CreateApiKey -> Maybe Text
description :: Prelude.Maybe Prelude.Text,
    -- | The ID for your GraphQL API.
    CreateApiKey -> Text
apiId :: Prelude.Text
  }
  deriving (CreateApiKey -> CreateApiKey -> Bool
(CreateApiKey -> CreateApiKey -> Bool)
-> (CreateApiKey -> CreateApiKey -> Bool) -> Eq CreateApiKey
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateApiKey -> CreateApiKey -> Bool
$c/= :: CreateApiKey -> CreateApiKey -> Bool
== :: CreateApiKey -> CreateApiKey -> Bool
$c== :: CreateApiKey -> CreateApiKey -> Bool
Prelude.Eq, ReadPrec [CreateApiKey]
ReadPrec CreateApiKey
Int -> ReadS CreateApiKey
ReadS [CreateApiKey]
(Int -> ReadS CreateApiKey)
-> ReadS [CreateApiKey]
-> ReadPrec CreateApiKey
-> ReadPrec [CreateApiKey]
-> Read CreateApiKey
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateApiKey]
$creadListPrec :: ReadPrec [CreateApiKey]
readPrec :: ReadPrec CreateApiKey
$creadPrec :: ReadPrec CreateApiKey
readList :: ReadS [CreateApiKey]
$creadList :: ReadS [CreateApiKey]
readsPrec :: Int -> ReadS CreateApiKey
$creadsPrec :: Int -> ReadS CreateApiKey
Prelude.Read, Int -> CreateApiKey -> ShowS
[CreateApiKey] -> ShowS
CreateApiKey -> String
(Int -> CreateApiKey -> ShowS)
-> (CreateApiKey -> String)
-> ([CreateApiKey] -> ShowS)
-> Show CreateApiKey
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateApiKey] -> ShowS
$cshowList :: [CreateApiKey] -> ShowS
show :: CreateApiKey -> String
$cshow :: CreateApiKey -> String
showsPrec :: Int -> CreateApiKey -> ShowS
$cshowsPrec :: Int -> CreateApiKey -> ShowS
Prelude.Show, (forall x. CreateApiKey -> Rep CreateApiKey x)
-> (forall x. Rep CreateApiKey x -> CreateApiKey)
-> Generic CreateApiKey
forall x. Rep CreateApiKey x -> CreateApiKey
forall x. CreateApiKey -> Rep CreateApiKey x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateApiKey x -> CreateApiKey
$cfrom :: forall x. CreateApiKey -> Rep CreateApiKey x
Prelude.Generic)

-- |
-- Create a value of 'CreateApiKey' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'expires', 'createApiKey_expires' - The time from creation time after which the API key expires. The date is
-- represented as seconds since the epoch, rounded down to the nearest
-- hour. The default value for this parameter is 7 days from creation time.
-- For more information, see .
--
-- 'description', 'createApiKey_description' - A description of the purpose of the API key.
--
-- 'apiId', 'createApiKey_apiId' - The ID for your GraphQL API.
newCreateApiKey ::
  -- | 'apiId'
  Prelude.Text ->
  CreateApiKey
newCreateApiKey :: Text -> CreateApiKey
newCreateApiKey Text
pApiId_ =
  CreateApiKey' :: Maybe Integer -> Maybe Text -> Text -> CreateApiKey
CreateApiKey'
    { $sel:expires:CreateApiKey' :: Maybe Integer
expires = Maybe Integer
forall a. Maybe a
Prelude.Nothing,
      $sel:description:CreateApiKey' :: Maybe Text
description = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:apiId:CreateApiKey' :: Text
apiId = Text
pApiId_
    }

-- | The time from creation time after which the API key expires. The date is
-- represented as seconds since the epoch, rounded down to the nearest
-- hour. The default value for this parameter is 7 days from creation time.
-- For more information, see .
createApiKey_expires :: Lens.Lens' CreateApiKey (Prelude.Maybe Prelude.Integer)
createApiKey_expires :: (Maybe Integer -> f (Maybe Integer))
-> CreateApiKey -> f CreateApiKey
createApiKey_expires = (CreateApiKey -> Maybe Integer)
-> (CreateApiKey -> Maybe Integer -> CreateApiKey)
-> Lens CreateApiKey CreateApiKey (Maybe Integer) (Maybe Integer)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateApiKey' {Maybe Integer
expires :: Maybe Integer
$sel:expires:CreateApiKey' :: CreateApiKey -> Maybe Integer
expires} -> Maybe Integer
expires) (\s :: CreateApiKey
s@CreateApiKey' {} Maybe Integer
a -> CreateApiKey
s {$sel:expires:CreateApiKey' :: Maybe Integer
expires = Maybe Integer
a} :: CreateApiKey)

-- | A description of the purpose of the API key.
createApiKey_description :: Lens.Lens' CreateApiKey (Prelude.Maybe Prelude.Text)
createApiKey_description :: (Maybe Text -> f (Maybe Text)) -> CreateApiKey -> f CreateApiKey
createApiKey_description = (CreateApiKey -> Maybe Text)
-> (CreateApiKey -> Maybe Text -> CreateApiKey)
-> Lens CreateApiKey CreateApiKey (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateApiKey' {Maybe Text
description :: Maybe Text
$sel:description:CreateApiKey' :: CreateApiKey -> Maybe Text
description} -> Maybe Text
description) (\s :: CreateApiKey
s@CreateApiKey' {} Maybe Text
a -> CreateApiKey
s {$sel:description:CreateApiKey' :: Maybe Text
description = Maybe Text
a} :: CreateApiKey)

-- | The ID for your GraphQL API.
createApiKey_apiId :: Lens.Lens' CreateApiKey Prelude.Text
createApiKey_apiId :: (Text -> f Text) -> CreateApiKey -> f CreateApiKey
createApiKey_apiId = (CreateApiKey -> Text)
-> (CreateApiKey -> Text -> CreateApiKey)
-> Lens CreateApiKey CreateApiKey Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateApiKey' {Text
apiId :: Text
$sel:apiId:CreateApiKey' :: CreateApiKey -> Text
apiId} -> Text
apiId) (\s :: CreateApiKey
s@CreateApiKey' {} Text
a -> CreateApiKey
s {$sel:apiId:CreateApiKey' :: Text
apiId = Text
a} :: CreateApiKey)

instance Core.AWSRequest CreateApiKey where
  type AWSResponse CreateApiKey = CreateApiKeyResponse
  request :: CreateApiKey -> Request CreateApiKey
request = Service -> CreateApiKey -> Request CreateApiKey
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateApiKey
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateApiKey)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse CreateApiKey))
-> Logger
-> Service
-> Proxy CreateApiKey
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateApiKey)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe ApiKey -> Int -> CreateApiKeyResponse
CreateApiKeyResponse'
            (Maybe ApiKey -> Int -> CreateApiKeyResponse)
-> Either String (Maybe ApiKey)
-> Either String (Int -> CreateApiKeyResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe ApiKey)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"apiKey")
            Either String (Int -> CreateApiKeyResponse)
-> Either String Int -> Either String CreateApiKeyResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable CreateApiKey

instance Prelude.NFData CreateApiKey

instance Core.ToHeaders CreateApiKey where
  toHeaders :: CreateApiKey -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateApiKey -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON CreateApiKey where
  toJSON :: CreateApiKey -> Value
toJSON CreateApiKey' {Maybe Integer
Maybe Text
Text
apiId :: Text
description :: Maybe Text
expires :: Maybe Integer
$sel:apiId:CreateApiKey' :: CreateApiKey -> Text
$sel:description:CreateApiKey' :: CreateApiKey -> Maybe Text
$sel:expires:CreateApiKey' :: CreateApiKey -> Maybe Integer
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"expires" Text -> Integer -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Integer -> Pair) -> Maybe Integer -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Integer
expires,
            (Text
"description" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
description
          ]
      )

instance Core.ToPath CreateApiKey where
  toPath :: CreateApiKey -> ByteString
toPath CreateApiKey' {Maybe Integer
Maybe Text
Text
apiId :: Text
description :: Maybe Text
expires :: Maybe Integer
$sel:apiId:CreateApiKey' :: CreateApiKey -> Text
$sel:description:CreateApiKey' :: CreateApiKey -> Maybe Text
$sel:expires:CreateApiKey' :: CreateApiKey -> Maybe Integer
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/v1/apis/", Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
apiId, ByteString
"/apikeys"]

instance Core.ToQuery CreateApiKey where
  toQuery :: CreateApiKey -> QueryString
toQuery = QueryString -> CreateApiKey -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newCreateApiKeyResponse' smart constructor.
data CreateApiKeyResponse = CreateApiKeyResponse'
  { -- | The API key.
    CreateApiKeyResponse -> Maybe ApiKey
apiKey :: Prelude.Maybe ApiKey,
    -- | The response's http status code.
    CreateApiKeyResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CreateApiKeyResponse -> CreateApiKeyResponse -> Bool
(CreateApiKeyResponse -> CreateApiKeyResponse -> Bool)
-> (CreateApiKeyResponse -> CreateApiKeyResponse -> Bool)
-> Eq CreateApiKeyResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateApiKeyResponse -> CreateApiKeyResponse -> Bool
$c/= :: CreateApiKeyResponse -> CreateApiKeyResponse -> Bool
== :: CreateApiKeyResponse -> CreateApiKeyResponse -> Bool
$c== :: CreateApiKeyResponse -> CreateApiKeyResponse -> Bool
Prelude.Eq, ReadPrec [CreateApiKeyResponse]
ReadPrec CreateApiKeyResponse
Int -> ReadS CreateApiKeyResponse
ReadS [CreateApiKeyResponse]
(Int -> ReadS CreateApiKeyResponse)
-> ReadS [CreateApiKeyResponse]
-> ReadPrec CreateApiKeyResponse
-> ReadPrec [CreateApiKeyResponse]
-> Read CreateApiKeyResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateApiKeyResponse]
$creadListPrec :: ReadPrec [CreateApiKeyResponse]
readPrec :: ReadPrec CreateApiKeyResponse
$creadPrec :: ReadPrec CreateApiKeyResponse
readList :: ReadS [CreateApiKeyResponse]
$creadList :: ReadS [CreateApiKeyResponse]
readsPrec :: Int -> ReadS CreateApiKeyResponse
$creadsPrec :: Int -> ReadS CreateApiKeyResponse
Prelude.Read, Int -> CreateApiKeyResponse -> ShowS
[CreateApiKeyResponse] -> ShowS
CreateApiKeyResponse -> String
(Int -> CreateApiKeyResponse -> ShowS)
-> (CreateApiKeyResponse -> String)
-> ([CreateApiKeyResponse] -> ShowS)
-> Show CreateApiKeyResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateApiKeyResponse] -> ShowS
$cshowList :: [CreateApiKeyResponse] -> ShowS
show :: CreateApiKeyResponse -> String
$cshow :: CreateApiKeyResponse -> String
showsPrec :: Int -> CreateApiKeyResponse -> ShowS
$cshowsPrec :: Int -> CreateApiKeyResponse -> ShowS
Prelude.Show, (forall x. CreateApiKeyResponse -> Rep CreateApiKeyResponse x)
-> (forall x. Rep CreateApiKeyResponse x -> CreateApiKeyResponse)
-> Generic CreateApiKeyResponse
forall x. Rep CreateApiKeyResponse x -> CreateApiKeyResponse
forall x. CreateApiKeyResponse -> Rep CreateApiKeyResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateApiKeyResponse x -> CreateApiKeyResponse
$cfrom :: forall x. CreateApiKeyResponse -> Rep CreateApiKeyResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateApiKeyResponse' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'apiKey', 'createApiKeyResponse_apiKey' - The API key.
--
-- 'httpStatus', 'createApiKeyResponse_httpStatus' - The response's http status code.
newCreateApiKeyResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateApiKeyResponse
newCreateApiKeyResponse :: Int -> CreateApiKeyResponse
newCreateApiKeyResponse Int
pHttpStatus_ =
  CreateApiKeyResponse' :: Maybe ApiKey -> Int -> CreateApiKeyResponse
CreateApiKeyResponse'
    { $sel:apiKey:CreateApiKeyResponse' :: Maybe ApiKey
apiKey = Maybe ApiKey
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateApiKeyResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The API key.
createApiKeyResponse_apiKey :: Lens.Lens' CreateApiKeyResponse (Prelude.Maybe ApiKey)
createApiKeyResponse_apiKey :: (Maybe ApiKey -> f (Maybe ApiKey))
-> CreateApiKeyResponse -> f CreateApiKeyResponse
createApiKeyResponse_apiKey = (CreateApiKeyResponse -> Maybe ApiKey)
-> (CreateApiKeyResponse -> Maybe ApiKey -> CreateApiKeyResponse)
-> Lens
     CreateApiKeyResponse
     CreateApiKeyResponse
     (Maybe ApiKey)
     (Maybe ApiKey)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateApiKeyResponse' {Maybe ApiKey
apiKey :: Maybe ApiKey
$sel:apiKey:CreateApiKeyResponse' :: CreateApiKeyResponse -> Maybe ApiKey
apiKey} -> Maybe ApiKey
apiKey) (\s :: CreateApiKeyResponse
s@CreateApiKeyResponse' {} Maybe ApiKey
a -> CreateApiKeyResponse
s {$sel:apiKey:CreateApiKeyResponse' :: Maybe ApiKey
apiKey = Maybe ApiKey
a} :: CreateApiKeyResponse)

-- | The response's http status code.
createApiKeyResponse_httpStatus :: Lens.Lens' CreateApiKeyResponse Prelude.Int
createApiKeyResponse_httpStatus :: (Int -> f Int) -> CreateApiKeyResponse -> f CreateApiKeyResponse
createApiKeyResponse_httpStatus = (CreateApiKeyResponse -> Int)
-> (CreateApiKeyResponse -> Int -> CreateApiKeyResponse)
-> Lens CreateApiKeyResponse CreateApiKeyResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateApiKeyResponse' {Int
httpStatus :: Int
$sel:httpStatus:CreateApiKeyResponse' :: CreateApiKeyResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: CreateApiKeyResponse
s@CreateApiKeyResponse' {} Int
a -> CreateApiKeyResponse
s {$sel:httpStatus:CreateApiKeyResponse' :: Int
httpStatus = Int
a} :: CreateApiKeyResponse)

instance Prelude.NFData CreateApiKeyResponse