{-# 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.SES.GetSendStatistics
-- 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)
--
-- Provides sending statistics for the current AWS Region. The result is a
-- list of data points, representing the last two weeks of sending
-- activity. Each data point in the list contains statistics for a
-- 15-minute period of time.
--
-- You can execute this operation no more than once per second.
module Amazonka.SES.GetSendStatistics
  ( -- * Creating a Request
    GetSendStatistics (..),
    newGetSendStatistics,

    -- * Destructuring the Response
    GetSendStatisticsResponse (..),
    newGetSendStatisticsResponse,

    -- * Response Lenses
    getSendStatisticsResponse_sendDataPoints,
    getSendStatisticsResponse_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.SES.Types

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

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

instance Core.AWSRequest GetSendStatistics where
  type
    AWSResponse GetSendStatistics =
      GetSendStatisticsResponse
  request :: GetSendStatistics -> Request GetSendStatistics
request = Service -> GetSendStatistics -> Request GetSendStatistics
forall a. ToRequest a => Service -> a -> Request a
Request.postQuery Service
defaultService
  response :: Logger
-> Service
-> Proxy GetSendStatistics
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetSendStatistics)))
response =
    Text
-> (Int
    -> ResponseHeaders
    -> [Node]
    -> Either String (AWSResponse GetSendStatistics))
-> Logger
-> Service
-> Proxy GetSendStatistics
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetSendStatistics)))
forall (m :: * -> *) a.
MonadResource m =>
Text
-> (Int
    -> ResponseHeaders -> [Node] -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveXMLWrapper
      Text
"GetSendStatisticsResult"
      ( \Int
s ResponseHeaders
h [Node]
x ->
          Maybe [SendDataPoint] -> Int -> GetSendStatisticsResponse
GetSendStatisticsResponse'
            (Maybe [SendDataPoint] -> Int -> GetSendStatisticsResponse)
-> Either String (Maybe [SendDataPoint])
-> Either String (Int -> GetSendStatisticsResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( [Node]
x [Node] -> Text -> Either String (Maybe [Node])
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"SendDataPoints" Either String (Maybe [Node]) -> [Node] -> Either String [Node]
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ [Node]
forall a. Monoid a => a
Prelude.mempty
                            Either String [Node]
-> ([Node] -> Either String (Maybe [SendDataPoint]))
-> Either String (Maybe [SendDataPoint])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= ([Node] -> Either String [SendDataPoint])
-> [Node] -> Either String (Maybe [SendDataPoint])
forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (Text -> [Node] -> Either String [SendDataPoint]
forall a. FromXML a => Text -> [Node] -> Either String [a]
Core.parseXMLList Text
"member")
                        )
            Either String (Int -> GetSendStatisticsResponse)
-> Either String Int -> Either String GetSendStatisticsResponse
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 GetSendStatistics

instance Prelude.NFData GetSendStatistics

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

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

instance Core.ToQuery GetSendStatistics where
  toQuery :: GetSendStatistics -> QueryString
toQuery =
    QueryString -> GetSendStatistics -> QueryString
forall a b. a -> b -> a
Prelude.const
      ( [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ ByteString
"Action"
              ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"GetSendStatistics" :: Prelude.ByteString),
            ByteString
"Version"
              ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"2010-12-01" :: Prelude.ByteString)
          ]
      )

-- | Represents a list of data points. This list contains aggregated data
-- from the previous two weeks of your sending activity with Amazon SES.
--
-- /See:/ 'newGetSendStatisticsResponse' smart constructor.
data GetSendStatisticsResponse = GetSendStatisticsResponse'
  { -- | A list of data points, each of which represents 15 minutes of activity.
    GetSendStatisticsResponse -> Maybe [SendDataPoint]
sendDataPoints :: Prelude.Maybe [SendDataPoint],
    -- | The response's http status code.
    GetSendStatisticsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetSendStatisticsResponse -> GetSendStatisticsResponse -> Bool
(GetSendStatisticsResponse -> GetSendStatisticsResponse -> Bool)
-> (GetSendStatisticsResponse -> GetSendStatisticsResponse -> Bool)
-> Eq GetSendStatisticsResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetSendStatisticsResponse -> GetSendStatisticsResponse -> Bool
$c/= :: GetSendStatisticsResponse -> GetSendStatisticsResponse -> Bool
== :: GetSendStatisticsResponse -> GetSendStatisticsResponse -> Bool
$c== :: GetSendStatisticsResponse -> GetSendStatisticsResponse -> Bool
Prelude.Eq, ReadPrec [GetSendStatisticsResponse]
ReadPrec GetSendStatisticsResponse
Int -> ReadS GetSendStatisticsResponse
ReadS [GetSendStatisticsResponse]
(Int -> ReadS GetSendStatisticsResponse)
-> ReadS [GetSendStatisticsResponse]
-> ReadPrec GetSendStatisticsResponse
-> ReadPrec [GetSendStatisticsResponse]
-> Read GetSendStatisticsResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetSendStatisticsResponse]
$creadListPrec :: ReadPrec [GetSendStatisticsResponse]
readPrec :: ReadPrec GetSendStatisticsResponse
$creadPrec :: ReadPrec GetSendStatisticsResponse
readList :: ReadS [GetSendStatisticsResponse]
$creadList :: ReadS [GetSendStatisticsResponse]
readsPrec :: Int -> ReadS GetSendStatisticsResponse
$creadsPrec :: Int -> ReadS GetSendStatisticsResponse
Prelude.Read, Int -> GetSendStatisticsResponse -> ShowS
[GetSendStatisticsResponse] -> ShowS
GetSendStatisticsResponse -> String
(Int -> GetSendStatisticsResponse -> ShowS)
-> (GetSendStatisticsResponse -> String)
-> ([GetSendStatisticsResponse] -> ShowS)
-> Show GetSendStatisticsResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetSendStatisticsResponse] -> ShowS
$cshowList :: [GetSendStatisticsResponse] -> ShowS
show :: GetSendStatisticsResponse -> String
$cshow :: GetSendStatisticsResponse -> String
showsPrec :: Int -> GetSendStatisticsResponse -> ShowS
$cshowsPrec :: Int -> GetSendStatisticsResponse -> ShowS
Prelude.Show, (forall x.
 GetSendStatisticsResponse -> Rep GetSendStatisticsResponse x)
-> (forall x.
    Rep GetSendStatisticsResponse x -> GetSendStatisticsResponse)
-> Generic GetSendStatisticsResponse
forall x.
Rep GetSendStatisticsResponse x -> GetSendStatisticsResponse
forall x.
GetSendStatisticsResponse -> Rep GetSendStatisticsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetSendStatisticsResponse x -> GetSendStatisticsResponse
$cfrom :: forall x.
GetSendStatisticsResponse -> Rep GetSendStatisticsResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetSendStatisticsResponse' 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:
--
-- 'sendDataPoints', 'getSendStatisticsResponse_sendDataPoints' - A list of data points, each of which represents 15 minutes of activity.
--
-- 'httpStatus', 'getSendStatisticsResponse_httpStatus' - The response's http status code.
newGetSendStatisticsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetSendStatisticsResponse
newGetSendStatisticsResponse :: Int -> GetSendStatisticsResponse
newGetSendStatisticsResponse Int
pHttpStatus_ =
  GetSendStatisticsResponse' :: Maybe [SendDataPoint] -> Int -> GetSendStatisticsResponse
GetSendStatisticsResponse'
    { $sel:sendDataPoints:GetSendStatisticsResponse' :: Maybe [SendDataPoint]
sendDataPoints =
        Maybe [SendDataPoint]
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetSendStatisticsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A list of data points, each of which represents 15 minutes of activity.
getSendStatisticsResponse_sendDataPoints :: Lens.Lens' GetSendStatisticsResponse (Prelude.Maybe [SendDataPoint])
getSendStatisticsResponse_sendDataPoints :: (Maybe [SendDataPoint] -> f (Maybe [SendDataPoint]))
-> GetSendStatisticsResponse -> f GetSendStatisticsResponse
getSendStatisticsResponse_sendDataPoints = (GetSendStatisticsResponse -> Maybe [SendDataPoint])
-> (GetSendStatisticsResponse
    -> Maybe [SendDataPoint] -> GetSendStatisticsResponse)
-> Lens
     GetSendStatisticsResponse
     GetSendStatisticsResponse
     (Maybe [SendDataPoint])
     (Maybe [SendDataPoint])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetSendStatisticsResponse' {Maybe [SendDataPoint]
sendDataPoints :: Maybe [SendDataPoint]
$sel:sendDataPoints:GetSendStatisticsResponse' :: GetSendStatisticsResponse -> Maybe [SendDataPoint]
sendDataPoints} -> Maybe [SendDataPoint]
sendDataPoints) (\s :: GetSendStatisticsResponse
s@GetSendStatisticsResponse' {} Maybe [SendDataPoint]
a -> GetSendStatisticsResponse
s {$sel:sendDataPoints:GetSendStatisticsResponse' :: Maybe [SendDataPoint]
sendDataPoints = Maybe [SendDataPoint]
a} :: GetSendStatisticsResponse) ((Maybe [SendDataPoint] -> f (Maybe [SendDataPoint]))
 -> GetSendStatisticsResponse -> f GetSendStatisticsResponse)
-> ((Maybe [SendDataPoint] -> f (Maybe [SendDataPoint]))
    -> Maybe [SendDataPoint] -> f (Maybe [SendDataPoint]))
-> (Maybe [SendDataPoint] -> f (Maybe [SendDataPoint]))
-> GetSendStatisticsResponse
-> f GetSendStatisticsResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [SendDataPoint] [SendDataPoint] [SendDataPoint] [SendDataPoint]
-> Iso
     (Maybe [SendDataPoint])
     (Maybe [SendDataPoint])
     (Maybe [SendDataPoint])
     (Maybe [SendDataPoint])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  [SendDataPoint] [SendDataPoint] [SendDataPoint] [SendDataPoint]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.NFData GetSendStatisticsResponse