{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.IoT.Types.HttpAction
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.IoT.Types.HttpAction where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.IoT.Types.HttpActionHeader
import Amazonka.IoT.Types.HttpAuthorization
import qualified Amazonka.Prelude as Prelude

-- | Send data to an HTTPS endpoint.
--
-- /See:/ 'newHttpAction' smart constructor.
data HttpAction = HttpAction'
  { -- | The authentication method to use when sending data to an HTTPS endpoint.
    HttpAction -> Maybe HttpAuthorization
auth :: Prelude.Maybe HttpAuthorization,
    -- | The URL to which IoT sends a confirmation message. The value of the
    -- confirmation URL must be a prefix of the endpoint URL. If you do not
    -- specify a confirmation URL IoT uses the endpoint URL as the confirmation
    -- URL. If you use substitution templates in the confirmationUrl, you must
    -- create and enable topic rule destinations that match each possible value
    -- of the substitution template before traffic is allowed to your endpoint
    -- URL.
    HttpAction -> Maybe Text
confirmationUrl :: Prelude.Maybe Prelude.Text,
    -- | The HTTP headers to send with the message data.
    HttpAction -> Maybe [HttpActionHeader]
headers :: Prelude.Maybe [HttpActionHeader],
    -- | The endpoint URL. If substitution templates are used in the URL, you
    -- must also specify a @confirmationUrl@. If this is a new destination, a
    -- new @TopicRuleDestination@ is created if possible.
    HttpAction -> Text
url :: Prelude.Text
  }
  deriving (HttpAction -> HttpAction -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HttpAction -> HttpAction -> Bool
$c/= :: HttpAction -> HttpAction -> Bool
== :: HttpAction -> HttpAction -> Bool
$c== :: HttpAction -> HttpAction -> Bool
Prelude.Eq, ReadPrec [HttpAction]
ReadPrec HttpAction
Int -> ReadS HttpAction
ReadS [HttpAction]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [HttpAction]
$creadListPrec :: ReadPrec [HttpAction]
readPrec :: ReadPrec HttpAction
$creadPrec :: ReadPrec HttpAction
readList :: ReadS [HttpAction]
$creadList :: ReadS [HttpAction]
readsPrec :: Int -> ReadS HttpAction
$creadsPrec :: Int -> ReadS HttpAction
Prelude.Read, Int -> HttpAction -> ShowS
[HttpAction] -> ShowS
HttpAction -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HttpAction] -> ShowS
$cshowList :: [HttpAction] -> ShowS
show :: HttpAction -> String
$cshow :: HttpAction -> String
showsPrec :: Int -> HttpAction -> ShowS
$cshowsPrec :: Int -> HttpAction -> ShowS
Prelude.Show, forall x. Rep HttpAction x -> HttpAction
forall x. HttpAction -> Rep HttpAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep HttpAction x -> HttpAction
$cfrom :: forall x. HttpAction -> Rep HttpAction x
Prelude.Generic)

-- |
-- Create a value of 'HttpAction' 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:
--
-- 'auth', 'httpAction_auth' - The authentication method to use when sending data to an HTTPS endpoint.
--
-- 'confirmationUrl', 'httpAction_confirmationUrl' - The URL to which IoT sends a confirmation message. The value of the
-- confirmation URL must be a prefix of the endpoint URL. If you do not
-- specify a confirmation URL IoT uses the endpoint URL as the confirmation
-- URL. If you use substitution templates in the confirmationUrl, you must
-- create and enable topic rule destinations that match each possible value
-- of the substitution template before traffic is allowed to your endpoint
-- URL.
--
-- 'headers', 'httpAction_headers' - The HTTP headers to send with the message data.
--
-- 'url', 'httpAction_url' - The endpoint URL. If substitution templates are used in the URL, you
-- must also specify a @confirmationUrl@. If this is a new destination, a
-- new @TopicRuleDestination@ is created if possible.
newHttpAction ::
  -- | 'url'
  Prelude.Text ->
  HttpAction
newHttpAction :: Text -> HttpAction
newHttpAction Text
pUrl_ =
  HttpAction'
    { $sel:auth:HttpAction' :: Maybe HttpAuthorization
auth = forall a. Maybe a
Prelude.Nothing,
      $sel:confirmationUrl:HttpAction' :: Maybe Text
confirmationUrl = forall a. Maybe a
Prelude.Nothing,
      $sel:headers:HttpAction' :: Maybe [HttpActionHeader]
headers = forall a. Maybe a
Prelude.Nothing,
      $sel:url:HttpAction' :: Text
url = Text
pUrl_
    }

-- | The authentication method to use when sending data to an HTTPS endpoint.
httpAction_auth :: Lens.Lens' HttpAction (Prelude.Maybe HttpAuthorization)
httpAction_auth :: Lens' HttpAction (Maybe HttpAuthorization)
httpAction_auth = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HttpAction' {Maybe HttpAuthorization
auth :: Maybe HttpAuthorization
$sel:auth:HttpAction' :: HttpAction -> Maybe HttpAuthorization
auth} -> Maybe HttpAuthorization
auth) (\s :: HttpAction
s@HttpAction' {} Maybe HttpAuthorization
a -> HttpAction
s {$sel:auth:HttpAction' :: Maybe HttpAuthorization
auth = Maybe HttpAuthorization
a} :: HttpAction)

-- | The URL to which IoT sends a confirmation message. The value of the
-- confirmation URL must be a prefix of the endpoint URL. If you do not
-- specify a confirmation URL IoT uses the endpoint URL as the confirmation
-- URL. If you use substitution templates in the confirmationUrl, you must
-- create and enable topic rule destinations that match each possible value
-- of the substitution template before traffic is allowed to your endpoint
-- URL.
httpAction_confirmationUrl :: Lens.Lens' HttpAction (Prelude.Maybe Prelude.Text)
httpAction_confirmationUrl :: Lens' HttpAction (Maybe Text)
httpAction_confirmationUrl = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HttpAction' {Maybe Text
confirmationUrl :: Maybe Text
$sel:confirmationUrl:HttpAction' :: HttpAction -> Maybe Text
confirmationUrl} -> Maybe Text
confirmationUrl) (\s :: HttpAction
s@HttpAction' {} Maybe Text
a -> HttpAction
s {$sel:confirmationUrl:HttpAction' :: Maybe Text
confirmationUrl = Maybe Text
a} :: HttpAction)

-- | The HTTP headers to send with the message data.
httpAction_headers :: Lens.Lens' HttpAction (Prelude.Maybe [HttpActionHeader])
httpAction_headers :: Lens' HttpAction (Maybe [HttpActionHeader])
httpAction_headers = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HttpAction' {Maybe [HttpActionHeader]
headers :: Maybe [HttpActionHeader]
$sel:headers:HttpAction' :: HttpAction -> Maybe [HttpActionHeader]
headers} -> Maybe [HttpActionHeader]
headers) (\s :: HttpAction
s@HttpAction' {} Maybe [HttpActionHeader]
a -> HttpAction
s {$sel:headers:HttpAction' :: Maybe [HttpActionHeader]
headers = Maybe [HttpActionHeader]
a} :: HttpAction) 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 endpoint URL. If substitution templates are used in the URL, you
-- must also specify a @confirmationUrl@. If this is a new destination, a
-- new @TopicRuleDestination@ is created if possible.
httpAction_url :: Lens.Lens' HttpAction Prelude.Text
httpAction_url :: Lens' HttpAction Text
httpAction_url = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HttpAction' {Text
url :: Text
$sel:url:HttpAction' :: HttpAction -> Text
url} -> Text
url) (\s :: HttpAction
s@HttpAction' {} Text
a -> HttpAction
s {$sel:url:HttpAction' :: Text
url = Text
a} :: HttpAction)

instance Data.FromJSON HttpAction where
  parseJSON :: Value -> Parser HttpAction
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"HttpAction"
      ( \Object
x ->
          Maybe HttpAuthorization
-> Maybe Text -> Maybe [HttpActionHeader] -> Text -> HttpAction
HttpAction'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"auth")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"confirmationUrl")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"headers" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"url")
      )

instance Prelude.Hashable HttpAction where
  hashWithSalt :: Int -> HttpAction -> Int
hashWithSalt Int
_salt HttpAction' {Maybe [HttpActionHeader]
Maybe Text
Maybe HttpAuthorization
Text
url :: Text
headers :: Maybe [HttpActionHeader]
confirmationUrl :: Maybe Text
auth :: Maybe HttpAuthorization
$sel:url:HttpAction' :: HttpAction -> Text
$sel:headers:HttpAction' :: HttpAction -> Maybe [HttpActionHeader]
$sel:confirmationUrl:HttpAction' :: HttpAction -> Maybe Text
$sel:auth:HttpAction' :: HttpAction -> Maybe HttpAuthorization
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe HttpAuthorization
auth
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
confirmationUrl
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [HttpActionHeader]
headers
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
url

instance Prelude.NFData HttpAction where
  rnf :: HttpAction -> ()
rnf HttpAction' {Maybe [HttpActionHeader]
Maybe Text
Maybe HttpAuthorization
Text
url :: Text
headers :: Maybe [HttpActionHeader]
confirmationUrl :: Maybe Text
auth :: Maybe HttpAuthorization
$sel:url:HttpAction' :: HttpAction -> Text
$sel:headers:HttpAction' :: HttpAction -> Maybe [HttpActionHeader]
$sel:confirmationUrl:HttpAction' :: HttpAction -> Maybe Text
$sel:auth:HttpAction' :: HttpAction -> Maybe HttpAuthorization
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe HttpAuthorization
auth
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
confirmationUrl
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [HttpActionHeader]
headers
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
url

instance Data.ToJSON HttpAction where
  toJSON :: HttpAction -> Value
toJSON HttpAction' {Maybe [HttpActionHeader]
Maybe Text
Maybe HttpAuthorization
Text
url :: Text
headers :: Maybe [HttpActionHeader]
confirmationUrl :: Maybe Text
auth :: Maybe HttpAuthorization
$sel:url:HttpAction' :: HttpAction -> Text
$sel:headers:HttpAction' :: HttpAction -> Maybe [HttpActionHeader]
$sel:confirmationUrl:HttpAction' :: HttpAction -> Maybe Text
$sel:auth:HttpAction' :: HttpAction -> Maybe HttpAuthorization
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"auth" 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 HttpAuthorization
auth,
            (Key
"confirmationUrl" 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
confirmationUrl,
            (Key
"headers" 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 [HttpActionHeader]
headers,
            forall a. a -> Maybe a
Prelude.Just (Key
"url" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
url)
          ]
      )