{-# 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-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)
module Amazonka.IoT.Types.HttpAction where

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

-- | Send data to an HTTPS endpoint.
--
-- /See:/ 'newHttpAction' smart constructor.
data HttpAction = 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 -> Maybe Text
confirmationUrl :: Prelude.Maybe Prelude.Text,
    -- | The authentication method to use when sending data to an HTTPS endpoint.
    HttpAction -> Maybe HttpAuthorization
auth :: Prelude.Maybe HttpAuthorization,
    -- | 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
(HttpAction -> HttpAction -> Bool)
-> (HttpAction -> HttpAction -> Bool) -> Eq HttpAction
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]
(Int -> ReadS HttpAction)
-> ReadS [HttpAction]
-> ReadPrec HttpAction
-> ReadPrec [HttpAction]
-> Read 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
(Int -> HttpAction -> ShowS)
-> (HttpAction -> String)
-> ([HttpAction] -> ShowS)
-> Show HttpAction
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. HttpAction -> Rep HttpAction x)
-> (forall x. Rep HttpAction x -> HttpAction) -> Generic HttpAction
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:
--
-- '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.
--
-- 'auth', 'httpAction_auth' - The authentication method to use when sending data to an HTTPS endpoint.
--
-- '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' :: Maybe Text
-> Maybe HttpAuthorization
-> Maybe [HttpActionHeader]
-> Text
-> HttpAction
HttpAction'
    { $sel:confirmationUrl:HttpAction' :: Maybe Text
confirmationUrl = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:auth:HttpAction' :: Maybe HttpAuthorization
auth = Maybe HttpAuthorization
forall a. Maybe a
Prelude.Nothing,
      $sel:headers:HttpAction' :: Maybe [HttpActionHeader]
headers = Maybe [HttpActionHeader]
forall a. Maybe a
Prelude.Nothing,
      $sel:url:HttpAction' :: Text
url = Text
pUrl_
    }

-- | 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 :: (Maybe Text -> f (Maybe Text)) -> HttpAction -> f HttpAction
httpAction_confirmationUrl = (HttpAction -> Maybe Text)
-> (HttpAction -> Maybe Text -> HttpAction)
-> Lens HttpAction HttpAction (Maybe Text) (Maybe Text)
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 authentication method to use when sending data to an HTTPS endpoint.
httpAction_auth :: Lens.Lens' HttpAction (Prelude.Maybe HttpAuthorization)
httpAction_auth :: (Maybe HttpAuthorization -> f (Maybe HttpAuthorization))
-> HttpAction -> f HttpAction
httpAction_auth = (HttpAction -> Maybe HttpAuthorization)
-> (HttpAction -> Maybe HttpAuthorization -> HttpAction)
-> Lens
     HttpAction
     HttpAction
     (Maybe HttpAuthorization)
     (Maybe HttpAuthorization)
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 HTTP headers to send with the message data.
httpAction_headers :: Lens.Lens' HttpAction (Prelude.Maybe [HttpActionHeader])
httpAction_headers :: (Maybe [HttpActionHeader] -> f (Maybe [HttpActionHeader]))
-> HttpAction -> f HttpAction
httpAction_headers = (HttpAction -> Maybe [HttpActionHeader])
-> (HttpAction -> Maybe [HttpActionHeader] -> HttpAction)
-> Lens
     HttpAction
     HttpAction
     (Maybe [HttpActionHeader])
     (Maybe [HttpActionHeader])
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) ((Maybe [HttpActionHeader] -> f (Maybe [HttpActionHeader]))
 -> HttpAction -> f HttpAction)
-> ((Maybe [HttpActionHeader] -> f (Maybe [HttpActionHeader]))
    -> Maybe [HttpActionHeader] -> f (Maybe [HttpActionHeader]))
-> (Maybe [HttpActionHeader] -> f (Maybe [HttpActionHeader]))
-> HttpAction
-> f HttpAction
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [HttpActionHeader]
  [HttpActionHeader]
  [HttpActionHeader]
  [HttpActionHeader]
-> Iso
     (Maybe [HttpActionHeader])
     (Maybe [HttpActionHeader])
     (Maybe [HttpActionHeader])
     (Maybe [HttpActionHeader])
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
  [HttpActionHeader]
  [HttpActionHeader]
  [HttpActionHeader]
  [HttpActionHeader]
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 :: (Text -> f Text) -> HttpAction -> f HttpAction
httpAction_url = (HttpAction -> Text)
-> (HttpAction -> Text -> HttpAction)
-> Lens HttpAction HttpAction Text Text
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 Core.FromJSON HttpAction where
  parseJSON :: Value -> Parser HttpAction
parseJSON =
    String
-> (Object -> Parser HttpAction) -> Value -> Parser HttpAction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"HttpAction"
      ( \Object
x ->
          Maybe Text
-> Maybe HttpAuthorization
-> Maybe [HttpActionHeader]
-> Text
-> HttpAction
HttpAction'
            (Maybe Text
 -> Maybe HttpAuthorization
 -> Maybe [HttpActionHeader]
 -> Text
 -> HttpAction)
-> Parser (Maybe Text)
-> Parser
     (Maybe HttpAuthorization
      -> Maybe [HttpActionHeader] -> Text -> HttpAction)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"confirmationUrl")
            Parser
  (Maybe HttpAuthorization
   -> Maybe [HttpActionHeader] -> Text -> HttpAction)
-> Parser (Maybe HttpAuthorization)
-> Parser (Maybe [HttpActionHeader] -> Text -> HttpAction)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe HttpAuthorization)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"auth")
            Parser (Maybe [HttpActionHeader] -> Text -> HttpAction)
-> Parser (Maybe [HttpActionHeader]) -> Parser (Text -> HttpAction)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (Maybe [HttpActionHeader]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"headers" Parser (Maybe (Maybe [HttpActionHeader]))
-> Maybe [HttpActionHeader] -> Parser (Maybe [HttpActionHeader])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [HttpActionHeader]
forall a. Monoid a => a
Prelude.mempty)
            Parser (Text -> HttpAction) -> Parser Text -> Parser HttpAction
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"url")
      )

instance Prelude.Hashable HttpAction

instance Prelude.NFData HttpAction

instance Core.ToJSON HttpAction where
  toJSON :: HttpAction -> Value
toJSON HttpAction' {Maybe [HttpActionHeader]
Maybe Text
Maybe HttpAuthorization
Text
url :: Text
headers :: Maybe [HttpActionHeader]
auth :: Maybe HttpAuthorization
confirmationUrl :: Maybe Text
$sel:url:HttpAction' :: HttpAction -> Text
$sel:headers:HttpAction' :: HttpAction -> Maybe [HttpActionHeader]
$sel:auth:HttpAction' :: HttpAction -> Maybe HttpAuthorization
$sel:confirmationUrl:HttpAction' :: HttpAction -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"confirmationUrl" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
confirmationUrl,
            (Text
"auth" Text -> HttpAuthorization -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (HttpAuthorization -> Pair)
-> Maybe HttpAuthorization -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe HttpAuthorization
auth,
            (Text
"headers" Text -> [HttpActionHeader] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([HttpActionHeader] -> Pair)
-> Maybe [HttpActionHeader] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [HttpActionHeader]
headers,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"url" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
url)
          ]
      )