{-# 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.CognitoSync.BulkPublish
-- 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)
--
-- Initiates a bulk publish of all existing datasets for an Identity Pool
-- to the configured stream. Customers are limited to one successful bulk
-- publish per 24 hours. Bulk publish is an asynchronous request, customers
-- can see the status of the request via the GetBulkPublishDetails
-- operation.
--
-- This API can only be called with developer credentials. You cannot call
-- this API with the temporary user credentials provided by Cognito
-- Identity.
module Amazonka.CognitoSync.BulkPublish
  ( -- * Creating a Request
    BulkPublish (..),
    newBulkPublish,

    -- * Request Lenses
    bulkPublish_identityPoolId,

    -- * Destructuring the Response
    BulkPublishResponse (..),
    newBulkPublishResponse,

    -- * Response Lenses
    bulkPublishResponse_identityPoolId,
    bulkPublishResponse_httpStatus,
  )
where

import Amazonka.CognitoSync.Types
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

-- | The input for the BulkPublish operation.
--
-- /See:/ 'newBulkPublish' smart constructor.
data BulkPublish = BulkPublish'
  { -- | A name-spaced GUID (for example,
    -- us-east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon
    -- Cognito. GUID generation is unique within a region.
    BulkPublish -> Text
identityPoolId :: Prelude.Text
  }
  deriving (BulkPublish -> BulkPublish -> Bool
(BulkPublish -> BulkPublish -> Bool)
-> (BulkPublish -> BulkPublish -> Bool) -> Eq BulkPublish
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BulkPublish -> BulkPublish -> Bool
$c/= :: BulkPublish -> BulkPublish -> Bool
== :: BulkPublish -> BulkPublish -> Bool
$c== :: BulkPublish -> BulkPublish -> Bool
Prelude.Eq, ReadPrec [BulkPublish]
ReadPrec BulkPublish
Int -> ReadS BulkPublish
ReadS [BulkPublish]
(Int -> ReadS BulkPublish)
-> ReadS [BulkPublish]
-> ReadPrec BulkPublish
-> ReadPrec [BulkPublish]
-> Read BulkPublish
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BulkPublish]
$creadListPrec :: ReadPrec [BulkPublish]
readPrec :: ReadPrec BulkPublish
$creadPrec :: ReadPrec BulkPublish
readList :: ReadS [BulkPublish]
$creadList :: ReadS [BulkPublish]
readsPrec :: Int -> ReadS BulkPublish
$creadsPrec :: Int -> ReadS BulkPublish
Prelude.Read, Int -> BulkPublish -> ShowS
[BulkPublish] -> ShowS
BulkPublish -> String
(Int -> BulkPublish -> ShowS)
-> (BulkPublish -> String)
-> ([BulkPublish] -> ShowS)
-> Show BulkPublish
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BulkPublish] -> ShowS
$cshowList :: [BulkPublish] -> ShowS
show :: BulkPublish -> String
$cshow :: BulkPublish -> String
showsPrec :: Int -> BulkPublish -> ShowS
$cshowsPrec :: Int -> BulkPublish -> ShowS
Prelude.Show, (forall x. BulkPublish -> Rep BulkPublish x)
-> (forall x. Rep BulkPublish x -> BulkPublish)
-> Generic BulkPublish
forall x. Rep BulkPublish x -> BulkPublish
forall x. BulkPublish -> Rep BulkPublish x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BulkPublish x -> BulkPublish
$cfrom :: forall x. BulkPublish -> Rep BulkPublish x
Prelude.Generic)

-- |
-- Create a value of 'BulkPublish' 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:
--
-- 'identityPoolId', 'bulkPublish_identityPoolId' - A name-spaced GUID (for example,
-- us-east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon
-- Cognito. GUID generation is unique within a region.
newBulkPublish ::
  -- | 'identityPoolId'
  Prelude.Text ->
  BulkPublish
newBulkPublish :: Text -> BulkPublish
newBulkPublish Text
pIdentityPoolId_ =
  BulkPublish' :: Text -> BulkPublish
BulkPublish' {$sel:identityPoolId:BulkPublish' :: Text
identityPoolId = Text
pIdentityPoolId_}

-- | A name-spaced GUID (for example,
-- us-east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon
-- Cognito. GUID generation is unique within a region.
bulkPublish_identityPoolId :: Lens.Lens' BulkPublish Prelude.Text
bulkPublish_identityPoolId :: (Text -> f Text) -> BulkPublish -> f BulkPublish
bulkPublish_identityPoolId = (BulkPublish -> Text)
-> (BulkPublish -> Text -> BulkPublish)
-> Lens BulkPublish BulkPublish Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BulkPublish' {Text
identityPoolId :: Text
$sel:identityPoolId:BulkPublish' :: BulkPublish -> Text
identityPoolId} -> Text
identityPoolId) (\s :: BulkPublish
s@BulkPublish' {} Text
a -> BulkPublish
s {$sel:identityPoolId:BulkPublish' :: Text
identityPoolId = Text
a} :: BulkPublish)

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

instance Prelude.NFData BulkPublish

instance Core.ToHeaders BulkPublish where
  toHeaders :: BulkPublish -> ResponseHeaders
toHeaders =
    ResponseHeaders -> BulkPublish -> 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 BulkPublish where
  toJSON :: BulkPublish -> Value
toJSON = Value -> BulkPublish -> Value
forall a b. a -> b -> a
Prelude.const (Object -> Value
Core.Object Object
forall a. Monoid a => a
Prelude.mempty)

instance Core.ToPath BulkPublish where
  toPath :: BulkPublish -> ByteString
toPath BulkPublish' {Text
identityPoolId :: Text
$sel:identityPoolId:BulkPublish' :: BulkPublish -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/identitypools/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
identityPoolId,
        ByteString
"/bulkpublish"
      ]

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

-- | The output for the BulkPublish operation.
--
-- /See:/ 'newBulkPublishResponse' smart constructor.
data BulkPublishResponse = BulkPublishResponse'
  { -- | A name-spaced GUID (for example,
    -- us-east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon
    -- Cognito. GUID generation is unique within a region.
    BulkPublishResponse -> Maybe Text
identityPoolId :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    BulkPublishResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (BulkPublishResponse -> BulkPublishResponse -> Bool
(BulkPublishResponse -> BulkPublishResponse -> Bool)
-> (BulkPublishResponse -> BulkPublishResponse -> Bool)
-> Eq BulkPublishResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BulkPublishResponse -> BulkPublishResponse -> Bool
$c/= :: BulkPublishResponse -> BulkPublishResponse -> Bool
== :: BulkPublishResponse -> BulkPublishResponse -> Bool
$c== :: BulkPublishResponse -> BulkPublishResponse -> Bool
Prelude.Eq, ReadPrec [BulkPublishResponse]
ReadPrec BulkPublishResponse
Int -> ReadS BulkPublishResponse
ReadS [BulkPublishResponse]
(Int -> ReadS BulkPublishResponse)
-> ReadS [BulkPublishResponse]
-> ReadPrec BulkPublishResponse
-> ReadPrec [BulkPublishResponse]
-> Read BulkPublishResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BulkPublishResponse]
$creadListPrec :: ReadPrec [BulkPublishResponse]
readPrec :: ReadPrec BulkPublishResponse
$creadPrec :: ReadPrec BulkPublishResponse
readList :: ReadS [BulkPublishResponse]
$creadList :: ReadS [BulkPublishResponse]
readsPrec :: Int -> ReadS BulkPublishResponse
$creadsPrec :: Int -> ReadS BulkPublishResponse
Prelude.Read, Int -> BulkPublishResponse -> ShowS
[BulkPublishResponse] -> ShowS
BulkPublishResponse -> String
(Int -> BulkPublishResponse -> ShowS)
-> (BulkPublishResponse -> String)
-> ([BulkPublishResponse] -> ShowS)
-> Show BulkPublishResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BulkPublishResponse] -> ShowS
$cshowList :: [BulkPublishResponse] -> ShowS
show :: BulkPublishResponse -> String
$cshow :: BulkPublishResponse -> String
showsPrec :: Int -> BulkPublishResponse -> ShowS
$cshowsPrec :: Int -> BulkPublishResponse -> ShowS
Prelude.Show, (forall x. BulkPublishResponse -> Rep BulkPublishResponse x)
-> (forall x. Rep BulkPublishResponse x -> BulkPublishResponse)
-> Generic BulkPublishResponse
forall x. Rep BulkPublishResponse x -> BulkPublishResponse
forall x. BulkPublishResponse -> Rep BulkPublishResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BulkPublishResponse x -> BulkPublishResponse
$cfrom :: forall x. BulkPublishResponse -> Rep BulkPublishResponse x
Prelude.Generic)

-- |
-- Create a value of 'BulkPublishResponse' 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:
--
-- 'identityPoolId', 'bulkPublishResponse_identityPoolId' - A name-spaced GUID (for example,
-- us-east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon
-- Cognito. GUID generation is unique within a region.
--
-- 'httpStatus', 'bulkPublishResponse_httpStatus' - The response's http status code.
newBulkPublishResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  BulkPublishResponse
newBulkPublishResponse :: Int -> BulkPublishResponse
newBulkPublishResponse Int
pHttpStatus_ =
  BulkPublishResponse' :: Maybe Text -> Int -> BulkPublishResponse
BulkPublishResponse'
    { $sel:identityPoolId:BulkPublishResponse' :: Maybe Text
identityPoolId =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:BulkPublishResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A name-spaced GUID (for example,
-- us-east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon
-- Cognito. GUID generation is unique within a region.
bulkPublishResponse_identityPoolId :: Lens.Lens' BulkPublishResponse (Prelude.Maybe Prelude.Text)
bulkPublishResponse_identityPoolId :: (Maybe Text -> f (Maybe Text))
-> BulkPublishResponse -> f BulkPublishResponse
bulkPublishResponse_identityPoolId = (BulkPublishResponse -> Maybe Text)
-> (BulkPublishResponse -> Maybe Text -> BulkPublishResponse)
-> Lens
     BulkPublishResponse BulkPublishResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BulkPublishResponse' {Maybe Text
identityPoolId :: Maybe Text
$sel:identityPoolId:BulkPublishResponse' :: BulkPublishResponse -> Maybe Text
identityPoolId} -> Maybe Text
identityPoolId) (\s :: BulkPublishResponse
s@BulkPublishResponse' {} Maybe Text
a -> BulkPublishResponse
s {$sel:identityPoolId:BulkPublishResponse' :: Maybe Text
identityPoolId = Maybe Text
a} :: BulkPublishResponse)

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

instance Prelude.NFData BulkPublishResponse