{-# 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.SNS.ListPlatformApplications
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Lists the platform application objects for the supported push
-- notification services, such as APNS and GCM (Firebase Cloud Messaging).
-- The results for @ListPlatformApplications@ are paginated and return a
-- limited list of applications, up to 100. If additional records are
-- available after the first page results, then a NextToken string will be
-- returned. To receive the next page, you call @ListPlatformApplications@
-- using the NextToken string received from the previous call. When there
-- are no more records to return, @NextToken@ will be null. For more
-- information, see
-- <https://docs.aws.amazon.com/sns/latest/dg/SNSMobilePush.html Using Amazon SNS Mobile Push Notifications>.
--
-- This action is throttled at 15 transactions per second (TPS).
--
-- This operation returns paginated results.
module Amazonka.SNS.ListPlatformApplications
  ( -- * Creating a Request
    ListPlatformApplications (..),
    newListPlatformApplications,

    -- * Request Lenses
    listPlatformApplications_nextToken,

    -- * Destructuring the Response
    ListPlatformApplicationsResponse (..),
    newListPlatformApplicationsResponse,

    -- * Response Lenses
    listPlatformApplicationsResponse_nextToken,
    listPlatformApplicationsResponse_platformApplications,
    listPlatformApplicationsResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response
import Amazonka.SNS.Types

-- | Input for ListPlatformApplications action.
--
-- /See:/ 'newListPlatformApplications' smart constructor.
data ListPlatformApplications = ListPlatformApplications'
  { -- | NextToken string is used when calling ListPlatformApplications action to
    -- retrieve additional records that are available after the first page
    -- results.
    ListPlatformApplications -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text
  }
  deriving (ListPlatformApplications -> ListPlatformApplications -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListPlatformApplications -> ListPlatformApplications -> Bool
$c/= :: ListPlatformApplications -> ListPlatformApplications -> Bool
== :: ListPlatformApplications -> ListPlatformApplications -> Bool
$c== :: ListPlatformApplications -> ListPlatformApplications -> Bool
Prelude.Eq, ReadPrec [ListPlatformApplications]
ReadPrec ListPlatformApplications
Int -> ReadS ListPlatformApplications
ReadS [ListPlatformApplications]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListPlatformApplications]
$creadListPrec :: ReadPrec [ListPlatformApplications]
readPrec :: ReadPrec ListPlatformApplications
$creadPrec :: ReadPrec ListPlatformApplications
readList :: ReadS [ListPlatformApplications]
$creadList :: ReadS [ListPlatformApplications]
readsPrec :: Int -> ReadS ListPlatformApplications
$creadsPrec :: Int -> ReadS ListPlatformApplications
Prelude.Read, Int -> ListPlatformApplications -> ShowS
[ListPlatformApplications] -> ShowS
ListPlatformApplications -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListPlatformApplications] -> ShowS
$cshowList :: [ListPlatformApplications] -> ShowS
show :: ListPlatformApplications -> String
$cshow :: ListPlatformApplications -> String
showsPrec :: Int -> ListPlatformApplications -> ShowS
$cshowsPrec :: Int -> ListPlatformApplications -> ShowS
Prelude.Show, forall x.
Rep ListPlatformApplications x -> ListPlatformApplications
forall x.
ListPlatformApplications -> Rep ListPlatformApplications x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ListPlatformApplications x -> ListPlatformApplications
$cfrom :: forall x.
ListPlatformApplications -> Rep ListPlatformApplications x
Prelude.Generic)

-- |
-- Create a value of 'ListPlatformApplications' 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:
--
-- 'nextToken', 'listPlatformApplications_nextToken' - NextToken string is used when calling ListPlatformApplications action to
-- retrieve additional records that are available after the first page
-- results.
newListPlatformApplications ::
  ListPlatformApplications
newListPlatformApplications :: ListPlatformApplications
newListPlatformApplications =
  ListPlatformApplications'
    { $sel:nextToken:ListPlatformApplications' :: Maybe Text
nextToken =
        forall a. Maybe a
Prelude.Nothing
    }

-- | NextToken string is used when calling ListPlatformApplications action to
-- retrieve additional records that are available after the first page
-- results.
listPlatformApplications_nextToken :: Lens.Lens' ListPlatformApplications (Prelude.Maybe Prelude.Text)
listPlatformApplications_nextToken :: Lens' ListPlatformApplications (Maybe Text)
listPlatformApplications_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListPlatformApplications' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListPlatformApplications' :: ListPlatformApplications -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListPlatformApplications
s@ListPlatformApplications' {} Maybe Text
a -> ListPlatformApplications
s {$sel:nextToken:ListPlatformApplications' :: Maybe Text
nextToken = Maybe Text
a} :: ListPlatformApplications)

instance Core.AWSPager ListPlatformApplications where
  page :: ListPlatformApplications
-> AWSResponse ListPlatformApplications
-> Maybe ListPlatformApplications
page ListPlatformApplications
rq AWSResponse ListPlatformApplications
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListPlatformApplications
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListPlatformApplicationsResponse (Maybe Text)
listPlatformApplicationsResponse_nextToken
            forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just
        ) =
        forall a. Maybe a
Prelude.Nothing
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListPlatformApplications
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens'
  ListPlatformApplicationsResponse (Maybe [PlatformApplication])
listPlatformApplicationsResponse_platformApplications
            forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just
        ) =
        forall a. Maybe a
Prelude.Nothing
    | Bool
Prelude.otherwise =
        forall a. a -> Maybe a
Prelude.Just
          forall a b. (a -> b) -> a -> b
Prelude.$ ListPlatformApplications
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' ListPlatformApplications (Maybe Text)
listPlatformApplications_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse ListPlatformApplications
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListPlatformApplicationsResponse (Maybe Text)
listPlatformApplicationsResponse_nextToken
          forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just

instance Core.AWSRequest ListPlatformApplications where
  type
    AWSResponse ListPlatformApplications =
      ListPlatformApplicationsResponse
  request :: (Service -> Service)
-> ListPlatformApplications -> Request ListPlatformApplications
request Service -> Service
overrides =
    forall a. ToRequest a => Service -> a -> Request a
Request.postQuery (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy ListPlatformApplications
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse ListPlatformApplications)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
Text
-> (Int
    -> ResponseHeaders -> [Node] -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveXMLWrapper
      Text
"ListPlatformApplicationsResult"
      ( \Int
s ResponseHeaders
h [Node]
x ->
          Maybe Text
-> Maybe [PlatformApplication]
-> Int
-> ListPlatformApplicationsResponse
ListPlatformApplicationsResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"NextToken")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( [Node]
x
                            forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"PlatformApplications"
                            forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty
                            forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (forall a. FromXML a => Text -> [Node] -> Either String [a]
Data.parseXMLList Text
"member")
                        )
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable ListPlatformApplications where
  hashWithSalt :: Int -> ListPlatformApplications -> Int
hashWithSalt Int
_salt ListPlatformApplications' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListPlatformApplications' :: ListPlatformApplications -> Maybe Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
nextToken

instance Prelude.NFData ListPlatformApplications where
  rnf :: ListPlatformApplications -> ()
rnf ListPlatformApplications' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListPlatformApplications' :: ListPlatformApplications -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
nextToken

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

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

instance Data.ToQuery ListPlatformApplications where
  toQuery :: ListPlatformApplications -> QueryString
toQuery ListPlatformApplications' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListPlatformApplications' :: ListPlatformApplications -> Maybe Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Action"
          forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: (ByteString
"ListPlatformApplications" :: Prelude.ByteString),
        ByteString
"Version"
          forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: (ByteString
"2010-03-31" :: Prelude.ByteString),
        ByteString
"NextToken" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Text
nextToken
      ]

-- | Response for ListPlatformApplications action.
--
-- /See:/ 'newListPlatformApplicationsResponse' smart constructor.
data ListPlatformApplicationsResponse = ListPlatformApplicationsResponse'
  { -- | NextToken string is returned when calling ListPlatformApplications
    -- action if additional records are available after the first page results.
    ListPlatformApplicationsResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | Platform applications returned when calling ListPlatformApplications
    -- action.
    ListPlatformApplicationsResponse -> Maybe [PlatformApplication]
platformApplications :: Prelude.Maybe [PlatformApplication],
    -- | The response's http status code.
    ListPlatformApplicationsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListPlatformApplicationsResponse
-> ListPlatformApplicationsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListPlatformApplicationsResponse
-> ListPlatformApplicationsResponse -> Bool
$c/= :: ListPlatformApplicationsResponse
-> ListPlatformApplicationsResponse -> Bool
== :: ListPlatformApplicationsResponse
-> ListPlatformApplicationsResponse -> Bool
$c== :: ListPlatformApplicationsResponse
-> ListPlatformApplicationsResponse -> Bool
Prelude.Eq, ReadPrec [ListPlatformApplicationsResponse]
ReadPrec ListPlatformApplicationsResponse
Int -> ReadS ListPlatformApplicationsResponse
ReadS [ListPlatformApplicationsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListPlatformApplicationsResponse]
$creadListPrec :: ReadPrec [ListPlatformApplicationsResponse]
readPrec :: ReadPrec ListPlatformApplicationsResponse
$creadPrec :: ReadPrec ListPlatformApplicationsResponse
readList :: ReadS [ListPlatformApplicationsResponse]
$creadList :: ReadS [ListPlatformApplicationsResponse]
readsPrec :: Int -> ReadS ListPlatformApplicationsResponse
$creadsPrec :: Int -> ReadS ListPlatformApplicationsResponse
Prelude.Read, Int -> ListPlatformApplicationsResponse -> ShowS
[ListPlatformApplicationsResponse] -> ShowS
ListPlatformApplicationsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListPlatformApplicationsResponse] -> ShowS
$cshowList :: [ListPlatformApplicationsResponse] -> ShowS
show :: ListPlatformApplicationsResponse -> String
$cshow :: ListPlatformApplicationsResponse -> String
showsPrec :: Int -> ListPlatformApplicationsResponse -> ShowS
$cshowsPrec :: Int -> ListPlatformApplicationsResponse -> ShowS
Prelude.Show, forall x.
Rep ListPlatformApplicationsResponse x
-> ListPlatformApplicationsResponse
forall x.
ListPlatformApplicationsResponse
-> Rep ListPlatformApplicationsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ListPlatformApplicationsResponse x
-> ListPlatformApplicationsResponse
$cfrom :: forall x.
ListPlatformApplicationsResponse
-> Rep ListPlatformApplicationsResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListPlatformApplicationsResponse' 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:
--
-- 'nextToken', 'listPlatformApplicationsResponse_nextToken' - NextToken string is returned when calling ListPlatformApplications
-- action if additional records are available after the first page results.
--
-- 'platformApplications', 'listPlatformApplicationsResponse_platformApplications' - Platform applications returned when calling ListPlatformApplications
-- action.
--
-- 'httpStatus', 'listPlatformApplicationsResponse_httpStatus' - The response's http status code.
newListPlatformApplicationsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListPlatformApplicationsResponse
newListPlatformApplicationsResponse :: Int -> ListPlatformApplicationsResponse
newListPlatformApplicationsResponse Int
pHttpStatus_ =
  ListPlatformApplicationsResponse'
    { $sel:nextToken:ListPlatformApplicationsResponse' :: Maybe Text
nextToken =
        forall a. Maybe a
Prelude.Nothing,
      $sel:platformApplications:ListPlatformApplicationsResponse' :: Maybe [PlatformApplication]
platformApplications = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListPlatformApplicationsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | NextToken string is returned when calling ListPlatformApplications
-- action if additional records are available after the first page results.
listPlatformApplicationsResponse_nextToken :: Lens.Lens' ListPlatformApplicationsResponse (Prelude.Maybe Prelude.Text)
listPlatformApplicationsResponse_nextToken :: Lens' ListPlatformApplicationsResponse (Maybe Text)
listPlatformApplicationsResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListPlatformApplicationsResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListPlatformApplicationsResponse' :: ListPlatformApplicationsResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListPlatformApplicationsResponse
s@ListPlatformApplicationsResponse' {} Maybe Text
a -> ListPlatformApplicationsResponse
s {$sel:nextToken:ListPlatformApplicationsResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListPlatformApplicationsResponse)

-- | Platform applications returned when calling ListPlatformApplications
-- action.
listPlatformApplicationsResponse_platformApplications :: Lens.Lens' ListPlatformApplicationsResponse (Prelude.Maybe [PlatformApplication])
listPlatformApplicationsResponse_platformApplications :: Lens'
  ListPlatformApplicationsResponse (Maybe [PlatformApplication])
listPlatformApplicationsResponse_platformApplications = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListPlatformApplicationsResponse' {Maybe [PlatformApplication]
platformApplications :: Maybe [PlatformApplication]
$sel:platformApplications:ListPlatformApplicationsResponse' :: ListPlatformApplicationsResponse -> Maybe [PlatformApplication]
platformApplications} -> Maybe [PlatformApplication]
platformApplications) (\s :: ListPlatformApplicationsResponse
s@ListPlatformApplicationsResponse' {} Maybe [PlatformApplication]
a -> ListPlatformApplicationsResponse
s {$sel:platformApplications:ListPlatformApplicationsResponse' :: Maybe [PlatformApplication]
platformApplications = Maybe [PlatformApplication]
a} :: ListPlatformApplicationsResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance
  Prelude.NFData
    ListPlatformApplicationsResponse
  where
  rnf :: ListPlatformApplicationsResponse -> ()
rnf ListPlatformApplicationsResponse' {Int
Maybe [PlatformApplication]
Maybe Text
httpStatus :: Int
platformApplications :: Maybe [PlatformApplication]
nextToken :: Maybe Text
$sel:httpStatus:ListPlatformApplicationsResponse' :: ListPlatformApplicationsResponse -> Int
$sel:platformApplications:ListPlatformApplicationsResponse' :: ListPlatformApplicationsResponse -> Maybe [PlatformApplication]
$sel:nextToken:ListPlatformApplicationsResponse' :: ListPlatformApplicationsResponse -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
nextToken
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [PlatformApplication]
platformApplications
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus