{-# 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.Pinpoint.GetInAppMessages
-- 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)
--
-- Retrieves the in-app messages targeted for the provided endpoint ID.
module Amazonka.Pinpoint.GetInAppMessages
  ( -- * Creating a Request
    GetInAppMessages (..),
    newGetInAppMessages,

    -- * Request Lenses
    getInAppMessages_applicationId,
    getInAppMessages_endpointId,

    -- * Destructuring the Response
    GetInAppMessagesResponse (..),
    newGetInAppMessagesResponse,

    -- * Response Lenses
    getInAppMessagesResponse_httpStatus,
    getInAppMessagesResponse_inAppMessagesResponse,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.Pinpoint.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newGetInAppMessages' smart constructor.
data GetInAppMessages = GetInAppMessages'
  { -- | The unique identifier for the application. This identifier is displayed
    -- as the __Project ID__ on the Amazon Pinpoint console.
    GetInAppMessages -> Text
applicationId :: Prelude.Text,
    -- | The unique identifier for the endpoint.
    GetInAppMessages -> Text
endpointId :: Prelude.Text
  }
  deriving (GetInAppMessages -> GetInAppMessages -> Bool
(GetInAppMessages -> GetInAppMessages -> Bool)
-> (GetInAppMessages -> GetInAppMessages -> Bool)
-> Eq GetInAppMessages
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetInAppMessages -> GetInAppMessages -> Bool
$c/= :: GetInAppMessages -> GetInAppMessages -> Bool
== :: GetInAppMessages -> GetInAppMessages -> Bool
$c== :: GetInAppMessages -> GetInAppMessages -> Bool
Prelude.Eq, ReadPrec [GetInAppMessages]
ReadPrec GetInAppMessages
Int -> ReadS GetInAppMessages
ReadS [GetInAppMessages]
(Int -> ReadS GetInAppMessages)
-> ReadS [GetInAppMessages]
-> ReadPrec GetInAppMessages
-> ReadPrec [GetInAppMessages]
-> Read GetInAppMessages
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetInAppMessages]
$creadListPrec :: ReadPrec [GetInAppMessages]
readPrec :: ReadPrec GetInAppMessages
$creadPrec :: ReadPrec GetInAppMessages
readList :: ReadS [GetInAppMessages]
$creadList :: ReadS [GetInAppMessages]
readsPrec :: Int -> ReadS GetInAppMessages
$creadsPrec :: Int -> ReadS GetInAppMessages
Prelude.Read, Int -> GetInAppMessages -> ShowS
[GetInAppMessages] -> ShowS
GetInAppMessages -> String
(Int -> GetInAppMessages -> ShowS)
-> (GetInAppMessages -> String)
-> ([GetInAppMessages] -> ShowS)
-> Show GetInAppMessages
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetInAppMessages] -> ShowS
$cshowList :: [GetInAppMessages] -> ShowS
show :: GetInAppMessages -> String
$cshow :: GetInAppMessages -> String
showsPrec :: Int -> GetInAppMessages -> ShowS
$cshowsPrec :: Int -> GetInAppMessages -> ShowS
Prelude.Show, (forall x. GetInAppMessages -> Rep GetInAppMessages x)
-> (forall x. Rep GetInAppMessages x -> GetInAppMessages)
-> Generic GetInAppMessages
forall x. Rep GetInAppMessages x -> GetInAppMessages
forall x. GetInAppMessages -> Rep GetInAppMessages x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetInAppMessages x -> GetInAppMessages
$cfrom :: forall x. GetInAppMessages -> Rep GetInAppMessages x
Prelude.Generic)

-- |
-- Create a value of 'GetInAppMessages' 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:
--
-- 'applicationId', 'getInAppMessages_applicationId' - The unique identifier for the application. This identifier is displayed
-- as the __Project ID__ on the Amazon Pinpoint console.
--
-- 'endpointId', 'getInAppMessages_endpointId' - The unique identifier for the endpoint.
newGetInAppMessages ::
  -- | 'applicationId'
  Prelude.Text ->
  -- | 'endpointId'
  Prelude.Text ->
  GetInAppMessages
newGetInAppMessages :: Text -> Text -> GetInAppMessages
newGetInAppMessages Text
pApplicationId_ Text
pEndpointId_ =
  GetInAppMessages' :: Text -> Text -> GetInAppMessages
GetInAppMessages'
    { $sel:applicationId:GetInAppMessages' :: Text
applicationId = Text
pApplicationId_,
      $sel:endpointId:GetInAppMessages' :: Text
endpointId = Text
pEndpointId_
    }

-- | The unique identifier for the application. This identifier is displayed
-- as the __Project ID__ on the Amazon Pinpoint console.
getInAppMessages_applicationId :: Lens.Lens' GetInAppMessages Prelude.Text
getInAppMessages_applicationId :: (Text -> f Text) -> GetInAppMessages -> f GetInAppMessages
getInAppMessages_applicationId = (GetInAppMessages -> Text)
-> (GetInAppMessages -> Text -> GetInAppMessages)
-> Lens GetInAppMessages GetInAppMessages Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetInAppMessages' {Text
applicationId :: Text
$sel:applicationId:GetInAppMessages' :: GetInAppMessages -> Text
applicationId} -> Text
applicationId) (\s :: GetInAppMessages
s@GetInAppMessages' {} Text
a -> GetInAppMessages
s {$sel:applicationId:GetInAppMessages' :: Text
applicationId = Text
a} :: GetInAppMessages)

-- | The unique identifier for the endpoint.
getInAppMessages_endpointId :: Lens.Lens' GetInAppMessages Prelude.Text
getInAppMessages_endpointId :: (Text -> f Text) -> GetInAppMessages -> f GetInAppMessages
getInAppMessages_endpointId = (GetInAppMessages -> Text)
-> (GetInAppMessages -> Text -> GetInAppMessages)
-> Lens GetInAppMessages GetInAppMessages Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetInAppMessages' {Text
endpointId :: Text
$sel:endpointId:GetInAppMessages' :: GetInAppMessages -> Text
endpointId} -> Text
endpointId) (\s :: GetInAppMessages
s@GetInAppMessages' {} Text
a -> GetInAppMessages
s {$sel:endpointId:GetInAppMessages' :: Text
endpointId = Text
a} :: GetInAppMessages)

instance Core.AWSRequest GetInAppMessages where
  type
    AWSResponse GetInAppMessages =
      GetInAppMessagesResponse
  request :: GetInAppMessages -> Request GetInAppMessages
request = Service -> GetInAppMessages -> Request GetInAppMessages
forall a. ToRequest a => Service -> a -> Request a
Request.get Service
defaultService
  response :: Logger
-> Service
-> Proxy GetInAppMessages
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetInAppMessages)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetInAppMessages))
-> Logger
-> Service
-> Proxy GetInAppMessages
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetInAppMessages)))
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 ->
          Int -> InAppMessagesResponse -> GetInAppMessagesResponse
GetInAppMessagesResponse'
            (Int -> InAppMessagesResponse -> GetInAppMessagesResponse)
-> Either String Int
-> Either
     String (InAppMessagesResponse -> GetInAppMessagesResponse)
forall (f :: * -> *) a b. Functor 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))
            Either String (InAppMessagesResponse -> GetInAppMessagesResponse)
-> Either String InAppMessagesResponse
-> Either String GetInAppMessagesResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object -> Either String InAppMessagesResponse
forall a. FromJSON a => Object -> Either String a
Core.eitherParseJSON Object
x)
      )

instance Prelude.Hashable GetInAppMessages

instance Prelude.NFData GetInAppMessages

instance Core.ToHeaders GetInAppMessages where
  toHeaders :: GetInAppMessages -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetInAppMessages -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ 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.ToPath GetInAppMessages where
  toPath :: GetInAppMessages -> ByteString
toPath GetInAppMessages' {Text
endpointId :: Text
applicationId :: Text
$sel:endpointId:GetInAppMessages' :: GetInAppMessages -> Text
$sel:applicationId:GetInAppMessages' :: GetInAppMessages -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/v1/apps/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
applicationId,
        ByteString
"/endpoints/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
endpointId,
        ByteString
"/inappmessages"
      ]

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

-- | /See:/ 'newGetInAppMessagesResponse' smart constructor.
data GetInAppMessagesResponse = GetInAppMessagesResponse'
  { -- | The response's http status code.
    GetInAppMessagesResponse -> Int
httpStatus :: Prelude.Int,
    GetInAppMessagesResponse -> InAppMessagesResponse
inAppMessagesResponse :: InAppMessagesResponse
  }
  deriving (GetInAppMessagesResponse -> GetInAppMessagesResponse -> Bool
(GetInAppMessagesResponse -> GetInAppMessagesResponse -> Bool)
-> (GetInAppMessagesResponse -> GetInAppMessagesResponse -> Bool)
-> Eq GetInAppMessagesResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetInAppMessagesResponse -> GetInAppMessagesResponse -> Bool
$c/= :: GetInAppMessagesResponse -> GetInAppMessagesResponse -> Bool
== :: GetInAppMessagesResponse -> GetInAppMessagesResponse -> Bool
$c== :: GetInAppMessagesResponse -> GetInAppMessagesResponse -> Bool
Prelude.Eq, ReadPrec [GetInAppMessagesResponse]
ReadPrec GetInAppMessagesResponse
Int -> ReadS GetInAppMessagesResponse
ReadS [GetInAppMessagesResponse]
(Int -> ReadS GetInAppMessagesResponse)
-> ReadS [GetInAppMessagesResponse]
-> ReadPrec GetInAppMessagesResponse
-> ReadPrec [GetInAppMessagesResponse]
-> Read GetInAppMessagesResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetInAppMessagesResponse]
$creadListPrec :: ReadPrec [GetInAppMessagesResponse]
readPrec :: ReadPrec GetInAppMessagesResponse
$creadPrec :: ReadPrec GetInAppMessagesResponse
readList :: ReadS [GetInAppMessagesResponse]
$creadList :: ReadS [GetInAppMessagesResponse]
readsPrec :: Int -> ReadS GetInAppMessagesResponse
$creadsPrec :: Int -> ReadS GetInAppMessagesResponse
Prelude.Read, Int -> GetInAppMessagesResponse -> ShowS
[GetInAppMessagesResponse] -> ShowS
GetInAppMessagesResponse -> String
(Int -> GetInAppMessagesResponse -> ShowS)
-> (GetInAppMessagesResponse -> String)
-> ([GetInAppMessagesResponse] -> ShowS)
-> Show GetInAppMessagesResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetInAppMessagesResponse] -> ShowS
$cshowList :: [GetInAppMessagesResponse] -> ShowS
show :: GetInAppMessagesResponse -> String
$cshow :: GetInAppMessagesResponse -> String
showsPrec :: Int -> GetInAppMessagesResponse -> ShowS
$cshowsPrec :: Int -> GetInAppMessagesResponse -> ShowS
Prelude.Show, (forall x.
 GetInAppMessagesResponse -> Rep GetInAppMessagesResponse x)
-> (forall x.
    Rep GetInAppMessagesResponse x -> GetInAppMessagesResponse)
-> Generic GetInAppMessagesResponse
forall x.
Rep GetInAppMessagesResponse x -> GetInAppMessagesResponse
forall x.
GetInAppMessagesResponse -> Rep GetInAppMessagesResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetInAppMessagesResponse x -> GetInAppMessagesResponse
$cfrom :: forall x.
GetInAppMessagesResponse -> Rep GetInAppMessagesResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetInAppMessagesResponse' 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:
--
-- 'httpStatus', 'getInAppMessagesResponse_httpStatus' - The response's http status code.
--
-- 'inAppMessagesResponse', 'getInAppMessagesResponse_inAppMessagesResponse' - Undocumented member.
newGetInAppMessagesResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'inAppMessagesResponse'
  InAppMessagesResponse ->
  GetInAppMessagesResponse
newGetInAppMessagesResponse :: Int -> InAppMessagesResponse -> GetInAppMessagesResponse
newGetInAppMessagesResponse
  Int
pHttpStatus_
  InAppMessagesResponse
pInAppMessagesResponse_ =
    GetInAppMessagesResponse' :: Int -> InAppMessagesResponse -> GetInAppMessagesResponse
GetInAppMessagesResponse'
      { $sel:httpStatus:GetInAppMessagesResponse' :: Int
httpStatus =
          Int
pHttpStatus_,
        $sel:inAppMessagesResponse:GetInAppMessagesResponse' :: InAppMessagesResponse
inAppMessagesResponse = InAppMessagesResponse
pInAppMessagesResponse_
      }

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

-- | Undocumented member.
getInAppMessagesResponse_inAppMessagesResponse :: Lens.Lens' GetInAppMessagesResponse InAppMessagesResponse
getInAppMessagesResponse_inAppMessagesResponse :: (InAppMessagesResponse -> f InAppMessagesResponse)
-> GetInAppMessagesResponse -> f GetInAppMessagesResponse
getInAppMessagesResponse_inAppMessagesResponse = (GetInAppMessagesResponse -> InAppMessagesResponse)
-> (GetInAppMessagesResponse
    -> InAppMessagesResponse -> GetInAppMessagesResponse)
-> Lens
     GetInAppMessagesResponse
     GetInAppMessagesResponse
     InAppMessagesResponse
     InAppMessagesResponse
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetInAppMessagesResponse' {InAppMessagesResponse
inAppMessagesResponse :: InAppMessagesResponse
$sel:inAppMessagesResponse:GetInAppMessagesResponse' :: GetInAppMessagesResponse -> InAppMessagesResponse
inAppMessagesResponse} -> InAppMessagesResponse
inAppMessagesResponse) (\s :: GetInAppMessagesResponse
s@GetInAppMessagesResponse' {} InAppMessagesResponse
a -> GetInAppMessagesResponse
s {$sel:inAppMessagesResponse:GetInAppMessagesResponse' :: InAppMessagesResponse
inAppMessagesResponse = InAppMessagesResponse
a} :: GetInAppMessagesResponse)

instance Prelude.NFData GetInAppMessagesResponse