{-# 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.PutMetadata
-- 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)
--
-- Inserts metadata into the active stream of the specified channel. At
-- most 5 requests per second per channel are allowed, each with a maximum
-- 1 KB payload. (If 5 TPS is not sufficient for your needs, we recommend
-- batching your data into a single PutMetadata call.) At most 155 requests
-- per second per account are allowed. Also see
-- <https://docs.aws.amazon.com/ivs/latest/userguide/metadata.html Embedding Metadata within a Video Stream>
-- in the /Amazon IVS User Guide/.
module Amazonka.IVS.PutMetadata
  ( -- * Creating a Request
    PutMetadata (..),
    newPutMetadata,

    -- * Request Lenses
    putMetadata_channelArn,
    putMetadata_metadata,

    -- * Destructuring the Response
    PutMetadataResponse (..),
    newPutMetadataResponse,
  )
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:/ 'newPutMetadata' smart constructor.
data PutMetadata = PutMetadata'
  { -- | ARN of the channel into which metadata is inserted. This channel must
    -- have an active stream.
    PutMetadata -> Text
channelArn :: Prelude.Text,
    -- | Metadata to insert into the stream. Maximum: 1 KB per request.
    PutMetadata -> Sensitive Text
metadata :: Core.Sensitive Prelude.Text
  }
  deriving (PutMetadata -> PutMetadata -> Bool
(PutMetadata -> PutMetadata -> Bool)
-> (PutMetadata -> PutMetadata -> Bool) -> Eq PutMetadata
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutMetadata -> PutMetadata -> Bool
$c/= :: PutMetadata -> PutMetadata -> Bool
== :: PutMetadata -> PutMetadata -> Bool
$c== :: PutMetadata -> PutMetadata -> Bool
Prelude.Eq, Int -> PutMetadata -> ShowS
[PutMetadata] -> ShowS
PutMetadata -> String
(Int -> PutMetadata -> ShowS)
-> (PutMetadata -> String)
-> ([PutMetadata] -> ShowS)
-> Show PutMetadata
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutMetadata] -> ShowS
$cshowList :: [PutMetadata] -> ShowS
show :: PutMetadata -> String
$cshow :: PutMetadata -> String
showsPrec :: Int -> PutMetadata -> ShowS
$cshowsPrec :: Int -> PutMetadata -> ShowS
Prelude.Show, (forall x. PutMetadata -> Rep PutMetadata x)
-> (forall x. Rep PutMetadata x -> PutMetadata)
-> Generic PutMetadata
forall x. Rep PutMetadata x -> PutMetadata
forall x. PutMetadata -> Rep PutMetadata x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutMetadata x -> PutMetadata
$cfrom :: forall x. PutMetadata -> Rep PutMetadata x
Prelude.Generic)

-- |
-- Create a value of 'PutMetadata' 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', 'putMetadata_channelArn' - ARN of the channel into which metadata is inserted. This channel must
-- have an active stream.
--
-- 'metadata', 'putMetadata_metadata' - Metadata to insert into the stream. Maximum: 1 KB per request.
newPutMetadata ::
  -- | 'channelArn'
  Prelude.Text ->
  -- | 'metadata'
  Prelude.Text ->
  PutMetadata
newPutMetadata :: Text -> Text -> PutMetadata
newPutMetadata Text
pChannelArn_ Text
pMetadata_ =
  PutMetadata' :: Text -> Sensitive Text -> PutMetadata
PutMetadata'
    { $sel:channelArn:PutMetadata' :: Text
channelArn = Text
pChannelArn_,
      $sel:metadata:PutMetadata' :: Sensitive Text
metadata = Tagged Text (Identity Text)
-> Tagged (Sensitive Text) (Identity (Sensitive Text))
forall a. Iso' (Sensitive a) a
Core._Sensitive (Tagged Text (Identity Text)
 -> Tagged (Sensitive Text) (Identity (Sensitive Text)))
-> Text -> Sensitive Text
forall t b. AReview t b -> b -> t
Lens.# Text
pMetadata_
    }

-- | ARN of the channel into which metadata is inserted. This channel must
-- have an active stream.
putMetadata_channelArn :: Lens.Lens' PutMetadata Prelude.Text
putMetadata_channelArn :: (Text -> f Text) -> PutMetadata -> f PutMetadata
putMetadata_channelArn = (PutMetadata -> Text)
-> (PutMetadata -> Text -> PutMetadata)
-> Lens PutMetadata PutMetadata Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutMetadata' {Text
channelArn :: Text
$sel:channelArn:PutMetadata' :: PutMetadata -> Text
channelArn} -> Text
channelArn) (\s :: PutMetadata
s@PutMetadata' {} Text
a -> PutMetadata
s {$sel:channelArn:PutMetadata' :: Text
channelArn = Text
a} :: PutMetadata)

-- | Metadata to insert into the stream. Maximum: 1 KB per request.
putMetadata_metadata :: Lens.Lens' PutMetadata Prelude.Text
putMetadata_metadata :: (Text -> f Text) -> PutMetadata -> f PutMetadata
putMetadata_metadata = (PutMetadata -> Sensitive Text)
-> (PutMetadata -> Sensitive Text -> PutMetadata)
-> Lens PutMetadata PutMetadata (Sensitive Text) (Sensitive Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutMetadata' {Sensitive Text
metadata :: Sensitive Text
$sel:metadata:PutMetadata' :: PutMetadata -> Sensitive Text
metadata} -> Sensitive Text
metadata) (\s :: PutMetadata
s@PutMetadata' {} Sensitive Text
a -> PutMetadata
s {$sel:metadata:PutMetadata' :: Sensitive Text
metadata = Sensitive Text
a} :: PutMetadata) ((Sensitive Text -> f (Sensitive Text))
 -> PutMetadata -> f PutMetadata)
-> ((Text -> f Text) -> Sensitive Text -> f (Sensitive Text))
-> (Text -> f Text)
-> PutMetadata
-> f PutMetadata
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (Text -> f Text) -> Sensitive Text -> f (Sensitive Text)
forall a. Iso' (Sensitive a) a
Core._Sensitive

instance Core.AWSRequest PutMetadata where
  type AWSResponse PutMetadata = PutMetadataResponse
  request :: PutMetadata -> Request PutMetadata
request = Service -> PutMetadata -> Request PutMetadata
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy PutMetadata
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse PutMetadata)))
response = AWSResponse PutMetadata
-> Logger
-> Service
-> Proxy PutMetadata
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse PutMetadata)))
forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull AWSResponse PutMetadata
PutMetadataResponse
PutMetadataResponse'

instance Prelude.Hashable PutMetadata

instance Prelude.NFData PutMetadata

instance Core.ToHeaders PutMetadata where
  toHeaders :: PutMetadata -> [Header]
toHeaders =
    [Header] -> PutMetadata -> [Header]
forall a b. a -> b -> a
Prelude.const
      ( [[Header]] -> [Header]
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              HeaderName -> ByteString -> [Header]
forall a. ToHeader a => HeaderName -> a -> [Header]
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON PutMetadata where
  toJSON :: PutMetadata -> Value
toJSON PutMetadata' {Text
Sensitive Text
metadata :: Sensitive Text
channelArn :: Text
$sel:metadata:PutMetadata' :: PutMetadata -> Sensitive Text
$sel:channelArn:PutMetadata' :: PutMetadata -> 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),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"metadata" Text -> Sensitive Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Sensitive Text
metadata)
          ]
      )

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

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

-- | /See:/ 'newPutMetadataResponse' smart constructor.
data PutMetadataResponse = PutMetadataResponse'
  {
  }
  deriving (PutMetadataResponse -> PutMetadataResponse -> Bool
(PutMetadataResponse -> PutMetadataResponse -> Bool)
-> (PutMetadataResponse -> PutMetadataResponse -> Bool)
-> Eq PutMetadataResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutMetadataResponse -> PutMetadataResponse -> Bool
$c/= :: PutMetadataResponse -> PutMetadataResponse -> Bool
== :: PutMetadataResponse -> PutMetadataResponse -> Bool
$c== :: PutMetadataResponse -> PutMetadataResponse -> Bool
Prelude.Eq, ReadPrec [PutMetadataResponse]
ReadPrec PutMetadataResponse
Int -> ReadS PutMetadataResponse
ReadS [PutMetadataResponse]
(Int -> ReadS PutMetadataResponse)
-> ReadS [PutMetadataResponse]
-> ReadPrec PutMetadataResponse
-> ReadPrec [PutMetadataResponse]
-> Read PutMetadataResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutMetadataResponse]
$creadListPrec :: ReadPrec [PutMetadataResponse]
readPrec :: ReadPrec PutMetadataResponse
$creadPrec :: ReadPrec PutMetadataResponse
readList :: ReadS [PutMetadataResponse]
$creadList :: ReadS [PutMetadataResponse]
readsPrec :: Int -> ReadS PutMetadataResponse
$creadsPrec :: Int -> ReadS PutMetadataResponse
Prelude.Read, Int -> PutMetadataResponse -> ShowS
[PutMetadataResponse] -> ShowS
PutMetadataResponse -> String
(Int -> PutMetadataResponse -> ShowS)
-> (PutMetadataResponse -> String)
-> ([PutMetadataResponse] -> ShowS)
-> Show PutMetadataResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutMetadataResponse] -> ShowS
$cshowList :: [PutMetadataResponse] -> ShowS
show :: PutMetadataResponse -> String
$cshow :: PutMetadataResponse -> String
showsPrec :: Int -> PutMetadataResponse -> ShowS
$cshowsPrec :: Int -> PutMetadataResponse -> ShowS
Prelude.Show, (forall x. PutMetadataResponse -> Rep PutMetadataResponse x)
-> (forall x. Rep PutMetadataResponse x -> PutMetadataResponse)
-> Generic PutMetadataResponse
forall x. Rep PutMetadataResponse x -> PutMetadataResponse
forall x. PutMetadataResponse -> Rep PutMetadataResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutMetadataResponse x -> PutMetadataResponse
$cfrom :: forall x. PutMetadataResponse -> Rep PutMetadataResponse x
Prelude.Generic)

-- |
-- Create a value of 'PutMetadataResponse' 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.
newPutMetadataResponse ::
  PutMetadataResponse
newPutMetadataResponse :: PutMetadataResponse
newPutMetadataResponse = PutMetadataResponse
PutMetadataResponse'

instance Prelude.NFData PutMetadataResponse