{-# 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.PersonalizeEvents.PutEvents
-- 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)
--
-- Records user interaction event data. For more information see
-- <https://docs.aws.amazon.com/personalize/latest/dg/recording-events.html Recording Events>.
module Amazonka.PersonalizeEvents.PutEvents
  ( -- * Creating a Request
    PutEvents (..),
    newPutEvents,

    -- * Request Lenses
    putEvents_userId,
    putEvents_trackingId,
    putEvents_sessionId,
    putEvents_eventList,

    -- * Destructuring the Response
    PutEventsResponse (..),
    newPutEventsResponse,
  )
where

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

-- | /See:/ 'newPutEvents' smart constructor.
data PutEvents = PutEvents'
  { -- | The user associated with the event.
    PutEvents -> Maybe Text
userId :: Prelude.Maybe Prelude.Text,
    -- | The tracking ID for the event. The ID is generated by a call to the
    -- <https://docs.aws.amazon.com/personalize/latest/dg/API_CreateEventTracker.html CreateEventTracker>
    -- API.
    PutEvents -> Text
trackingId :: Prelude.Text,
    -- | The session ID associated with the user\'s visit. Your application
    -- generates the sessionId when a user first visits your website or uses
    -- your application. Amazon Personalize uses the sessionId to associate
    -- events with the user before they log in. For more information, see
    -- <https://docs.aws.amazon.com/personalize/latest/dg/recording-events.html Recording Events>.
    PutEvents -> Text
sessionId :: Prelude.Text,
    -- | A list of event data from the session.
    PutEvents -> NonEmpty Event
eventList :: Prelude.NonEmpty Event
  }
  deriving (PutEvents -> PutEvents -> Bool
(PutEvents -> PutEvents -> Bool)
-> (PutEvents -> PutEvents -> Bool) -> Eq PutEvents
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutEvents -> PutEvents -> Bool
$c/= :: PutEvents -> PutEvents -> Bool
== :: PutEvents -> PutEvents -> Bool
$c== :: PutEvents -> PutEvents -> Bool
Prelude.Eq, ReadPrec [PutEvents]
ReadPrec PutEvents
Int -> ReadS PutEvents
ReadS [PutEvents]
(Int -> ReadS PutEvents)
-> ReadS [PutEvents]
-> ReadPrec PutEvents
-> ReadPrec [PutEvents]
-> Read PutEvents
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutEvents]
$creadListPrec :: ReadPrec [PutEvents]
readPrec :: ReadPrec PutEvents
$creadPrec :: ReadPrec PutEvents
readList :: ReadS [PutEvents]
$creadList :: ReadS [PutEvents]
readsPrec :: Int -> ReadS PutEvents
$creadsPrec :: Int -> ReadS PutEvents
Prelude.Read, Int -> PutEvents -> ShowS
[PutEvents] -> ShowS
PutEvents -> String
(Int -> PutEvents -> ShowS)
-> (PutEvents -> String)
-> ([PutEvents] -> ShowS)
-> Show PutEvents
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutEvents] -> ShowS
$cshowList :: [PutEvents] -> ShowS
show :: PutEvents -> String
$cshow :: PutEvents -> String
showsPrec :: Int -> PutEvents -> ShowS
$cshowsPrec :: Int -> PutEvents -> ShowS
Prelude.Show, (forall x. PutEvents -> Rep PutEvents x)
-> (forall x. Rep PutEvents x -> PutEvents) -> Generic PutEvents
forall x. Rep PutEvents x -> PutEvents
forall x. PutEvents -> Rep PutEvents x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutEvents x -> PutEvents
$cfrom :: forall x. PutEvents -> Rep PutEvents x
Prelude.Generic)

-- |
-- Create a value of 'PutEvents' 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:
--
-- 'userId', 'putEvents_userId' - The user associated with the event.
--
-- 'trackingId', 'putEvents_trackingId' - The tracking ID for the event. The ID is generated by a call to the
-- <https://docs.aws.amazon.com/personalize/latest/dg/API_CreateEventTracker.html CreateEventTracker>
-- API.
--
-- 'sessionId', 'putEvents_sessionId' - The session ID associated with the user\'s visit. Your application
-- generates the sessionId when a user first visits your website or uses
-- your application. Amazon Personalize uses the sessionId to associate
-- events with the user before they log in. For more information, see
-- <https://docs.aws.amazon.com/personalize/latest/dg/recording-events.html Recording Events>.
--
-- 'eventList', 'putEvents_eventList' - A list of event data from the session.
newPutEvents ::
  -- | 'trackingId'
  Prelude.Text ->
  -- | 'sessionId'
  Prelude.Text ->
  -- | 'eventList'
  Prelude.NonEmpty Event ->
  PutEvents
newPutEvents :: Text -> Text -> NonEmpty Event -> PutEvents
newPutEvents Text
pTrackingId_ Text
pSessionId_ NonEmpty Event
pEventList_ =
  PutEvents' :: Maybe Text -> Text -> Text -> NonEmpty Event -> PutEvents
PutEvents'
    { $sel:userId:PutEvents' :: Maybe Text
userId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:trackingId:PutEvents' :: Text
trackingId = Text
pTrackingId_,
      $sel:sessionId:PutEvents' :: Text
sessionId = Text
pSessionId_,
      $sel:eventList:PutEvents' :: NonEmpty Event
eventList = Tagged (NonEmpty Event) (Identity (NonEmpty Event))
-> Tagged (NonEmpty Event) (Identity (NonEmpty Event))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged (NonEmpty Event) (Identity (NonEmpty Event))
 -> Tagged (NonEmpty Event) (Identity (NonEmpty Event)))
-> NonEmpty Event -> NonEmpty Event
forall t b. AReview t b -> b -> t
Lens.# NonEmpty Event
pEventList_
    }

-- | The user associated with the event.
putEvents_userId :: Lens.Lens' PutEvents (Prelude.Maybe Prelude.Text)
putEvents_userId :: (Maybe Text -> f (Maybe Text)) -> PutEvents -> f PutEvents
putEvents_userId = (PutEvents -> Maybe Text)
-> (PutEvents -> Maybe Text -> PutEvents)
-> Lens PutEvents PutEvents (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutEvents' {Maybe Text
userId :: Maybe Text
$sel:userId:PutEvents' :: PutEvents -> Maybe Text
userId} -> Maybe Text
userId) (\s :: PutEvents
s@PutEvents' {} Maybe Text
a -> PutEvents
s {$sel:userId:PutEvents' :: Maybe Text
userId = Maybe Text
a} :: PutEvents)

-- | The tracking ID for the event. The ID is generated by a call to the
-- <https://docs.aws.amazon.com/personalize/latest/dg/API_CreateEventTracker.html CreateEventTracker>
-- API.
putEvents_trackingId :: Lens.Lens' PutEvents Prelude.Text
putEvents_trackingId :: (Text -> f Text) -> PutEvents -> f PutEvents
putEvents_trackingId = (PutEvents -> Text)
-> (PutEvents -> Text -> PutEvents)
-> Lens PutEvents PutEvents Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutEvents' {Text
trackingId :: Text
$sel:trackingId:PutEvents' :: PutEvents -> Text
trackingId} -> Text
trackingId) (\s :: PutEvents
s@PutEvents' {} Text
a -> PutEvents
s {$sel:trackingId:PutEvents' :: Text
trackingId = Text
a} :: PutEvents)

-- | The session ID associated with the user\'s visit. Your application
-- generates the sessionId when a user first visits your website or uses
-- your application. Amazon Personalize uses the sessionId to associate
-- events with the user before they log in. For more information, see
-- <https://docs.aws.amazon.com/personalize/latest/dg/recording-events.html Recording Events>.
putEvents_sessionId :: Lens.Lens' PutEvents Prelude.Text
putEvents_sessionId :: (Text -> f Text) -> PutEvents -> f PutEvents
putEvents_sessionId = (PutEvents -> Text)
-> (PutEvents -> Text -> PutEvents)
-> Lens PutEvents PutEvents Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutEvents' {Text
sessionId :: Text
$sel:sessionId:PutEvents' :: PutEvents -> Text
sessionId} -> Text
sessionId) (\s :: PutEvents
s@PutEvents' {} Text
a -> PutEvents
s {$sel:sessionId:PutEvents' :: Text
sessionId = Text
a} :: PutEvents)

-- | A list of event data from the session.
putEvents_eventList :: Lens.Lens' PutEvents (Prelude.NonEmpty Event)
putEvents_eventList :: (NonEmpty Event -> f (NonEmpty Event)) -> PutEvents -> f PutEvents
putEvents_eventList = (PutEvents -> NonEmpty Event)
-> (PutEvents -> NonEmpty Event -> PutEvents)
-> Lens PutEvents PutEvents (NonEmpty Event) (NonEmpty Event)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutEvents' {NonEmpty Event
eventList :: NonEmpty Event
$sel:eventList:PutEvents' :: PutEvents -> NonEmpty Event
eventList} -> NonEmpty Event
eventList) (\s :: PutEvents
s@PutEvents' {} NonEmpty Event
a -> PutEvents
s {$sel:eventList:PutEvents' :: NonEmpty Event
eventList = NonEmpty Event
a} :: PutEvents) ((NonEmpty Event -> f (NonEmpty Event))
 -> PutEvents -> f PutEvents)
-> ((NonEmpty Event -> f (NonEmpty Event))
    -> NonEmpty Event -> f (NonEmpty Event))
-> (NonEmpty Event -> f (NonEmpty Event))
-> PutEvents
-> f PutEvents
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty Event -> f (NonEmpty Event))
-> NonEmpty Event -> f (NonEmpty Event)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest PutEvents where
  type AWSResponse PutEvents = PutEventsResponse
  request :: PutEvents -> Request PutEvents
request = Service -> PutEvents -> Request PutEvents
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy PutEvents
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse PutEvents)))
response = AWSResponse PutEvents
-> Logger
-> Service
-> Proxy PutEvents
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse PutEvents)))
forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull AWSResponse PutEvents
PutEventsResponse
PutEventsResponse'

instance Prelude.Hashable PutEvents

instance Prelude.NFData PutEvents

instance Core.ToHeaders PutEvents where
  toHeaders :: PutEvents -> [Header]
toHeaders =
    [Header] -> PutEvents -> [Header]
forall a b. a -> b -> a
Prelude.const
      ( [[Header]] -> [Header]
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              HeaderName -> ByteString -> [Header]
forall a. ToHeader a => HeaderName -> a -> [Header]
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON PutEvents where
  toJSON :: PutEvents -> Value
toJSON PutEvents' {Maybe Text
NonEmpty Event
Text
eventList :: NonEmpty Event
sessionId :: Text
trackingId :: Text
userId :: Maybe Text
$sel:eventList:PutEvents' :: PutEvents -> NonEmpty Event
$sel:sessionId:PutEvents' :: PutEvents -> Text
$sel:trackingId:PutEvents' :: PutEvents -> Text
$sel:userId:PutEvents' :: PutEvents -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"userId" 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
userId,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"trackingId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
trackingId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"sessionId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
sessionId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"eventList" Text -> NonEmpty Event -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NonEmpty Event
eventList)
          ]
      )

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

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

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

-- |
-- Create a value of 'PutEventsResponse' 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.
newPutEventsResponse ::
  PutEventsResponse
newPutEventsResponse :: PutEventsResponse
newPutEventsResponse = PutEventsResponse
PutEventsResponse'

instance Prelude.NFData PutEventsResponse