{-# 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.Amplify.ListWebhooks
-- 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)
--
-- Returns a list of webhooks for an Amplify app.
module Amazonka.Amplify.ListWebhooks
  ( -- * Creating a Request
    ListWebhooks (..),
    newListWebhooks,

    -- * Request Lenses
    listWebhooks_nextToken,
    listWebhooks_maxResults,
    listWebhooks_appId,

    -- * Destructuring the Response
    ListWebhooksResponse (..),
    newListWebhooksResponse,

    -- * Response Lenses
    listWebhooksResponse_nextToken,
    listWebhooksResponse_httpStatus,
    listWebhooksResponse_webhooks,
  )
where

import Amazonka.Amplify.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 request structure for the list webhooks request.
--
-- /See:/ 'newListWebhooks' smart constructor.
data ListWebhooks = ListWebhooks'
  { -- | A pagination token. Set to null to start listing webhooks from the
    -- start. If non-null,the pagination token is returned in a result. Pass
    -- its value in here to list more webhooks.
    ListWebhooks -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The maximum number of records to list in a single response.
    ListWebhooks -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural,
    -- | The unique ID for an Amplify app.
    ListWebhooks -> Text
appId :: Prelude.Text
  }
  deriving (ListWebhooks -> ListWebhooks -> Bool
(ListWebhooks -> ListWebhooks -> Bool)
-> (ListWebhooks -> ListWebhooks -> Bool) -> Eq ListWebhooks
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListWebhooks -> ListWebhooks -> Bool
$c/= :: ListWebhooks -> ListWebhooks -> Bool
== :: ListWebhooks -> ListWebhooks -> Bool
$c== :: ListWebhooks -> ListWebhooks -> Bool
Prelude.Eq, ReadPrec [ListWebhooks]
ReadPrec ListWebhooks
Int -> ReadS ListWebhooks
ReadS [ListWebhooks]
(Int -> ReadS ListWebhooks)
-> ReadS [ListWebhooks]
-> ReadPrec ListWebhooks
-> ReadPrec [ListWebhooks]
-> Read ListWebhooks
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListWebhooks]
$creadListPrec :: ReadPrec [ListWebhooks]
readPrec :: ReadPrec ListWebhooks
$creadPrec :: ReadPrec ListWebhooks
readList :: ReadS [ListWebhooks]
$creadList :: ReadS [ListWebhooks]
readsPrec :: Int -> ReadS ListWebhooks
$creadsPrec :: Int -> ReadS ListWebhooks
Prelude.Read, Int -> ListWebhooks -> ShowS
[ListWebhooks] -> ShowS
ListWebhooks -> String
(Int -> ListWebhooks -> ShowS)
-> (ListWebhooks -> String)
-> ([ListWebhooks] -> ShowS)
-> Show ListWebhooks
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListWebhooks] -> ShowS
$cshowList :: [ListWebhooks] -> ShowS
show :: ListWebhooks -> String
$cshow :: ListWebhooks -> String
showsPrec :: Int -> ListWebhooks -> ShowS
$cshowsPrec :: Int -> ListWebhooks -> ShowS
Prelude.Show, (forall x. ListWebhooks -> Rep ListWebhooks x)
-> (forall x. Rep ListWebhooks x -> ListWebhooks)
-> Generic ListWebhooks
forall x. Rep ListWebhooks x -> ListWebhooks
forall x. ListWebhooks -> Rep ListWebhooks x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListWebhooks x -> ListWebhooks
$cfrom :: forall x. ListWebhooks -> Rep ListWebhooks x
Prelude.Generic)

-- |
-- Create a value of 'ListWebhooks' 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', 'listWebhooks_nextToken' - A pagination token. Set to null to start listing webhooks from the
-- start. If non-null,the pagination token is returned in a result. Pass
-- its value in here to list more webhooks.
--
-- 'maxResults', 'listWebhooks_maxResults' - The maximum number of records to list in a single response.
--
-- 'appId', 'listWebhooks_appId' - The unique ID for an Amplify app.
newListWebhooks ::
  -- | 'appId'
  Prelude.Text ->
  ListWebhooks
newListWebhooks :: Text -> ListWebhooks
newListWebhooks Text
pAppId_ =
  ListWebhooks' :: Maybe Text -> Maybe Natural -> Text -> ListWebhooks
ListWebhooks'
    { $sel:nextToken:ListWebhooks' :: Maybe Text
nextToken = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:maxResults:ListWebhooks' :: Maybe Natural
maxResults = Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:appId:ListWebhooks' :: Text
appId = Text
pAppId_
    }

-- | A pagination token. Set to null to start listing webhooks from the
-- start. If non-null,the pagination token is returned in a result. Pass
-- its value in here to list more webhooks.
listWebhooks_nextToken :: Lens.Lens' ListWebhooks (Prelude.Maybe Prelude.Text)
listWebhooks_nextToken :: (Maybe Text -> f (Maybe Text)) -> ListWebhooks -> f ListWebhooks
listWebhooks_nextToken = (ListWebhooks -> Maybe Text)
-> (ListWebhooks -> Maybe Text -> ListWebhooks)
-> Lens ListWebhooks ListWebhooks (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListWebhooks' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListWebhooks' :: ListWebhooks -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListWebhooks
s@ListWebhooks' {} Maybe Text
a -> ListWebhooks
s {$sel:nextToken:ListWebhooks' :: Maybe Text
nextToken = Maybe Text
a} :: ListWebhooks)

-- | The maximum number of records to list in a single response.
listWebhooks_maxResults :: Lens.Lens' ListWebhooks (Prelude.Maybe Prelude.Natural)
listWebhooks_maxResults :: (Maybe Natural -> f (Maybe Natural))
-> ListWebhooks -> f ListWebhooks
listWebhooks_maxResults = (ListWebhooks -> Maybe Natural)
-> (ListWebhooks -> Maybe Natural -> ListWebhooks)
-> Lens ListWebhooks ListWebhooks (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListWebhooks' {Maybe Natural
maxResults :: Maybe Natural
$sel:maxResults:ListWebhooks' :: ListWebhooks -> Maybe Natural
maxResults} -> Maybe Natural
maxResults) (\s :: ListWebhooks
s@ListWebhooks' {} Maybe Natural
a -> ListWebhooks
s {$sel:maxResults:ListWebhooks' :: Maybe Natural
maxResults = Maybe Natural
a} :: ListWebhooks)

-- | The unique ID for an Amplify app.
listWebhooks_appId :: Lens.Lens' ListWebhooks Prelude.Text
listWebhooks_appId :: (Text -> f Text) -> ListWebhooks -> f ListWebhooks
listWebhooks_appId = (ListWebhooks -> Text)
-> (ListWebhooks -> Text -> ListWebhooks)
-> Lens ListWebhooks ListWebhooks Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListWebhooks' {Text
appId :: Text
$sel:appId:ListWebhooks' :: ListWebhooks -> Text
appId} -> Text
appId) (\s :: ListWebhooks
s@ListWebhooks' {} Text
a -> ListWebhooks
s {$sel:appId:ListWebhooks' :: Text
appId = Text
a} :: ListWebhooks)

instance Core.AWSRequest ListWebhooks where
  type AWSResponse ListWebhooks = ListWebhooksResponse
  request :: ListWebhooks -> Request ListWebhooks
request = Service -> ListWebhooks -> Request ListWebhooks
forall a. ToRequest a => Service -> a -> Request a
Request.get Service
defaultService
  response :: Logger
-> Service
-> Proxy ListWebhooks
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListWebhooks)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse ListWebhooks))
-> Logger
-> Service
-> Proxy ListWebhooks
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListWebhooks)))
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 -> [Webhook] -> ListWebhooksResponse
ListWebhooksResponse'
            (Maybe Text -> Int -> [Webhook] -> ListWebhooksResponse)
-> Either String (Maybe Text)
-> Either String (Int -> [Webhook] -> ListWebhooksResponse)
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
"nextToken")
            Either String (Int -> [Webhook] -> ListWebhooksResponse)
-> Either String Int
-> Either String ([Webhook] -> ListWebhooksResponse)
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))
            Either String ([Webhook] -> ListWebhooksResponse)
-> Either String [Webhook] -> Either String ListWebhooksResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe [Webhook])
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"webhooks" Either String (Maybe [Webhook])
-> [Webhook] -> Either String [Webhook]
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ [Webhook]
forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable ListWebhooks

instance Prelude.NFData ListWebhooks

instance Core.ToHeaders ListWebhooks where
  toHeaders :: ListWebhooks -> ResponseHeaders
toHeaders =
    ResponseHeaders -> ListWebhooks -> 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 ListWebhooks where
  toPath :: ListWebhooks -> ByteString
toPath ListWebhooks' {Maybe Natural
Maybe Text
Text
appId :: Text
maxResults :: Maybe Natural
nextToken :: Maybe Text
$sel:appId:ListWebhooks' :: ListWebhooks -> Text
$sel:maxResults:ListWebhooks' :: ListWebhooks -> Maybe Natural
$sel:nextToken:ListWebhooks' :: ListWebhooks -> Maybe Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/apps/", Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
appId, ByteString
"/webhooks"]

instance Core.ToQuery ListWebhooks where
  toQuery :: ListWebhooks -> QueryString
toQuery ListWebhooks' {Maybe Natural
Maybe Text
Text
appId :: Text
maxResults :: Maybe Natural
nextToken :: Maybe Text
$sel:appId:ListWebhooks' :: ListWebhooks -> Text
$sel:maxResults:ListWebhooks' :: ListWebhooks -> Maybe Natural
$sel:nextToken:ListWebhooks' :: ListWebhooks -> Maybe Text
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"nextToken" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
nextToken,
        ByteString
"maxResults" ByteString -> Maybe Natural -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Natural
maxResults
      ]

-- | The result structure for the list webhooks request.
--
-- /See:/ 'newListWebhooksResponse' smart constructor.
data ListWebhooksResponse = ListWebhooksResponse'
  { -- | A pagination token. If non-null, the pagination token is returned in a
    -- result. Pass its value in another request to retrieve more entries.
    ListWebhooksResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    ListWebhooksResponse -> Int
httpStatus :: Prelude.Int,
    -- | A list of webhooks.
    ListWebhooksResponse -> [Webhook]
webhooks :: [Webhook]
  }
  deriving (ListWebhooksResponse -> ListWebhooksResponse -> Bool
(ListWebhooksResponse -> ListWebhooksResponse -> Bool)
-> (ListWebhooksResponse -> ListWebhooksResponse -> Bool)
-> Eq ListWebhooksResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListWebhooksResponse -> ListWebhooksResponse -> Bool
$c/= :: ListWebhooksResponse -> ListWebhooksResponse -> Bool
== :: ListWebhooksResponse -> ListWebhooksResponse -> Bool
$c== :: ListWebhooksResponse -> ListWebhooksResponse -> Bool
Prelude.Eq, ReadPrec [ListWebhooksResponse]
ReadPrec ListWebhooksResponse
Int -> ReadS ListWebhooksResponse
ReadS [ListWebhooksResponse]
(Int -> ReadS ListWebhooksResponse)
-> ReadS [ListWebhooksResponse]
-> ReadPrec ListWebhooksResponse
-> ReadPrec [ListWebhooksResponse]
-> Read ListWebhooksResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListWebhooksResponse]
$creadListPrec :: ReadPrec [ListWebhooksResponse]
readPrec :: ReadPrec ListWebhooksResponse
$creadPrec :: ReadPrec ListWebhooksResponse
readList :: ReadS [ListWebhooksResponse]
$creadList :: ReadS [ListWebhooksResponse]
readsPrec :: Int -> ReadS ListWebhooksResponse
$creadsPrec :: Int -> ReadS ListWebhooksResponse
Prelude.Read, Int -> ListWebhooksResponse -> ShowS
[ListWebhooksResponse] -> ShowS
ListWebhooksResponse -> String
(Int -> ListWebhooksResponse -> ShowS)
-> (ListWebhooksResponse -> String)
-> ([ListWebhooksResponse] -> ShowS)
-> Show ListWebhooksResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListWebhooksResponse] -> ShowS
$cshowList :: [ListWebhooksResponse] -> ShowS
show :: ListWebhooksResponse -> String
$cshow :: ListWebhooksResponse -> String
showsPrec :: Int -> ListWebhooksResponse -> ShowS
$cshowsPrec :: Int -> ListWebhooksResponse -> ShowS
Prelude.Show, (forall x. ListWebhooksResponse -> Rep ListWebhooksResponse x)
-> (forall x. Rep ListWebhooksResponse x -> ListWebhooksResponse)
-> Generic ListWebhooksResponse
forall x. Rep ListWebhooksResponse x -> ListWebhooksResponse
forall x. ListWebhooksResponse -> Rep ListWebhooksResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListWebhooksResponse x -> ListWebhooksResponse
$cfrom :: forall x. ListWebhooksResponse -> Rep ListWebhooksResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListWebhooksResponse' 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', 'listWebhooksResponse_nextToken' - A pagination token. If non-null, the pagination token is returned in a
-- result. Pass its value in another request to retrieve more entries.
--
-- 'httpStatus', 'listWebhooksResponse_httpStatus' - The response's http status code.
--
-- 'webhooks', 'listWebhooksResponse_webhooks' - A list of webhooks.
newListWebhooksResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListWebhooksResponse
newListWebhooksResponse :: Int -> ListWebhooksResponse
newListWebhooksResponse Int
pHttpStatus_ =
  ListWebhooksResponse' :: Maybe Text -> Int -> [Webhook] -> ListWebhooksResponse
ListWebhooksResponse'
    { $sel:nextToken:ListWebhooksResponse' :: Maybe Text
nextToken = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListWebhooksResponse' :: Int
httpStatus = Int
pHttpStatus_,
      $sel:webhooks:ListWebhooksResponse' :: [Webhook]
webhooks = [Webhook]
forall a. Monoid a => a
Prelude.mempty
    }

-- | A pagination token. If non-null, the pagination token is returned in a
-- result. Pass its value in another request to retrieve more entries.
listWebhooksResponse_nextToken :: Lens.Lens' ListWebhooksResponse (Prelude.Maybe Prelude.Text)
listWebhooksResponse_nextToken :: (Maybe Text -> f (Maybe Text))
-> ListWebhooksResponse -> f ListWebhooksResponse
listWebhooksResponse_nextToken = (ListWebhooksResponse -> Maybe Text)
-> (ListWebhooksResponse -> Maybe Text -> ListWebhooksResponse)
-> Lens
     ListWebhooksResponse ListWebhooksResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListWebhooksResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListWebhooksResponse' :: ListWebhooksResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListWebhooksResponse
s@ListWebhooksResponse' {} Maybe Text
a -> ListWebhooksResponse
s {$sel:nextToken:ListWebhooksResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListWebhooksResponse)

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

-- | A list of webhooks.
listWebhooksResponse_webhooks :: Lens.Lens' ListWebhooksResponse [Webhook]
listWebhooksResponse_webhooks :: ([Webhook] -> f [Webhook])
-> ListWebhooksResponse -> f ListWebhooksResponse
listWebhooksResponse_webhooks = (ListWebhooksResponse -> [Webhook])
-> (ListWebhooksResponse -> [Webhook] -> ListWebhooksResponse)
-> Lens
     ListWebhooksResponse ListWebhooksResponse [Webhook] [Webhook]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListWebhooksResponse' {[Webhook]
webhooks :: [Webhook]
$sel:webhooks:ListWebhooksResponse' :: ListWebhooksResponse -> [Webhook]
webhooks} -> [Webhook]
webhooks) (\s :: ListWebhooksResponse
s@ListWebhooksResponse' {} [Webhook]
a -> ListWebhooksResponse
s {$sel:webhooks:ListWebhooksResponse' :: [Webhook]
webhooks = [Webhook]
a} :: ListWebhooksResponse) (([Webhook] -> f [Webhook])
 -> ListWebhooksResponse -> f ListWebhooksResponse)
-> (([Webhook] -> f [Webhook]) -> [Webhook] -> f [Webhook])
-> ([Webhook] -> f [Webhook])
-> ListWebhooksResponse
-> f ListWebhooksResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Webhook] -> f [Webhook]) -> [Webhook] -> f [Webhook]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Prelude.NFData ListWebhooksResponse