{-# 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.DeviceFarm.GetUpload
-- 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 information about an upload.
module Amazonka.DeviceFarm.GetUpload
  ( -- * Creating a Request
    GetUpload (..),
    newGetUpload,

    -- * Request Lenses
    getUpload_arn,

    -- * Destructuring the Response
    GetUploadResponse (..),
    newGetUploadResponse,

    -- * Response Lenses
    getUploadResponse_upload,
    getUploadResponse_httpStatus,
  )
where

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

-- | Represents a request to the get upload operation.
--
-- /See:/ 'newGetUpload' smart constructor.
data GetUpload = GetUpload'
  { -- | The upload\'s ARN.
    GetUpload -> Text
arn :: Prelude.Text
  }
  deriving (GetUpload -> GetUpload -> Bool
(GetUpload -> GetUpload -> Bool)
-> (GetUpload -> GetUpload -> Bool) -> Eq GetUpload
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetUpload -> GetUpload -> Bool
$c/= :: GetUpload -> GetUpload -> Bool
== :: GetUpload -> GetUpload -> Bool
$c== :: GetUpload -> GetUpload -> Bool
Prelude.Eq, ReadPrec [GetUpload]
ReadPrec GetUpload
Int -> ReadS GetUpload
ReadS [GetUpload]
(Int -> ReadS GetUpload)
-> ReadS [GetUpload]
-> ReadPrec GetUpload
-> ReadPrec [GetUpload]
-> Read GetUpload
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetUpload]
$creadListPrec :: ReadPrec [GetUpload]
readPrec :: ReadPrec GetUpload
$creadPrec :: ReadPrec GetUpload
readList :: ReadS [GetUpload]
$creadList :: ReadS [GetUpload]
readsPrec :: Int -> ReadS GetUpload
$creadsPrec :: Int -> ReadS GetUpload
Prelude.Read, Int -> GetUpload -> ShowS
[GetUpload] -> ShowS
GetUpload -> String
(Int -> GetUpload -> ShowS)
-> (GetUpload -> String)
-> ([GetUpload] -> ShowS)
-> Show GetUpload
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetUpload] -> ShowS
$cshowList :: [GetUpload] -> ShowS
show :: GetUpload -> String
$cshow :: GetUpload -> String
showsPrec :: Int -> GetUpload -> ShowS
$cshowsPrec :: Int -> GetUpload -> ShowS
Prelude.Show, (forall x. GetUpload -> Rep GetUpload x)
-> (forall x. Rep GetUpload x -> GetUpload) -> Generic GetUpload
forall x. Rep GetUpload x -> GetUpload
forall x. GetUpload -> Rep GetUpload x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetUpload x -> GetUpload
$cfrom :: forall x. GetUpload -> Rep GetUpload x
Prelude.Generic)

-- |
-- Create a value of 'GetUpload' 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:
--
-- 'arn', 'getUpload_arn' - The upload\'s ARN.
newGetUpload ::
  -- | 'arn'
  Prelude.Text ->
  GetUpload
newGetUpload :: Text -> GetUpload
newGetUpload Text
pArn_ = GetUpload' :: Text -> GetUpload
GetUpload' {$sel:arn:GetUpload' :: Text
arn = Text
pArn_}

-- | The upload\'s ARN.
getUpload_arn :: Lens.Lens' GetUpload Prelude.Text
getUpload_arn :: (Text -> f Text) -> GetUpload -> f GetUpload
getUpload_arn = (GetUpload -> Text)
-> (GetUpload -> Text -> GetUpload)
-> Lens GetUpload GetUpload Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetUpload' {Text
arn :: Text
$sel:arn:GetUpload' :: GetUpload -> Text
arn} -> Text
arn) (\s :: GetUpload
s@GetUpload' {} Text
a -> GetUpload
s {$sel:arn:GetUpload' :: Text
arn = Text
a} :: GetUpload)

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

instance Prelude.NFData GetUpload

instance Core.ToHeaders GetUpload where
  toHeaders :: GetUpload -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetUpload -> 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
"DeviceFarm_20150623.GetUpload" ::
                          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 GetUpload where
  toJSON :: GetUpload -> Value
toJSON GetUpload' {Text
arn :: Text
$sel:arn:GetUpload' :: GetUpload -> 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
"arn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
arn)]
      )

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

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

-- | Represents the result of a get upload request.
--
-- /See:/ 'newGetUploadResponse' smart constructor.
data GetUploadResponse = GetUploadResponse'
  { -- | An app or a set of one or more tests to upload or that have been
    -- uploaded.
    GetUploadResponse -> Maybe Upload
upload :: Prelude.Maybe Upload,
    -- | The response's http status code.
    GetUploadResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetUploadResponse -> GetUploadResponse -> Bool
(GetUploadResponse -> GetUploadResponse -> Bool)
-> (GetUploadResponse -> GetUploadResponse -> Bool)
-> Eq GetUploadResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetUploadResponse -> GetUploadResponse -> Bool
$c/= :: GetUploadResponse -> GetUploadResponse -> Bool
== :: GetUploadResponse -> GetUploadResponse -> Bool
$c== :: GetUploadResponse -> GetUploadResponse -> Bool
Prelude.Eq, Int -> GetUploadResponse -> ShowS
[GetUploadResponse] -> ShowS
GetUploadResponse -> String
(Int -> GetUploadResponse -> ShowS)
-> (GetUploadResponse -> String)
-> ([GetUploadResponse] -> ShowS)
-> Show GetUploadResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetUploadResponse] -> ShowS
$cshowList :: [GetUploadResponse] -> ShowS
show :: GetUploadResponse -> String
$cshow :: GetUploadResponse -> String
showsPrec :: Int -> GetUploadResponse -> ShowS
$cshowsPrec :: Int -> GetUploadResponse -> ShowS
Prelude.Show, (forall x. GetUploadResponse -> Rep GetUploadResponse x)
-> (forall x. Rep GetUploadResponse x -> GetUploadResponse)
-> Generic GetUploadResponse
forall x. Rep GetUploadResponse x -> GetUploadResponse
forall x. GetUploadResponse -> Rep GetUploadResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetUploadResponse x -> GetUploadResponse
$cfrom :: forall x. GetUploadResponse -> Rep GetUploadResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetUploadResponse' 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:
--
-- 'upload', 'getUploadResponse_upload' - An app or a set of one or more tests to upload or that have been
-- uploaded.
--
-- 'httpStatus', 'getUploadResponse_httpStatus' - The response's http status code.
newGetUploadResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetUploadResponse
newGetUploadResponse :: Int -> GetUploadResponse
newGetUploadResponse Int
pHttpStatus_ =
  GetUploadResponse' :: Maybe Upload -> Int -> GetUploadResponse
GetUploadResponse'
    { $sel:upload:GetUploadResponse' :: Maybe Upload
upload = Maybe Upload
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetUploadResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | An app or a set of one or more tests to upload or that have been
-- uploaded.
getUploadResponse_upload :: Lens.Lens' GetUploadResponse (Prelude.Maybe Upload)
getUploadResponse_upload :: (Maybe Upload -> f (Maybe Upload))
-> GetUploadResponse -> f GetUploadResponse
getUploadResponse_upload = (GetUploadResponse -> Maybe Upload)
-> (GetUploadResponse -> Maybe Upload -> GetUploadResponse)
-> Lens
     GetUploadResponse GetUploadResponse (Maybe Upload) (Maybe Upload)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetUploadResponse' {Maybe Upload
upload :: Maybe Upload
$sel:upload:GetUploadResponse' :: GetUploadResponse -> Maybe Upload
upload} -> Maybe Upload
upload) (\s :: GetUploadResponse
s@GetUploadResponse' {} Maybe Upload
a -> GetUploadResponse
s {$sel:upload:GetUploadResponse' :: Maybe Upload
upload = Maybe Upload
a} :: GetUploadResponse)

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

instance Prelude.NFData GetUploadResponse