{-# 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.APIGateway.GetApiKey
-- 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)
--
-- Gets information about the current ApiKey resource.
module Amazonka.APIGateway.GetApiKey
  ( -- * Creating a Request
    GetApiKey (..),
    newGetApiKey,

    -- * Request Lenses
    getApiKey_includeValue,
    getApiKey_apiKey,

    -- * Destructuring the Response
    ApiKey (..),
    newApiKey,

    -- * Response Lenses
    apiKey_enabled,
    apiKey_value,
    apiKey_customerId,
    apiKey_createdDate,
    apiKey_name,
    apiKey_id,
    apiKey_stageKeys,
    apiKey_lastUpdatedDate,
    apiKey_description,
    apiKey_tags,
  )
where

import Amazonka.APIGateway.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

-- | A request to get information about the current ApiKey resource.
--
-- /See:/ 'newGetApiKey' smart constructor.
data GetApiKey = GetApiKey'
  { -- | A boolean flag to specify whether (@true@) or not (@false@) the result
    -- contains the key value.
    GetApiKey -> Maybe Bool
includeValue :: Prelude.Maybe Prelude.Bool,
    -- | [Required] The identifier of the ApiKey resource.
    GetApiKey -> Text
apiKey :: Prelude.Text
  }
  deriving (GetApiKey -> GetApiKey -> Bool
(GetApiKey -> GetApiKey -> Bool)
-> (GetApiKey -> GetApiKey -> Bool) -> Eq GetApiKey
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetApiKey -> GetApiKey -> Bool
$c/= :: GetApiKey -> GetApiKey -> Bool
== :: GetApiKey -> GetApiKey -> Bool
$c== :: GetApiKey -> GetApiKey -> Bool
Prelude.Eq, ReadPrec [GetApiKey]
ReadPrec GetApiKey
Int -> ReadS GetApiKey
ReadS [GetApiKey]
(Int -> ReadS GetApiKey)
-> ReadS [GetApiKey]
-> ReadPrec GetApiKey
-> ReadPrec [GetApiKey]
-> Read GetApiKey
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetApiKey]
$creadListPrec :: ReadPrec [GetApiKey]
readPrec :: ReadPrec GetApiKey
$creadPrec :: ReadPrec GetApiKey
readList :: ReadS [GetApiKey]
$creadList :: ReadS [GetApiKey]
readsPrec :: Int -> ReadS GetApiKey
$creadsPrec :: Int -> ReadS GetApiKey
Prelude.Read, Int -> GetApiKey -> ShowS
[GetApiKey] -> ShowS
GetApiKey -> String
(Int -> GetApiKey -> ShowS)
-> (GetApiKey -> String)
-> ([GetApiKey] -> ShowS)
-> Show GetApiKey
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetApiKey] -> ShowS
$cshowList :: [GetApiKey] -> ShowS
show :: GetApiKey -> String
$cshow :: GetApiKey -> String
showsPrec :: Int -> GetApiKey -> ShowS
$cshowsPrec :: Int -> GetApiKey -> ShowS
Prelude.Show, (forall x. GetApiKey -> Rep GetApiKey x)
-> (forall x. Rep GetApiKey x -> GetApiKey) -> Generic GetApiKey
forall x. Rep GetApiKey x -> GetApiKey
forall x. GetApiKey -> Rep GetApiKey x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetApiKey x -> GetApiKey
$cfrom :: forall x. GetApiKey -> Rep GetApiKey x
Prelude.Generic)

-- |
-- Create a value of 'GetApiKey' 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:
--
-- 'includeValue', 'getApiKey_includeValue' - A boolean flag to specify whether (@true@) or not (@false@) the result
-- contains the key value.
--
-- 'apiKey', 'getApiKey_apiKey' - [Required] The identifier of the ApiKey resource.
newGetApiKey ::
  -- | 'apiKey'
  Prelude.Text ->
  GetApiKey
newGetApiKey :: Text -> GetApiKey
newGetApiKey Text
pApiKey_ =
  GetApiKey' :: Maybe Bool -> Text -> GetApiKey
GetApiKey'
    { $sel:includeValue:GetApiKey' :: Maybe Bool
includeValue = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:apiKey:GetApiKey' :: Text
apiKey = Text
pApiKey_
    }

-- | A boolean flag to specify whether (@true@) or not (@false@) the result
-- contains the key value.
getApiKey_includeValue :: Lens.Lens' GetApiKey (Prelude.Maybe Prelude.Bool)
getApiKey_includeValue :: (Maybe Bool -> f (Maybe Bool)) -> GetApiKey -> f GetApiKey
getApiKey_includeValue = (GetApiKey -> Maybe Bool)
-> (GetApiKey -> Maybe Bool -> GetApiKey)
-> Lens GetApiKey GetApiKey (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetApiKey' {Maybe Bool
includeValue :: Maybe Bool
$sel:includeValue:GetApiKey' :: GetApiKey -> Maybe Bool
includeValue} -> Maybe Bool
includeValue) (\s :: GetApiKey
s@GetApiKey' {} Maybe Bool
a -> GetApiKey
s {$sel:includeValue:GetApiKey' :: Maybe Bool
includeValue = Maybe Bool
a} :: GetApiKey)

-- | [Required] The identifier of the ApiKey resource.
getApiKey_apiKey :: Lens.Lens' GetApiKey Prelude.Text
getApiKey_apiKey :: (Text -> f Text) -> GetApiKey -> f GetApiKey
getApiKey_apiKey = (GetApiKey -> Text)
-> (GetApiKey -> Text -> GetApiKey)
-> Lens GetApiKey GetApiKey Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetApiKey' {Text
apiKey :: Text
$sel:apiKey:GetApiKey' :: GetApiKey -> Text
apiKey} -> Text
apiKey) (\s :: GetApiKey
s@GetApiKey' {} Text
a -> GetApiKey
s {$sel:apiKey:GetApiKey' :: Text
apiKey = Text
a} :: GetApiKey)

instance Core.AWSRequest GetApiKey where
  type AWSResponse GetApiKey = ApiKey
  request :: GetApiKey -> Request GetApiKey
request = Service -> GetApiKey -> Request GetApiKey
forall a. ToRequest a => Service -> a -> Request a
Request.get Service
defaultService
  response :: Logger
-> Service
-> Proxy GetApiKey
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetApiKey)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetApiKey))
-> Logger
-> Service
-> Proxy GetApiKey
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetApiKey)))
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 -> Object -> Either String ApiKey
forall a. FromJSON a => Object -> Either String a
Core.eitherParseJSON Object
x)

instance Prelude.Hashable GetApiKey

instance Prelude.NFData GetApiKey

instance Core.ToHeaders GetApiKey where
  toHeaders :: GetApiKey -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetApiKey -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Accept"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# (ByteString
"application/json" :: Prelude.ByteString)
          ]
      )

instance Core.ToPath GetApiKey where
  toPath :: GetApiKey -> ByteString
toPath GetApiKey' {Maybe Bool
Text
apiKey :: Text
includeValue :: Maybe Bool
$sel:apiKey:GetApiKey' :: GetApiKey -> Text
$sel:includeValue:GetApiKey' :: GetApiKey -> Maybe Bool
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat [ByteString
"/apikeys/", Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
apiKey]

instance Core.ToQuery GetApiKey where
  toQuery :: GetApiKey -> QueryString
toQuery GetApiKey' {Maybe Bool
Text
apiKey :: Text
includeValue :: Maybe Bool
$sel:apiKey:GetApiKey' :: GetApiKey -> Text
$sel:includeValue:GetApiKey' :: GetApiKey -> Maybe Bool
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"includeValue" ByteString -> Maybe Bool -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Bool
includeValue]