{-# 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.GetResource
-- 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)
--
-- Lists information about a resource.
module Amazonka.APIGateway.GetResource
  ( -- * Creating a Request
    GetResource (..),
    newGetResource,

    -- * Request Lenses
    getResource_embed,
    getResource_restApiId,
    getResource_resourceId,

    -- * Destructuring the Response
    Resource (..),
    newResource,

    -- * Response Lenses
    resource_pathPart,
    resource_path,
    resource_id,
    resource_resourceMethods,
    resource_parentId,
  )
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

-- | Request to list information about a resource.
--
-- /See:/ 'newGetResource' smart constructor.
data GetResource = GetResource'
  { -- | A query parameter to retrieve the specified resources embedded in the
    -- returned Resource representation in the response. This @embed@ parameter
    -- value is a list of comma-separated strings. Currently, the request
    -- supports only retrieval of the embedded Method resources this way. The
    -- query parameter value must be a single-valued list and contain the
    -- @\"methods\"@ string. For example,
    -- @GET \/restapis\/{restapi_id}\/resources\/{resource_id}?embed=methods@.
    GetResource -> Maybe [Text]
embed :: Prelude.Maybe [Prelude.Text],
    -- | [Required] The string identifier of the associated RestApi.
    GetResource -> Text
restApiId :: Prelude.Text,
    -- | [Required] The identifier for the Resource resource.
    GetResource -> Text
resourceId :: Prelude.Text
  }
  deriving (GetResource -> GetResource -> Bool
(GetResource -> GetResource -> Bool)
-> (GetResource -> GetResource -> Bool) -> Eq GetResource
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetResource -> GetResource -> Bool
$c/= :: GetResource -> GetResource -> Bool
== :: GetResource -> GetResource -> Bool
$c== :: GetResource -> GetResource -> Bool
Prelude.Eq, ReadPrec [GetResource]
ReadPrec GetResource
Int -> ReadS GetResource
ReadS [GetResource]
(Int -> ReadS GetResource)
-> ReadS [GetResource]
-> ReadPrec GetResource
-> ReadPrec [GetResource]
-> Read GetResource
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetResource]
$creadListPrec :: ReadPrec [GetResource]
readPrec :: ReadPrec GetResource
$creadPrec :: ReadPrec GetResource
readList :: ReadS [GetResource]
$creadList :: ReadS [GetResource]
readsPrec :: Int -> ReadS GetResource
$creadsPrec :: Int -> ReadS GetResource
Prelude.Read, Int -> GetResource -> ShowS
[GetResource] -> ShowS
GetResource -> String
(Int -> GetResource -> ShowS)
-> (GetResource -> String)
-> ([GetResource] -> ShowS)
-> Show GetResource
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetResource] -> ShowS
$cshowList :: [GetResource] -> ShowS
show :: GetResource -> String
$cshow :: GetResource -> String
showsPrec :: Int -> GetResource -> ShowS
$cshowsPrec :: Int -> GetResource -> ShowS
Prelude.Show, (forall x. GetResource -> Rep GetResource x)
-> (forall x. Rep GetResource x -> GetResource)
-> Generic GetResource
forall x. Rep GetResource x -> GetResource
forall x. GetResource -> Rep GetResource x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetResource x -> GetResource
$cfrom :: forall x. GetResource -> Rep GetResource x
Prelude.Generic)

-- |
-- Create a value of 'GetResource' 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:
--
-- 'embed', 'getResource_embed' - A query parameter to retrieve the specified resources embedded in the
-- returned Resource representation in the response. This @embed@ parameter
-- value is a list of comma-separated strings. Currently, the request
-- supports only retrieval of the embedded Method resources this way. The
-- query parameter value must be a single-valued list and contain the
-- @\"methods\"@ string. For example,
-- @GET \/restapis\/{restapi_id}\/resources\/{resource_id}?embed=methods@.
--
-- 'restApiId', 'getResource_restApiId' - [Required] The string identifier of the associated RestApi.
--
-- 'resourceId', 'getResource_resourceId' - [Required] The identifier for the Resource resource.
newGetResource ::
  -- | 'restApiId'
  Prelude.Text ->
  -- | 'resourceId'
  Prelude.Text ->
  GetResource
newGetResource :: Text -> Text -> GetResource
newGetResource Text
pRestApiId_ Text
pResourceId_ =
  GetResource' :: Maybe [Text] -> Text -> Text -> GetResource
GetResource'
    { $sel:embed:GetResource' :: Maybe [Text]
embed = Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:restApiId:GetResource' :: Text
restApiId = Text
pRestApiId_,
      $sel:resourceId:GetResource' :: Text
resourceId = Text
pResourceId_
    }

-- | A query parameter to retrieve the specified resources embedded in the
-- returned Resource representation in the response. This @embed@ parameter
-- value is a list of comma-separated strings. Currently, the request
-- supports only retrieval of the embedded Method resources this way. The
-- query parameter value must be a single-valued list and contain the
-- @\"methods\"@ string. For example,
-- @GET \/restapis\/{restapi_id}\/resources\/{resource_id}?embed=methods@.
getResource_embed :: Lens.Lens' GetResource (Prelude.Maybe [Prelude.Text])
getResource_embed :: (Maybe [Text] -> f (Maybe [Text])) -> GetResource -> f GetResource
getResource_embed = (GetResource -> Maybe [Text])
-> (GetResource -> Maybe [Text] -> GetResource)
-> Lens GetResource GetResource (Maybe [Text]) (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetResource' {Maybe [Text]
embed :: Maybe [Text]
$sel:embed:GetResource' :: GetResource -> Maybe [Text]
embed} -> Maybe [Text]
embed) (\s :: GetResource
s@GetResource' {} Maybe [Text]
a -> GetResource
s {$sel:embed:GetResource' :: Maybe [Text]
embed = Maybe [Text]
a} :: GetResource) ((Maybe [Text] -> f (Maybe [Text]))
 -> GetResource -> f GetResource)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> GetResource
-> f GetResource
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [Text])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso [Text] [Text] [Text] [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

-- | [Required] The identifier for the Resource resource.
getResource_resourceId :: Lens.Lens' GetResource Prelude.Text
getResource_resourceId :: (Text -> f Text) -> GetResource -> f GetResource
getResource_resourceId = (GetResource -> Text)
-> (GetResource -> Text -> GetResource)
-> Lens GetResource GetResource Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetResource' {Text
resourceId :: Text
$sel:resourceId:GetResource' :: GetResource -> Text
resourceId} -> Text
resourceId) (\s :: GetResource
s@GetResource' {} Text
a -> GetResource
s {$sel:resourceId:GetResource' :: Text
resourceId = Text
a} :: GetResource)

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

instance Prelude.Hashable GetResource

instance Prelude.NFData GetResource

instance Core.ToHeaders GetResource where
  toHeaders :: GetResource -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetResource -> 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 GetResource where
  toPath :: GetResource -> ByteString
toPath GetResource' {Maybe [Text]
Text
resourceId :: Text
restApiId :: Text
embed :: Maybe [Text]
$sel:resourceId:GetResource' :: GetResource -> Text
$sel:restApiId:GetResource' :: GetResource -> Text
$sel:embed:GetResource' :: GetResource -> Maybe [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
"/resources/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
resourceId
      ]

instance Core.ToQuery GetResource where
  toQuery :: GetResource -> QueryString
toQuery GetResource' {Maybe [Text]
Text
resourceId :: Text
restApiId :: Text
embed :: Maybe [Text]
$sel:resourceId:GetResource' :: GetResource -> Text
$sel:restApiId:GetResource' :: GetResource -> Text
$sel:embed:GetResource' :: GetResource -> Maybe [Text]
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"embed"
          ByteString -> QueryString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe QueryString -> QueryString
forall a. ToQuery a => a -> QueryString
Core.toQuery
            (ByteString -> [Text] -> QueryString
forall a.
(IsList a, ToQuery (Item a)) =>
ByteString -> a -> QueryString
Core.toQueryList ByteString
"member" ([Text] -> QueryString) -> Maybe [Text] -> Maybe QueryString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Text]
embed)
      ]