{-# 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.ConnectParticipant.GetAttachment
-- 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)
--
-- Provides a pre-signed URL for download of a completed attachment. This
-- is an asynchronous API for use with active contacts.
module Amazonka.ConnectParticipant.GetAttachment
  ( -- * Creating a Request
    GetAttachment (..),
    newGetAttachment,

    -- * Request Lenses
    getAttachment_attachmentId,
    getAttachment_connectionToken,

    -- * Destructuring the Response
    GetAttachmentResponse (..),
    newGetAttachmentResponse,

    -- * Response Lenses
    getAttachmentResponse_urlExpiry,
    getAttachmentResponse_url,
    getAttachmentResponse_httpStatus,
  )
where

import Amazonka.ConnectParticipant.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:/ 'newGetAttachment' smart constructor.
data GetAttachment = GetAttachment'
  { -- | A unique identifier for the attachment.
    GetAttachment -> Text
attachmentId :: Prelude.Text,
    -- | The authentication token associated with the participant\'s connection.
    GetAttachment -> Text
connectionToken :: Prelude.Text
  }
  deriving (GetAttachment -> GetAttachment -> Bool
(GetAttachment -> GetAttachment -> Bool)
-> (GetAttachment -> GetAttachment -> Bool) -> Eq GetAttachment
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetAttachment -> GetAttachment -> Bool
$c/= :: GetAttachment -> GetAttachment -> Bool
== :: GetAttachment -> GetAttachment -> Bool
$c== :: GetAttachment -> GetAttachment -> Bool
Prelude.Eq, ReadPrec [GetAttachment]
ReadPrec GetAttachment
Int -> ReadS GetAttachment
ReadS [GetAttachment]
(Int -> ReadS GetAttachment)
-> ReadS [GetAttachment]
-> ReadPrec GetAttachment
-> ReadPrec [GetAttachment]
-> Read GetAttachment
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetAttachment]
$creadListPrec :: ReadPrec [GetAttachment]
readPrec :: ReadPrec GetAttachment
$creadPrec :: ReadPrec GetAttachment
readList :: ReadS [GetAttachment]
$creadList :: ReadS [GetAttachment]
readsPrec :: Int -> ReadS GetAttachment
$creadsPrec :: Int -> ReadS GetAttachment
Prelude.Read, Int -> GetAttachment -> ShowS
[GetAttachment] -> ShowS
GetAttachment -> String
(Int -> GetAttachment -> ShowS)
-> (GetAttachment -> String)
-> ([GetAttachment] -> ShowS)
-> Show GetAttachment
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetAttachment] -> ShowS
$cshowList :: [GetAttachment] -> ShowS
show :: GetAttachment -> String
$cshow :: GetAttachment -> String
showsPrec :: Int -> GetAttachment -> ShowS
$cshowsPrec :: Int -> GetAttachment -> ShowS
Prelude.Show, (forall x. GetAttachment -> Rep GetAttachment x)
-> (forall x. Rep GetAttachment x -> GetAttachment)
-> Generic GetAttachment
forall x. Rep GetAttachment x -> GetAttachment
forall x. GetAttachment -> Rep GetAttachment x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetAttachment x -> GetAttachment
$cfrom :: forall x. GetAttachment -> Rep GetAttachment x
Prelude.Generic)

-- |
-- Create a value of 'GetAttachment' 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:
--
-- 'attachmentId', 'getAttachment_attachmentId' - A unique identifier for the attachment.
--
-- 'connectionToken', 'getAttachment_connectionToken' - The authentication token associated with the participant\'s connection.
newGetAttachment ::
  -- | 'attachmentId'
  Prelude.Text ->
  -- | 'connectionToken'
  Prelude.Text ->
  GetAttachment
newGetAttachment :: Text -> Text -> GetAttachment
newGetAttachment Text
pAttachmentId_ Text
pConnectionToken_ =
  GetAttachment' :: Text -> Text -> GetAttachment
GetAttachment'
    { $sel:attachmentId:GetAttachment' :: Text
attachmentId = Text
pAttachmentId_,
      $sel:connectionToken:GetAttachment' :: Text
connectionToken = Text
pConnectionToken_
    }

-- | A unique identifier for the attachment.
getAttachment_attachmentId :: Lens.Lens' GetAttachment Prelude.Text
getAttachment_attachmentId :: (Text -> f Text) -> GetAttachment -> f GetAttachment
getAttachment_attachmentId = (GetAttachment -> Text)
-> (GetAttachment -> Text -> GetAttachment)
-> Lens GetAttachment GetAttachment Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetAttachment' {Text
attachmentId :: Text
$sel:attachmentId:GetAttachment' :: GetAttachment -> Text
attachmentId} -> Text
attachmentId) (\s :: GetAttachment
s@GetAttachment' {} Text
a -> GetAttachment
s {$sel:attachmentId:GetAttachment' :: Text
attachmentId = Text
a} :: GetAttachment)

-- | The authentication token associated with the participant\'s connection.
getAttachment_connectionToken :: Lens.Lens' GetAttachment Prelude.Text
getAttachment_connectionToken :: (Text -> f Text) -> GetAttachment -> f GetAttachment
getAttachment_connectionToken = (GetAttachment -> Text)
-> (GetAttachment -> Text -> GetAttachment)
-> Lens GetAttachment GetAttachment Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetAttachment' {Text
connectionToken :: Text
$sel:connectionToken:GetAttachment' :: GetAttachment -> Text
connectionToken} -> Text
connectionToken) (\s :: GetAttachment
s@GetAttachment' {} Text
a -> GetAttachment
s {$sel:connectionToken:GetAttachment' :: Text
connectionToken = Text
a} :: GetAttachment)

instance Core.AWSRequest GetAttachment where
  type
    AWSResponse GetAttachment =
      GetAttachmentResponse
  request :: GetAttachment -> Request GetAttachment
request = Service -> GetAttachment -> Request GetAttachment
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy GetAttachment
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetAttachment)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetAttachment))
-> Logger
-> Service
-> Proxy GetAttachment
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetAttachment)))
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 Text -> Maybe Text -> Int -> GetAttachmentResponse
GetAttachmentResponse'
            (Maybe Text -> Maybe Text -> Int -> GetAttachmentResponse)
-> Either String (Maybe Text)
-> Either String (Maybe Text -> Int -> GetAttachmentResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"UrlExpiry")
            Either String (Maybe Text -> Int -> GetAttachmentResponse)
-> Either String (Maybe Text)
-> Either String (Int -> GetAttachmentResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Url")
            Either String (Int -> GetAttachmentResponse)
-> Either String Int -> Either String GetAttachmentResponse
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 GetAttachment

instance Prelude.NFData GetAttachment

instance Core.ToHeaders GetAttachment where
  toHeaders :: GetAttachment -> ResponseHeaders
toHeaders GetAttachment' {Text
connectionToken :: Text
attachmentId :: Text
$sel:connectionToken:GetAttachment' :: GetAttachment -> Text
$sel:attachmentId:GetAttachment' :: GetAttachment -> Text
..} =
    [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ HeaderName
"X-Amz-Bearer" HeaderName -> Text -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# Text
connectionToken,
        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 GetAttachment where
  toJSON :: GetAttachment -> Value
toJSON GetAttachment' {Text
connectionToken :: Text
attachmentId :: Text
$sel:connectionToken:GetAttachment' :: GetAttachment -> Text
$sel:attachmentId:GetAttachment' :: GetAttachment -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"AttachmentId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
attachmentId)]
      )

instance Core.ToPath GetAttachment where
  toPath :: GetAttachment -> ByteString
toPath = ByteString -> GetAttachment -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/participant/attachment"

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

-- | /See:/ 'newGetAttachmentResponse' smart constructor.
data GetAttachmentResponse = GetAttachmentResponse'
  { -- | The expiration time of the URL in ISO timestamp. It\'s specified in ISO
    -- 8601 format: yyyy-MM-ddThh:mm:ss.SSSZ. For example,
    -- 2019-11-08T02:41:28.172Z.
    GetAttachmentResponse -> Maybe Text
urlExpiry :: Prelude.Maybe Prelude.Text,
    -- | The pre-signed URL using which file would be downloaded from Amazon S3
    -- by the API caller.
    GetAttachmentResponse -> Maybe Text
url :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    GetAttachmentResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetAttachmentResponse -> GetAttachmentResponse -> Bool
(GetAttachmentResponse -> GetAttachmentResponse -> Bool)
-> (GetAttachmentResponse -> GetAttachmentResponse -> Bool)
-> Eq GetAttachmentResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetAttachmentResponse -> GetAttachmentResponse -> Bool
$c/= :: GetAttachmentResponse -> GetAttachmentResponse -> Bool
== :: GetAttachmentResponse -> GetAttachmentResponse -> Bool
$c== :: GetAttachmentResponse -> GetAttachmentResponse -> Bool
Prelude.Eq, ReadPrec [GetAttachmentResponse]
ReadPrec GetAttachmentResponse
Int -> ReadS GetAttachmentResponse
ReadS [GetAttachmentResponse]
(Int -> ReadS GetAttachmentResponse)
-> ReadS [GetAttachmentResponse]
-> ReadPrec GetAttachmentResponse
-> ReadPrec [GetAttachmentResponse]
-> Read GetAttachmentResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetAttachmentResponse]
$creadListPrec :: ReadPrec [GetAttachmentResponse]
readPrec :: ReadPrec GetAttachmentResponse
$creadPrec :: ReadPrec GetAttachmentResponse
readList :: ReadS [GetAttachmentResponse]
$creadList :: ReadS [GetAttachmentResponse]
readsPrec :: Int -> ReadS GetAttachmentResponse
$creadsPrec :: Int -> ReadS GetAttachmentResponse
Prelude.Read, Int -> GetAttachmentResponse -> ShowS
[GetAttachmentResponse] -> ShowS
GetAttachmentResponse -> String
(Int -> GetAttachmentResponse -> ShowS)
-> (GetAttachmentResponse -> String)
-> ([GetAttachmentResponse] -> ShowS)
-> Show GetAttachmentResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetAttachmentResponse] -> ShowS
$cshowList :: [GetAttachmentResponse] -> ShowS
show :: GetAttachmentResponse -> String
$cshow :: GetAttachmentResponse -> String
showsPrec :: Int -> GetAttachmentResponse -> ShowS
$cshowsPrec :: Int -> GetAttachmentResponse -> ShowS
Prelude.Show, (forall x. GetAttachmentResponse -> Rep GetAttachmentResponse x)
-> (forall x. Rep GetAttachmentResponse x -> GetAttachmentResponse)
-> Generic GetAttachmentResponse
forall x. Rep GetAttachmentResponse x -> GetAttachmentResponse
forall x. GetAttachmentResponse -> Rep GetAttachmentResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetAttachmentResponse x -> GetAttachmentResponse
$cfrom :: forall x. GetAttachmentResponse -> Rep GetAttachmentResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetAttachmentResponse' 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:
--
-- 'urlExpiry', 'getAttachmentResponse_urlExpiry' - The expiration time of the URL in ISO timestamp. It\'s specified in ISO
-- 8601 format: yyyy-MM-ddThh:mm:ss.SSSZ. For example,
-- 2019-11-08T02:41:28.172Z.
--
-- 'url', 'getAttachmentResponse_url' - The pre-signed URL using which file would be downloaded from Amazon S3
-- by the API caller.
--
-- 'httpStatus', 'getAttachmentResponse_httpStatus' - The response's http status code.
newGetAttachmentResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetAttachmentResponse
newGetAttachmentResponse :: Int -> GetAttachmentResponse
newGetAttachmentResponse Int
pHttpStatus_ =
  GetAttachmentResponse' :: Maybe Text -> Maybe Text -> Int -> GetAttachmentResponse
GetAttachmentResponse'
    { $sel:urlExpiry:GetAttachmentResponse' :: Maybe Text
urlExpiry = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:url:GetAttachmentResponse' :: Maybe Text
url = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetAttachmentResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The expiration time of the URL in ISO timestamp. It\'s specified in ISO
-- 8601 format: yyyy-MM-ddThh:mm:ss.SSSZ. For example,
-- 2019-11-08T02:41:28.172Z.
getAttachmentResponse_urlExpiry :: Lens.Lens' GetAttachmentResponse (Prelude.Maybe Prelude.Text)
getAttachmentResponse_urlExpiry :: (Maybe Text -> f (Maybe Text))
-> GetAttachmentResponse -> f GetAttachmentResponse
getAttachmentResponse_urlExpiry = (GetAttachmentResponse -> Maybe Text)
-> (GetAttachmentResponse -> Maybe Text -> GetAttachmentResponse)
-> Lens
     GetAttachmentResponse
     GetAttachmentResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetAttachmentResponse' {Maybe Text
urlExpiry :: Maybe Text
$sel:urlExpiry:GetAttachmentResponse' :: GetAttachmentResponse -> Maybe Text
urlExpiry} -> Maybe Text
urlExpiry) (\s :: GetAttachmentResponse
s@GetAttachmentResponse' {} Maybe Text
a -> GetAttachmentResponse
s {$sel:urlExpiry:GetAttachmentResponse' :: Maybe Text
urlExpiry = Maybe Text
a} :: GetAttachmentResponse)

-- | The pre-signed URL using which file would be downloaded from Amazon S3
-- by the API caller.
getAttachmentResponse_url :: Lens.Lens' GetAttachmentResponse (Prelude.Maybe Prelude.Text)
getAttachmentResponse_url :: (Maybe Text -> f (Maybe Text))
-> GetAttachmentResponse -> f GetAttachmentResponse
getAttachmentResponse_url = (GetAttachmentResponse -> Maybe Text)
-> (GetAttachmentResponse -> Maybe Text -> GetAttachmentResponse)
-> Lens
     GetAttachmentResponse
     GetAttachmentResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetAttachmentResponse' {Maybe Text
url :: Maybe Text
$sel:url:GetAttachmentResponse' :: GetAttachmentResponse -> Maybe Text
url} -> Maybe Text
url) (\s :: GetAttachmentResponse
s@GetAttachmentResponse' {} Maybe Text
a -> GetAttachmentResponse
s {$sel:url:GetAttachmentResponse' :: Maybe Text
url = Maybe Text
a} :: GetAttachmentResponse)

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

instance Prelude.NFData GetAttachmentResponse