{-# 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.CodePipeline.ListWebhooks
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Gets a listing of all the webhooks in this AWS Region for this account.
-- The output lists all webhooks and includes the webhook URL and ARN and
-- the configuration for each webhook.
--
-- This operation returns paginated results.
module Amazonka.CodePipeline.ListWebhooks
  ( -- * Creating a Request
    ListWebhooks (..),
    newListWebhooks,

    -- * Request Lenses
    listWebhooks_maxResults,
    listWebhooks_nextToken,

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

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

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

-- | /See:/ 'newListWebhooks' smart constructor.
data ListWebhooks = ListWebhooks'
  { -- | The maximum number of results to return in a single call. To retrieve
    -- the remaining results, make another call with the returned nextToken
    -- value.
    ListWebhooks -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural,
    -- | The token that was returned from the previous ListWebhooks call, which
    -- can be used to return the next set of webhooks in the list.
    ListWebhooks -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text
  }
  deriving (ListWebhooks -> ListWebhooks -> Bool
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]
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
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. 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:
--
-- 'maxResults', 'listWebhooks_maxResults' - The maximum number of results to return in a single call. To retrieve
-- the remaining results, make another call with the returned nextToken
-- value.
--
-- 'nextToken', 'listWebhooks_nextToken' - The token that was returned from the previous ListWebhooks call, which
-- can be used to return the next set of webhooks in the list.
newListWebhooks ::
  ListWebhooks
newListWebhooks :: ListWebhooks
newListWebhooks =
  ListWebhooks'
    { $sel:maxResults:ListWebhooks' :: Maybe Natural
maxResults = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListWebhooks' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing
    }

-- | The maximum number of results to return in a single call. To retrieve
-- the remaining results, make another call with the returned nextToken
-- value.
listWebhooks_maxResults :: Lens.Lens' ListWebhooks (Prelude.Maybe Prelude.Natural)
listWebhooks_maxResults :: Lens' ListWebhooks (Maybe Natural)
listWebhooks_maxResults = 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 token that was returned from the previous ListWebhooks call, which
-- can be used to return the next set of webhooks in the list.
listWebhooks_nextToken :: Lens.Lens' ListWebhooks (Prelude.Maybe Prelude.Text)
listWebhooks_nextToken :: Lens' ListWebhooks (Maybe Text)
listWebhooks_nextToken = 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)

instance Core.AWSPager ListWebhooks where
  page :: ListWebhooks -> AWSResponse ListWebhooks -> Maybe ListWebhooks
page ListWebhooks
rq AWSResponse ListWebhooks
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListWebhooks
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListWebhooksResponse (Maybe Text)
listWebhooksResponse_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 ListWebhooks
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListWebhooksResponse (Maybe [ListWebhookItem])
listWebhooksResponse_webhooks
            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.$ ListWebhooks
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' ListWebhooks (Maybe Text)
listWebhooks_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse ListWebhooks
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListWebhooksResponse (Maybe Text)
listWebhooksResponse_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 ListWebhooks where
  type AWSResponse ListWebhooks = ListWebhooksResponse
  request :: (Service -> Service) -> ListWebhooks -> Request ListWebhooks
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy ListWebhooks
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListWebhooks)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Text
-> Maybe [ListWebhookItem] -> Int -> ListWebhooksResponse
ListWebhooksResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"NextToken")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"webhooks" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
            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 ListWebhooks where
  hashWithSalt :: Int -> ListWebhooks -> Int
hashWithSalt Int
_salt ListWebhooks' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:nextToken:ListWebhooks' :: ListWebhooks -> Maybe Text
$sel:maxResults:ListWebhooks' :: ListWebhooks -> Maybe Natural
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
maxResults
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
nextToken

instance Prelude.NFData ListWebhooks where
  rnf :: ListWebhooks -> ()
rnf ListWebhooks' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:nextToken:ListWebhooks' :: ListWebhooks -> Maybe Text
$sel:maxResults:ListWebhooks' :: ListWebhooks -> Maybe Natural
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
maxResults
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
nextToken

instance Data.ToHeaders ListWebhooks where
  toHeaders :: ListWebhooks -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"CodePipeline_20150709.ListWebhooks" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON ListWebhooks where
  toJSON :: ListWebhooks -> Value
toJSON ListWebhooks' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:nextToken:ListWebhooks' :: ListWebhooks -> Maybe Text
$sel:maxResults:ListWebhooks' :: ListWebhooks -> Maybe Natural
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"MaxResults" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
maxResults,
            (Key
"NextToken" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
nextToken
          ]
      )

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

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

-- | /See:/ 'newListWebhooksResponse' smart constructor.
data ListWebhooksResponse = ListWebhooksResponse'
  { -- | If the amount of returned information is significantly large, an
    -- identifier is also returned and can be used in a subsequent ListWebhooks
    -- call to return the next set of webhooks in the list.
    ListWebhooksResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The JSON detail returned for each webhook in the list output for the
    -- ListWebhooks call.
    ListWebhooksResponse -> Maybe [ListWebhookItem]
webhooks :: Prelude.Maybe [ListWebhookItem],
    -- | The response's http status code.
    ListWebhooksResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListWebhooksResponse -> ListWebhooksResponse -> Bool
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]
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
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. 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' - If the amount of returned information is significantly large, an
-- identifier is also returned and can be used in a subsequent ListWebhooks
-- call to return the next set of webhooks in the list.
--
-- 'webhooks', 'listWebhooksResponse_webhooks' - The JSON detail returned for each webhook in the list output for the
-- ListWebhooks call.
--
-- 'httpStatus', 'listWebhooksResponse_httpStatus' - The response's http status code.
newListWebhooksResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListWebhooksResponse
newListWebhooksResponse :: Int -> ListWebhooksResponse
newListWebhooksResponse Int
pHttpStatus_ =
  ListWebhooksResponse'
    { $sel:nextToken:ListWebhooksResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:webhooks:ListWebhooksResponse' :: Maybe [ListWebhookItem]
webhooks = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListWebhooksResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | If the amount of returned information is significantly large, an
-- identifier is also returned and can be used in a subsequent ListWebhooks
-- call to return the next set of webhooks in the list.
listWebhooksResponse_nextToken :: Lens.Lens' ListWebhooksResponse (Prelude.Maybe Prelude.Text)
listWebhooksResponse_nextToken :: Lens' ListWebhooksResponse (Maybe Text)
listWebhooksResponse_nextToken = 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 JSON detail returned for each webhook in the list output for the
-- ListWebhooks call.
listWebhooksResponse_webhooks :: Lens.Lens' ListWebhooksResponse (Prelude.Maybe [ListWebhookItem])
listWebhooksResponse_webhooks :: Lens' ListWebhooksResponse (Maybe [ListWebhookItem])
listWebhooksResponse_webhooks = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListWebhooksResponse' {Maybe [ListWebhookItem]
webhooks :: Maybe [ListWebhookItem]
$sel:webhooks:ListWebhooksResponse' :: ListWebhooksResponse -> Maybe [ListWebhookItem]
webhooks} -> Maybe [ListWebhookItem]
webhooks) (\s :: ListWebhooksResponse
s@ListWebhooksResponse' {} Maybe [ListWebhookItem]
a -> ListWebhooksResponse
s {$sel:webhooks:ListWebhooksResponse' :: Maybe [ListWebhookItem]
webhooks = Maybe [ListWebhookItem]
a} :: ListWebhooksResponse) 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.
listWebhooksResponse_httpStatus :: Lens.Lens' ListWebhooksResponse Prelude.Int
listWebhooksResponse_httpStatus :: Lens' ListWebhooksResponse Int
listWebhooksResponse_httpStatus = 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)

instance Prelude.NFData ListWebhooksResponse where
  rnf :: ListWebhooksResponse -> ()
rnf ListWebhooksResponse' {Int
Maybe [ListWebhookItem]
Maybe Text
httpStatus :: Int
webhooks :: Maybe [ListWebhookItem]
nextToken :: Maybe Text
$sel:httpStatus:ListWebhooksResponse' :: ListWebhooksResponse -> Int
$sel:webhooks:ListWebhooksResponse' :: ListWebhooksResponse -> Maybe [ListWebhookItem]
$sel:nextToken:ListWebhooksResponse' :: ListWebhooksResponse -> 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 [ListWebhookItem]
webhooks
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus