{-# 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.PutWebhook
-- 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)
--
-- Defines a webhook and returns a unique webhook URL generated by
-- CodePipeline. This URL can be supplied to third party source hosting
-- providers to call every time there\'s a code change. When CodePipeline
-- receives a POST request on this URL, the pipeline defined in the webhook
-- is started as long as the POST request satisfied the authentication and
-- filtering requirements supplied when defining the webhook.
-- RegisterWebhookWithThirdParty and DeregisterWebhookWithThirdParty APIs
-- can be used to automatically configure supported third parties to call
-- the generated webhook URL.
module Amazonka.CodePipeline.PutWebhook
  ( -- * Creating a Request
    PutWebhook (..),
    newPutWebhook,

    -- * Request Lenses
    putWebhook_tags,
    putWebhook_webhook,

    -- * Destructuring the Response
    PutWebhookResponse (..),
    newPutWebhookResponse,

    -- * Response Lenses
    putWebhookResponse_webhook,
    putWebhookResponse_httpStatus,
  )
where

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

-- | /See:/ 'newPutWebhook' smart constructor.
data PutWebhook = PutWebhook'
  { -- | The tags for the webhook.
    PutWebhook -> Maybe [Tag]
tags :: Prelude.Maybe [Tag],
    -- | The detail provided in an input file to create the webhook, such as the
    -- webhook name, the pipeline name, and the action name. Give the webhook a
    -- unique name that helps you identify it. You might name the webhook after
    -- the pipeline and action it targets so that you can easily recognize what
    -- it\'s used for later.
    PutWebhook -> WebhookDefinition
webhook :: WebhookDefinition
  }
  deriving (PutWebhook -> PutWebhook -> Bool
(PutWebhook -> PutWebhook -> Bool)
-> (PutWebhook -> PutWebhook -> Bool) -> Eq PutWebhook
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutWebhook -> PutWebhook -> Bool
$c/= :: PutWebhook -> PutWebhook -> Bool
== :: PutWebhook -> PutWebhook -> Bool
$c== :: PutWebhook -> PutWebhook -> Bool
Prelude.Eq, ReadPrec [PutWebhook]
ReadPrec PutWebhook
Int -> ReadS PutWebhook
ReadS [PutWebhook]
(Int -> ReadS PutWebhook)
-> ReadS [PutWebhook]
-> ReadPrec PutWebhook
-> ReadPrec [PutWebhook]
-> Read PutWebhook
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutWebhook]
$creadListPrec :: ReadPrec [PutWebhook]
readPrec :: ReadPrec PutWebhook
$creadPrec :: ReadPrec PutWebhook
readList :: ReadS [PutWebhook]
$creadList :: ReadS [PutWebhook]
readsPrec :: Int -> ReadS PutWebhook
$creadsPrec :: Int -> ReadS PutWebhook
Prelude.Read, Int -> PutWebhook -> ShowS
[PutWebhook] -> ShowS
PutWebhook -> String
(Int -> PutWebhook -> ShowS)
-> (PutWebhook -> String)
-> ([PutWebhook] -> ShowS)
-> Show PutWebhook
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutWebhook] -> ShowS
$cshowList :: [PutWebhook] -> ShowS
show :: PutWebhook -> String
$cshow :: PutWebhook -> String
showsPrec :: Int -> PutWebhook -> ShowS
$cshowsPrec :: Int -> PutWebhook -> ShowS
Prelude.Show, (forall x. PutWebhook -> Rep PutWebhook x)
-> (forall x. Rep PutWebhook x -> PutWebhook) -> Generic PutWebhook
forall x. Rep PutWebhook x -> PutWebhook
forall x. PutWebhook -> Rep PutWebhook x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutWebhook x -> PutWebhook
$cfrom :: forall x. PutWebhook -> Rep PutWebhook x
Prelude.Generic)

-- |
-- Create a value of 'PutWebhook' 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:
--
-- 'tags', 'putWebhook_tags' - The tags for the webhook.
--
-- 'webhook', 'putWebhook_webhook' - The detail provided in an input file to create the webhook, such as the
-- webhook name, the pipeline name, and the action name. Give the webhook a
-- unique name that helps you identify it. You might name the webhook after
-- the pipeline and action it targets so that you can easily recognize what
-- it\'s used for later.
newPutWebhook ::
  -- | 'webhook'
  WebhookDefinition ->
  PutWebhook
newPutWebhook :: WebhookDefinition -> PutWebhook
newPutWebhook WebhookDefinition
pWebhook_ =
  PutWebhook' :: Maybe [Tag] -> WebhookDefinition -> PutWebhook
PutWebhook'
    { $sel:tags:PutWebhook' :: Maybe [Tag]
tags = Maybe [Tag]
forall a. Maybe a
Prelude.Nothing,
      $sel:webhook:PutWebhook' :: WebhookDefinition
webhook = WebhookDefinition
pWebhook_
    }

-- | The tags for the webhook.
putWebhook_tags :: Lens.Lens' PutWebhook (Prelude.Maybe [Tag])
putWebhook_tags :: (Maybe [Tag] -> f (Maybe [Tag])) -> PutWebhook -> f PutWebhook
putWebhook_tags = (PutWebhook -> Maybe [Tag])
-> (PutWebhook -> Maybe [Tag] -> PutWebhook)
-> Lens PutWebhook PutWebhook (Maybe [Tag]) (Maybe [Tag])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutWebhook' {Maybe [Tag]
tags :: Maybe [Tag]
$sel:tags:PutWebhook' :: PutWebhook -> Maybe [Tag]
tags} -> Maybe [Tag]
tags) (\s :: PutWebhook
s@PutWebhook' {} Maybe [Tag]
a -> PutWebhook
s {$sel:tags:PutWebhook' :: Maybe [Tag]
tags = Maybe [Tag]
a} :: PutWebhook) ((Maybe [Tag] -> f (Maybe [Tag])) -> PutWebhook -> f PutWebhook)
-> ((Maybe [Tag] -> f (Maybe [Tag]))
    -> Maybe [Tag] -> f (Maybe [Tag]))
-> (Maybe [Tag] -> f (Maybe [Tag]))
-> PutWebhook
-> f PutWebhook
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Tag] [Tag] [Tag] [Tag]
-> Iso (Maybe [Tag]) (Maybe [Tag]) (Maybe [Tag]) (Maybe [Tag])
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 AnIso [Tag] [Tag] [Tag] [Tag]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The detail provided in an input file to create the webhook, such as the
-- webhook name, the pipeline name, and the action name. Give the webhook a
-- unique name that helps you identify it. You might name the webhook after
-- the pipeline and action it targets so that you can easily recognize what
-- it\'s used for later.
putWebhook_webhook :: Lens.Lens' PutWebhook WebhookDefinition
putWebhook_webhook :: (WebhookDefinition -> f WebhookDefinition)
-> PutWebhook -> f PutWebhook
putWebhook_webhook = (PutWebhook -> WebhookDefinition)
-> (PutWebhook -> WebhookDefinition -> PutWebhook)
-> Lens PutWebhook PutWebhook WebhookDefinition WebhookDefinition
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutWebhook' {WebhookDefinition
webhook :: WebhookDefinition
$sel:webhook:PutWebhook' :: PutWebhook -> WebhookDefinition
webhook} -> WebhookDefinition
webhook) (\s :: PutWebhook
s@PutWebhook' {} WebhookDefinition
a -> PutWebhook
s {$sel:webhook:PutWebhook' :: WebhookDefinition
webhook = WebhookDefinition
a} :: PutWebhook)

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

instance Prelude.NFData PutWebhook

instance Core.ToHeaders PutWebhook where
  toHeaders :: PutWebhook -> ResponseHeaders
toHeaders =
    ResponseHeaders -> PutWebhook -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"CodePipeline_20150709.PutWebhook" ::
                          Prelude.ByteString
                      ),
            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 PutWebhook where
  toJSON :: PutWebhook -> Value
toJSON PutWebhook' {Maybe [Tag]
WebhookDefinition
webhook :: WebhookDefinition
tags :: Maybe [Tag]
$sel:webhook:PutWebhook' :: PutWebhook -> WebhookDefinition
$sel:tags:PutWebhook' :: PutWebhook -> Maybe [Tag]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"tags" Key -> [Tag] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Core..=) ([Tag] -> Pair) -> Maybe [Tag] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Tag]
tags,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Key
"webhook" Key -> WebhookDefinition -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Core..= WebhookDefinition
webhook)
          ]
      )

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

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

-- | /See:/ 'newPutWebhookResponse' smart constructor.
data PutWebhookResponse = PutWebhookResponse'
  { -- | The detail returned from creating the webhook, such as the webhook name,
    -- webhook URL, and webhook ARN.
    PutWebhookResponse -> Maybe ListWebhookItem
webhook :: Prelude.Maybe ListWebhookItem,
    -- | The response's http status code.
    PutWebhookResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (PutWebhookResponse -> PutWebhookResponse -> Bool
(PutWebhookResponse -> PutWebhookResponse -> Bool)
-> (PutWebhookResponse -> PutWebhookResponse -> Bool)
-> Eq PutWebhookResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutWebhookResponse -> PutWebhookResponse -> Bool
$c/= :: PutWebhookResponse -> PutWebhookResponse -> Bool
== :: PutWebhookResponse -> PutWebhookResponse -> Bool
$c== :: PutWebhookResponse -> PutWebhookResponse -> Bool
Prelude.Eq, ReadPrec [PutWebhookResponse]
ReadPrec PutWebhookResponse
Int -> ReadS PutWebhookResponse
ReadS [PutWebhookResponse]
(Int -> ReadS PutWebhookResponse)
-> ReadS [PutWebhookResponse]
-> ReadPrec PutWebhookResponse
-> ReadPrec [PutWebhookResponse]
-> Read PutWebhookResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutWebhookResponse]
$creadListPrec :: ReadPrec [PutWebhookResponse]
readPrec :: ReadPrec PutWebhookResponse
$creadPrec :: ReadPrec PutWebhookResponse
readList :: ReadS [PutWebhookResponse]
$creadList :: ReadS [PutWebhookResponse]
readsPrec :: Int -> ReadS PutWebhookResponse
$creadsPrec :: Int -> ReadS PutWebhookResponse
Prelude.Read, Int -> PutWebhookResponse -> ShowS
[PutWebhookResponse] -> ShowS
PutWebhookResponse -> String
(Int -> PutWebhookResponse -> ShowS)
-> (PutWebhookResponse -> String)
-> ([PutWebhookResponse] -> ShowS)
-> Show PutWebhookResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutWebhookResponse] -> ShowS
$cshowList :: [PutWebhookResponse] -> ShowS
show :: PutWebhookResponse -> String
$cshow :: PutWebhookResponse -> String
showsPrec :: Int -> PutWebhookResponse -> ShowS
$cshowsPrec :: Int -> PutWebhookResponse -> ShowS
Prelude.Show, (forall x. PutWebhookResponse -> Rep PutWebhookResponse x)
-> (forall x. Rep PutWebhookResponse x -> PutWebhookResponse)
-> Generic PutWebhookResponse
forall x. Rep PutWebhookResponse x -> PutWebhookResponse
forall x. PutWebhookResponse -> Rep PutWebhookResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutWebhookResponse x -> PutWebhookResponse
$cfrom :: forall x. PutWebhookResponse -> Rep PutWebhookResponse x
Prelude.Generic)

-- |
-- Create a value of 'PutWebhookResponse' 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:
--
-- 'webhook', 'putWebhookResponse_webhook' - The detail returned from creating the webhook, such as the webhook name,
-- webhook URL, and webhook ARN.
--
-- 'httpStatus', 'putWebhookResponse_httpStatus' - The response's http status code.
newPutWebhookResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  PutWebhookResponse
newPutWebhookResponse :: Int -> PutWebhookResponse
newPutWebhookResponse Int
pHttpStatus_ =
  PutWebhookResponse' :: Maybe ListWebhookItem -> Int -> PutWebhookResponse
PutWebhookResponse'
    { $sel:webhook:PutWebhookResponse' :: Maybe ListWebhookItem
webhook = Maybe ListWebhookItem
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:PutWebhookResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The detail returned from creating the webhook, such as the webhook name,
-- webhook URL, and webhook ARN.
putWebhookResponse_webhook :: Lens.Lens' PutWebhookResponse (Prelude.Maybe ListWebhookItem)
putWebhookResponse_webhook :: (Maybe ListWebhookItem -> f (Maybe ListWebhookItem))
-> PutWebhookResponse -> f PutWebhookResponse
putWebhookResponse_webhook = (PutWebhookResponse -> Maybe ListWebhookItem)
-> (PutWebhookResponse
    -> Maybe ListWebhookItem -> PutWebhookResponse)
-> Lens
     PutWebhookResponse
     PutWebhookResponse
     (Maybe ListWebhookItem)
     (Maybe ListWebhookItem)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutWebhookResponse' {Maybe ListWebhookItem
webhook :: Maybe ListWebhookItem
$sel:webhook:PutWebhookResponse' :: PutWebhookResponse -> Maybe ListWebhookItem
webhook} -> Maybe ListWebhookItem
webhook) (\s :: PutWebhookResponse
s@PutWebhookResponse' {} Maybe ListWebhookItem
a -> PutWebhookResponse
s {$sel:webhook:PutWebhookResponse' :: Maybe ListWebhookItem
webhook = Maybe ListWebhookItem
a} :: PutWebhookResponse)

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

instance Prelude.NFData PutWebhookResponse