{-# 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.Wisdom.GetContent
-- 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)
--
-- Retrieves content, including a pre-signed URL to download the content.
module Amazonka.Wisdom.GetContent
  ( -- * Creating a Request
    GetContent (..),
    newGetContent,

    -- * Request Lenses
    getContent_contentId,
    getContent_knowledgeBaseId,

    -- * Destructuring the Response
    GetContentResponse (..),
    newGetContentResponse,

    -- * Response Lenses
    getContentResponse_content,
    getContentResponse_httpStatus,
  )
where

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
import Amazonka.Wisdom.Types

-- | /See:/ 'newGetContent' smart constructor.
data GetContent = GetContent'
  { -- | The identifier of the content. Can be either the ID or the ARN. URLs
    -- cannot contain the ARN.
    GetContent -> Text
contentId :: Prelude.Text,
    -- | The the identifier of the knowledge base. Can be either the ID or the
    -- ARN. URLs cannot contain the ARN.
    GetContent -> Text
knowledgeBaseId :: Prelude.Text
  }
  deriving (GetContent -> GetContent -> Bool
(GetContent -> GetContent -> Bool)
-> (GetContent -> GetContent -> Bool) -> Eq GetContent
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetContent -> GetContent -> Bool
$c/= :: GetContent -> GetContent -> Bool
== :: GetContent -> GetContent -> Bool
$c== :: GetContent -> GetContent -> Bool
Prelude.Eq, ReadPrec [GetContent]
ReadPrec GetContent
Int -> ReadS GetContent
ReadS [GetContent]
(Int -> ReadS GetContent)
-> ReadS [GetContent]
-> ReadPrec GetContent
-> ReadPrec [GetContent]
-> Read GetContent
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetContent]
$creadListPrec :: ReadPrec [GetContent]
readPrec :: ReadPrec GetContent
$creadPrec :: ReadPrec GetContent
readList :: ReadS [GetContent]
$creadList :: ReadS [GetContent]
readsPrec :: Int -> ReadS GetContent
$creadsPrec :: Int -> ReadS GetContent
Prelude.Read, Int -> GetContent -> ShowS
[GetContent] -> ShowS
GetContent -> String
(Int -> GetContent -> ShowS)
-> (GetContent -> String)
-> ([GetContent] -> ShowS)
-> Show GetContent
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetContent] -> ShowS
$cshowList :: [GetContent] -> ShowS
show :: GetContent -> String
$cshow :: GetContent -> String
showsPrec :: Int -> GetContent -> ShowS
$cshowsPrec :: Int -> GetContent -> ShowS
Prelude.Show, (forall x. GetContent -> Rep GetContent x)
-> (forall x. Rep GetContent x -> GetContent) -> Generic GetContent
forall x. Rep GetContent x -> GetContent
forall x. GetContent -> Rep GetContent x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetContent x -> GetContent
$cfrom :: forall x. GetContent -> Rep GetContent x
Prelude.Generic)

-- |
-- Create a value of 'GetContent' 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:
--
-- 'contentId', 'getContent_contentId' - The identifier of the content. Can be either the ID or the ARN. URLs
-- cannot contain the ARN.
--
-- 'knowledgeBaseId', 'getContent_knowledgeBaseId' - The the identifier of the knowledge base. Can be either the ID or the
-- ARN. URLs cannot contain the ARN.
newGetContent ::
  -- | 'contentId'
  Prelude.Text ->
  -- | 'knowledgeBaseId'
  Prelude.Text ->
  GetContent
newGetContent :: Text -> Text -> GetContent
newGetContent Text
pContentId_ Text
pKnowledgeBaseId_ =
  GetContent' :: Text -> Text -> GetContent
GetContent'
    { $sel:contentId:GetContent' :: Text
contentId = Text
pContentId_,
      $sel:knowledgeBaseId:GetContent' :: Text
knowledgeBaseId = Text
pKnowledgeBaseId_
    }

-- | The identifier of the content. Can be either the ID or the ARN. URLs
-- cannot contain the ARN.
getContent_contentId :: Lens.Lens' GetContent Prelude.Text
getContent_contentId :: (Text -> f Text) -> GetContent -> f GetContent
getContent_contentId = (GetContent -> Text)
-> (GetContent -> Text -> GetContent)
-> Lens GetContent GetContent Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetContent' {Text
contentId :: Text
$sel:contentId:GetContent' :: GetContent -> Text
contentId} -> Text
contentId) (\s :: GetContent
s@GetContent' {} Text
a -> GetContent
s {$sel:contentId:GetContent' :: Text
contentId = Text
a} :: GetContent)

-- | The the identifier of the knowledge base. Can be either the ID or the
-- ARN. URLs cannot contain the ARN.
getContent_knowledgeBaseId :: Lens.Lens' GetContent Prelude.Text
getContent_knowledgeBaseId :: (Text -> f Text) -> GetContent -> f GetContent
getContent_knowledgeBaseId = (GetContent -> Text)
-> (GetContent -> Text -> GetContent)
-> Lens GetContent GetContent Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetContent' {Text
knowledgeBaseId :: Text
$sel:knowledgeBaseId:GetContent' :: GetContent -> Text
knowledgeBaseId} -> Text
knowledgeBaseId) (\s :: GetContent
s@GetContent' {} Text
a -> GetContent
s {$sel:knowledgeBaseId:GetContent' :: Text
knowledgeBaseId = Text
a} :: GetContent)

instance Core.AWSRequest GetContent where
  type AWSResponse GetContent = GetContentResponse
  request :: GetContent -> Request GetContent
request = Service -> GetContent -> Request GetContent
forall a. ToRequest a => Service -> a -> Request a
Request.get Service
defaultService
  response :: Logger
-> Service
-> Proxy GetContent
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetContent)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetContent))
-> Logger
-> Service
-> Proxy GetContent
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetContent)))
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 ContentData -> Int -> GetContentResponse
GetContentResponse'
            (Maybe ContentData -> Int -> GetContentResponse)
-> Either String (Maybe ContentData)
-> Either String (Int -> GetContentResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe ContentData)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"content")
            Either String (Int -> GetContentResponse)
-> Either String Int -> Either String GetContentResponse
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 GetContent

instance Prelude.NFData GetContent

instance Core.ToHeaders GetContent where
  toHeaders :: GetContent -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetContent -> 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.ToPath GetContent where
  toPath :: GetContent -> ByteString
toPath GetContent' {Text
knowledgeBaseId :: Text
contentId :: Text
$sel:knowledgeBaseId:GetContent' :: GetContent -> Text
$sel:contentId:GetContent' :: GetContent -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/knowledgeBases/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
knowledgeBaseId,
        ByteString
"/contents/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
contentId
      ]

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

-- | /See:/ 'newGetContentResponse' smart constructor.
data GetContentResponse = GetContentResponse'
  { -- | The content.
    GetContentResponse -> Maybe ContentData
content :: Prelude.Maybe ContentData,
    -- | The response's http status code.
    GetContentResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetContentResponse -> GetContentResponse -> Bool
(GetContentResponse -> GetContentResponse -> Bool)
-> (GetContentResponse -> GetContentResponse -> Bool)
-> Eq GetContentResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetContentResponse -> GetContentResponse -> Bool
$c/= :: GetContentResponse -> GetContentResponse -> Bool
== :: GetContentResponse -> GetContentResponse -> Bool
$c== :: GetContentResponse -> GetContentResponse -> Bool
Prelude.Eq, Int -> GetContentResponse -> ShowS
[GetContentResponse] -> ShowS
GetContentResponse -> String
(Int -> GetContentResponse -> ShowS)
-> (GetContentResponse -> String)
-> ([GetContentResponse] -> ShowS)
-> Show GetContentResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetContentResponse] -> ShowS
$cshowList :: [GetContentResponse] -> ShowS
show :: GetContentResponse -> String
$cshow :: GetContentResponse -> String
showsPrec :: Int -> GetContentResponse -> ShowS
$cshowsPrec :: Int -> GetContentResponse -> ShowS
Prelude.Show, (forall x. GetContentResponse -> Rep GetContentResponse x)
-> (forall x. Rep GetContentResponse x -> GetContentResponse)
-> Generic GetContentResponse
forall x. Rep GetContentResponse x -> GetContentResponse
forall x. GetContentResponse -> Rep GetContentResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetContentResponse x -> GetContentResponse
$cfrom :: forall x. GetContentResponse -> Rep GetContentResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetContentResponse' 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:
--
-- 'content', 'getContentResponse_content' - The content.
--
-- 'httpStatus', 'getContentResponse_httpStatus' - The response's http status code.
newGetContentResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetContentResponse
newGetContentResponse :: Int -> GetContentResponse
newGetContentResponse Int
pHttpStatus_ =
  GetContentResponse' :: Maybe ContentData -> Int -> GetContentResponse
GetContentResponse'
    { $sel:content:GetContentResponse' :: Maybe ContentData
content = Maybe ContentData
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetContentResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The content.
getContentResponse_content :: Lens.Lens' GetContentResponse (Prelude.Maybe ContentData)
getContentResponse_content :: (Maybe ContentData -> f (Maybe ContentData))
-> GetContentResponse -> f GetContentResponse
getContentResponse_content = (GetContentResponse -> Maybe ContentData)
-> (GetContentResponse -> Maybe ContentData -> GetContentResponse)
-> Lens
     GetContentResponse
     GetContentResponse
     (Maybe ContentData)
     (Maybe ContentData)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetContentResponse' {Maybe ContentData
content :: Maybe ContentData
$sel:content:GetContentResponse' :: GetContentResponse -> Maybe ContentData
content} -> Maybe ContentData
content) (\s :: GetContentResponse
s@GetContentResponse' {} Maybe ContentData
a -> GetContentResponse
s {$sel:content:GetContentResponse' :: Maybe ContentData
content = Maybe ContentData
a} :: GetContentResponse)

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

instance Prelude.NFData GetContentResponse