{-# 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.IVS.GetStreamKey
-- 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 stream-key information for a specified ARN.
module Amazonka.IVS.GetStreamKey
  ( -- * Creating a Request
    GetStreamKey (..),
    newGetStreamKey,

    -- * Request Lenses
    getStreamKey_arn,

    -- * Destructuring the Response
    GetStreamKeyResponse (..),
    newGetStreamKeyResponse,

    -- * Response Lenses
    getStreamKeyResponse_streamKey,
    getStreamKeyResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.IVS.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

-- | /See:/ 'newGetStreamKey' smart constructor.
data GetStreamKey = GetStreamKey'
  { -- | ARN for the stream key to be retrieved.
    GetStreamKey -> Text
arn :: Prelude.Text
  }
  deriving (GetStreamKey -> GetStreamKey -> Bool
(GetStreamKey -> GetStreamKey -> Bool)
-> (GetStreamKey -> GetStreamKey -> Bool) -> Eq GetStreamKey
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetStreamKey -> GetStreamKey -> Bool
$c/= :: GetStreamKey -> GetStreamKey -> Bool
== :: GetStreamKey -> GetStreamKey -> Bool
$c== :: GetStreamKey -> GetStreamKey -> Bool
Prelude.Eq, ReadPrec [GetStreamKey]
ReadPrec GetStreamKey
Int -> ReadS GetStreamKey
ReadS [GetStreamKey]
(Int -> ReadS GetStreamKey)
-> ReadS [GetStreamKey]
-> ReadPrec GetStreamKey
-> ReadPrec [GetStreamKey]
-> Read GetStreamKey
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetStreamKey]
$creadListPrec :: ReadPrec [GetStreamKey]
readPrec :: ReadPrec GetStreamKey
$creadPrec :: ReadPrec GetStreamKey
readList :: ReadS [GetStreamKey]
$creadList :: ReadS [GetStreamKey]
readsPrec :: Int -> ReadS GetStreamKey
$creadsPrec :: Int -> ReadS GetStreamKey
Prelude.Read, Int -> GetStreamKey -> ShowS
[GetStreamKey] -> ShowS
GetStreamKey -> String
(Int -> GetStreamKey -> ShowS)
-> (GetStreamKey -> String)
-> ([GetStreamKey] -> ShowS)
-> Show GetStreamKey
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetStreamKey] -> ShowS
$cshowList :: [GetStreamKey] -> ShowS
show :: GetStreamKey -> String
$cshow :: GetStreamKey -> String
showsPrec :: Int -> GetStreamKey -> ShowS
$cshowsPrec :: Int -> GetStreamKey -> ShowS
Prelude.Show, (forall x. GetStreamKey -> Rep GetStreamKey x)
-> (forall x. Rep GetStreamKey x -> GetStreamKey)
-> Generic GetStreamKey
forall x. Rep GetStreamKey x -> GetStreamKey
forall x. GetStreamKey -> Rep GetStreamKey x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetStreamKey x -> GetStreamKey
$cfrom :: forall x. GetStreamKey -> Rep GetStreamKey x
Prelude.Generic)

-- |
-- Create a value of 'GetStreamKey' 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', 'getStreamKey_arn' - ARN for the stream key to be retrieved.
newGetStreamKey ::
  -- | 'arn'
  Prelude.Text ->
  GetStreamKey
newGetStreamKey :: Text -> GetStreamKey
newGetStreamKey Text
pArn_ = GetStreamKey' :: Text -> GetStreamKey
GetStreamKey' {$sel:arn:GetStreamKey' :: Text
arn = Text
pArn_}

-- | ARN for the stream key to be retrieved.
getStreamKey_arn :: Lens.Lens' GetStreamKey Prelude.Text
getStreamKey_arn :: (Text -> f Text) -> GetStreamKey -> f GetStreamKey
getStreamKey_arn = (GetStreamKey -> Text)
-> (GetStreamKey -> Text -> GetStreamKey)
-> Lens GetStreamKey GetStreamKey Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetStreamKey' {Text
arn :: Text
$sel:arn:GetStreamKey' :: GetStreamKey -> Text
arn} -> Text
arn) (\s :: GetStreamKey
s@GetStreamKey' {} Text
a -> GetStreamKey
s {$sel:arn:GetStreamKey' :: Text
arn = Text
a} :: GetStreamKey)

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

instance Prelude.NFData GetStreamKey

instance Core.ToHeaders GetStreamKey where
  toHeaders :: GetStreamKey -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetStreamKey -> 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.ToJSON GetStreamKey where
  toJSON :: GetStreamKey -> Value
toJSON GetStreamKey' {Text
arn :: Text
$sel:arn:GetStreamKey' :: GetStreamKey -> 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 GetStreamKey where
  toPath :: GetStreamKey -> ByteString
toPath = ByteString -> GetStreamKey -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/GetStreamKey"

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

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

-- |
-- Create a value of 'GetStreamKeyResponse' 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:
--
-- 'streamKey', 'getStreamKeyResponse_streamKey' -
--
-- 'httpStatus', 'getStreamKeyResponse_httpStatus' - The response's http status code.
newGetStreamKeyResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetStreamKeyResponse
newGetStreamKeyResponse :: Int -> GetStreamKeyResponse
newGetStreamKeyResponse Int
pHttpStatus_ =
  GetStreamKeyResponse' :: Maybe StreamKey -> Int -> GetStreamKeyResponse
GetStreamKeyResponse'
    { $sel:streamKey:GetStreamKeyResponse' :: Maybe StreamKey
streamKey = Maybe StreamKey
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetStreamKeyResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- |
getStreamKeyResponse_streamKey :: Lens.Lens' GetStreamKeyResponse (Prelude.Maybe StreamKey)
getStreamKeyResponse_streamKey :: (Maybe StreamKey -> f (Maybe StreamKey))
-> GetStreamKeyResponse -> f GetStreamKeyResponse
getStreamKeyResponse_streamKey = (GetStreamKeyResponse -> Maybe StreamKey)
-> (GetStreamKeyResponse
    -> Maybe StreamKey -> GetStreamKeyResponse)
-> Lens
     GetStreamKeyResponse
     GetStreamKeyResponse
     (Maybe StreamKey)
     (Maybe StreamKey)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetStreamKeyResponse' {Maybe StreamKey
streamKey :: Maybe StreamKey
$sel:streamKey:GetStreamKeyResponse' :: GetStreamKeyResponse -> Maybe StreamKey
streamKey} -> Maybe StreamKey
streamKey) (\s :: GetStreamKeyResponse
s@GetStreamKeyResponse' {} Maybe StreamKey
a -> GetStreamKeyResponse
s {$sel:streamKey:GetStreamKeyResponse' :: Maybe StreamKey
streamKey = Maybe StreamKey
a} :: GetStreamKeyResponse)

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

instance Prelude.NFData GetStreamKeyResponse