{-# 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.GetGatewayResponse
-- 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 a GatewayResponse of a specified response type on the given
-- RestApi.
module Amazonka.APIGateway.GetGatewayResponse
  ( -- * Creating a Request
    GetGatewayResponse (..),
    newGetGatewayResponse,

    -- * Request Lenses
    getGatewayResponse_restApiId,
    getGatewayResponse_responseType,

    -- * Destructuring the Response
    GatewayResponse (..),
    newGatewayResponse,

    -- * Response Lenses
    gatewayResponse_defaultResponse,
    gatewayResponse_responseTemplates,
    gatewayResponse_responseType,
    gatewayResponse_statusCode,
    gatewayResponse_responseParameters,
  )
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

-- | Gets a GatewayResponse of a specified response type on the given
-- RestApi.
--
-- /See:/ 'newGetGatewayResponse' smart constructor.
data GetGatewayResponse = GetGatewayResponse'
  { -- | [Required] The string identifier of the associated RestApi.
    GetGatewayResponse -> Text
restApiId :: Prelude.Text,
    -- | [Required]
    --
    -- The response type of the associated GatewayResponse.
    GetGatewayResponse -> GatewayResponseType
responseType :: GatewayResponseType
  }
  deriving (GetGatewayResponse -> GetGatewayResponse -> Bool
(GetGatewayResponse -> GetGatewayResponse -> Bool)
-> (GetGatewayResponse -> GetGatewayResponse -> Bool)
-> Eq GetGatewayResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetGatewayResponse -> GetGatewayResponse -> Bool
$c/= :: GetGatewayResponse -> GetGatewayResponse -> Bool
== :: GetGatewayResponse -> GetGatewayResponse -> Bool
$c== :: GetGatewayResponse -> GetGatewayResponse -> Bool
Prelude.Eq, ReadPrec [GetGatewayResponse]
ReadPrec GetGatewayResponse
Int -> ReadS GetGatewayResponse
ReadS [GetGatewayResponse]
(Int -> ReadS GetGatewayResponse)
-> ReadS [GetGatewayResponse]
-> ReadPrec GetGatewayResponse
-> ReadPrec [GetGatewayResponse]
-> Read GetGatewayResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetGatewayResponse]
$creadListPrec :: ReadPrec [GetGatewayResponse]
readPrec :: ReadPrec GetGatewayResponse
$creadPrec :: ReadPrec GetGatewayResponse
readList :: ReadS [GetGatewayResponse]
$creadList :: ReadS [GetGatewayResponse]
readsPrec :: Int -> ReadS GetGatewayResponse
$creadsPrec :: Int -> ReadS GetGatewayResponse
Prelude.Read, Int -> GetGatewayResponse -> ShowS
[GetGatewayResponse] -> ShowS
GetGatewayResponse -> String
(Int -> GetGatewayResponse -> ShowS)
-> (GetGatewayResponse -> String)
-> ([GetGatewayResponse] -> ShowS)
-> Show GetGatewayResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetGatewayResponse] -> ShowS
$cshowList :: [GetGatewayResponse] -> ShowS
show :: GetGatewayResponse -> String
$cshow :: GetGatewayResponse -> String
showsPrec :: Int -> GetGatewayResponse -> ShowS
$cshowsPrec :: Int -> GetGatewayResponse -> ShowS
Prelude.Show, (forall x. GetGatewayResponse -> Rep GetGatewayResponse x)
-> (forall x. Rep GetGatewayResponse x -> GetGatewayResponse)
-> Generic GetGatewayResponse
forall x. Rep GetGatewayResponse x -> GetGatewayResponse
forall x. GetGatewayResponse -> Rep GetGatewayResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetGatewayResponse x -> GetGatewayResponse
$cfrom :: forall x. GetGatewayResponse -> Rep GetGatewayResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetGatewayResponse' 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:
--
-- 'restApiId', 'getGatewayResponse_restApiId' - [Required] The string identifier of the associated RestApi.
--
-- 'responseType', 'getGatewayResponse_responseType' - [Required]
--
-- The response type of the associated GatewayResponse.
newGetGatewayResponse ::
  -- | 'restApiId'
  Prelude.Text ->
  -- | 'responseType'
  GatewayResponseType ->
  GetGatewayResponse
newGetGatewayResponse :: Text -> GatewayResponseType -> GetGatewayResponse
newGetGatewayResponse Text
pRestApiId_ GatewayResponseType
pResponseType_ =
  GetGatewayResponse' :: Text -> GatewayResponseType -> GetGatewayResponse
GetGatewayResponse'
    { $sel:restApiId:GetGatewayResponse' :: Text
restApiId = Text
pRestApiId_,
      $sel:responseType:GetGatewayResponse' :: GatewayResponseType
responseType = GatewayResponseType
pResponseType_
    }

-- | [Required] The string identifier of the associated RestApi.
getGatewayResponse_restApiId :: Lens.Lens' GetGatewayResponse Prelude.Text
getGatewayResponse_restApiId :: (Text -> f Text) -> GetGatewayResponse -> f GetGatewayResponse
getGatewayResponse_restApiId = (GetGatewayResponse -> Text)
-> (GetGatewayResponse -> Text -> GetGatewayResponse)
-> Lens GetGatewayResponse GetGatewayResponse Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetGatewayResponse' {Text
restApiId :: Text
$sel:restApiId:GetGatewayResponse' :: GetGatewayResponse -> Text
restApiId} -> Text
restApiId) (\s :: GetGatewayResponse
s@GetGatewayResponse' {} Text
a -> GetGatewayResponse
s {$sel:restApiId:GetGatewayResponse' :: Text
restApiId = Text
a} :: GetGatewayResponse)

-- | [Required]
--
-- The response type of the associated GatewayResponse.
getGatewayResponse_responseType :: Lens.Lens' GetGatewayResponse GatewayResponseType
getGatewayResponse_responseType :: (GatewayResponseType -> f GatewayResponseType)
-> GetGatewayResponse -> f GetGatewayResponse
getGatewayResponse_responseType = (GetGatewayResponse -> GatewayResponseType)
-> (GetGatewayResponse
    -> GatewayResponseType -> GetGatewayResponse)
-> Lens
     GetGatewayResponse
     GetGatewayResponse
     GatewayResponseType
     GatewayResponseType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetGatewayResponse' {GatewayResponseType
responseType :: GatewayResponseType
$sel:responseType:GetGatewayResponse' :: GetGatewayResponse -> GatewayResponseType
responseType} -> GatewayResponseType
responseType) (\s :: GetGatewayResponse
s@GetGatewayResponse' {} GatewayResponseType
a -> GetGatewayResponse
s {$sel:responseType:GetGatewayResponse' :: GatewayResponseType
responseType = GatewayResponseType
a} :: GetGatewayResponse)

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

instance Prelude.Hashable GetGatewayResponse

instance Prelude.NFData GetGatewayResponse

instance Core.ToHeaders GetGatewayResponse where
  toHeaders :: GetGatewayResponse -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetGatewayResponse -> 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 GetGatewayResponse where
  toPath :: GetGatewayResponse -> ByteString
toPath GetGatewayResponse' {Text
GatewayResponseType
responseType :: GatewayResponseType
restApiId :: Text
$sel:responseType:GetGatewayResponse' :: GetGatewayResponse -> GatewayResponseType
$sel:restApiId:GetGatewayResponse' :: GetGatewayResponse -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/restapis/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
restApiId,
        ByteString
"/gatewayresponses/",
        GatewayResponseType -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS GatewayResponseType
responseType
      ]

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