{-# 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.XRay.PutTelemetryRecords
-- 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)
--
-- Used by the Amazon Web Services X-Ray daemon to upload telemetry.
module Amazonka.XRay.PutTelemetryRecords
  ( -- * Creating a Request
    PutTelemetryRecords (..),
    newPutTelemetryRecords,

    -- * Request Lenses
    putTelemetryRecords_hostname,
    putTelemetryRecords_eC2InstanceId,
    putTelemetryRecords_resourceARN,
    putTelemetryRecords_telemetryRecords,

    -- * Destructuring the Response
    PutTelemetryRecordsResponse (..),
    newPutTelemetryRecordsResponse,

    -- * Response Lenses
    putTelemetryRecordsResponse_httpStatus,
  )
where

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

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

-- |
-- Create a value of 'PutTelemetryRecords' 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:
--
-- 'hostname', 'putTelemetryRecords_hostname' -
--
-- 'eC2InstanceId', 'putTelemetryRecords_eC2InstanceId' -
--
-- 'resourceARN', 'putTelemetryRecords_resourceARN' -
--
-- 'telemetryRecords', 'putTelemetryRecords_telemetryRecords' -
newPutTelemetryRecords ::
  PutTelemetryRecords
newPutTelemetryRecords :: PutTelemetryRecords
newPutTelemetryRecords =
  PutTelemetryRecords' :: Maybe Text
-> Maybe Text
-> Maybe Text
-> [TelemetryRecord]
-> PutTelemetryRecords
PutTelemetryRecords'
    { $sel:hostname:PutTelemetryRecords' :: Maybe Text
hostname = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:eC2InstanceId:PutTelemetryRecords' :: Maybe Text
eC2InstanceId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:resourceARN:PutTelemetryRecords' :: Maybe Text
resourceARN = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:telemetryRecords:PutTelemetryRecords' :: [TelemetryRecord]
telemetryRecords = [TelemetryRecord]
forall a. Monoid a => a
Prelude.mempty
    }

-- |
putTelemetryRecords_hostname :: Lens.Lens' PutTelemetryRecords (Prelude.Maybe Prelude.Text)
putTelemetryRecords_hostname :: (Maybe Text -> f (Maybe Text))
-> PutTelemetryRecords -> f PutTelemetryRecords
putTelemetryRecords_hostname = (PutTelemetryRecords -> Maybe Text)
-> (PutTelemetryRecords -> Maybe Text -> PutTelemetryRecords)
-> Lens
     PutTelemetryRecords PutTelemetryRecords (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutTelemetryRecords' {Maybe Text
hostname :: Maybe Text
$sel:hostname:PutTelemetryRecords' :: PutTelemetryRecords -> Maybe Text
hostname} -> Maybe Text
hostname) (\s :: PutTelemetryRecords
s@PutTelemetryRecords' {} Maybe Text
a -> PutTelemetryRecords
s {$sel:hostname:PutTelemetryRecords' :: Maybe Text
hostname = Maybe Text
a} :: PutTelemetryRecords)

-- |
putTelemetryRecords_eC2InstanceId :: Lens.Lens' PutTelemetryRecords (Prelude.Maybe Prelude.Text)
putTelemetryRecords_eC2InstanceId :: (Maybe Text -> f (Maybe Text))
-> PutTelemetryRecords -> f PutTelemetryRecords
putTelemetryRecords_eC2InstanceId = (PutTelemetryRecords -> Maybe Text)
-> (PutTelemetryRecords -> Maybe Text -> PutTelemetryRecords)
-> Lens
     PutTelemetryRecords PutTelemetryRecords (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutTelemetryRecords' {Maybe Text
eC2InstanceId :: Maybe Text
$sel:eC2InstanceId:PutTelemetryRecords' :: PutTelemetryRecords -> Maybe Text
eC2InstanceId} -> Maybe Text
eC2InstanceId) (\s :: PutTelemetryRecords
s@PutTelemetryRecords' {} Maybe Text
a -> PutTelemetryRecords
s {$sel:eC2InstanceId:PutTelemetryRecords' :: Maybe Text
eC2InstanceId = Maybe Text
a} :: PutTelemetryRecords)

-- |
putTelemetryRecords_resourceARN :: Lens.Lens' PutTelemetryRecords (Prelude.Maybe Prelude.Text)
putTelemetryRecords_resourceARN :: (Maybe Text -> f (Maybe Text))
-> PutTelemetryRecords -> f PutTelemetryRecords
putTelemetryRecords_resourceARN = (PutTelemetryRecords -> Maybe Text)
-> (PutTelemetryRecords -> Maybe Text -> PutTelemetryRecords)
-> Lens
     PutTelemetryRecords PutTelemetryRecords (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutTelemetryRecords' {Maybe Text
resourceARN :: Maybe Text
$sel:resourceARN:PutTelemetryRecords' :: PutTelemetryRecords -> Maybe Text
resourceARN} -> Maybe Text
resourceARN) (\s :: PutTelemetryRecords
s@PutTelemetryRecords' {} Maybe Text
a -> PutTelemetryRecords
s {$sel:resourceARN:PutTelemetryRecords' :: Maybe Text
resourceARN = Maybe Text
a} :: PutTelemetryRecords)

-- |
putTelemetryRecords_telemetryRecords :: Lens.Lens' PutTelemetryRecords [TelemetryRecord]
putTelemetryRecords_telemetryRecords :: ([TelemetryRecord] -> f [TelemetryRecord])
-> PutTelemetryRecords -> f PutTelemetryRecords
putTelemetryRecords_telemetryRecords = (PutTelemetryRecords -> [TelemetryRecord])
-> (PutTelemetryRecords
    -> [TelemetryRecord] -> PutTelemetryRecords)
-> Lens
     PutTelemetryRecords
     PutTelemetryRecords
     [TelemetryRecord]
     [TelemetryRecord]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutTelemetryRecords' {[TelemetryRecord]
telemetryRecords :: [TelemetryRecord]
$sel:telemetryRecords:PutTelemetryRecords' :: PutTelemetryRecords -> [TelemetryRecord]
telemetryRecords} -> [TelemetryRecord]
telemetryRecords) (\s :: PutTelemetryRecords
s@PutTelemetryRecords' {} [TelemetryRecord]
a -> PutTelemetryRecords
s {$sel:telemetryRecords:PutTelemetryRecords' :: [TelemetryRecord]
telemetryRecords = [TelemetryRecord]
a} :: PutTelemetryRecords) (([TelemetryRecord] -> f [TelemetryRecord])
 -> PutTelemetryRecords -> f PutTelemetryRecords)
-> (([TelemetryRecord] -> f [TelemetryRecord])
    -> [TelemetryRecord] -> f [TelemetryRecord])
-> ([TelemetryRecord] -> f [TelemetryRecord])
-> PutTelemetryRecords
-> f PutTelemetryRecords
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([TelemetryRecord] -> f [TelemetryRecord])
-> [TelemetryRecord] -> f [TelemetryRecord]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest PutTelemetryRecords where
  type
    AWSResponse PutTelemetryRecords =
      PutTelemetryRecordsResponse
  request :: PutTelemetryRecords -> Request PutTelemetryRecords
request = Service -> PutTelemetryRecords -> Request PutTelemetryRecords
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy PutTelemetryRecords
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse PutTelemetryRecords)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse PutTelemetryRecords))
-> Logger
-> Service
-> Proxy PutTelemetryRecords
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse PutTelemetryRecords)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> PutTelemetryRecordsResponse
PutTelemetryRecordsResponse'
            (Int -> PutTelemetryRecordsResponse)
-> Either String Int -> Either String PutTelemetryRecordsResponse
forall (f :: * -> *) a b. Functor 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 PutTelemetryRecords

instance Prelude.NFData PutTelemetryRecords

instance Core.ToHeaders PutTelemetryRecords where
  toHeaders :: PutTelemetryRecords -> ResponseHeaders
toHeaders = ResponseHeaders -> PutTelemetryRecords -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const ResponseHeaders
forall a. Monoid a => a
Prelude.mempty

instance Core.ToJSON PutTelemetryRecords where
  toJSON :: PutTelemetryRecords -> Value
toJSON PutTelemetryRecords' {[TelemetryRecord]
Maybe Text
telemetryRecords :: [TelemetryRecord]
resourceARN :: Maybe Text
eC2InstanceId :: Maybe Text
hostname :: Maybe Text
$sel:telemetryRecords:PutTelemetryRecords' :: PutTelemetryRecords -> [TelemetryRecord]
$sel:resourceARN:PutTelemetryRecords' :: PutTelemetryRecords -> Maybe Text
$sel:eC2InstanceId:PutTelemetryRecords' :: PutTelemetryRecords -> Maybe Text
$sel:hostname:PutTelemetryRecords' :: PutTelemetryRecords -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Hostname" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
hostname,
            (Text
"EC2InstanceId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
eC2InstanceId,
            (Text
"ResourceARN" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
resourceARN,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"TelemetryRecords" Text -> [TelemetryRecord] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [TelemetryRecord]
telemetryRecords)
          ]
      )

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

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

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

-- |
-- Create a value of 'PutTelemetryRecordsResponse' 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:
--
-- 'httpStatus', 'putTelemetryRecordsResponse_httpStatus' - The response's http status code.
newPutTelemetryRecordsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  PutTelemetryRecordsResponse
newPutTelemetryRecordsResponse :: Int -> PutTelemetryRecordsResponse
newPutTelemetryRecordsResponse Int
pHttpStatus_ =
  PutTelemetryRecordsResponse' :: Int -> PutTelemetryRecordsResponse
PutTelemetryRecordsResponse'
    { $sel:httpStatus:PutTelemetryRecordsResponse' :: Int
httpStatus =
        Int
pHttpStatus_
    }

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

instance Prelude.NFData PutTelemetryRecordsResponse