{-# 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.GetStream
-- 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 the active (live) stream on a specified channel.
module Amazonka.IVS.GetStream
  ( -- * Creating a Request
    GetStream (..),
    newGetStream,

    -- * Request Lenses
    getStream_channelArn,

    -- * Destructuring the Response
    GetStreamResponse (..),
    newGetStreamResponse,

    -- * Response Lenses
    getStreamResponse_stream,
    getStreamResponse_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:/ 'newGetStream' smart constructor.
data GetStream = GetStream'
  { -- | Channel ARN for stream to be accessed.
    GetStream -> Text
channelArn :: Prelude.Text
  }
  deriving (GetStream -> GetStream -> Bool
(GetStream -> GetStream -> Bool)
-> (GetStream -> GetStream -> Bool) -> Eq GetStream
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetStream -> GetStream -> Bool
$c/= :: GetStream -> GetStream -> Bool
== :: GetStream -> GetStream -> Bool
$c== :: GetStream -> GetStream -> Bool
Prelude.Eq, ReadPrec [GetStream]
ReadPrec GetStream
Int -> ReadS GetStream
ReadS [GetStream]
(Int -> ReadS GetStream)
-> ReadS [GetStream]
-> ReadPrec GetStream
-> ReadPrec [GetStream]
-> Read GetStream
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetStream]
$creadListPrec :: ReadPrec [GetStream]
readPrec :: ReadPrec GetStream
$creadPrec :: ReadPrec GetStream
readList :: ReadS [GetStream]
$creadList :: ReadS [GetStream]
readsPrec :: Int -> ReadS GetStream
$creadsPrec :: Int -> ReadS GetStream
Prelude.Read, Int -> GetStream -> ShowS
[GetStream] -> ShowS
GetStream -> String
(Int -> GetStream -> ShowS)
-> (GetStream -> String)
-> ([GetStream] -> ShowS)
-> Show GetStream
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetStream] -> ShowS
$cshowList :: [GetStream] -> ShowS
show :: GetStream -> String
$cshow :: GetStream -> String
showsPrec :: Int -> GetStream -> ShowS
$cshowsPrec :: Int -> GetStream -> ShowS
Prelude.Show, (forall x. GetStream -> Rep GetStream x)
-> (forall x. Rep GetStream x -> GetStream) -> Generic GetStream
forall x. Rep GetStream x -> GetStream
forall x. GetStream -> Rep GetStream x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetStream x -> GetStream
$cfrom :: forall x. GetStream -> Rep GetStream x
Prelude.Generic)

-- |
-- Create a value of 'GetStream' 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:
--
-- 'channelArn', 'getStream_channelArn' - Channel ARN for stream to be accessed.
newGetStream ::
  -- | 'channelArn'
  Prelude.Text ->
  GetStream
newGetStream :: Text -> GetStream
newGetStream Text
pChannelArn_ =
  GetStream' :: Text -> GetStream
GetStream' {$sel:channelArn:GetStream' :: Text
channelArn = Text
pChannelArn_}

-- | Channel ARN for stream to be accessed.
getStream_channelArn :: Lens.Lens' GetStream Prelude.Text
getStream_channelArn :: (Text -> f Text) -> GetStream -> f GetStream
getStream_channelArn = (GetStream -> Text)
-> (GetStream -> Text -> GetStream)
-> Lens GetStream GetStream Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetStream' {Text
channelArn :: Text
$sel:channelArn:GetStream' :: GetStream -> Text
channelArn} -> Text
channelArn) (\s :: GetStream
s@GetStream' {} Text
a -> GetStream
s {$sel:channelArn:GetStream' :: Text
channelArn = Text
a} :: GetStream)

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

instance Prelude.NFData GetStream

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

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

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

-- | /See:/ 'newGetStreamResponse' smart constructor.
data GetStreamResponse = GetStreamResponse'
  { GetStreamResponse -> Maybe Stream
stream :: Prelude.Maybe Stream,
    -- | The response's http status code.
    GetStreamResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetStreamResponse -> GetStreamResponse -> Bool
(GetStreamResponse -> GetStreamResponse -> Bool)
-> (GetStreamResponse -> GetStreamResponse -> Bool)
-> Eq GetStreamResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetStreamResponse -> GetStreamResponse -> Bool
$c/= :: GetStreamResponse -> GetStreamResponse -> Bool
== :: GetStreamResponse -> GetStreamResponse -> Bool
$c== :: GetStreamResponse -> GetStreamResponse -> Bool
Prelude.Eq, ReadPrec [GetStreamResponse]
ReadPrec GetStreamResponse
Int -> ReadS GetStreamResponse
ReadS [GetStreamResponse]
(Int -> ReadS GetStreamResponse)
-> ReadS [GetStreamResponse]
-> ReadPrec GetStreamResponse
-> ReadPrec [GetStreamResponse]
-> Read GetStreamResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetStreamResponse]
$creadListPrec :: ReadPrec [GetStreamResponse]
readPrec :: ReadPrec GetStreamResponse
$creadPrec :: ReadPrec GetStreamResponse
readList :: ReadS [GetStreamResponse]
$creadList :: ReadS [GetStreamResponse]
readsPrec :: Int -> ReadS GetStreamResponse
$creadsPrec :: Int -> ReadS GetStreamResponse
Prelude.Read, Int -> GetStreamResponse -> ShowS
[GetStreamResponse] -> ShowS
GetStreamResponse -> String
(Int -> GetStreamResponse -> ShowS)
-> (GetStreamResponse -> String)
-> ([GetStreamResponse] -> ShowS)
-> Show GetStreamResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetStreamResponse] -> ShowS
$cshowList :: [GetStreamResponse] -> ShowS
show :: GetStreamResponse -> String
$cshow :: GetStreamResponse -> String
showsPrec :: Int -> GetStreamResponse -> ShowS
$cshowsPrec :: Int -> GetStreamResponse -> ShowS
Prelude.Show, (forall x. GetStreamResponse -> Rep GetStreamResponse x)
-> (forall x. Rep GetStreamResponse x -> GetStreamResponse)
-> Generic GetStreamResponse
forall x. Rep GetStreamResponse x -> GetStreamResponse
forall x. GetStreamResponse -> Rep GetStreamResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetStreamResponse x -> GetStreamResponse
$cfrom :: forall x. GetStreamResponse -> Rep GetStreamResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetStreamResponse' 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:
--
-- 'stream', 'getStreamResponse_stream' -
--
-- 'httpStatus', 'getStreamResponse_httpStatus' - The response's http status code.
newGetStreamResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetStreamResponse
newGetStreamResponse :: Int -> GetStreamResponse
newGetStreamResponse Int
pHttpStatus_ =
  GetStreamResponse' :: Maybe Stream -> Int -> GetStreamResponse
GetStreamResponse'
    { $sel:stream:GetStreamResponse' :: Maybe Stream
stream = Maybe Stream
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetStreamResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- |
getStreamResponse_stream :: Lens.Lens' GetStreamResponse (Prelude.Maybe Stream)
getStreamResponse_stream :: (Maybe Stream -> f (Maybe Stream))
-> GetStreamResponse -> f GetStreamResponse
getStreamResponse_stream = (GetStreamResponse -> Maybe Stream)
-> (GetStreamResponse -> Maybe Stream -> GetStreamResponse)
-> Lens
     GetStreamResponse GetStreamResponse (Maybe Stream) (Maybe Stream)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetStreamResponse' {Maybe Stream
stream :: Maybe Stream
$sel:stream:GetStreamResponse' :: GetStreamResponse -> Maybe Stream
stream} -> Maybe Stream
stream) (\s :: GetStreamResponse
s@GetStreamResponse' {} Maybe Stream
a -> GetStreamResponse
s {$sel:stream:GetStreamResponse' :: Maybe Stream
stream = Maybe Stream
a} :: GetStreamResponse)

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

instance Prelude.NFData GetStreamResponse