{-# 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.MechanicalTurk.GetFileUploadURL
-- 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)
--
-- The @GetFileUploadURL@ operation generates and returns a temporary URL.
-- You use the temporary URL to retrieve a file uploaded by a Worker as an
-- answer to a FileUploadAnswer question for a HIT. The temporary URL is
-- generated the instant the GetFileUploadURL operation is called, and is
-- valid for 60 seconds. You can get a temporary file upload URL any time
-- until the HIT is disposed. After the HIT is disposed, any uploaded files
-- are deleted, and cannot be retrieved. Pending Deprecation on December
-- 12, 2017. The Answer Specification structure will no longer support the
-- @FileUploadAnswer@ element to be used for the QuestionForm data
-- structure. Instead, we recommend that Requesters who want to create HITs
-- asking Workers to upload files to use Amazon S3.
module Amazonka.MechanicalTurk.GetFileUploadURL
  ( -- * Creating a Request
    GetFileUploadURL (..),
    newGetFileUploadURL,

    -- * Request Lenses
    getFileUploadURL_assignmentId,
    getFileUploadURL_questionIdentifier,

    -- * Destructuring the Response
    GetFileUploadURLResponse (..),
    newGetFileUploadURLResponse,

    -- * Response Lenses
    getFileUploadURLResponse_fileUploadURL,
    getFileUploadURLResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.MechanicalTurk.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newGetFileUploadURL' smart constructor.
data GetFileUploadURL = GetFileUploadURL'
  { -- | The ID of the assignment that contains the question with a
    -- FileUploadAnswer.
    GetFileUploadURL -> Text
assignmentId :: Prelude.Text,
    -- | The identifier of the question with a FileUploadAnswer, as specified in
    -- the QuestionForm of the HIT.
    GetFileUploadURL -> Text
questionIdentifier :: Prelude.Text
  }
  deriving (GetFileUploadURL -> GetFileUploadURL -> Bool
(GetFileUploadURL -> GetFileUploadURL -> Bool)
-> (GetFileUploadURL -> GetFileUploadURL -> Bool)
-> Eq GetFileUploadURL
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetFileUploadURL -> GetFileUploadURL -> Bool
$c/= :: GetFileUploadURL -> GetFileUploadURL -> Bool
== :: GetFileUploadURL -> GetFileUploadURL -> Bool
$c== :: GetFileUploadURL -> GetFileUploadURL -> Bool
Prelude.Eq, ReadPrec [GetFileUploadURL]
ReadPrec GetFileUploadURL
Int -> ReadS GetFileUploadURL
ReadS [GetFileUploadURL]
(Int -> ReadS GetFileUploadURL)
-> ReadS [GetFileUploadURL]
-> ReadPrec GetFileUploadURL
-> ReadPrec [GetFileUploadURL]
-> Read GetFileUploadURL
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetFileUploadURL]
$creadListPrec :: ReadPrec [GetFileUploadURL]
readPrec :: ReadPrec GetFileUploadURL
$creadPrec :: ReadPrec GetFileUploadURL
readList :: ReadS [GetFileUploadURL]
$creadList :: ReadS [GetFileUploadURL]
readsPrec :: Int -> ReadS GetFileUploadURL
$creadsPrec :: Int -> ReadS GetFileUploadURL
Prelude.Read, Int -> GetFileUploadURL -> ShowS
[GetFileUploadURL] -> ShowS
GetFileUploadURL -> String
(Int -> GetFileUploadURL -> ShowS)
-> (GetFileUploadURL -> String)
-> ([GetFileUploadURL] -> ShowS)
-> Show GetFileUploadURL
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetFileUploadURL] -> ShowS
$cshowList :: [GetFileUploadURL] -> ShowS
show :: GetFileUploadURL -> String
$cshow :: GetFileUploadURL -> String
showsPrec :: Int -> GetFileUploadURL -> ShowS
$cshowsPrec :: Int -> GetFileUploadURL -> ShowS
Prelude.Show, (forall x. GetFileUploadURL -> Rep GetFileUploadURL x)
-> (forall x. Rep GetFileUploadURL x -> GetFileUploadURL)
-> Generic GetFileUploadURL
forall x. Rep GetFileUploadURL x -> GetFileUploadURL
forall x. GetFileUploadURL -> Rep GetFileUploadURL x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetFileUploadURL x -> GetFileUploadURL
$cfrom :: forall x. GetFileUploadURL -> Rep GetFileUploadURL x
Prelude.Generic)

-- |
-- Create a value of 'GetFileUploadURL' 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:
--
-- 'assignmentId', 'getFileUploadURL_assignmentId' - The ID of the assignment that contains the question with a
-- FileUploadAnswer.
--
-- 'questionIdentifier', 'getFileUploadURL_questionIdentifier' - The identifier of the question with a FileUploadAnswer, as specified in
-- the QuestionForm of the HIT.
newGetFileUploadURL ::
  -- | 'assignmentId'
  Prelude.Text ->
  -- | 'questionIdentifier'
  Prelude.Text ->
  GetFileUploadURL
newGetFileUploadURL :: Text -> Text -> GetFileUploadURL
newGetFileUploadURL
  Text
pAssignmentId_
  Text
pQuestionIdentifier_ =
    GetFileUploadURL' :: Text -> Text -> GetFileUploadURL
GetFileUploadURL'
      { $sel:assignmentId:GetFileUploadURL' :: Text
assignmentId = Text
pAssignmentId_,
        $sel:questionIdentifier:GetFileUploadURL' :: Text
questionIdentifier = Text
pQuestionIdentifier_
      }

-- | The ID of the assignment that contains the question with a
-- FileUploadAnswer.
getFileUploadURL_assignmentId :: Lens.Lens' GetFileUploadURL Prelude.Text
getFileUploadURL_assignmentId :: (Text -> f Text) -> GetFileUploadURL -> f GetFileUploadURL
getFileUploadURL_assignmentId = (GetFileUploadURL -> Text)
-> (GetFileUploadURL -> Text -> GetFileUploadURL)
-> Lens GetFileUploadURL GetFileUploadURL Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetFileUploadURL' {Text
assignmentId :: Text
$sel:assignmentId:GetFileUploadURL' :: GetFileUploadURL -> Text
assignmentId} -> Text
assignmentId) (\s :: GetFileUploadURL
s@GetFileUploadURL' {} Text
a -> GetFileUploadURL
s {$sel:assignmentId:GetFileUploadURL' :: Text
assignmentId = Text
a} :: GetFileUploadURL)

-- | The identifier of the question with a FileUploadAnswer, as specified in
-- the QuestionForm of the HIT.
getFileUploadURL_questionIdentifier :: Lens.Lens' GetFileUploadURL Prelude.Text
getFileUploadURL_questionIdentifier :: (Text -> f Text) -> GetFileUploadURL -> f GetFileUploadURL
getFileUploadURL_questionIdentifier = (GetFileUploadURL -> Text)
-> (GetFileUploadURL -> Text -> GetFileUploadURL)
-> Lens GetFileUploadURL GetFileUploadURL Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetFileUploadURL' {Text
questionIdentifier :: Text
$sel:questionIdentifier:GetFileUploadURL' :: GetFileUploadURL -> Text
questionIdentifier} -> Text
questionIdentifier) (\s :: GetFileUploadURL
s@GetFileUploadURL' {} Text
a -> GetFileUploadURL
s {$sel:questionIdentifier:GetFileUploadURL' :: Text
questionIdentifier = Text
a} :: GetFileUploadURL)

instance Core.AWSRequest GetFileUploadURL where
  type
    AWSResponse GetFileUploadURL =
      GetFileUploadURLResponse
  request :: GetFileUploadURL -> Request GetFileUploadURL
request = Service -> GetFileUploadURL -> Request GetFileUploadURL
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy GetFileUploadURL
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetFileUploadURL)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetFileUploadURL))
-> Logger
-> Service
-> Proxy GetFileUploadURL
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetFileUploadURL)))
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 -> Int -> GetFileUploadURLResponse
GetFileUploadURLResponse'
            (Maybe Text -> Int -> GetFileUploadURLResponse)
-> Either String (Maybe Text)
-> Either String (Int -> GetFileUploadURLResponse)
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
"FileUploadURL")
            Either String (Int -> GetFileUploadURLResponse)
-> Either String Int -> Either String GetFileUploadURLResponse
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 GetFileUploadURL

instance Prelude.NFData GetFileUploadURL

instance Core.ToHeaders GetFileUploadURL where
  toHeaders :: GetFileUploadURL -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetFileUploadURL -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"MTurkRequesterServiceV20170117.GetFileUploadURL" ::
                          Prelude.ByteString
                      ),
            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 GetFileUploadURL where
  toJSON :: GetFileUploadURL -> Value
toJSON GetFileUploadURL' {Text
questionIdentifier :: Text
assignmentId :: Text
$sel:questionIdentifier:GetFileUploadURL' :: GetFileUploadURL -> Text
$sel:assignmentId:GetFileUploadURL' :: GetFileUploadURL -> 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
"AssignmentId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
assignmentId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"QuestionIdentifier" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
questionIdentifier)
          ]
      )

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

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

-- | /See:/ 'newGetFileUploadURLResponse' smart constructor.
data GetFileUploadURLResponse = GetFileUploadURLResponse'
  { -- | A temporary URL for the file that the Worker uploaded for the answer.
    GetFileUploadURLResponse -> Maybe Text
fileUploadURL :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    GetFileUploadURLResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetFileUploadURLResponse -> GetFileUploadURLResponse -> Bool
(GetFileUploadURLResponse -> GetFileUploadURLResponse -> Bool)
-> (GetFileUploadURLResponse -> GetFileUploadURLResponse -> Bool)
-> Eq GetFileUploadURLResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetFileUploadURLResponse -> GetFileUploadURLResponse -> Bool
$c/= :: GetFileUploadURLResponse -> GetFileUploadURLResponse -> Bool
== :: GetFileUploadURLResponse -> GetFileUploadURLResponse -> Bool
$c== :: GetFileUploadURLResponse -> GetFileUploadURLResponse -> Bool
Prelude.Eq, ReadPrec [GetFileUploadURLResponse]
ReadPrec GetFileUploadURLResponse
Int -> ReadS GetFileUploadURLResponse
ReadS [GetFileUploadURLResponse]
(Int -> ReadS GetFileUploadURLResponse)
-> ReadS [GetFileUploadURLResponse]
-> ReadPrec GetFileUploadURLResponse
-> ReadPrec [GetFileUploadURLResponse]
-> Read GetFileUploadURLResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetFileUploadURLResponse]
$creadListPrec :: ReadPrec [GetFileUploadURLResponse]
readPrec :: ReadPrec GetFileUploadURLResponse
$creadPrec :: ReadPrec GetFileUploadURLResponse
readList :: ReadS [GetFileUploadURLResponse]
$creadList :: ReadS [GetFileUploadURLResponse]
readsPrec :: Int -> ReadS GetFileUploadURLResponse
$creadsPrec :: Int -> ReadS GetFileUploadURLResponse
Prelude.Read, Int -> GetFileUploadURLResponse -> ShowS
[GetFileUploadURLResponse] -> ShowS
GetFileUploadURLResponse -> String
(Int -> GetFileUploadURLResponse -> ShowS)
-> (GetFileUploadURLResponse -> String)
-> ([GetFileUploadURLResponse] -> ShowS)
-> Show GetFileUploadURLResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetFileUploadURLResponse] -> ShowS
$cshowList :: [GetFileUploadURLResponse] -> ShowS
show :: GetFileUploadURLResponse -> String
$cshow :: GetFileUploadURLResponse -> String
showsPrec :: Int -> GetFileUploadURLResponse -> ShowS
$cshowsPrec :: Int -> GetFileUploadURLResponse -> ShowS
Prelude.Show, (forall x.
 GetFileUploadURLResponse -> Rep GetFileUploadURLResponse x)
-> (forall x.
    Rep GetFileUploadURLResponse x -> GetFileUploadURLResponse)
-> Generic GetFileUploadURLResponse
forall x.
Rep GetFileUploadURLResponse x -> GetFileUploadURLResponse
forall x.
GetFileUploadURLResponse -> Rep GetFileUploadURLResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetFileUploadURLResponse x -> GetFileUploadURLResponse
$cfrom :: forall x.
GetFileUploadURLResponse -> Rep GetFileUploadURLResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetFileUploadURLResponse' 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:
--
-- 'fileUploadURL', 'getFileUploadURLResponse_fileUploadURL' - A temporary URL for the file that the Worker uploaded for the answer.
--
-- 'httpStatus', 'getFileUploadURLResponse_httpStatus' - The response's http status code.
newGetFileUploadURLResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetFileUploadURLResponse
newGetFileUploadURLResponse :: Int -> GetFileUploadURLResponse
newGetFileUploadURLResponse Int
pHttpStatus_ =
  GetFileUploadURLResponse' :: Maybe Text -> Int -> GetFileUploadURLResponse
GetFileUploadURLResponse'
    { $sel:fileUploadURL:GetFileUploadURLResponse' :: Maybe Text
fileUploadURL =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetFileUploadURLResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A temporary URL for the file that the Worker uploaded for the answer.
getFileUploadURLResponse_fileUploadURL :: Lens.Lens' GetFileUploadURLResponse (Prelude.Maybe Prelude.Text)
getFileUploadURLResponse_fileUploadURL :: (Maybe Text -> f (Maybe Text))
-> GetFileUploadURLResponse -> f GetFileUploadURLResponse
getFileUploadURLResponse_fileUploadURL = (GetFileUploadURLResponse -> Maybe Text)
-> (GetFileUploadURLResponse
    -> Maybe Text -> GetFileUploadURLResponse)
-> Lens
     GetFileUploadURLResponse
     GetFileUploadURLResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetFileUploadURLResponse' {Maybe Text
fileUploadURL :: Maybe Text
$sel:fileUploadURL:GetFileUploadURLResponse' :: GetFileUploadURLResponse -> Maybe Text
fileUploadURL} -> Maybe Text
fileUploadURL) (\s :: GetFileUploadURLResponse
s@GetFileUploadURLResponse' {} Maybe Text
a -> GetFileUploadURLResponse
s {$sel:fileUploadURL:GetFileUploadURLResponse' :: Maybe Text
fileUploadURL = Maybe Text
a} :: GetFileUploadURLResponse)

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

instance Prelude.NFData GetFileUploadURLResponse