{-# 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.ConfirmSubscription
-- 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)
--
-- Verifies an endpoint owner\'s intent to receive messages by validating
-- the token sent to the endpoint by an earlier @Subscribe@ action. If the
-- token is valid, the action creates a new subscription and returns its
-- Amazon Resource Name (ARN). This call requires an AWS signature only
-- when the @AuthenticateOnUnsubscribe@ flag is set to \"true\".
module Amazonka.SNS.ConfirmSubscription
  ( -- * Creating a Request
    ConfirmSubscription (..),
    newConfirmSubscription,

    -- * Request Lenses
    confirmSubscription_authenticateOnUnsubscribe,
    confirmSubscription_topicArn,
    confirmSubscription_token,

    -- * Destructuring the Response
    ConfirmSubscriptionResponse (..),
    newConfirmSubscriptionResponse,

    -- * Response Lenses
    confirmSubscriptionResponse_subscriptionArn,
    confirmSubscriptionResponse_httpStatus,
  )
where

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

-- | Input for ConfirmSubscription action.
--
-- /See:/ 'newConfirmSubscription' smart constructor.
data ConfirmSubscription = ConfirmSubscription'
  { -- | Disallows unauthenticated unsubscribes of the subscription. If the value
    -- of this parameter is @true@ and the request has an Amazon Web Services
    -- signature, then only the topic owner and the subscription owner can
    -- unsubscribe the endpoint. The unsubscribe action requires Amazon Web
    -- Services authentication.
    ConfirmSubscription -> Maybe Text
authenticateOnUnsubscribe :: Prelude.Maybe Prelude.Text,
    -- | The ARN of the topic for which you wish to confirm a subscription.
    ConfirmSubscription -> Text
topicArn :: Prelude.Text,
    -- | Short-lived token sent to an endpoint during the @Subscribe@ action.
    ConfirmSubscription -> Text
token :: Prelude.Text
  }
  deriving (ConfirmSubscription -> ConfirmSubscription -> Bool
(ConfirmSubscription -> ConfirmSubscription -> Bool)
-> (ConfirmSubscription -> ConfirmSubscription -> Bool)
-> Eq ConfirmSubscription
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ConfirmSubscription -> ConfirmSubscription -> Bool
$c/= :: ConfirmSubscription -> ConfirmSubscription -> Bool
== :: ConfirmSubscription -> ConfirmSubscription -> Bool
$c== :: ConfirmSubscription -> ConfirmSubscription -> Bool
Prelude.Eq, ReadPrec [ConfirmSubscription]
ReadPrec ConfirmSubscription
Int -> ReadS ConfirmSubscription
ReadS [ConfirmSubscription]
(Int -> ReadS ConfirmSubscription)
-> ReadS [ConfirmSubscription]
-> ReadPrec ConfirmSubscription
-> ReadPrec [ConfirmSubscription]
-> Read ConfirmSubscription
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ConfirmSubscription]
$creadListPrec :: ReadPrec [ConfirmSubscription]
readPrec :: ReadPrec ConfirmSubscription
$creadPrec :: ReadPrec ConfirmSubscription
readList :: ReadS [ConfirmSubscription]
$creadList :: ReadS [ConfirmSubscription]
readsPrec :: Int -> ReadS ConfirmSubscription
$creadsPrec :: Int -> ReadS ConfirmSubscription
Prelude.Read, Int -> ConfirmSubscription -> ShowS
[ConfirmSubscription] -> ShowS
ConfirmSubscription -> String
(Int -> ConfirmSubscription -> ShowS)
-> (ConfirmSubscription -> String)
-> ([ConfirmSubscription] -> ShowS)
-> Show ConfirmSubscription
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ConfirmSubscription] -> ShowS
$cshowList :: [ConfirmSubscription] -> ShowS
show :: ConfirmSubscription -> String
$cshow :: ConfirmSubscription -> String
showsPrec :: Int -> ConfirmSubscription -> ShowS
$cshowsPrec :: Int -> ConfirmSubscription -> ShowS
Prelude.Show, (forall x. ConfirmSubscription -> Rep ConfirmSubscription x)
-> (forall x. Rep ConfirmSubscription x -> ConfirmSubscription)
-> Generic ConfirmSubscription
forall x. Rep ConfirmSubscription x -> ConfirmSubscription
forall x. ConfirmSubscription -> Rep ConfirmSubscription x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ConfirmSubscription x -> ConfirmSubscription
$cfrom :: forall x. ConfirmSubscription -> Rep ConfirmSubscription x
Prelude.Generic)

-- |
-- Create a value of 'ConfirmSubscription' 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:
--
-- 'authenticateOnUnsubscribe', 'confirmSubscription_authenticateOnUnsubscribe' - Disallows unauthenticated unsubscribes of the subscription. If the value
-- of this parameter is @true@ and the request has an Amazon Web Services
-- signature, then only the topic owner and the subscription owner can
-- unsubscribe the endpoint. The unsubscribe action requires Amazon Web
-- Services authentication.
--
-- 'topicArn', 'confirmSubscription_topicArn' - The ARN of the topic for which you wish to confirm a subscription.
--
-- 'token', 'confirmSubscription_token' - Short-lived token sent to an endpoint during the @Subscribe@ action.
newConfirmSubscription ::
  -- | 'topicArn'
  Prelude.Text ->
  -- | 'token'
  Prelude.Text ->
  ConfirmSubscription
newConfirmSubscription :: Text -> Text -> ConfirmSubscription
newConfirmSubscription Text
pTopicArn_ Text
pToken_ =
  ConfirmSubscription' :: Maybe Text -> Text -> Text -> ConfirmSubscription
ConfirmSubscription'
    { $sel:authenticateOnUnsubscribe:ConfirmSubscription' :: Maybe Text
authenticateOnUnsubscribe =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:topicArn:ConfirmSubscription' :: Text
topicArn = Text
pTopicArn_,
      $sel:token:ConfirmSubscription' :: Text
token = Text
pToken_
    }

-- | Disallows unauthenticated unsubscribes of the subscription. If the value
-- of this parameter is @true@ and the request has an Amazon Web Services
-- signature, then only the topic owner and the subscription owner can
-- unsubscribe the endpoint. The unsubscribe action requires Amazon Web
-- Services authentication.
confirmSubscription_authenticateOnUnsubscribe :: Lens.Lens' ConfirmSubscription (Prelude.Maybe Prelude.Text)
confirmSubscription_authenticateOnUnsubscribe :: (Maybe Text -> f (Maybe Text))
-> ConfirmSubscription -> f ConfirmSubscription
confirmSubscription_authenticateOnUnsubscribe = (ConfirmSubscription -> Maybe Text)
-> (ConfirmSubscription -> Maybe Text -> ConfirmSubscription)
-> Lens
     ConfirmSubscription ConfirmSubscription (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ConfirmSubscription' {Maybe Text
authenticateOnUnsubscribe :: Maybe Text
$sel:authenticateOnUnsubscribe:ConfirmSubscription' :: ConfirmSubscription -> Maybe Text
authenticateOnUnsubscribe} -> Maybe Text
authenticateOnUnsubscribe) (\s :: ConfirmSubscription
s@ConfirmSubscription' {} Maybe Text
a -> ConfirmSubscription
s {$sel:authenticateOnUnsubscribe:ConfirmSubscription' :: Maybe Text
authenticateOnUnsubscribe = Maybe Text
a} :: ConfirmSubscription)

-- | The ARN of the topic for which you wish to confirm a subscription.
confirmSubscription_topicArn :: Lens.Lens' ConfirmSubscription Prelude.Text
confirmSubscription_topicArn :: (Text -> f Text) -> ConfirmSubscription -> f ConfirmSubscription
confirmSubscription_topicArn = (ConfirmSubscription -> Text)
-> (ConfirmSubscription -> Text -> ConfirmSubscription)
-> Lens ConfirmSubscription ConfirmSubscription Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ConfirmSubscription' {Text
topicArn :: Text
$sel:topicArn:ConfirmSubscription' :: ConfirmSubscription -> Text
topicArn} -> Text
topicArn) (\s :: ConfirmSubscription
s@ConfirmSubscription' {} Text
a -> ConfirmSubscription
s {$sel:topicArn:ConfirmSubscription' :: Text
topicArn = Text
a} :: ConfirmSubscription)

-- | Short-lived token sent to an endpoint during the @Subscribe@ action.
confirmSubscription_token :: Lens.Lens' ConfirmSubscription Prelude.Text
confirmSubscription_token :: (Text -> f Text) -> ConfirmSubscription -> f ConfirmSubscription
confirmSubscription_token = (ConfirmSubscription -> Text)
-> (ConfirmSubscription -> Text -> ConfirmSubscription)
-> Lens ConfirmSubscription ConfirmSubscription Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ConfirmSubscription' {Text
token :: Text
$sel:token:ConfirmSubscription' :: ConfirmSubscription -> Text
token} -> Text
token) (\s :: ConfirmSubscription
s@ConfirmSubscription' {} Text
a -> ConfirmSubscription
s {$sel:token:ConfirmSubscription' :: Text
token = Text
a} :: ConfirmSubscription)

instance Core.AWSRequest ConfirmSubscription where
  type
    AWSResponse ConfirmSubscription =
      ConfirmSubscriptionResponse
  request :: ConfirmSubscription -> Request ConfirmSubscription
request = Service -> ConfirmSubscription -> Request ConfirmSubscription
forall a. ToRequest a => Service -> a -> Request a
Request.postQuery Service
defaultService
  response :: Logger
-> Service
-> Proxy ConfirmSubscription
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse ConfirmSubscription)))
response =
    Text
-> (Int
    -> ResponseHeaders
    -> [Node]
    -> Either String (AWSResponse ConfirmSubscription))
-> Logger
-> Service
-> Proxy ConfirmSubscription
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse ConfirmSubscription)))
forall (m :: * -> *) a.
MonadResource m =>
Text
-> (Int
    -> ResponseHeaders -> [Node] -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveXMLWrapper
      Text
"ConfirmSubscriptionResult"
      ( \Int
s ResponseHeaders
h [Node]
x ->
          Maybe Text -> Int -> ConfirmSubscriptionResponse
ConfirmSubscriptionResponse'
            (Maybe Text -> Int -> ConfirmSubscriptionResponse)
-> Either String (Maybe Text)
-> Either String (Int -> ConfirmSubscriptionResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"SubscriptionArn")
            Either String (Int -> ConfirmSubscriptionResponse)
-> Either String Int -> Either String ConfirmSubscriptionResponse
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 ConfirmSubscription

instance Prelude.NFData ConfirmSubscription

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

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

instance Core.ToQuery ConfirmSubscription where
  toQuery :: ConfirmSubscription -> QueryString
toQuery ConfirmSubscription' {Maybe Text
Text
token :: Text
topicArn :: Text
authenticateOnUnsubscribe :: Maybe Text
$sel:token:ConfirmSubscription' :: ConfirmSubscription -> Text
$sel:topicArn:ConfirmSubscription' :: ConfirmSubscription -> Text
$sel:authenticateOnUnsubscribe:ConfirmSubscription' :: ConfirmSubscription -> Maybe Text
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Action"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"ConfirmSubscription" :: Prelude.ByteString),
        ByteString
"Version"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"2010-03-31" :: Prelude.ByteString),
        ByteString
"AuthenticateOnUnsubscribe"
          ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
authenticateOnUnsubscribe,
        ByteString
"TopicArn" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
topicArn,
        ByteString
"Token" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
token
      ]

-- | Response for ConfirmSubscriptions action.
--
-- /See:/ 'newConfirmSubscriptionResponse' smart constructor.
data ConfirmSubscriptionResponse = ConfirmSubscriptionResponse'
  { -- | The ARN of the created subscription.
    ConfirmSubscriptionResponse -> Maybe Text
subscriptionArn :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    ConfirmSubscriptionResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ConfirmSubscriptionResponse -> ConfirmSubscriptionResponse -> Bool
(ConfirmSubscriptionResponse
 -> ConfirmSubscriptionResponse -> Bool)
-> (ConfirmSubscriptionResponse
    -> ConfirmSubscriptionResponse -> Bool)
-> Eq ConfirmSubscriptionResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ConfirmSubscriptionResponse -> ConfirmSubscriptionResponse -> Bool
$c/= :: ConfirmSubscriptionResponse -> ConfirmSubscriptionResponse -> Bool
== :: ConfirmSubscriptionResponse -> ConfirmSubscriptionResponse -> Bool
$c== :: ConfirmSubscriptionResponse -> ConfirmSubscriptionResponse -> Bool
Prelude.Eq, ReadPrec [ConfirmSubscriptionResponse]
ReadPrec ConfirmSubscriptionResponse
Int -> ReadS ConfirmSubscriptionResponse
ReadS [ConfirmSubscriptionResponse]
(Int -> ReadS ConfirmSubscriptionResponse)
-> ReadS [ConfirmSubscriptionResponse]
-> ReadPrec ConfirmSubscriptionResponse
-> ReadPrec [ConfirmSubscriptionResponse]
-> Read ConfirmSubscriptionResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ConfirmSubscriptionResponse]
$creadListPrec :: ReadPrec [ConfirmSubscriptionResponse]
readPrec :: ReadPrec ConfirmSubscriptionResponse
$creadPrec :: ReadPrec ConfirmSubscriptionResponse
readList :: ReadS [ConfirmSubscriptionResponse]
$creadList :: ReadS [ConfirmSubscriptionResponse]
readsPrec :: Int -> ReadS ConfirmSubscriptionResponse
$creadsPrec :: Int -> ReadS ConfirmSubscriptionResponse
Prelude.Read, Int -> ConfirmSubscriptionResponse -> ShowS
[ConfirmSubscriptionResponse] -> ShowS
ConfirmSubscriptionResponse -> String
(Int -> ConfirmSubscriptionResponse -> ShowS)
-> (ConfirmSubscriptionResponse -> String)
-> ([ConfirmSubscriptionResponse] -> ShowS)
-> Show ConfirmSubscriptionResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ConfirmSubscriptionResponse] -> ShowS
$cshowList :: [ConfirmSubscriptionResponse] -> ShowS
show :: ConfirmSubscriptionResponse -> String
$cshow :: ConfirmSubscriptionResponse -> String
showsPrec :: Int -> ConfirmSubscriptionResponse -> ShowS
$cshowsPrec :: Int -> ConfirmSubscriptionResponse -> ShowS
Prelude.Show, (forall x.
 ConfirmSubscriptionResponse -> Rep ConfirmSubscriptionResponse x)
-> (forall x.
    Rep ConfirmSubscriptionResponse x -> ConfirmSubscriptionResponse)
-> Generic ConfirmSubscriptionResponse
forall x.
Rep ConfirmSubscriptionResponse x -> ConfirmSubscriptionResponse
forall x.
ConfirmSubscriptionResponse -> Rep ConfirmSubscriptionResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ConfirmSubscriptionResponse x -> ConfirmSubscriptionResponse
$cfrom :: forall x.
ConfirmSubscriptionResponse -> Rep ConfirmSubscriptionResponse x
Prelude.Generic)

-- |
-- Create a value of 'ConfirmSubscriptionResponse' 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:
--
-- 'subscriptionArn', 'confirmSubscriptionResponse_subscriptionArn' - The ARN of the created subscription.
--
-- 'httpStatus', 'confirmSubscriptionResponse_httpStatus' - The response's http status code.
newConfirmSubscriptionResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ConfirmSubscriptionResponse
newConfirmSubscriptionResponse :: Int -> ConfirmSubscriptionResponse
newConfirmSubscriptionResponse Int
pHttpStatus_ =
  ConfirmSubscriptionResponse' :: Maybe Text -> Int -> ConfirmSubscriptionResponse
ConfirmSubscriptionResponse'
    { $sel:subscriptionArn:ConfirmSubscriptionResponse' :: Maybe Text
subscriptionArn =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ConfirmSubscriptionResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The ARN of the created subscription.
confirmSubscriptionResponse_subscriptionArn :: Lens.Lens' ConfirmSubscriptionResponse (Prelude.Maybe Prelude.Text)
confirmSubscriptionResponse_subscriptionArn :: (Maybe Text -> f (Maybe Text))
-> ConfirmSubscriptionResponse -> f ConfirmSubscriptionResponse
confirmSubscriptionResponse_subscriptionArn = (ConfirmSubscriptionResponse -> Maybe Text)
-> (ConfirmSubscriptionResponse
    -> Maybe Text -> ConfirmSubscriptionResponse)
-> Lens
     ConfirmSubscriptionResponse
     ConfirmSubscriptionResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ConfirmSubscriptionResponse' {Maybe Text
subscriptionArn :: Maybe Text
$sel:subscriptionArn:ConfirmSubscriptionResponse' :: ConfirmSubscriptionResponse -> Maybe Text
subscriptionArn} -> Maybe Text
subscriptionArn) (\s :: ConfirmSubscriptionResponse
s@ConfirmSubscriptionResponse' {} Maybe Text
a -> ConfirmSubscriptionResponse
s {$sel:subscriptionArn:ConfirmSubscriptionResponse' :: Maybe Text
subscriptionArn = Maybe Text
a} :: ConfirmSubscriptionResponse)

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

instance Prelude.NFData ConfirmSubscriptionResponse