{-# 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.DescribeDataset
-- 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 meta data about a dataset by identity and dataset name. With Amazon
-- Cognito Sync, each identity has access only to its own data. Thus, the
-- credentials used to make this API call need to have access to the
-- identity data.
--
-- This API can be called with temporary user credentials provided by
-- Cognito Identity or with developer credentials. You should use Cognito
-- Identity credentials to make this API call.
module Amazonka.CognitoSync.DescribeDataset
  ( -- * Creating a Request
    DescribeDataset (..),
    newDescribeDataset,

    -- * Request Lenses
    describeDataset_identityPoolId,
    describeDataset_identityId,
    describeDataset_datasetName,

    -- * Destructuring the Response
    DescribeDatasetResponse (..),
    newDescribeDatasetResponse,

    -- * Response Lenses
    describeDatasetResponse_dataset,
    describeDatasetResponse_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

-- | A request for meta data about a dataset (creation date, number of
-- records, size) by owner and dataset name.
--
-- /See:/ 'newDescribeDataset' smart constructor.
data DescribeDataset = DescribeDataset'
  { -- | 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.
    DescribeDataset -> Text
identityPoolId :: Prelude.Text,
    -- | 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.
    DescribeDataset -> Text
identityId :: Prelude.Text,
    -- | A string of up to 128 characters. Allowed characters are a-z, A-Z, 0-9,
    -- \'_\' (underscore), \'-\' (dash), and \'.\' (dot).
    DescribeDataset -> Text
datasetName :: Prelude.Text
  }
  deriving (DescribeDataset -> DescribeDataset -> Bool
(DescribeDataset -> DescribeDataset -> Bool)
-> (DescribeDataset -> DescribeDataset -> Bool)
-> Eq DescribeDataset
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribeDataset -> DescribeDataset -> Bool
$c/= :: DescribeDataset -> DescribeDataset -> Bool
== :: DescribeDataset -> DescribeDataset -> Bool
$c== :: DescribeDataset -> DescribeDataset -> Bool
Prelude.Eq, ReadPrec [DescribeDataset]
ReadPrec DescribeDataset
Int -> ReadS DescribeDataset
ReadS [DescribeDataset]
(Int -> ReadS DescribeDataset)
-> ReadS [DescribeDataset]
-> ReadPrec DescribeDataset
-> ReadPrec [DescribeDataset]
-> Read DescribeDataset
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DescribeDataset]
$creadListPrec :: ReadPrec [DescribeDataset]
readPrec :: ReadPrec DescribeDataset
$creadPrec :: ReadPrec DescribeDataset
readList :: ReadS [DescribeDataset]
$creadList :: ReadS [DescribeDataset]
readsPrec :: Int -> ReadS DescribeDataset
$creadsPrec :: Int -> ReadS DescribeDataset
Prelude.Read, Int -> DescribeDataset -> ShowS
[DescribeDataset] -> ShowS
DescribeDataset -> String
(Int -> DescribeDataset -> ShowS)
-> (DescribeDataset -> String)
-> ([DescribeDataset] -> ShowS)
-> Show DescribeDataset
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribeDataset] -> ShowS
$cshowList :: [DescribeDataset] -> ShowS
show :: DescribeDataset -> String
$cshow :: DescribeDataset -> String
showsPrec :: Int -> DescribeDataset -> ShowS
$cshowsPrec :: Int -> DescribeDataset -> ShowS
Prelude.Show, (forall x. DescribeDataset -> Rep DescribeDataset x)
-> (forall x. Rep DescribeDataset x -> DescribeDataset)
-> Generic DescribeDataset
forall x. Rep DescribeDataset x -> DescribeDataset
forall x. DescribeDataset -> Rep DescribeDataset x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DescribeDataset x -> DescribeDataset
$cfrom :: forall x. DescribeDataset -> Rep DescribeDataset x
Prelude.Generic)

-- |
-- Create a value of 'DescribeDataset' 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', 'describeDataset_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.
--
-- 'identityId', 'describeDataset_identityId' - 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.
--
-- 'datasetName', 'describeDataset_datasetName' - A string of up to 128 characters. Allowed characters are a-z, A-Z, 0-9,
-- \'_\' (underscore), \'-\' (dash), and \'.\' (dot).
newDescribeDataset ::
  -- | 'identityPoolId'
  Prelude.Text ->
  -- | 'identityId'
  Prelude.Text ->
  -- | 'datasetName'
  Prelude.Text ->
  DescribeDataset
newDescribeDataset :: Text -> Text -> Text -> DescribeDataset
newDescribeDataset
  Text
pIdentityPoolId_
  Text
pIdentityId_
  Text
pDatasetName_ =
    DescribeDataset' :: Text -> Text -> Text -> DescribeDataset
DescribeDataset'
      { $sel:identityPoolId:DescribeDataset' :: Text
identityPoolId = Text
pIdentityPoolId_,
        $sel:identityId:DescribeDataset' :: Text
identityId = Text
pIdentityId_,
        $sel:datasetName:DescribeDataset' :: Text
datasetName = Text
pDatasetName_
      }

-- | 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.
describeDataset_identityPoolId :: Lens.Lens' DescribeDataset Prelude.Text
describeDataset_identityPoolId :: (Text -> f Text) -> DescribeDataset -> f DescribeDataset
describeDataset_identityPoolId = (DescribeDataset -> Text)
-> (DescribeDataset -> Text -> DescribeDataset)
-> Lens DescribeDataset DescribeDataset Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeDataset' {Text
identityPoolId :: Text
$sel:identityPoolId:DescribeDataset' :: DescribeDataset -> Text
identityPoolId} -> Text
identityPoolId) (\s :: DescribeDataset
s@DescribeDataset' {} Text
a -> DescribeDataset
s {$sel:identityPoolId:DescribeDataset' :: Text
identityPoolId = Text
a} :: DescribeDataset)

-- | 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.
describeDataset_identityId :: Lens.Lens' DescribeDataset Prelude.Text
describeDataset_identityId :: (Text -> f Text) -> DescribeDataset -> f DescribeDataset
describeDataset_identityId = (DescribeDataset -> Text)
-> (DescribeDataset -> Text -> DescribeDataset)
-> Lens DescribeDataset DescribeDataset Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeDataset' {Text
identityId :: Text
$sel:identityId:DescribeDataset' :: DescribeDataset -> Text
identityId} -> Text
identityId) (\s :: DescribeDataset
s@DescribeDataset' {} Text
a -> DescribeDataset
s {$sel:identityId:DescribeDataset' :: Text
identityId = Text
a} :: DescribeDataset)

-- | A string of up to 128 characters. Allowed characters are a-z, A-Z, 0-9,
-- \'_\' (underscore), \'-\' (dash), and \'.\' (dot).
describeDataset_datasetName :: Lens.Lens' DescribeDataset Prelude.Text
describeDataset_datasetName :: (Text -> f Text) -> DescribeDataset -> f DescribeDataset
describeDataset_datasetName = (DescribeDataset -> Text)
-> (DescribeDataset -> Text -> DescribeDataset)
-> Lens DescribeDataset DescribeDataset Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeDataset' {Text
datasetName :: Text
$sel:datasetName:DescribeDataset' :: DescribeDataset -> Text
datasetName} -> Text
datasetName) (\s :: DescribeDataset
s@DescribeDataset' {} Text
a -> DescribeDataset
s {$sel:datasetName:DescribeDataset' :: Text
datasetName = Text
a} :: DescribeDataset)

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

instance Prelude.NFData DescribeDataset

instance Core.ToHeaders DescribeDataset where
  toHeaders :: DescribeDataset -> ResponseHeaders
toHeaders =
    ResponseHeaders -> DescribeDataset -> 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.ToPath DescribeDataset where
  toPath :: DescribeDataset -> ByteString
toPath DescribeDataset' {Text
datasetName :: Text
identityId :: Text
identityPoolId :: Text
$sel:datasetName:DescribeDataset' :: DescribeDataset -> Text
$sel:identityId:DescribeDataset' :: DescribeDataset -> Text
$sel:identityPoolId:DescribeDataset' :: DescribeDataset -> 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
"/identities/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
identityId,
        ByteString
"/datasets/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
datasetName
      ]

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

-- | Response to a successful DescribeDataset request.
--
-- /See:/ 'newDescribeDatasetResponse' smart constructor.
data DescribeDatasetResponse = DescribeDatasetResponse'
  { -- | Meta data for a collection of data for an identity. An identity can have
    -- multiple datasets. A dataset can be general or associated with a
    -- particular entity in an application (like a saved game). Datasets are
    -- automatically created if they don\'t exist. Data is synced by dataset,
    -- and a dataset can hold up to 1MB of key-value pairs.
    DescribeDatasetResponse -> Maybe Dataset
dataset :: Prelude.Maybe Dataset,
    -- | The response's http status code.
    DescribeDatasetResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (DescribeDatasetResponse -> DescribeDatasetResponse -> Bool
(DescribeDatasetResponse -> DescribeDatasetResponse -> Bool)
-> (DescribeDatasetResponse -> DescribeDatasetResponse -> Bool)
-> Eq DescribeDatasetResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribeDatasetResponse -> DescribeDatasetResponse -> Bool
$c/= :: DescribeDatasetResponse -> DescribeDatasetResponse -> Bool
== :: DescribeDatasetResponse -> DescribeDatasetResponse -> Bool
$c== :: DescribeDatasetResponse -> DescribeDatasetResponse -> Bool
Prelude.Eq, ReadPrec [DescribeDatasetResponse]
ReadPrec DescribeDatasetResponse
Int -> ReadS DescribeDatasetResponse
ReadS [DescribeDatasetResponse]
(Int -> ReadS DescribeDatasetResponse)
-> ReadS [DescribeDatasetResponse]
-> ReadPrec DescribeDatasetResponse
-> ReadPrec [DescribeDatasetResponse]
-> Read DescribeDatasetResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DescribeDatasetResponse]
$creadListPrec :: ReadPrec [DescribeDatasetResponse]
readPrec :: ReadPrec DescribeDatasetResponse
$creadPrec :: ReadPrec DescribeDatasetResponse
readList :: ReadS [DescribeDatasetResponse]
$creadList :: ReadS [DescribeDatasetResponse]
readsPrec :: Int -> ReadS DescribeDatasetResponse
$creadsPrec :: Int -> ReadS DescribeDatasetResponse
Prelude.Read, Int -> DescribeDatasetResponse -> ShowS
[DescribeDatasetResponse] -> ShowS
DescribeDatasetResponse -> String
(Int -> DescribeDatasetResponse -> ShowS)
-> (DescribeDatasetResponse -> String)
-> ([DescribeDatasetResponse] -> ShowS)
-> Show DescribeDatasetResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribeDatasetResponse] -> ShowS
$cshowList :: [DescribeDatasetResponse] -> ShowS
show :: DescribeDatasetResponse -> String
$cshow :: DescribeDatasetResponse -> String
showsPrec :: Int -> DescribeDatasetResponse -> ShowS
$cshowsPrec :: Int -> DescribeDatasetResponse -> ShowS
Prelude.Show, (forall x.
 DescribeDatasetResponse -> Rep DescribeDatasetResponse x)
-> (forall x.
    Rep DescribeDatasetResponse x -> DescribeDatasetResponse)
-> Generic DescribeDatasetResponse
forall x. Rep DescribeDatasetResponse x -> DescribeDatasetResponse
forall x. DescribeDatasetResponse -> Rep DescribeDatasetResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DescribeDatasetResponse x -> DescribeDatasetResponse
$cfrom :: forall x. DescribeDatasetResponse -> Rep DescribeDatasetResponse x
Prelude.Generic)

-- |
-- Create a value of 'DescribeDatasetResponse' 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:
--
-- 'dataset', 'describeDatasetResponse_dataset' - Meta data for a collection of data for an identity. An identity can have
-- multiple datasets. A dataset can be general or associated with a
-- particular entity in an application (like a saved game). Datasets are
-- automatically created if they don\'t exist. Data is synced by dataset,
-- and a dataset can hold up to 1MB of key-value pairs.
--
-- 'httpStatus', 'describeDatasetResponse_httpStatus' - The response's http status code.
newDescribeDatasetResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DescribeDatasetResponse
newDescribeDatasetResponse :: Int -> DescribeDatasetResponse
newDescribeDatasetResponse Int
pHttpStatus_ =
  DescribeDatasetResponse' :: Maybe Dataset -> Int -> DescribeDatasetResponse
DescribeDatasetResponse'
    { $sel:dataset:DescribeDatasetResponse' :: Maybe Dataset
dataset = Maybe Dataset
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DescribeDatasetResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Meta data for a collection of data for an identity. An identity can have
-- multiple datasets. A dataset can be general or associated with a
-- particular entity in an application (like a saved game). Datasets are
-- automatically created if they don\'t exist. Data is synced by dataset,
-- and a dataset can hold up to 1MB of key-value pairs.
describeDatasetResponse_dataset :: Lens.Lens' DescribeDatasetResponse (Prelude.Maybe Dataset)
describeDatasetResponse_dataset :: (Maybe Dataset -> f (Maybe Dataset))
-> DescribeDatasetResponse -> f DescribeDatasetResponse
describeDatasetResponse_dataset = (DescribeDatasetResponse -> Maybe Dataset)
-> (DescribeDatasetResponse
    -> Maybe Dataset -> DescribeDatasetResponse)
-> Lens
     DescribeDatasetResponse
     DescribeDatasetResponse
     (Maybe Dataset)
     (Maybe Dataset)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeDatasetResponse' {Maybe Dataset
dataset :: Maybe Dataset
$sel:dataset:DescribeDatasetResponse' :: DescribeDatasetResponse -> Maybe Dataset
dataset} -> Maybe Dataset
dataset) (\s :: DescribeDatasetResponse
s@DescribeDatasetResponse' {} Maybe Dataset
a -> DescribeDatasetResponse
s {$sel:dataset:DescribeDatasetResponse' :: Maybe Dataset
dataset = Maybe Dataset
a} :: DescribeDatasetResponse)

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

instance Prelude.NFData DescribeDatasetResponse